2

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

Saraba

EsPisangIjo

PalluMata

DanpoGoreng

DanpoRebus

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) :

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?

Thanks.

Community
  • 1
  • 1
Jeje
  • 35
  • 4

1 Answers1

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:

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:

filter contains(str(?FoodAndBeveragesRecipes), "Danpo")
Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • it's working, it feels so good, thanks a lot :) actually i want to match the regular expression against the text of the IRI, so i will use the regex funciton. – Jeje Mar 30 '16 at 16:50
  • @Jeje OK, I wasn't sure, since there's actually no regular expression in your example (it's just matching a string). If you just want to check case insensitively, you can check whether **contains(lcase(str(?FoodAndBeveragesRecipres)), "danpo")**. That might be less expensive than a **regex**. – Joshua Taylor Mar 30 '16 at 17:10
  • ok, i take your advice. im sorry im new in sparql query, could you please explain to me when and why i should use contains instead regex? and what do you mean "there's actually no regular expression in your example? i thought it was the regex? or should i make a new question? thanks – Jeje Mar 30 '16 at 23:35
  • @jeje there **is** a regex in your query, but it's not a very complicated one. It's just checking for a single string, case insensitively. Regular expressions can find much more complicated things, like repetitions or alternatives. E.g., "a[bc]?" matches a, ab, and ac. Checking simple string containment doesn't require all the power of regular expressions. I was just suggesting that you use the simplest tool that works, which in this case would be **contains**. – Joshua Taylor Mar 31 '16 at 00:01
  • i'm trying to match and find exact value using REGEX boundary. this is SPARQL query `+ "FILTER regex(str(?FoodAndBeverages), \"\\b" + recipe + "\\b\")}"`. I'm running the same SPARQL query on protege too. When i perform the query, Jena returns an empty set (not even null pointer exception) while Protégé return/find the correct results. I don't know if the problem is with the REGEX code or what. I was wondering why my REGEX is not working correctly ? could you help me? [http://stackoverflow.com/questions/38601796/sparql-query-regex-boundary-in-java-returns-empty] – Jeje Jul 27 '16 at 13:42