I have built an application that uses Jena API and lets you create an ontology for Products and have different type of products like sports, electronics products etc. Now what I have to do is to change certain rules. Like one rule is subClassOf which give you specific class and its Parent class. Making a change so that it would be a subClassOf would give me any Property of that class or beside giving me the parent class it would return me the child of that class. Basic Aim is to play with axioms of jena API.
Thanks
The rule for subClassOf defined in, for example etc/owl-fb-mini.rules creates (or allows query for) new triples in the underlying graph that now relate some individual to its ancestor classes (through subClassOf) rather than its direct parent. These rules attempt to implement rdfs and owl inference.
So, for example, if your graph contained:
<urn:ex:instance> <rdf:type> <urn:ex:ClassA>
<urn:ex:ClassA> <rdfs:subClassOf> <urn:ex:ClassB>
Then, with basic class reasoning, the graph should behave as though it contained the following triples, instead:
<urn:ex:instance> <rdf:type> <urn:ex:ClassA>
<urn:ex:ClassA> <rdfs:subClassOf> <urn:ex:ClassB>
<urn:ex:instance> <rdf:type> <urn:ex:ClassB>
If you want to change the interpretation of OWL or RDFS axioms as expressed in RDF, that is, what triples you can access through the graph, then you would need to make your own versions of the rdfs and/or owl rules files. If you wish to do that, you will need to study the Reasoners and Rule Engines documentation as well as the existing rules files within jena-core.
Implementing your example would be a matter of adding an additional rule to the existing RDFS or OWL rulesets:
[andPropertiesToo: (?child rdfs:subClassOf ?parent),
(?parent ?p ?o) ->
(?child ?p ?o)
]
You could, for example, retrieve the set of rules that is used for RDFS, and then add this new rule as well, then create a GenericRuleReasoner whose List<Rule> contained all of them:
final String customRule =
"[andPropertiesToo: (?child rdfs:subClassOf ?parent),\n"+
"(?parent ?p ?o) ->\n"+
"(?child ?p ?o)\n"+
"]";
final List<Rule> customRules = new ArrayList<Rule>(){{
this.addAll(RDFSRuleReasoner.loadRulesLevel(RDFSRuleReasoner.SIMPLE_RULES));
try( final BufferedReader src = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(customRule.getBytes()))) ) {
this.addAll(Rule.parseRules(Rule.rulesParserFromReader(src)));
}
}};
final RuleReasoner reasoner = (RuleReasoner)GenericRuleReasonerFactory.theInstance().create(null);
reasoner.setRules(customRules);
final InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
model.prepare();
Related
Can anyone tell me the steps that are required to populate an Ontology?
I have created a domain-specific Ontology (TBox = Terminological knowledge) which consists of defined classes and relations.
On the other hand, I have an IFC file (The Industry Foundation Classes) which has the instances.
I have converted the IFC file to IFC OWL and have understood that I need to map the classes into the newly created ontology.
However, I don't understand how I can get the instances of the associated classes and relations into my created ontology.
You have created two ontology files, one with the tbox and one with the abox. Usually, in this scenario the abox would use an owl:imports annotation to refer to the tbox, and would not, itself, need class declarations - it would use the IRIs for the classes already declared in the tbox. In protégé, creating an imports is straightforward.
A common issue is incorrect IRIs: if you've created your abox without initially importing the tbox, it's possible the classes you used do not match the tbox classes (e.g., the abox classes use the abox IRI as their base IRI instead of the tbox).
I have an exercise in Semantic Web. I must extract some individuals from the DBpedia. These individuals must be inserted into an ontology that I must create. My question is. Can I retrieve individuals from the DBedia?
Let me clarify !
When I send this sparql query
PREFIX dbo: <http://dbpedia.org/ontology>
SELECT distinct * WHERE
{
?album a dbo:Album .
} LIMIT 10
I get 10 URIs. Should I get whole instances ? I mean, label, object properties, data properties etc. in order to insert them to my ontology?
I want them as a complete instance. I don't want to add more variables e.g
?album dbo:artist ?artist .
Can I use a java api e.g. Jena ?
EDIT:
Let me give you an example. Suppose that you get an Album with URI
http://dbpedia.org/resource/...Baby_One_More_Time_(album)
This album has also some properties with their values e.g.
dbo:artist dbr:Britney_Spears
dbo:releaseDate 1999-01-12 (xsd:date)
...
How could I get all of them in order to create an indivual album for my ontology with properties artist and releaseDate and values Britney_Spears and 1999-01-12 respectively ?
Well, a good point always to start is your requirements! What do you exactly need? There is scientific plethora research on Ontology Module Extraction (see for example here).
My rule of thumb is that: the amount you extract must align with the required constraints of soundness and completeness of results, which in turn, aligns with your requirements. To make it clear, consider the following: A DBpedia Artist is a subClassOf Person. Now consider that you extract all the instances of Artist from DBPedia, without the piece of information that Artist is a subClassOf Person. Now if you query your dataset asking for Person, you will get nothing. Is this a sound result? yes, but is it complete? No! However, if you don't care about the fact that each Artist is a Person, then it's okay. A mentioning worthy thing is that it depends on the DBpedia endpoint itself and what kind of reasoning it performs as well.
Concluding: Specify what you really need. While you can suffice for a couple of classes with their instances, you can as well extract the whole DBpedia.
Regarding getting the data, there are multiple ways; again depending on your requirements. For simple purposes, you can use Jena TDB for triples storage and access them via Jena. You can even store your data simply in an RDF file. You can, for example, use a construct query on DBpedia endpoint and specify the results format as RDF and then insert them to your RDF engine. Another option, for example, this answer, states how to use an INSERT query to perform the insert task into a local graph.
You can retrieve instances from DBpedia with whatever metadata you want, but it depends on your ontology that you would like to create. Please take a look at this document, it will help you to understand some notions.
Should you get whole instances? I think you are asking if you should take all the proporties and objects depending on the subject. Not necessarily..It depends on your ontology as stated in first step and you decide what to take.
Should you use Jena? You can but you don't have to! If you pose a CONSTRUCT query to the endpoint you can get the data but as far as I understood you don't want to add variables. So you can pose a query as follows by asking all the metadata regarding to the instance.
CONSTRUCT { ?album ?p ?o } WHERE {
?album a dbo:Album .
?album ?p ?o
}
If you would like to get a limited number of instances then you can add limit again at the end of this query.
is there any way individual (instance) connect to class with object property? For example, individual in this case is module name: Web Programming. Object property : isClassified. Class: Network.
I've tried to define Web Programming as class, and it works because the domain and range are both classes. Same goes if I define both Web Programming & Network as individuals, it works. If the domain is a class and the range is individual, it still works. But what if the domain is individual and the range is class? Is there any way I can connect it with object property: isClassifiedIn?
Protégé is an OWL 2 DL editor (since version 4). In OWL 2 DL, an individual cannot be a class, and an object property must relate individuals to individuals only. So what you want cannot be expressed in the way you formulate it. However, you could do two things:
use an annotation property instead of an object property. This may not be ideal because an OWL DL reasoner must ignore annotation properties in the reasoning process. They are just that: annotations, similar to comments in a programming code.
relate the individual to another individual that has the same name as the class. Let me give details about this.
In OWL 2 DL, although it is not possible for individuals to be classes, it is possible for individual names to be class names at the same time. For instance, one can say (in Turtle syntax):
ex:Module a owl:Class .
ex:Network a owl:Class, owl:Thing .
ex:isClassified a owl:ObjectProperty .
ex:webProgramming a ex:Module;
ex:isClassified ex:Network .
Note that ex:webProgramming here is not related to a class. It is related to an individual of type owl:Thing. This individual has nothing to do, a priori, with the class named ex:Network, although it has the same name. This is called "punning" in the OWL 2 specification.
There is a third way: change your knowledge model such that you do not encounter this problem. I do not know your ontology, but it could be hinting at an antipattern that you should avoid.
You have to use "value".
Write your own expression using the class expression editor.
Select the class Than write:
"property" value "individual"
I was wondering if it was possible to get the exact time stamp in a dateTime format for when a particular property, object or data, was added to the ontology. For example if I have three owl individuals A, B and C and through my code in either OWL API or Apache Jena I add a property relatedTo to the ontology and create the assertions A relatedTo B and A relatedTo C, is there some function I can call on A to see that A relatedTo B was asserted at some hh:mm:ss dd:mm:yyyy?
Thanks in advance for any help.
Not in any API that I'm familiar with - by default, OWL does not record any such information. You could build a pattern to add a timestamp to each axiom (adding an axiom annotation to each axiom) but it would only be available for data you produce.
Some OWL storage systems might have that information internally, but I'm not aware of any of them exposing this for SPARQL interrogation.
I'm creating an ontology that is based on wordnet. I want to know what level of information I should add to my own ontology? Like, for example, if the lexica has a "instance of" and "hypernym" relation, do I need to import all this in my ontology? or it's ok to just refer to the lexica in my ontology and use namespace of wordnet as a reference?
Note that I've a list of terms that I want to somehow link to wordnet so these terms make sense.