Using Python rdflib: how to include literals in sparql queries?

后端 未结 1 648
萌比男神i
萌比男神i 2021-02-09 17:34

I can include URIs and variables in my queries, but I can\'t include literals in my queries.

Here, I have some code which successfully reads an RDF file, finds all the

1条回答
  •  别那么骄傲
    2021-02-09 18:01

    If the literals in your data have datatypes, or are strings with language tags, then a plain literal, that is, one without a datatype or language tag, injected into the query won't match.

    The RDFLib docs on Literals show ways of creating literals with datatypes, but don't have an example of creating one with a language tag. However, the docs also have the source attached and the signature for Literal's __new__ is:

    static __new__(lexical_or_value, lang=None, datatype=None, normalize=None)
    

    Since the literal in your data has a language tag ('en'), you should to create your literal as

    o = rdflib.Literal(u'Jackkifing',lang='en')
    

    so that the language tag is associated with the literal.

    0 讨论(0)
提交回复
热议问题