@@ -170,8 +170,7 @@ def initialize(value, language: nil, datatype: nil, lexical: nil, validate: fals
170170 @language = language . to_s . downcase . to_sym if language
171171 @datatype = RDF ::URI ( datatype ) . freeze if datatype
172172 @datatype ||= self . class . const_get ( :DATATYPE ) if self . class . const_defined? ( :DATATYPE )
173- @datatype ||= @language ? RDF . langString : RDF ::XSD . string
174- raise ArgumentError , "datatype of rdf:langString requires a language" if !@language && @datatype == RDF ::langString
173+ @datatype ||= @language ? RDF . langString : RDF ::URI ( "http://www.w3.org/2001/XMLSchema#string" )
175174 end
176175
177176 ##
@@ -226,8 +225,8 @@ def compatible?(other)
226225 # * The arguments are plain literals with identical language tags
227226 # * The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
228227 has_language? ?
229- ( language == other . language || other . datatype == RDF ::XSD . string ) :
230- other . datatype == RDF ::XSD . string
228+ ( language == other . language || other . datatype == RDF ::URI ( "http://www.w3.org/2001/XMLSchema# string" ) ) :
229+ other . datatype == RDF ::URI ( "http://www.w3.org/2001/XMLSchema# string" )
231230 end
232231
233232 ##
@@ -317,7 +316,7 @@ def ==(other)
317316 # @return [Boolean] `true` or `false`
318317 # @see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
319318 def plain?
320- [ RDF . langString , RDF ::XSD . string ] . include? ( datatype )
319+ [ RDF . langString , RDF ::URI ( "http://www.w3.org/2001/XMLSchema# string" ) ] . include? ( datatype )
321320 end
322321
323322 ##
@@ -327,7 +326,7 @@ def plain?
327326 # @return [Boolean] `true` or `false`
328327 # @see http://www.w3.org/TR/sparql11-query/#simple_literal
329328 def simple?
330- datatype == RDF ::XSD . string
329+ datatype == RDF ::URI ( "http://www.w3.org/2001/XMLSchema# string" )
331330 end
332331
333332 ##
@@ -361,6 +360,8 @@ def has_datatype?
361360 # @return [Boolean] `true` or `false`
362361 # @since 0.2.1
363362 def valid?
363+ return false if language? && language . to_s !~ /^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/
364+ return false if datatype? && datatype . invalid?
364365 grammar = self . class . const_get ( :GRAMMAR ) rescue nil
365366 grammar . nil? || !!( value =~ grammar )
366367 end
@@ -487,15 +488,15 @@ def inspect
487488 def method_missing ( name , *args )
488489 case name
489490 when :to_str
490- return to_s if @datatype == RDF . langString || @datatype == RDF ::XSD . string
491+ return to_s if @datatype == RDF . langString || @datatype == RDF ::URI ( "http://www.w3.org/2001/XMLSchema# string" )
491492 end
492493 super
493494 end
494495
495496 def respond_to_missing? ( name , include_private = false )
496497 case name
497498 when :to_str
498- return true if @datatype == RDF . langString || @datatype == RDF ::XSD . string
499+ return true if @datatype == RDF . langString || @datatype == RDF ::URI ( "http://www.w3.org/2001/XMLSchema# string" )
499500 end
500501 super
501502 end
0 commit comments