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

时间秒杀一切 提交于 2019-12-03 09:06:17

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!