Infer a data property using a object property - owl

I have an ontology with the Object Property "married with" and a data property "has num child".
Does exists a way (in protege) to infer how many child has Bob given the assertion that Bob is married with Mary and Mary has 1 child?
Or i have to insert manually the data property has num child to Bob?

Related

GAE: How to access a property value from within #classmethod

How can we access a property value within a #classmethod? For example:
class Account(polymodel.PolyModel):
someprop = ndb.StringProperty(required=True)
​
#classmethod
def get_or_create_someprop(cls):
if not cls.someprop:
# create someprop
else:
return cls.someprop
In this example code above, I am trying create someprop if it doesn’t exist, or return it if it already exists. I assumed that the above code would achieve this. However, the first step I need to do is access the someprop value from within the classmethod. Using cls.someprop does not actually return the value of someprop but instead returns StringProperty('state').
I have tried to use this and self which are undefined.
So, is it possible to access a property value of an entity using a classmethod? If so, how?
In general you cannot do this from a class method because a property belongs to an object, i.e. an instance of the class (the class is just the object generator). In other words you need the self argument to refer to the object and its properties.
In your particular case the class is an entity model (the blueprint for creating entities), not an entity and you can only refer to a property of an entity itself.
But you should be able to achieve what you seek simply by not declaring it a class method - then it becomes a method of the object/entity and in that case you can reference the entity's property via self instead of cls: self.someprop.
I'd make the check a bit more specific, though, to cover the case in which the property has a value like 0 or an empty string which is interpreted by python as False in a logical check: if self.someprop is None instead of if not self.someprop.

OWL axiom: Given an individual of a particular class, enforce an existence of an Object Property relation with another individual

In OWL, is there a way to state that an individual of a particular class must be related to another individual via a specific object property?
For example, I would like to state that:
forall(x) Object(x) -> exists(y) Shape(y) ^ hasShape(x, y)
i.e., "For all objects, there exists a shape that is the shape of the object."
so that if there is an individual of the type Object that has no shape associated with it, a reasoner would find it to be inconsistent.
I tried an axiom:
Object SubClassOf hasShape min 1 Shape
but it's not working.
It seems like the issue is because Object Property in OWL has no identity, but is there a workaround for this issue?
(I'm using Protege 5.2.0)
You are correct that the meaning of Object SubClassOf hasShape min 1 Shape is that every individual of Object is associated with an individual of Shape via the hasShape property.
So if you create an individual x of type Object without x being associated with an individual of Shape, why does the reasoner not determine that your ontology is inconsistent? The reason for this is due to the open world assumption. Informally it means that the only inferences that the reasoner can make from an ontology is based on explicit information stated in the ontology or what can derived from explicit stated information.
When you state x is an Object, there is no explicit information in the ontology that states that x is not associated with an individual of Shape via the hasShape property. To make explicit that x is not is such a relation, you have to define x as follows:
Individual: x
Types:
Object,
hasShape max 0 owl:Thing
Btw, this problem has nothing to do with identity as you stated.
One solution I found was to make the ontology "closed world", by making owl:Thing equivalent to the set of all individuals defined so far.

similar syntax to represent xs:unique in OWL

Is it possible to express the meaning of xs:unique in OWL?
Say, I define a property hasID whose range is integer. 2 different individuals A and B could not have the same ID. So you don't have A hasID 1 and B hasID 1 at the same time.
That's an inverse functional property. In OWL, there are inverse functional object properties, such that if p is an inverse functional object property then p(A,C) and p(B,C) imply A = B.
From the specification:
9.2.8 Inverse-Functional Object Properties
An object property inverse functionality axiom
InverseFunctionalObjectProperty( OPE ) states that the object property
expression OPE is inverse-functional — that is, for each individual x,
there can be at most one individual y such that y is connected by OPE
with x. Each such axiom can be seen as a syntactic shortcut for the
following axiom:
SubClassOf( owl:Thing ObjectMaxCardinality( 1 ObjectInverseOf( OPE ) ) )
However, OWL doesn't have inverse functional datatype properties. This is the subject of What's the problem with inverse-functional datatype properties? on answers.semanticweb.com. (I'm providing a link to the WaybackMachine's archived version of that page, since the actual site seems to be down.)

Assigning a value to a property based on a SWRL rule (Protege 4.3 with Pellet as reasoner)

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

About the relationship in two entities

I'm thinking to create a property which store the key or the ID of the other entity as a reference to the entity.
I want to know two things.
1. Which data should the property store, the key or the ID?
2. What should the type of the property be? maybe StringProperty?
The Datastore has a special property type for this: ReferenceProperty. There are two ways to use it.
One:
someothermodel = db.ReferenceProperty()
Two:
someotherspecificmodel = db.ReferenceProperty(SomeModel)
In example 2, only models with the type of SomeModel can be assigned, in example one, any model can be assigned.
The value type of ReferenceProperty is db.Key.

Resources