Rules are not working?

I have made an example of ontology, data and SWRL rule. But it is not working.
Can anyone send me example of SWRL rules ?

Hi Hassan,

Welcome to Stardog Community! This PDF has plenty of examples of SWRL rules. Is this enough to get you started?

Best,
Steve

hi,
how can i share my files with you and get help ?

I already build an example and want to know why it is not working?

thanks for advice

concepts and data.txt (3.1 KB)
rule3.ttl (689 Bytes)
sparql_query.txt (258 Bytes)

I have ontology and data in the concepts and data.txt, as I was not able to upload .owl file here.
I have swrl rule in rule3.ttl file and the sparql query to get apply rule Adult. but it is not working. Can someone see this issue in studio and help me to apply rule on data please
your help will be appreciated.

Hi Hassan,

there is an invalid triple pattern in the head of your rule: if you bind a UUID() to ?myInstance, it cannot be in subject position of a triple pattern because it is not a valid IRI. Also there are some minor issues in the rule. Instead, I think your rule should look something like this (not tested):

[] a rule:SPARQLRule ;
rule:content """
PREFIX reasoning: <http://www.semanticweb.org/stardog/reasoning#>
IF {
  ?indiv a reasoning:Person .
  ?indiv reasoning:age ?age .
  FILTER (?age >= 18) .
}
THEN {
  ?indiv a reasoning:Adult .
 }""" . 

You can also always check whether your rules are correct and infer the desired triples by running a simple construct query with the body of the rule in the WHERE-clause and the head of the rule in the CONSTRUCT pattern.
For example:

CONSTRUCT { ?indiv a reasoning:Adult .  }
WHERE {
  ?indiv a reasoning:Person .
  ?indiv reasoning:age ?age .
  FILTER (?age >= 18) 
}

If that query, returns the desired triple, the body and head of the rule are correct.

I hope, this helps you to get started.

Best regards
Lars

family.ttl (695 Bytes)
Thanks for your reply and it worked fine.

As I have many many rules so visual designer is helpful.

Now I have created rules in designer visually, when exported the familly.ttl has the rules and concepts.
Can you tell me what should be the sparql query now? I am writing the following but not able to get result.

prefix reasoning:http://www.semanticweb.org/stardog/reasoning#
SELECT DISTINCT ?indiv WHERE {
?indiv a reasoning:child.
}

OR SELECT DISTINCT ?indiv WHERE {
?indiv rdf:type ? reasoning:child.
}

Both ways it has not worked.

Hi,

first, when you want to query your data with reasoning, make sure that reasoning is enabled when you execute the query (e.g., using the toggle in Studio). Second, make sure that the classes in your data/model and query align: In your query, you are querying for instances of type <http://www.semanticweb.org/stardog/reasoning#child> while in the file you provided it uses the a different IRI for the child class, <tag:stardog:designer:Friend:model:child>. Again, as a test you can use a simple query to check which classes are actually in your data:

SELECT DISTINCT ?class
{
   ?x a ?class .
}

Lastly, make sure your queries are syntactically correct: In you second example query, there is an unnecessary ? .

Best regards
Lars