[英]Literal as subject in SPARQL CONSTRUCT query
我正在努力创建正确的SPARQL查询,该查询将产生正确的格式,以便可以在Protege中打开它。 我们的本体是关于鸡尾酒的,我们希望在数据库中包含所有DBPedia鸡尾酒,包括成分( dbp:ingredients
)和配方( dbp:prep
)。 将鸡尾酒调入数据库可以正常工作,但配料和配方却不行。 我现在有以下查询:
CONSTRUCT {?drink dct:subject ?category.
?drink dbp:prep ?recipe.
?drink dbp:ingredients ?ingredients.
?drink rdf:type owl:NamedIndividual .
?category rdf:type owl:Class.
dct:subject rdf:type owl:ObjectProperty.
dbp:prep rdf:type owl:ObjectProperty.
dbp:ingredient rdf:type owl:Objectproperty.
}
WHERE {
?drink dct:subject ?category.
?drink dbp:prep ?recipe.
?drink dbp:ingredients ?ingredients.}
由于现在未声明成分和配方,因此不会在Protege的“个人”选项卡中显示。 但是,当我将其添加到查询的CONSTRUCT部分时:
?recipe rdf:type owl:NamedIndividual.
?ingredients rdf:type owl:NamedIndividual.
我收到一个错误:
Virtuoso RDF01错误CONSTRUCT中的变量值错误:“ * 5 cL伏特加* 10 cL橙汁”(标记246框标记0)不是有效的主题,只有三元组的对象可以是文字
我认为因为dbpedia的准备和成分只是一个字符串,没有链接的数据。 但是,如何使这项工作能够在Protege中显示呢?
文字不能作为RDF三元组的主题。 相反,创建配方和配料的资源+将字符串值附加为rdfs:comment
(或者可能是rdfs:label
)可能是一种解决方法。 它是这样的:
CONSTRUCT {
?drink dct:subject ?category.
?drink dbp:prep ?recipe.
?drink dbp:ingredients ?ingredients.
?drink rdf:type owl:NamedIndividual .
?category rdf:type owl:Class.
dct:subject rdf:type owl:ObjectProperty.
dbp:prep rdf:type owl:ObjectProperty.
dbp:ingredients rdf:type owl:Objectproperty.
# add string values as rdfs:comment
?recipe rdfs:comment ?recipe_str .
?ingredients rdfs:comment ?ingredients_str
}
WHERE {
?drink dct:subject ?category.
?drink dbp:prep ?recipe_str.
?drink dbp:ingredients ?ingredients_str.
BIND(URI(CONCAT("http://dbpedia.org/resource/recipe", MD5(STR(?recipe_str)))) as ?recipe)
BIND(URI(CONCAT("http://dbpedia.org/resource/ingredients", MD5(STR(?ingredients_str)))) as ?ingredients)
}
注意,如果配方(配料)已经是一种资源,它将以某种方式失败。 它不适用于DBpedia上的dbp:prep
和dbp:ingredients
,但是总的来说,如果您不确定并且有一些rdf:Property
实际上允许资源和文字,则需要正确处理,例如,通过使用IF-ELSE
构造:
BIND(IF(isLiteral(?recipe_str), URI(CONCAT("http://dbpedia.org/resource/recipe", MD5(STR(?recipe_str)))), ?recipe_str) as ?recipe)
BIND(IF(isLiteral(?ingredients_str), URI(CONCAT("http://dbpedia.org/resource/ingredients", MD5(STR(?ingredients_str)))), ?ingredients_str) as ?ingredients)
而且您还必须省略rdfs:comment
三元组,然后的确是...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.