我的烹饪食谱本体论中有两个课程:
<Class rdf:about="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes">
<equivalentClass>
<Restriction>
<onProperty rdf:resource="&SouthSulawesiCulinaryRecipes;NumberOfIngredientsRequired"/>
<minQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</minQualifiedCardinality>
<onDataRange rdf:resource="&xsd;int"/>
</Restriction>
</equivalentClass>
<equivalentClass>
<Restriction>
<onProperty rdf:resource="&SouthSulawesiCulinaryRecipes;UsesTools"/>
<onClass rdf:resource="&SouthSulawesiCulinaryRecipes;KitchenEquipment"/>
<minQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</minQualifiedCardinality>
</Restriction>
</equivalentClass>
</Class>
<Class rdf:about="&SouthSulawesiCulinaryRecipes;Place"/>
这是对象属性:
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#HasIngredients -->
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeverages"/>
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;_IngR"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#HasRecipe -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;HasRecipe">
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes"/>
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;Place"/>
<rdfs:subPropertyOf rdf:resource="&owl;topObjectProperty"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#IngR -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;IngR">
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes"/>
<inverseOf rdf:resource="&SouthSulawesiCulinaryRecipes;Relation_Of"/>
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;_IngR"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#Ing_Type -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;Ing_Type">
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;IngType"/>
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;_IngR"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#IngredientUsedToMake -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;IngredientUsedToMake">
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeverages"/>
<inverseOf rdf:resource="&SouthSulawesiCulinaryRecipes;HasIngredients"/>
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;_IngR"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#MeasurementUnit -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;MeasurementUnit">
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;CookingMeasurements"/>
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;_IngR"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#RecipeOrigin -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;RecipeOrigin">
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes"/>
<inverseOf rdf:resource="&SouthSulawesiCulinaryRecipes;HasRecipe"/>
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;Place"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#Relation_Of -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;Relation_Of">
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes"/>
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;_IngR"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#ToolsUsedByRecipe -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;ToolsUsedByRecipe">
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes"/>
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;KitchenEquipment"/>
<inverseOf rdf:resource="&SouthSulawesiCulinaryRecipes;UsesTools"/>
</ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2014/4/SouthSulawesiCulinaryRecipes#UsesTools -->
<ObjectProperty rdf:about="&SouthSulawesiCulinaryRecipes;UsesTools">
<rdfs:domain rdf:resource="&SouthSulawesiCulinaryRecipes;FoodAndBeveragesRecipes"/>
<rdfs:range rdf:resource="&SouthSulawesiCulinaryRecipes;KitchenEquipment"/>
</ObjectProperty> here
首先,我有这个查询来获取我的本体中的所有食谱
SELECT ?FoodAndBeveragesRecipes
WHERE {
?Place :HasRecipe ?FoodAndBeveragesRecipes
}
结果是:
CotoMakassar
再见
EsPisangIjo
PalluMata
DanpoGoreng
DanpoRebus
SambalMangga
现在我正在尝试运行此查询以获取配方名称为“Danpo”的所有数据集(我不知道是否还有其他代码比这个更简单,如果您知道也请告诉我):< / p>
SELECT ?FoodAndBeveragesRecipes
WHERE {
?Place :HasRecipe ?FoodAndBeveragesRecipes .
FILTER regex (?FoodAndBeveragesRecipes ,"Danpo", "i")
}
查询正在运行,但它是空的,我没有得到我的数据,我认为没有错误。 我想知道为什么我的过滤器工作不正常?如何在我的正则表达式中获取与我的关键字完全相同的数据集? 有人能帮助我吗?
感谢。
答案 0 :(得分:2)
我很确定这是Extract triples containing particular substring using SPARQL的副本,我已将其标记为此类,但这也可能有助于提供更多解释。 hasRecipe 属性是对象属性。这意味着它的对象应该是个体,这意味着它们将成为IRI。 正则表达式函数需要一个字符串作为参数。如果要将正则表达式与IRI文本进行匹配,则需要使用 str 函数:
FILTER regex (str(?FoodAndBeveragesRecipes) ,"Danpo", "i")
也就是说,如果您只想检查它是否包含字符串,并且您使用的是SPARQL 1.1,则可以使用contains:
filter contains(str(?FoodAndBeveragesRecipes), "Danpo")