@@ -1467,8 +1467,6 @@ def compact_iri(iri, base: nil, reverse: false, value: nil, vocab: nil)
14671467 end
14681468 end
14691469
1470- RDF_LITERAL_NATIVE_TYPES = Set . new ( [ RDF ::XSD . boolean , RDF ::XSD . integer , RDF ::XSD . double ] ) . freeze
1471-
14721470 ##
14731471 # If active property has a type mapping in the active context set to @id or @vocab, a JSON object with a single member @id whose value is the result of using the IRI Expansion algorithm on value is returned.
14741472 #
@@ -1500,50 +1498,12 @@ def expand_value(property, value, useNativeTypes: false, rdfDirection: nil, base
15001498 return { '@id' => expand_iri ( value , vocab : true , documentRelative : true , base : base ) . to_s }
15011499 end
15021500
1503- value = RDF ::Literal ( value ) if
1504- value . is_a? ( Date ) ||
1505- value . is_a? ( DateTime ) ||
1506- value . is_a? ( Time )
1507-
15081501 result = case value
15091502 when RDF ::URI , RDF ::Node
15101503 { '@id' => value . to_s }
1511- when RDF ::Literal
1512- res = { }
1513- if value . datatype == RDF ::URI ( RDF . to_uri + "JSON" ) && processingMode ( 'json-ld-1.1' )
1514- # Value parsed as JSON
1515- # FIXME: MultiJson
1516- res [ '@type' ] = '@json'
1517- res [ '@value' ] = ::JSON . parse ( value . object )
1518- elsif value . datatype . start_with? ( "https://www.w3.org/ns/i18n#" ) && rdfDirection == 'i18n-datatype' && processingMode ( 'json-ld-1.1' )
1519- lang , dir = value . datatype . fragment . split ( '_' )
1520- res [ '@value' ] = value . to_s
1521- unless lang . empty?
1522- if lang !~ /^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/
1523- if options [ :validate ]
1524- raise JsonLdError ::InvalidLanguageMapping , "rdf:language must be valid BCP47: #{ lang . inspect } "
1525- else
1526- warn "rdf:language must be valid BCP47: #{ lang . inspect } "
1527- end
1528- end
1529- res [ '@language' ] = lang
1530- end
1531- res [ '@direction' ] = dir
1532- elsif useNativeTypes && RDF_LITERAL_NATIVE_TYPES . include? ( value . datatype ) && value . valid?
1533- res [ '@type' ] = uri ( coerce ( property ) ) if coerce ( property )
1534- res [ '@value' ] = value . object
1535- else
1536- value . canonicalize! if value . valid? && value . datatype == RDF ::XSD . double
1537- if coerce ( property )
1538- res [ '@type' ] = uri ( coerce ( property ) ) . to_s
1539- elsif value . datatype?
1540- res [ '@type' ] = uri ( value . datatype ) . to_s
1541- elsif value . language? || language ( property )
1542- res [ '@language' ] = ( value . language || language ( property ) ) . to_s
1543- end
1544- res [ '@value' ] = value . to_s
1545- end
1546- res
1504+ when Date , DateTime , Time
1505+ lit = RDF ::Literal . new ( value )
1506+ { '@value' => lit . to_s , '@type' => lit . datatype . to_s }
15471507 else
15481508 # Otherwise, initialize result to a JSON object with an @value member whose value is set to value.
15491509 res = { }
@@ -1561,8 +1521,6 @@ def expand_value(property, value, useNativeTypes: false, rdfDirection: nil, base
15611521 end
15621522
15631523 result
1564- rescue ::JSON ::ParserError => e
1565- raise JSON ::LD ::JsonLdError ::InvalidJsonLiteral , e . message
15661524 end
15671525
15681526 ##
0 commit comments