Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_datatype? returns false when datatype is XMLSchema#string #396

Closed
elrayle opened this issue May 10, 2019 · 3 comments
Closed

has_datatype? returns false when datatype is XMLSchema#string #396

elrayle opened this issue May 10, 2019 · 3 comments

Comments

@elrayle
Copy link

elrayle commented May 10, 2019

Description

I want to apply ldpath rules that limit returned results to objects with type xsd:string. But I am not able to create a graph with literals that have datatype xsd:string that will return true for datatype?.

The check I want to use is...

type = RDF::URI.new('http://www.w3.org/2001/XMLSchema#string')
rdf_literal if rdf_literal.has_datatype? && rdf_literal.datatype == type

There are multiple literals that have datatype http://www.w3.org/2001/XMLSchema#string, but none match because in all cases rdf_literal.has_datatype? returns false.

Examples

Numeric is auto-assigned a datatype.

>> y = RDF::Literal.new(2)
#<RDF::Literal::Integer:0x3fc1ae1605d0("2"^^<http://www.w3.org/2001/XMLSchema#integer>)>
>> y.has_datatype?
true
>> y.datatype
#<RDF::URI:0x3fc1ab871944 URI:http://www.w3.org/2001/XMLSchema#integer>

String is not auto-assigned a datatype... sort of?

>> x = RDF::Literal.new('hello world')
#<RDF::Literal:0x3fc1ae171484("hello world")>
>> x.has_datatype?
false
>> x.datatype
#<RDF::URI:0x3fc1ae1713a8 URI:http://www.w3.org/2001/XMLSchema#string>

Cannot explicitly assign a datatype by setting a language.

>> value = RDF::Literal.new("Hello!", language: :en)
#<RDF::Literal:0x3fc1ae148d2c("Hello!"@en)>
>> value.has_datatype?
false
>>value.datatype
#<RDF::Vocabulary::Term:0x3fc1aac306bc ID:http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>

Cannot explicitly assign a datatype to a string literal.

>> value = RDF::Literal.new("hello world", datatype: RDF::XSD.string)
#<RDF::Literal:0x3fc1ae1314b0("hello world")>
>> value.has_datatype?
false
>> value.datatype
#<RDF::Vocabulary::Term:0x3fc1aad352d8 ID:http://www.w3.org/2001/XMLSchema#string>
@elrayle
Copy link
Author

elrayle commented May 10, 2019

https://github.com/ruby-rdf/rdf/blob/develop/lib/rdf/model/literal.rb#L342-L351

States that strings are excluded for historical reasons. Can someone elaborate?

@gkellogg
Copy link
Member

The notion that a literal with datatype xsd:string somewhat predates RDF 1.1, and there are a number of different gems that look to see if a literal has a datatype. With RDF 1.1 all literals have a datatype, so xsd:string is treated as if there is no datatype, same with rdf:langString. Otherwise, it's not useful to ask if a literal has a datatype.

As you note, "foo" and "foo"^^xsd:string are equivalent, which was decided as part of RDF 1.1. There is no way create a literal without a datatype anymore.

In RDF 1.0, and normatively, but not practically, in SPARQL 1.1, "foo" and "foo"^^xsd:string are different terms, but with RDF 1.1, pretty much all processors now treat them as being the same term. The datatype rdf:langString was created to ensure that all literals have a datatype.

Much 1.0 code that looked to distinguish between datatyped literals, and literals with no datatype with or without a language would make use of this. And, serializations of literals datatype xsd:string or rdf:langString will omit the datatype during serialization. The Changes since RDF 1.0 document may be useful in seeing these differences.

@no-reply
Copy link
Member

no-reply commented Oct 12, 2019

proposing to close with no changes, per @gkellogg's comment.

the main alternative seems to be to deprecate and remove has_datatype?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants