3.1 library(semweb/rdf11): The RDF database
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog Semantic Web Library 3.0
        • Two RDF APIs
          • library(semweb/rdf11): The RDF database
            • Query the RDF database
            • Enumerating and testing objects
            • RDF literals
              • rdf_canonical_literal/2
              • rdf_lexical_form/2
              • rdf_compare/3
            • Accessing RDF graphs
            • Modifying the RDF store
            • Accessing RDF collections

3.1.3 RDF literals

[det]rdf_canonical_literal(++In, -Literal)
Transform a relaxed literal specification as allowed for rdf_assert/3 into its canonical form. The following Prolog terms are translated:
Prolog Term Datatype IRI
floatxsd:double
integerxsd:integer
stringxsd:string
true or false xsd:boolean
date(Y,M,D) xsd:date
date_time(Y,M,D,HH,MM,SS) xsd:dateTime
date_time(Y,M,D,HH,MM,SS,TZ) xsd:dateTime
month_day(M,D) xsd:gMonthDay
year_month(Y,M) xsd:gYearMonth
time(HH,MM,SS) xsd:time

For example:

?- rdf_canonical_literal(42, X).
X = 42^^'http://www.w3.org/2001/XMLSchema#integer'.
[det]rdf_lexical_form(++Literal, -Lexical:compound)
True when Lexical is the lexical form for the literal Literal. Lexical is of one of the forms below. The ntriples serialization is obtained by transforming String into a proper ntriples string using double quotes and escaping where needed and turning Type into a proper IRI reference.

  • String^^Type
  • String@Lang
[det]rdf_compare(-Diff, +Left, +Right)
True if the RDF terms Left and Right are ordered according to the comparison operator Diff. The ordering is defines as:

  • Literal < BNode < IRI
  • For literals

    • Numeric < non-numeric
    • Numeric literals are ordered by value. If both are equal, floats are ordered before integers.
    • Other data types are ordered lexicographically.

  • BNodes and IRIs are ordered lexicographically.

Note that this ordering is a complete ordering of RDF terms that is consistent with the partial ordering defined by SPARQL.

Diff is one of <, = or >