The "SWI-Prolog Semantic Web Library 3.0" allows you to easily assert and query an RDF triple like this:
- rdf_assert(number, is, 1).
true.
?- rdf(number, is, X).
X = 1^^'http://www.w3.org/2001/XMLSchema#integer'.
How can you convert X from the "type qualified literal" format (described here) to a standard Prolog atom: X = 1?
I found xsdp_convert/3 but it needs the type ('http://www.w3.org/2001/XMLSchema#integer'
) and the value (1
) passed in as separate arguments. How do I break apart the "type qualified literal" (1^^'http://www.w3.org/2001/XMLSchema#integer'
) to do this?
Or better yet: does that value^^type
format actually mean something in Prolog and allow for a more elegant way to do it?
You can use unification, decompose the compound term that you get, or access its arguments:
?- use_module(library(semweb/rdf11)).
true.
?- rdf_assert(number, is, 1).
true.
?- rdf(number, is, N^^URI).
N = 1,
URI = 'http://www.w3.org/2001/XMLSchema#integer'.
?- rdf(number, is, X), X =.. List.
X = 1^^'http://www.w3.org/2001/XMLSchema#integer',
List = [^^, 1, 'http://www.w3.org/2001/XMLSchema#integer'].
?- rdf(number, is, X), arg(1, X, N).
X = 1^^'http://www.w3.org/2001/XMLSchema#integer',
N = 1.