1

I'm working on a validator that validates turtle files. When working on a function to check if the cardinality that's stated is correct for each object, I can't figure out how to access the value of a literal.

The literal value is Card=literal(type(xsd:nonNegativeInteger, '1')) (or 1^^'http://www.w3.org/2001/XMLSchema#nonNegativeInteger').

I find a bag of properties of length L. How can I check that L == Card?

I already tried the following:

% L and Card are both 1
rdf_canonical_literal(L, LiteralL), rdf_compare(=, LiteralL, Card).
% false

rdf_canonical_literal(L, LiteralL).
% LiteralL = 1^^'http://www.w3.org/2001/XMLSchema#integer'.

The problem is that xsd:integer and xsd:nonNegativeInteger don't compare as equal.

However, the easiest thing to me would seem to get the value of Card but I really don't see how to do it. Any solutions or pointers where to find an example of this would be much appreciated!!

MacHeath
  • 108
  • 7
  • Solved it eventually. You can make good use of Prolog unification to get the value from the literal. `parse_literal(Lit, N) :- Lit = N^^_Type.` Am still open to better / other approaches. – MacHeath Apr 27 '17 at 22:02

1 Answers1

1

If you use library rdf11 then most common datatype IRIs are automatically interpreted as Prolog values. In other words: there is no need to convert from RDF literals to Prolog values at all. Example:

?- [library(semweb/rdf11)].
?- rdf_assert(rdf:a, rdf:b, 1^^xsd:int).
?- rdf(_S, _P, N^^xsd:int).
N = 1.

You can extend library rdf11 with a hook for less common datatype IRIs, e.g., I use a lot of geographic data (datatype IRI geo:wktLiteral) which I let rdf/[3,4] interpret as Prolog Well-Known Text (WKT) notation automatically.

Wouter Beek
  • 3,307
  • 16
  • 29