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

后端 未结 1 1331
鱼传尺愫
鱼传尺愫 2021-02-09 17:26

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 17:52

    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)
提交回复
热议问题