I´m not an expert, but I had no answers with simple GRAPHDB query. I created in Protege a small ontology:
CLASS VarValue
SUBCLASS1 - HighVarValue
SUBCLASS2 - LowVarValue
The class HighVarValue has a general Class axiom:
varDATA some xsd:float[>= 0.5f] SubClassOf HighVarValue
The class LowVarValue has a general Class axiom:
varDATA some xsd:float[< 0.5f] SubClassOf HighVarValue
The instance of the class VarValue has a value of 100.0f with varDATA dataProperty (image 2).
The inference with Protege (image 3) is OK to the simple query:
select ?x WHERE
{
?x a :HighVarValue .
}
But, using GRAPHDDB with RuleSet OWL2-QL or OWL2-RL, the result of the same query is empty.
Am I missing something? Thanks a lot.
Subclass HighVarValue checking the value of VarValue instance:actualValue
Instance actualValue with dataProperty varDATA=100.0f
After reasoner, we can see: actualValue rdf:type HighVarvalue
Related
Suppose the range of an object property is defined through a class expression. I want to know whether a particular instance of the class can be used in the range of the object property. Is it possible to use the OWL API and check if a particular class is subsumed by this class expression ?
OWLAPI cannot provide a complete answer for this - an OWLReasoner implementation is necessary for complete results.
Given an implementation of OWLReasoner, to check entailment you can either list all the subclasses of a class expression and check if the class you're interested in appears in the response, or ask the reasoner if your class of interest is a subclass, i.e.,
OWLDataFactory df = ...
OWLClassExpression ce = ...
OWLClass c = ...
OWLReasoner r = ...
OWLAxiom ax = df.getOWLObjectSubClassOf(c, ce);
boolean cIsSubclassOfCE = r.isEntailed(ax);
In my project, I'd like to get all the range class related to the given class by an restricted(somevaluefrom or allvalues from) objectproperties. I can get the restricted subclassofAxioms expressions including the given class, but how can I get the range class in these expressions? In other word, how can I get all the related classes to the given class excluding inherited subclass.
For example:
public static void printSubClassOfAxioms(OWLOntology ontology,OWLReasoner reasoner,OWLClass owlClass){
for(OWLSubClassOfAxiom ax:ontology.getSubClassAxiomsForSubClass(owlClass)){
OWLClassExpression expression=ax.getSuperClass();
System.out.println(ax);
System.out.println(expression);
}
}
The results are:
SubClassOf(<#FourCheesesTopping> <#CheeseTopping>)
SubClassOf(<#FourCheesesTopping> ObjectSomeValuesFrom(<#hasSpiciness> <#Mild>))
SubClassOf(<#FourCheesesTopping> ObjectAllValuesFrom(<#hasCountryOfOrigin> #Country>))
How can I just get the range classes #Country and #Mild
Thank you for your attention!
Write an OWLObjectVisitor and override the visit(OWL... Type) for the restrictions you're interested in. At that point,
type.getFiller()
will yield the class you're after.
Examples are in the documentation: https://github.com/owlcs/owlapi/wiki/Documentation
public class RestrictionVisitor extends OWLClassExpressionVisitor {
#Override
public void visit(#Nonnull OWLObjectSomeValuesFrom ce) {
// This method gets called when a class expression is an existential
// (someValuesFrom) restriction and it asks us to visit it
}
}
I want to use knowledge, which is modelled between classes. E.g. I have modelled a car and a bus have 4 wheels, a bike 2 wheels. Now, I want to express that bike can tip (if you don't keep them in balance - incompetent driver).
If I add an instance "CB450", subClassOf Bike, a rule should enable reasoning: can(CB450,Tip).
Way:
Type(Cb450,Bike) and has(Bike,TwoWheels) and can(TwoWheels,Tip) -> can (CB450,Tip)
I did not find any way to express this rule in SWRL, or Jena rules. Is there a possibility?
I know that it can be modelled differently, but I need to use class relations for rules in instances.
I use Protege 5.16 with pellet 2.3.1.
See the example ontology below
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/vehicle>
ObjectProperty: <http://www.semanticweb.org/vehicle#has>
ObjectProperty: <http://www.semanticweb.org/vehicle#can>
Class: <http://www.semanticweb.org/vehicle#Car>
SubClassOf:
<http://www.semanticweb.org/vehicle#Vehicle>,
<http://www.semanticweb.org/vehicle#has> some <http://www.semanticweb.org/vehicle#FourWheels>
Class: <http://www.semanticweb.org/vehicle#Vehicle>
Class: <http://www.semanticweb.org/vehicle#Bike>
SubClassOf:
<http://www.semanticweb.org/vehicle#Vehicle>,
<http://www.semanticweb.org/vehicle#has> some <http://www.semanticweb.org/vehicle#TwoWheels>
Class: <http://www.semanticweb.org/vehicle#FourWheels>
SubClassOf:
<http://www.semanticweb.org/vehicle#Property>
Class: <http://www.semanticweb.org/vehicle#TwoWheels>
SubClassOf:
<http://www.semanticweb.org/vehicle#can> some <http://www.semanticweb.org/vehicle#Tip>,
<http://www.semanticweb.org/vehicle#Property>
Class: <http://www.semanticweb.org/vehicle#Property>
Class: <http://www.semanticweb.org/vehicle#Tip>
SubClassOf:
<http://www.semanticweb.org/vehicle#Property>
Individual: <http://www.semanticweb.org/vehicle#CB450>
Types:
<http://www.semanticweb.org/vehicle#Bike>
Individual: <http://www.semanticweb.org/vehicle#Tip>
Types:
<http://www.semanticweb.org/vehicle#Tip>
Based on the way you have explained the problem it looks like "CB40" isn't a subclass of Bike but rather an individual of type Bike. So say you have a class Vehicle, a data property hasWheels on Vehicle and a boolean property canTip on Vehicle, you can write a SWRL rule as
Vehicle(?x) ^ hasWheels(?x, 2) -> canTip(?x, true)
which translates as "A vehicle with two wheels can tip over" . The ?x is any individual of the specified type. So if you create a class Bike as a subclass of Vehicle and an individual CB40 of that class and set all the relevant data properties a reasoner will assign the canTip property to true for CB40
I'm using Protege 4.3 to create my first ontology, so I encountered a few problems
Let's say we have the classes Shop, Mall, and Person and the properties works-inand is-part-of.
So the first problem is we want: if a Person works-in Shop and Shop is-part-of Mall then Person works-in Mall.
I tried to add the property chain works-in o is-part-of to the property is-part-of but then the reasoner died when I activated it.
Any idea how to solve that?
Thanks.
To answer your first question: you are looking for property chains. In Protege you can say that works-in o is-part-of is a subPropertyOf (Chain) works-in, this will give you expected inferences
EDIT: I did the following experiment:
a) create general ontology following your description (in Manchester syntax):
Ontology: <http://www.semanticweb.org/o>
ObjectProperty: <http://www.semanticweb.org/o#works-in>
SubPropertyChain:
<http://www.semanticweb.org/o#works-in> o <http://www.semanticweb.org/o#is-part-of>
ObjectProperty: <http://www.semanticweb.org/o#is-part-of>
Domain:
<http://www.semanticweb.org/o#Department> or <http://www.semanticweb.org/o#Shop>
Range:
<http://www.semanticweb.org/o#Mall> or <http://www.semanticweb.org/o#Shop>
Class: <http://www.semanticweb.org/o#Shop>
Class: <http://www.semanticweb.org/o#Mall>
Class: <http://www.semanticweb.org/o#Department>
Class: <http://www.semanticweb.org/o#Person>
b) Add some individuals to that ontology to check the inference. After classifying with FaCT++ Protege shows that person1 is related to mall1 via works-in. The additional axioms are as follows:
Individual: <http://www.semanticweb.org/o#shop1>
Types:
<http://www.semanticweb.org/o#Shop>
Facts:
<http://www.semanticweb.org/o#is-part-of> <http://www.semanticweb.org/o#mall1>
Individual: <http://www.semanticweb.org/o#mall1>
Types:
<http://www.semanticweb.org/o#Mall>
Individual: <http://www.semanticweb.org/o#person1>
Types:
<http://www.semanticweb.org/o#Person>
Facts:
<http://www.semanticweb.org/o#works-in> <http://www.semanticweb.org/o#shop1>
c) Add axioms saying that Person works in Shop, and Shop is part of Mall to the ontology from a). In this case again Person is a part of WorksInMall class, that shows that the property chain axiom is taken into account. Additional axioms are:
Class: <http://www.semanticweb.org/o#WorksInMall>
EquivalentTo:
<http://www.semanticweb.org/o#works-in> some <http://www.semanticweb.org/o#Mall>
Class: <http://www.semanticweb.org/o#Person>
SubClassOf:
<http://www.semanticweb.org/o#works-in> some <http://www.semanticweb.org/o#Shop>
Class: <http://www.semanticweb.org/o#Shop>
SubClassOf:
<http://www.semanticweb.org/o#is-part-of> some <http://www.semanticweb.org/o#Mall>
I basically have a large file of a few thousand names each on a new line in .txt. I am using Protege to build my ontology and I want a quicker way to insert these names as Individuals into the concept 'Person' in my Ontology. is there anyway that this can be done using Protege or the OWL API as clicking the add button in protege and typing/copying each name then adding it to the 'Person' concept will take some time.
Thanks for any suggestions.
If using the OWL API, there is an example of how to do just this in the examples provided in the documentation:
public void shouldAddClassAssertion() throws OWLOntologyCreationException,
OWLOntologyStorageException {
// For more information on classes and instances see the OWL 2 Primer
// http://www.w3.org/TR/2009/REC-owl2-primer-20091027/#Classes_and_Instances
// In order to say that an individual is an instance of a class (in an
// ontology), we can add a ClassAssertion to the ontology. For example,
// suppose we wanted to specify that :Mary is an instance of the class
// :Person. First we need to obtain the individual :Mary and the class
// :Person Create an ontology manager to work with
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
// The IRIs used here are taken from the OWL 2 Primer
String base = "http://example.com/owl/families/";
PrefixManager pm = new DefaultPrefixManager(base);
// Get the reference to the :Person class (the full IRI will be
// <http://example.com/owl/families/Person>)
OWLClass person = dataFactory.getOWLClass(":Person", pm);
// Get the reference to the :Mary class (the full IRI will be
// <http://example.com/owl/families/Mary>)
OWLNamedIndividual mary = dataFactory
.getOWLNamedIndividual(":Mary", pm);
// Now create a ClassAssertion to specify that :Mary is an instance of
// :Person
OWLClassAssertionAxiom classAssertion = dataFactory
.getOWLClassAssertionAxiom(person, mary);
// We need to add the class assertion to the ontology that we want
// specify that :Mary is a :Person
OWLOntology ontology = manager.createOntology(IRI.create(base));
// Add the class assertion
manager.addAxiom(ontology, classAssertion);
// Dump the ontology to stdout
manager.saveOntology(ontology, new StreamDocumentTarget(
new ByteArrayOutputStream()));
}