SPARQL REGEX正在运行,但没有显示任何内容[重复]

时间:2022-09-16 18:05:26

This question already has an answer here:

这个问题已经有了答案:

I have two Class in my culinary recipe ontology :

我的烹饪本体论有两堂课:

<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"/>

This is the Object Properties :

这是对象属性:

<!-- 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

At first, i have this query to get all recipe in my ontology

首先,我有这个查询来获取我的本体中的所有配方

SELECT   ?FoodAndBeveragesRecipes
   WHERE {
         ?Place :HasRecipe ?FoodAndBeveragesRecipes 
    }

The result is :

其结果是:

CotoMakassar

CotoMakassar

Saraba

Saraba

EsPisangIjo

EsPisangIjo

PalluMata

PalluMata

DanpoGoreng

DanpoGoreng

DanpoRebus

DanpoRebus

SambalMangga

SambalMangga

and now i am trying to run this query in order to get all datasets with the recipe name "Danpo" (i dont know if there are other code more simple than this one, if you know please tell me too) :

现在我正在尝试运行这个查询,以获取所有具有“Danpo”菜谱名称的数据集(我不知道是否还有其他代码比这个更简单,如果您知道请告诉我):

SELECT   ?FoodAndBeveragesRecipes
   WHERE {
         ?Place :HasRecipe ?FoodAndBeveragesRecipes .
        FILTER regex (?FoodAndBeveragesRecipes ,"Danpo", "i")
    }

The query is running but it’s empty, i don't get my data and i think nothing error. I was wondering why my filter is not working correctly ? and what should I do to get the datasets with the exact of my keyword in my regex? Can someone help me?

查询正在运行,但它是空的,我没有得到我的数据,我认为没有错误。我想知道为什么我的过滤器不能正常工作?在regex中,我应该怎样做才能得到与我的关键字相符的数据集呢?有人能帮助我吗?

Thanks.

谢谢。

1 个解决方案

#1


2  

I'm pretty sure that this is a duplicate of Extract triples containing particular substring using SPARQL, and I've marked it as such, but it might help to provide a little bit more explanation here, too. The hasRecipe property is an object property. That means that its objects should be individuals, which means that they'll be IRIs. The regex function requires a string as an argument. If you want to match the regular expression against the text of the IRI, you'll need to use the str function:

我很确定,这是一个使用SPARQL包含特定子字符串的提取三元组的副本,我已经标记了它,但是在这里也可以提供更多的解释。hasRecipe属性是一个对象属性。这意味着它的对象应该是个体,也就是说它们将是虹膜。regex函数需要一个字符串作为参数。如果要将正则表达式与IRI文本匹配,需要使用str函数:

FILTER regex (str(?FoodAndBeveragesRecipes) ,"Danpo", "i")

That said, if you just want to check whether it contains a string, and if you're using SPARQL 1.1, you can use contains:

也就是说,如果您只想检查它是否包含一个字符串,如果您使用SPARQL 1.1,您可以使用contains:

filter contains(str(?FoodAndBeveragesRecipes), "Danpo")

#1


2  

I'm pretty sure that this is a duplicate of Extract triples containing particular substring using SPARQL, and I've marked it as such, but it might help to provide a little bit more explanation here, too. The hasRecipe property is an object property. That means that its objects should be individuals, which means that they'll be IRIs. The regex function requires a string as an argument. If you want to match the regular expression against the text of the IRI, you'll need to use the str function:

我很确定,这是一个使用SPARQL包含特定子字符串的提取三元组的副本,我已经标记了它,但是在这里也可以提供更多的解释。hasRecipe属性是一个对象属性。这意味着它的对象应该是个体,也就是说它们将是虹膜。regex函数需要一个字符串作为参数。如果要将正则表达式与IRI文本匹配,需要使用str函数:

FILTER regex (str(?FoodAndBeveragesRecipes) ,"Danpo", "i")

That said, if you just want to check whether it contains a string, and if you're using SPARQL 1.1, you can use contains:

也就是说,如果您只想检查它是否包含一个字符串,如果您使用SPARQL 1.1,您可以使用contains:

filter contains(str(?FoodAndBeveragesRecipes), "Danpo")