0

My question is related to SWRL rules and actually was already asked by another user (see Ontology property definition in Protégé-OWL / SWRL). Still, after following the instructions on how to get it to work, I was not successful.

In my ontology I have to work with some complex temporal facts (related to time intervals etc.), therefore I import the Time Ontology. Before tackling the real problem, I'm consider a simple example, testing how to assign a value to a data property based on a SWRL rule. The simple example deals with a class Person. There also is a class BirthYear (subclass of the Instant class from the Time Ontology). The object property bornInYear, with domain Person and range BirthYear relates a Person with the year of his/her birth. I would like to calculate the age of the person in the current year, therefore I formulate this SWRL rule:

Person(?p) ∧ bornInYear(?p, ?birthYear) ∧ subtract(?age, 2014, ?birthYear) → age(?p, ?age)

After creating an individual of class Person and asserting that his/her BirthYear has the value "1977", I would expect Pellet to calculate that this person's age is 37. This does not happen. Any idea why? Is the SWRL rule correct? (In order to know if the value 37 is asserted to the data property age, I look at the "Property assertions" view of the individual p. I also make sure, that in the reasoner preferences the check box 'Object Property Assertions" is checked.) My example ontology reads as follows:

Prefix(SWRLexample:=<http://www.semanticweb.org/ontologies/2014/1/SWRLexample#>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(:=<http://www.semanticweb.org/ontologies/2014/1/untitled-ontology-101#>)
Prefix(time:=<http://www.w3.org/2006/time#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)


Ontology(<http://www.semanticweb.org/ontologies/2014/1/SWRLexample>
Import(<http://www.w3.org/2006/time>)

Declaration(Class(SWRLexample:BirthYear))
SubClassOf(SWRLexample:BirthYear time:Instant)
Declaration(Class(SWRLexample:Person))
Declaration(ObjectProperty(SWRLexample:bornInYear))
ObjectPropertyDomain(SWRLexample:bornInYear SWRLexample:Person)
ObjectPropertyRange(SWRLexample:bornInYear SWRLexample:BirthYear)
Declaration(DataProperty(SWRLexample:age))
AnnotationAssertion(rdfs:comment SWRLexample:age "Age of a person in years")
DataPropertyDomain(SWRLexample:age SWRLexample:Person)
DataPropertyRange(SWRLexample:age xsd:int)
Declaration(NamedIndividual(SWRLexample:birthYear1))
ClassAssertion(SWRLexample:BirthYear SWRLexample:birthYear1)
DataPropertyAssertion(time:year SWRLexample:birthYear1 "1977"^^xsd:gYear)
Declaration(NamedIndividual(SWRLexample:p1))
ClassAssertion(SWRLexample:Person SWRLexample:p1)
ObjectPropertyAssertion(SWRLexample:bornInYear SWRLexample:p1 SWRLexample:birthYear1)
DLSafeRule(Body(ClassAtom(SWRLexample:Person Variable(<urn:swrl#p>)) ObjectPropertyAtom(SWRLexample:bornInYear Variable(<urn:swrl#p>) Variable(<urn:swrl#birthYear>)) BuiltInAtom(swrlb:subtract Variable(<urn:swrl#age>) "2014"^^xsd:integer Variable(<urn:swrl#birthYear>)))Head(DataPropertyAtom(SWRLexample:age Variable(<urn:swrl#p>) Variable(<urn:swrl#age>))))
)
Community
  • 1
  • 1
Sabina
  • 306
  • 1
  • 4
  • 6
  • Actually, I just noticed, that Pellet produces the following error message: Feb 11, 2014 1:43:45 PM com.clarkparsia.pellet.rules.BindingGeneratorStrategyImp l createGenerator Warnung: IGNORING RULE Rule([Person(?p), bornInYear(?p,?birthYear), subtract([?age, "2014"^^integer, ?birthYear])] => [age(?p,?age)]): Could not generate safe ordering for body constraints. Pellet classified in 280ms – Sabina Feb 11 '14 at 12:48

2 Answers2

0

There are a few problems (but I'm glad that that other answer was a useful starting point):

  • age is a data property, so you not only need to make sure that "the check box 'Object Property Assertions' is checked," but also 'Data Property Assertions', since it's a datatype assertion that you're looking for.

  • BornInYear is an object property, so ?birthYear in bornInYear(?p, ?birthYear) must be an individual. However, swrlb:subtract's arguments must be numeric literals. To use swrlb:subtract, you'll need to get the integer value of the year in the rule and perform the arithmetic on that. You should be able to do that without too much trouble, although I'm not sure if you'll still be able to use the value "1977"^^xsd:gYear. SWRL does define some functions working with dates and times, though (see 8.5. Built-Ins for Date, Time and Duration). Not all the reasoners support that, though (e.g., I don't think Pellet does). However, the value of the year property does need to be an xsd:gYear.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thank you Joshua, of course you are right. It is a data property, and I checked the "data property assertions " check box. Just did confuse the terminology in my post. Your second point about the arguments of the substract SWRL built in, might be the solution to my problem. I am going to look into this now! Thanks – Sabina Feb 11 '14 at 13:09
  • @Sabina I've been looking into to it too, I think you'll be able to you use the date arithmetic functions (if you use a reasoner that supports them), but you'll need to figure out how to construct the date or time objects within the SWRL rules; I don't think you'll just be able to use the gYears. – Joshua Taylor Feb 11 '14 at 13:18
  • @ Joshua Pellet supports some of the dateTime related SWRL built ins (http://clarkparsia.com/pellet/faq/rules ). And that's why I resorted to the time ontology, because working with simple int values and the supported SWRL seems not expressive enough. E.g. when I need to state in my use case, that the warranty time is 2 years, starting from the date of purchase of an item. If there was something like casting a gYear to an int, this would help, I think for my current problem. – Sabina Feb 11 '14 at 13:24
  • @Sabina. Pellet supports the five that allow you to construct from components, or extract components from, durations, dates, times, and datetimes. Depending on what kinds the components are that you can extract, you might be able to get the numbers you want if you've used dates or datetimes in other places. – Joshua Taylor Feb 11 '14 at 13:37
0

Here are the successive steps :

  • Go to metadata tab
  • Import temporal ontology, prefix it as temporal.
  • Go to SWRL tab

Write rule as follows :

Person(?x) ^ hasDOB(?x, ?dob) ^ temporal:duration(?age, "now", ?dob, temporal:Years) -> hasAge(?x,  ?age)

where Person is a class hasDOB,hasAge are object properties

Gilles-Antoine Nys
  • 1,481
  • 16
  • 21
ranjna
  • 1
  • 1
    Please take a second to [format you answer](http://stackoverflow.com/help/formatting)! – leo Aug 08 '14 at 10:41