I'm trying to add an equivalent axiom of the following form:
owl:Thing EquivalentTo {individual1, indivdual2, ... individualN}
Below is how I'm trying to add the axiom:
String individualSet = "{a, b, c, d}"
OWLAxiom a = df.getOWLEquivalentClassesAxiom(df.getOWLClass(individualSet), df.getOWLThing());
manager.addAxiom(ontology, a);
The problem is that this actually creates an extra class with the name "{a, b, c, d}", which prevents a reasoner from making right conclusions as intended.
In Protege, I can add this type of Equivalent To axiom without resulting in an extra class... How can I do the same with OWL-API?
I figured it out. I had to use OWLObjectOneOf to compose a set of individuals and make that equivalent to owl:Thing.
Related
My goal: find the disjoint axioms (asserted and inferred) in an ontology which contains around 5000 axioms.
My code:
for (OWLClass clazz1 : ontology.getClassesInSignature()) {
for (OWLClass clazz2 : ontology.getClassesInSignature()) {
OWLAxiom axiom = MyModel.factory.getOWLDisjointClassesAxiom(clazz2, clazz1);
if( !(ontology.containsAxiom(axiom)) && reasoner.isEntailed(axiom))
{
System.out.println(clazz2.toString() + " disjoint with " + clazz1.toString());
}
The problem: the execution time is extremely slow, I'd say eternal. Even if I reduce the number of comparison with some if statement, the situation is still the same.
Protege seems to be very quick to compute those inferred axioms and it's based on the same API I am using (OWLAPI). So, am I in the wrong approach?
Profiling the code will very likely reveal that the slow part is
reasoner.isEntailed(axiom)
This form requires the reasoner to recompute entailments for each class pair, including the pairs where clazz1 and clazz2 are equal (you might want to skip that).
Alternatively, you can iterate through the classes in signature once and use the reasoner to get all disjoint classes:
Set<OWLClass> visited=new HashSet<>();
for (OWLClass c: ontology.getClassesInSignature()) {
if (visited.add(c)) {
NodeSet set = reasoner.getDisjointClasses(c);
for (Node node: set.getNodes()) {
System.out.println("Disjoint with "+c+": "+node);
visited.addAll(node.getEntities());
}
}
}
Worst case scenario, this will make one reasoner call per class (because no class is disjoint). Best case scenario, all classes are disjoint or equivalent to another class, so only one reasoner call is required.
I am using Protege 3.4 and I built my ontology and extended it with SWRL rules using SWRL and sqwrl built ins . The rules classifies instances of a class of the ontology ; the RHS is class assertion of an instance .It works successfully but when I change the values of the causes in the LHS no reclassification is done the instance is asserted to the same class
Why does this happen ? How to reclassify instances ?
ex:
SWRL rules:
1. Message(?m) hasInterest(?m,?i) hasCategory(?m,?c) sqwrl:makeset(?s1,?i) sqwrl:makeset(?s2,?c) sqwrl:intersection(?s3,?s1,?s2) sqwrl:size(?n,?s3) swrlb:greaterThan(?n,0) -> Ham(?m)
Message(?m) hasInterest(?m,?i) hasCategory(?m,?c) sqwrl:makeset(?s1,?i) sqwrl:makeset(?s2,?c) sqwrl:difference(?s3,?s1,?s2) sqwrl:size(?n,?s3) swrlb:greaterThan(?n,0) -> Spam(?m)
So once the message instance is classified as ham for example , whenever I change the values of i or c it will always be ham .
I have a generic class, which is constructed from multi-dimensional data (i.e. n-dimensional Ararys or Vectors).
In this case, I would like the class to be instantiated by one type only (e.g. Vector), aside from its dimensionality (Vector[Vector[T]] but not Vector[Array[T]]).
Having this class signature:
class Foo[T](x: Vector[T], y: Bar[T])
how could I guarantee that T would be for example Vector[T] or Vector[Vector[T]] (or etc...) but NOT Array[T] or Vector[Array[T]]?
While generics are wiped out at compile time by type-erasure, you can rely on the "evidence" mechanism.
An evidence is a special typeclass whose goal is only to witness the relation between type A and type B.
A<:<B is a witness that A is a subclass of B
A=:=B is a witness that A is a B
A>:>B is a witness that A is a superclass of B
so you can write something like that
case class MyContainer[A,B](b:Vector[B])(implicit ev: B <:< Vector[A])
Inside your class, you can simply treat every element of vector b as a Vector A by applying the evidence to each item: i.e.
b flatMap {
x => ev(x) map {_.toString}
}
Using Protege and SWRL tab, I have the ontology mentioned hereinafter. It is composed of the Class Test and the class Shadow, where Test has three individuals t1, t2, t3. I was trying to define an SWRL rule that creates an individual of Shadow class for each existing individual of Test, the rule is
Test(?x) ^ swrlx:makeOWLThing(?new, ?x) -> Shadow(?new)
QUESTIONS:
Only one individual of Shadow, named fred is created, instead of three (corresponding to t1, t2, t3).
How to control the naming of the resulting individual which is always named fred?
Prefix(:=<http://www.semanticweb.org/hilal/ontologies/2016/5/untitled- ontology-58#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www.semanticweb.org/hilal/ontologies/2016/5/untitled- ontology-58>
Declaration(Class(:Shadow))
Declaration(Class(:Test))
Declaration(NamedIndividual(:t1))
Declaration(NamedIndividual(:t2))
Declaration(NamedIndividual(:t3))
Declaration(AnnotationProperty(<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled>))
############################
# Named Individuals
############################
# Individual: :t1 (:t1)
ClassAssertion(:Test :t1)
# Individual: :t2 (:t2)
ClassAssertion(:Test :t2)
# Individual: :t3 (:t3)
ClassAssertion(:Test :t3)
DLSafeRule(Annotation(<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean) Annotation(rdfs:comment ""^^xsd:string) Annotation(rdfs:label "S1"^^xsd:string) Body(BuiltInAtom(<http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing> Variable(<new>) Variable(<x>)) ClassAtom(:Test Variable(<x>)))Head(ClassAtom(:Shadow Variable(<new>))))
)
SWRL rules cannot create new individuals, as far as I understand the DL Safe conditions.
In the comments, you linked to an article describing the semantics of that extension:
One of the the first built-ins I implemented provided the ability to create new individuals in a controlled manner. There is a detailed explanation in [2], but basically a built-in called swrlx:makeOWLThing creates a new individual and binds it to its first unbound argument; a new individual is created for each unique pattern of the remaining arguments.
Now, let's take a look at your rule as written in the question:
Test(?x) ^ swrlx:makeOWLThing(?new, ?x) -> Shadow(?new)
If the atoms are processed from left to right, then ?x should be bound when makeOWLThing is encountered, but ?new isn't. That means that you should get a new individuals bound to the variable ?new, and for each value of ?x you should get a different value of ?new. That's what it sounds like you want. However, in the code you posted, I see this:
DLSafeRule(
Annotation(<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean)
Annotation(rdfs:comment ""^^xsd:string)
Annotation(rdfs:label "S1"^^xsd:string)
Body(
BuiltInAtom(<http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing>
Variable(<new>)
Variable(<x>))
ClassAtom(:Test Variable(<x>)))
Head(
ClassAtom(:Shadow Variable(<new>))))
)
I'm not certain, but if that's processed from left to right as well, the makeOWLThing(?new,?x) appears first, in which case ?x would be unbound when the new individual is created, so you'd only get one new individual.
Im regenerating an ontology to OWL2 using the OWL-API and testing with Protégé.
There are some concepts that are subclass of many superclasses, and some DataProperties that should take multiple values, for example:
Artifactual Location & Artifactual Area
And I want to specify that:
• For Artifactual Location the DataProperty hasConcreteEntityType should take the values LOCATION and ARTIFACT
• For Artifactual Area the DataProperty hasConcreteEntityType should take the values ARTIFACTUAL_LOCATION and AREA
Class Tree & Class Descriptions
But after activating the reasoner, I get Artifactual Location misclassified to Nothing(but not both)
Inference Explanations
And I don't understand what's wrong with the inference explanation,but seems that there should be a third explanation like the second but related to the value AREA, so seems that doesn't support bi-valued properties like this, or, maybe there is another way to define and constraint the values of a multi-valued DataProperty or even the reasoner doesn't work fine with this,
im using Hermit 1.3.8.3
Quoting the comment on my previous answer (I've deleted the answer because it is incorrect)
[The ontology] should be here drive.google.com/file/d/0B2FYMQD3DD8DNWtteUlLcDgyTGM/ Look at the linguisticUnitType property for Morphosyntactic Unit, as I defined it (to have 2 values, MORPHOLOGICAL and SYNTACTIC) it is classified fine by the reasoner, but it doesn't behave the same with the properties hasConcreteEntityType and hasLocationType regarding the classes at Nothing Artifactual Area and Artifactual Location. I don't understand why for one case is fine but not for the other, because the properties and restrictions are defined in the same manner.
The problem is that Artifactual Area is defined as subclass of Location, which already restricts the values of hasConcreteType to only one value (LOCATION). In order to allow Artifactual Area to have exactly two values, the restriction on the superclass must be removed or amended.
For future reference, the fragment in Functional syntax is here:
Ontology(<http://localhost/pruebaLUO.owl>
DataPropertyDomain(:hasConcreteEntityType :ConcreteEntity)
DataPropertyRange(:hasConcreteEntityType DataOneOf("ARTIFACT"^^xsd:string "FOOD"^^xsd:string "LIVING_ENTITY"^^xsd:string "LOCATION"^^xsd:string "MATERIAL"^^xsd:string "ORGANIC_OBJECT"^^xsd:string "PHYSICAL_OBJECT"^^xsd:string "SUBSTANCE"^^xsd:string))
DataPropertyDomain(:hasLocationType :Location)
DataPropertyRange(:hasLocationType DataOneOf("3D"^^xsd:string "AREA"^^xsd:string "ARTIFACTUAL_LOCATION"^^xsd:string "GEOPOLITICAL"^^xsd:string "OPENING"^^xsd:string "OTHER"^^xsd:string))
DataPropertyDomain(:linguisticUnitType :LinguisticUnit)
DataPropertyRange(:linguisticUnitType DataOneOf("MORPHOLOGICAL"^^xsd:string "SEMANTIC"^^xsd:string "SYNTACTIC"^^xsd:string))
AnnotationAssertion(rdfs:label :Area "Area"#en)
SubClassOf(:Area :Location)
SubClassOf(:Area DataHasValue(:hasLocationType "AREA"^^xsd:string))
AnnotationAssertion(rdfs:label :Artifact "Artifact"#en)
SubClassOf(:Artifact :ConcreteEntity)
SubClassOf(:Artifact DataHasValue(:hasConcreteEntityType "ARTIFACT"^^xsd:string))
SubClassOf(:ArtifactualArea :Area)
SubClassOf(:ArtifactualArea :ArtifactualLocation)
SubClassOf(:ArtifactualArea DataExactCardinality(2 :hasLocationType DataOneOf("AREA"^^xsd:string "ARTIFACTUAL_ LOCATION"^^xsd:string)))
SubClassOf(:ArtifactualLocation :Artifact)
SubClassOf(:ArtifactualLocation :Location)
SubClassOf(:ArtifactualLocation DataHasValue(:hasLocationType "ARTIFACTUAL_ LOCATION"^^xsd:string))
SubClassOf(:ArtifactualLocation DataExactCardinality(2 :hasConcreteEntityType DataOneOf("ARTIFACT"^^xsd:string "LOCATION"^^xsd:string)))
SubClassOf(:Building :ArtifactualLocation)
SubClassOf(:ConcreteEntity :GenericEntity)
SubClassOf(:Entity :PropositionalComponent)
SubClassOf(:GenericEntity :Entity)
SubClassOf(:Location :ConcreteEntity)
SubClassOf(:Location DataHasValue(:hasConcreteEntityType "LOCATION"^^xsd:string))
SubClassOf(:MorphologicalUnit :LinguisticUnit)
SubClassOf(:MorphologicalUnit DataHasValue(:linguisticUnitType "MORPHOLOGICAL"^^xsd:string))
SubClassOf(:MorphosyntacticUnit :MorphologicalUnit)
SubClassOf(:MorphosyntacticUnit :Token)
SubClassOf(:MorphosyntacticUnit DataExactCardinality(2 :linguisticUnitType DataOneOf("MORPHOLOGICAL"^^xsd:string "SYNTACTIC"^^xsd:string)))
SubClassOf(:PropositionalComponent :SemanticUnit)
SubClassOf(:SemanticUnit :LinguisticUnit)
SubClassOf(:SemanticUnit DataHasValue(:linguisticUnitType "SEMANTIC"^^xsd:string))
SubClassOf(:SyntacticUnit :LinguisticUnit)
SubClassOf(:SyntacticUnit DataHasValue(:linguisticUnitType "SYNTACTIC"^^xsd:string))
SubClassOf(:Token :SyntacticUnit)
)