Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b7bfa772 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- cleaned up all tutorial4 for better working with Pellet 2.1

parent f31723e6
No related branches found
No related tags found
No related merge requests found
...@@ -130,7 +130,7 @@ public class MyApp { ...@@ -130,7 +130,7 @@ public class MyApp {
} }
public void run( String[] args ) { public void run( String[] args ) {
String myId = "JETest"; String myId = "Test";
Alignment al = null; Alignment al = null;
URI uri1 = null; URI uri1 = null;
URI uri2 = null; URI uri2 = null;
...@@ -166,7 +166,7 @@ public class MyApp { ...@@ -166,7 +166,7 @@ public class MyApp {
found = getFromURLString( RESTServ+"retrieve?method=fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor&id="+alid, false ); found = getFromURLString( RESTServ+"retrieve?method=fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor&id="+alid, false );
alset = extractFromResult( found, "//retrieveResponse/result/*[1]",true ); alset = extractFromResult( found, "//retrieveResponse/result/*[1]",true );
// This code is heavy as hell // This code is heavy
String xmlString = null; String xmlString = null;
try { try {
// Set up the output transformer // Set up the output transformer
...@@ -186,7 +186,6 @@ public class MyApp { ...@@ -186,7 +186,6 @@ public class MyApp {
} }
// parse it as an alignment // parse it as an alignment
// (better passing to the SAXHandler)
try { try {
AlignmentParser aparser = new AlignmentParser(0); AlignmentParser aparser = new AlignmentParser(0);
Alignment alu = aparser.parseString( xmlString ); Alignment alu = aparser.parseString( xmlString );
...@@ -243,17 +242,16 @@ public class MyApp { ...@@ -243,17 +242,16 @@ public class MyApp {
// (Sol2) import the data from one ontology into the other // (Sol2) import the data from one ontology into the other
// ***** Third exercise: querying/reasoning ***** // ***** Third exercise: querying and reasoning *****
// (Sol1) Use SPARQL to answer queries (at the data level) // (Sol1) Use SPARQL to answer queries (at the data level)
InputStream in = null; InputStream in = null;
QueryExecution qe = null; QueryExecution qe = null;
try { try {
in = new FileInputStream( merged ); in = new FileInputStream( merged );
//in = new URL("http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl").openStream(); //OntModelSpec.OWL_MEM_RDFS_INF or no arguments to see the difference...
//OntModelSpec.OWL_MEM_RDFS_INF or no arguments to see the difference... Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF,null);
Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF,null); model.read( in, "file:"+tempOntoFileName );
model.read(in,"file:results/myresult.owl");
in.close(); in.close();
// Create a new query // Create a new query
...@@ -289,16 +287,10 @@ public class MyApp { ...@@ -289,16 +287,10 @@ public class MyApp {
if ( qe != null ) qe.close(); if ( qe != null ) qe.close();
} }
// Alternative: Use Pellet to answer queries // (Sol2) Use Pellet to answer queries (at the ontology level)
// ***** Fourth exercise: reasoning *****
// Variant 1: reasoning with merged ontologies
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
//Pellet
OWLReasoner reasoner = null; OWLReasoner reasoner = null;
//System.setErr( new PrintStream( new NullStream() ) );
// Load the ontology // Load the ontology
try { try {
OWLOntology ontology = manager.loadOntology( IRI.create( "file:"+tempOntoFileName ) ); OWLOntology ontology = manager.loadOntology( IRI.create( "file:"+tempOntoFileName ) );
...@@ -318,7 +310,7 @@ public class MyApp { ...@@ -318,7 +310,7 @@ public class MyApp {
testPelletSubClass( manager, reasoner, estud, person ); testPelletSubClass( manager, reasoner, estud, person );
testPelletSubClass( manager, reasoner, estud, student ); testPelletSubClass( manager, reasoner, estud, student );
// Variant 2: reasoning with distributed semantics (IDDL) // (Sol3) reasoning with distributed semantics (IDDL)
// test consistency of aligned ontologies // test consistency of aligned ontologies
IDDLReasoner dreasoner = new IDDLReasoner( Semantics.DL ); IDDLReasoner dreasoner = new IDDLReasoner( Semantics.DL );
dreasoner.addOntology( uri1 ); dreasoner.addOntology( uri1 );
...@@ -339,8 +331,7 @@ public class MyApp { ...@@ -339,8 +331,7 @@ public class MyApp {
public void testPelletSubClass( OWLOntologyManager manager, OWLReasoner reasoner, OWLClassExpression d1, OWLClassExpression d2 ) { public void testPelletSubClass( OWLOntologyManager manager, OWLReasoner reasoner, OWLClassExpression d1, OWLClassExpression d2 ) {
OWLAxiom axiom = manager.getOWLDataFactory().getOWLSubClassOfAxiom( d1, d2 ); OWLAxiom axiom = manager.getOWLDataFactory().getOWLSubClassOfAxiom( d1, d2 );
boolean isit = reasoner.isEntailed( axiom ); if ( reasoner.isEntailed( axiom ) ) {
if ( isit ) {
System.out.println( "Pellet(Merged): "+clname(d1)+" is subclass of "+clname(d2) ); System.out.println( "Pellet(Merged): "+clname(d1)+" is subclass of "+clname(d2) );
} else { } else {
System.out.println( "Pellet(Merged): "+clname(d1)+" is not necessarily subclass of "+clname(d2) ); System.out.println( "Pellet(Merged): "+clname(d1)+" is not necessarily subclass of "+clname(d2) );
......
/* /*
* $Id$ * $Id$
* *
* Copyright (C) INRIA, 2009 * Copyright (C) INRIA, 2009-2010
* *
* Modifications to the initial code base are copyright of their * Modifications to the initial code base are copyright of their
* respective authors, or their employers as appropriate. Authorship * respective authors, or their employers as appropriate. Authorship
...@@ -29,7 +29,6 @@ import org.semanticweb.owl.align.Alignment; ...@@ -29,7 +29,6 @@ import org.semanticweb.owl.align.Alignment;
import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentException;
import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentProcess;
import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentVisitor;
import org.semanticweb.owl.align.Parameters;
// Alignment API implementation classes // Alignment API implementation classes
import fr.inrialpes.exmo.align.impl.BasicParameters; import fr.inrialpes.exmo.align.impl.BasicParameters;
...@@ -38,6 +37,7 @@ import fr.inrialpes.exmo.align.impl.URIAlignment; ...@@ -38,6 +37,7 @@ import fr.inrialpes.exmo.align.impl.URIAlignment;
import fr.inrialpes.exmo.align.impl.BasicAlignment; import fr.inrialpes.exmo.align.impl.BasicAlignment;
import fr.inrialpes.exmo.align.impl.method.StringDistAlignment; import fr.inrialpes.exmo.align.impl.method.StringDistAlignment;
import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor; import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor;
import fr.inrialpes.exmo.align.util.NullStream;
import fr.inrialpes.exmo.align.parser.AlignmentParser; import fr.inrialpes.exmo.align.parser.AlignmentParser;
// Jena // Jena
...@@ -51,7 +51,20 @@ import com.hp.hpl.jena.query.ResultSetFormatter; ...@@ -51,7 +51,20 @@ import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryExecutionFactory;
// OWL API
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
// Pellet // Pellet
import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
// IDDL // IDDL
import fr.inrialpes.exmo.iddl.IDDLReasoner; import fr.inrialpes.exmo.iddl.IDDLReasoner;
...@@ -79,6 +92,8 @@ import javax.xml.xpath.XPathExpressionException; ...@@ -79,6 +92,8 @@ import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathConstants;
// Java standard classes // Java standard classes
import java.util.Set;
import java.util.Properties;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.BufferedWriter; import java.io.BufferedWriter;
...@@ -87,6 +102,7 @@ import java.io.BufferedReader; ...@@ -87,6 +102,7 @@ import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.PrintStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.StringReader; import java.io.StringReader;
...@@ -105,34 +121,34 @@ import java.net.URISyntaxException; ...@@ -105,34 +121,34 @@ import java.net.URISyntaxException;
* Reconcile two ontologies in various ways * Reconcile two ontologies in various ways
*/ */
public class MyApp { public class Skeleton {
String RESTServ = "http://aserv.inrialpes.fr/rest/"; String RESTServ = "http://aserv.inrialpes.fr/rest/";
public static void main( String[] args ) { public static void main( String[] args ) {
new MyApp().run( args ); new Skeleton().run( args );
} }
public void run( String[] args ) { public void run( String[] args ) {
// Setting variables // Setting variables
String myId = "JETest"; String myId = "Test";
Alignment al = null; Alignment al = null;
URI uri1 = null; URI uri1 = null;
URI uri2 = null; URI uri2 = null;
//String u1 = "http://alignapi.gforge.inria.fr/tutorial4/ontology1.owl";
//String u2 = "http://alignapi.gforge.inria.fr/tutorial4/ontology2.owl";
String u1 = "file:ontology1.owl"; String u1 = "file:ontology1.owl";
String u2 = "file:ontology2.owl"; String u2 = "file:ontology2.owl";
String method = "fr.inrialpes.exmo.align.impl.method.StringDistAlignment"; String method = "fr.inrialpes.exmo.align.impl.method.StringDistAlignment";
Parameters params = new BasicParameters(); String tempOntoFileName = "results/myresult.owl";
Properties params = new BasicParameters();
try { try {
uri1 = new URI( u1 ); uri1 = new URI( u1 );
uri2 = new URI( u2 ); uri2 = new URI( u2 );
} catch (URISyntaxException use) { use.printStackTrace(); exit(); } } catch (URISyntaxException use) { use.printStackTrace(); System.exit(-1); }
try { try {
System.out.println( "You are ready to play" );
// ***** First exercise: matching ***** // ***** First exercise: matching *****
// (Sol1) Try to find an alignment between two ontologies from the server // (Sol1) Try to find an alignment between two ontologies from the server
// ask for it // ask for it
...@@ -169,7 +185,9 @@ public class MyApp { ...@@ -169,7 +185,9 @@ public class MyApp {
// (Sol2) Use Pellet to answer queries (at the ontology level) // (Sol2) Use Pellet to answer queries (at the ontology level)
} catch (Exception e) { e.printStackTrace(); exit(); } // (Sol3) reasoning with distributed semantics (IDDL)
} catch (Exception e) { e.printStackTrace(); System.exit(-1); }
} }
public String getFromURLString( String u, boolean print ){ public String getFromURLString( String u, boolean print ){
...@@ -195,7 +213,7 @@ public class MyApp { ...@@ -195,7 +213,7 @@ public class MyApp {
public NodeList extractFromResult( String found, String path, boolean print ){ public NodeList extractFromResult( String found, String path, boolean print ){
Document document = null; Document document = null;
NodeList nodes = null; NodeList nodes = null;
try { // Parse the returned string as XML try { // Parse the returned stringAS XML
DocumentBuilder parser = DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = parser.parse(new ByteArrayInputStream( found.getBytes() )); document = parser.parse(new ByteArrayInputStream( found.getBytes() ));
...@@ -206,6 +224,7 @@ public class MyApp { ...@@ -206,6 +224,7 @@ public class MyApp {
try { // Apply the Xpath expression try { // Apply the Xpath expression
XPathFactory factory = XPathFactory.newInstance(); XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath(); XPath xpath = factory.newXPath();
//XPathExpression expr = xpath.compile("//book[author='Neal Stephenson']/title/text()");
XPathExpression expr = xpath.compile( path ); XPathExpression expr = xpath.compile( path );
Object result = expr.evaluate( document, XPathConstants.NODESET ); Object result = expr.evaluate( document, XPathConstants.NODESET );
nodes = (NodeList)result; nodes = (NodeList)result;
...@@ -218,3 +237,4 @@ public class MyApp { ...@@ -218,3 +237,4 @@ public class MyApp {
return nodes; return nodes;
} }
} }
...@@ -102,15 +102,14 @@ The list of jars is long, but at least it is explicit and you ...@@ -102,15 +102,14 @@ The list of jars is long, but at least it is explicit and you
should be safe with this one. should be safe with this one.
This programme can be compiled by: This programme can be compiled by:
<div class="fragment"> <div class="fragment">
$ javac -d results MyApp.java $ javac -d results Skeleton.java
</div> </div>
</p> </p>
<p>This <p>This programme can be run by:
programme can be run by:
<div class="fragment"> <div class="fragment">
$ java MyApp $ java Skeleton
</div></p> </div>
You can start with the empty template <a href="Skeleton.java">Skeleton.java</a>. It provides no output for the moment.
</p> </p>
<h2>Matching ontologies</h2> <h2>Matching ontologies</h2>
...@@ -135,68 +134,68 @@ and, if none is found, computes one. ...@@ -135,68 +134,68 @@ and, if none is found, computes one.
<input type="button" onclick="show('qu1')" value="Show solution 1"/> <input type="button" onclick="show('qu1')" value="Show solution 1"/>
<input type="button" onclick="show('qu2')" value="Show solution 2"/> <input type="button" onclick="show('qu2')" value="Show solution 2"/>
<input type="button" onclick="show('qu3')" value="Show solution 3"/> <input type="button" onclick="show('qu3')" value="Show solution 3"/>
<input type="button" onclick="hide('qu1');hide('qu2');hide('qu3');" value="Hide solutions"/> <input type="button" onclick="hide('qu0');hide('qu1');hide('qu2');hide('qu3');" value="Hide solutions"/>
</div> </div>
<div class="explain" id="qu0"> <div class="explain" id="qu0">
<p>After introducing the main variables:</p> <p>After introducing the main variables:</p>
<pre> <pre>
String myId = "JETest"; String myId = "Test";
Alignment al = null; Alignment al = null;
URI uri1 = null; URI uri1 = null;
URI uri2 = null; URI uri2 = null;
String u1 = "file:ontology1.owl"; String u1 = "file:ontology1.owl";
String u2 = "file:ontology2.owl"; String u2 = "file:ontology2.owl";
String method = "fr.inrialpes.exmo.align.impl.method.StringDistAlignment"; String method = "fr.inrialpes.exmo.align.impl.method.StringDistAlignment";
String tempOntoFileName = "/tmp/myresult.owl"; String tempOntoFileName = "results/myresult.owl";
Parameters params = new BasicParameters(); Properties params = new BasicParameters();
try { try {
uri1 = new URI( u1 ); uri1 = new URI( u1 );
uri2 = new URI( u2 ); uri2 = new URI( u2 );
} catch (URISyntaxException use) { use.printStackTrace(); } } catch (URISyntaxException use) { use.printStackTrace(); }
</pre> </pre>
</div> </div>
<div class="explain" id="qu1"> <div class="explain" id="qu1">
<p>The programme will invoke the alignment server:</p> <p>The programme will invoke the alignment server:</p>
<pre> <pre>
// (Sol1) Try to find an alignment between two ontologies from the server // (Sol1) Try to find an alignment between two ontologies from the server
// ask for it // ask for it
String found = getFromURLString( RESTServ+"find?onto1="+u1+"&onto2="+u2, false ); String found = getFromURLString( RESTServ+"find?onto1="+u1+"&onto2="+u2, false );
</pre> </pre>
<p>Retrieve the alignment itself:</p> <p>Retrieve the alignment itself:</p>
<pre> <pre>
// retrieve it // retrieve it
// If there exists alignments, ask for the first one // If there exists alignments, ask for the first one
NodeList alset = extractFromResult( found, "//findResponse/alignmentList/alid[1]/text()", false ); NodeList alset = extractFromResult( found, "//findResponse/alignmentList/alid[1]/text()", false );
</pre> </pre>
<p>And parse it:</p> <p>And parse it:</p>
<pre> <pre>
// parse it as an alignment // parse it as an alignment
// (better passing to the SAXHandler) AlignmentParser aparser = new AlignmentParser(0);
AlignmentParser aparser = new AlignmentParser(0); Alignment alu = aparser.parseString( xmlString );
Alignment alu = aparser.parseString( xmlString ); al = ObjectAlignment.toObjectAlignment((URIAlignment)alu);
al = ObjectAlignment.toObjectAlignment((URIAlignment)alu);
</pre> </pre>
</div> </div>
<div class="explain" id="qu2"><p>Just create an instance of <div class="explain" id="qu2">
AlignmentProcess and call it:</p> <p>Just create an instance of AlignmentProcess and call it:</p>
<pre> <pre>
// (Sol2) Match the ontologies with a local algorithm // (Sol2) Match the ontologies with a local algorithm
if ( al == null ){ // Unfortunatelly no alignment was available if ( al == null ){ // Unfortunatelly no alignment was available
AlignmentProcess ap = new StringDistAlignment(); AlignmentProcess ap = new StringDistAlignment();
ap.init( uri1, uri2 ); ap.init( uri1, uri2 );
params.setParameter("stringFunction","smoaDistance"); params.setProperty("stringFunction","smoaDistance");
ap.align( (Alignment)null, params ); params.setProperty("noinst","1");
al = ap; ap.align( (Alignment)null, params );
} al = ap;
}
</pre> </pre>
</div> </div>
<div class="explain" id="qu3"><p>Match on the server:</p> <div class="explain" id="qu3"><p>Match on the server:</p>
<pre> <pre>
// (Sol3) Match the ontologies on the server // (Sol3) Match the ontologies on the server
if ( alset.getLength() == 0 ) { if ( alset.getLength() == 0 ) {
// call for matching // call for matching
String match = getFromURLString( RESTServ+"match?onto1="+u1+"&onto2="+u2+"&method="+method+"&pretty="+myId+"&action=Match&force=true", true ); String match = getFromURLString( RESTServ+"match?onto1="+u1+"&onto2="+u2+"&method="+method+"&pretty="+myId+"&action=Match", true );
} }
</pre> </pre>
<p>The remainder is the same as in the first solution.</p> <p>The remainder is the same as in the first solution.</p>
</div> </div>
...@@ -234,15 +233,16 @@ This can be done with the alignment API support. ...@@ -234,15 +233,16 @@ This can be done with the alignment API support.
<div class="explain" id="qu5"> <div class="explain" id="qu5">
<p>In fact everything is done in one step:</p> <p>In fact everything is done in one step:</p>
<pre> <pre>
// (Sol1) generate a merged ontology between the ontologies (OWLAxioms) // (Sol1) generate a merged ontology between the ontologies (OWLAxioms)
File merged = new File( tempOntoFileName ); PrintWriter writer = null;
PrintWriter writer = new PrintWriter ( new FileWriter( merged, false ), true ); File merged = new File( tempOntoFileName );
AlignmentVisitor renderer = new OWLAxiomsRendererVisitor(writer); writer = new PrintWriter ( new FileWriter( merged, false ), true );
al.render(renderer); AlignmentVisitor renderer = new OWLAxiomsRendererVisitor(writer);
writer.flush(); al.render(renderer);
writer.close(); writer.flush();
writer.close();
</pre> </pre>
<p>You can look at the result in myresult.owl</p> <p>You can look at the result in <a href="results/myresult.owl">results/myresult.owl</a>.</p>
</div> </div>
<div class="explain" id="qu6"><p>Not ready yet</p> <div class="explain" id="qu6"><p>Not ready yet</p>
<pre> <pre>
...@@ -264,9 +264,17 @@ This can be done in three ways: ...@@ -264,9 +264,17 @@ This can be done in three ways:
<p> <p>
In case you go for SPARQL please, take care of the inference regime In case you go for SPARQL please, take care of the inference regime
and observe what are the differences in this case. You can of course and observe what are the differences in this case. You can of course
run various queries and start by runing them in one of the initial run various queries and start by running them in one of the initial
ontologies instead of the merged one. ontologies instead of the merged one.
</p> </p>
<p>
For using Pellet, it will be necessary
to <a href="http://clarkparsia.com/pellet/download">download
Pellet</a> and add in
the classpath the corresponding pellet-rules.jar,
pellet-datatypes.jar, pellet-query.jar and pellet-el.jar jar-files
which are not shipped with the Alignment API.
</p>
</p> </p>
<div class="button"> <div class="button">
<input type="button" onclick="show('qu7')" value="Show solution 1"/> <input type="button" onclick="show('qu7')" value="Show solution 1"/>
...@@ -277,74 +285,78 @@ ontologies instead of the merged one. ...@@ -277,74 +285,78 @@ ontologies instead of the merged one.
<div class="explain" id="qu7"> <div class="explain" id="qu7">
<p>Prepare the system:</p> <p>Prepare the system:</p>
<pre> <pre>
// (Sol1) Use SPARQL to answer queries (at the data level) // (Sol1) Use SPARQL to answer queries (at the data level)
InputStream in = new FileInputStream( merged ); InputStream in = new FileInputStream( merged );
//OntModelSpec.OWL_MEM_RDFS_INF or no arguments to see the difference... Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF,null);
Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF,null); model.read( in, "file:"+tempOntoFileName );
model.read(in,"file:///tmp/myresult.owl"); in.close();
in.close();
</pre> </pre>
<p>Query (please play by changing the query)</p> <p>Query (please play by changing the query)</p>
<pre> <pre>
// Create a new query // Create a new query
String queryString = String queryString =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX aa: <http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#> " + "PREFIX aa: <http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#> " +
"SELECT ?fn ?ln ?t " + "SELECT ?fn ?ln ?t ?s " +
"WHERE {" + "WHERE {" +
" ?student rdf:type aa:Person . " + " ?student rdf:type aa:Estudiante . " +
" ?student aa:firstname ?fn. " + " ?student aa:firstname ?fn. " +
" ?student aa:lastname ?ln. " + " ?student aa:lastname ?ln. " +
" ?student aa:topic ?t . " + "OPTIONAL { ?student aa:affiliation ?t . } " +
"OPTIONAL { ?student aa:supervisor ?s . } " +
" }"; " }";
Query query = QueryFactory.create(queryString);
</pre> </pre>
<p>Evaluation:</p> <p>Evaluation:</p>
<pre> <pre>
Query query = QueryFactory.create(queryString); // Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Execute the query and obtain results // Output query results
QueryExecution qe = QueryExecutionFactory.create(query, model); ResultSetFormatter.out(System.out, results, query);
ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
</pre> </pre>
</div> </div>
<div class="explain" id="qu8"> <div class="explain" id="qu8">
<p>Create Reasoner instance and load the merged ontologies:</p> <p>Create Reasoner instance and load the merged ontologies:</p>
<pre> <pre>
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
Reasoner reasoner = new Reasoner( manager ); // Load the ontology
try { OWLOntology ontology = manager.loadOntology( IRI.create( "file:"+tempOntoFileName ) );
OWLOntology ontology = manager.loadOntology( URI.create( "file://"+tempOntoFileName ) ); OWLReasoner reasoner = new PelletReasoner( ontology, org.semanticweb.owlapi.reasoner.BufferingMode.NON_BUFFERING );
reasoner.loadOntology( ontology ); reasoner.prepareReasoner();
} catch (OWLOntologyCreationException ooce) { ooce.printStackTrace(); }
</pre> </pre>
<p>Get the instances of "Estudiantes":</p> <p>Get the instances of "Estudiantes":</p>
<pre> <pre>
OWLClass estud = manager.getOWLDataFactory().getOWLClass( URI.create( "http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#Estudiante" ) ); // get the instances of a class
OWLClass person = manager.getOWLDataFactory().getOWLClass( URI.create( "http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#Person" ) ); OWLClass estud = manager.getOWLDataFactory().getOWLClass( IRI.create( "http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#Estudiante" ) );
OWLClass student = manager.getOWLDataFactory().getOWLClass( URI.create( "http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#Student" ) ); OWLClass person = manager.getOWLDataFactory().getOWLClass( IRI.create( "http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#Person" ) );
Set instances = reasoner.getIndividuals( estud, false ); OWLClass student = manager.getOWLDataFactory().getOWLClass( IRI.create( "http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#Student" ) );
System.err.println("Pellet(Merged): There are "+instances.size()+" students "+estud.getURI()); Set<OWLNamedIndividual> instances = reasoner.getInstances( estud, false ).getFlattened();
System.err.println("Pellet(Merged): There are "+instances.size()+" students "+clname(estud));
</pre> </pre>
<p>Some subsumption tests:</p> <p>Some subsumption tests:</p>
<pre> <pre>
testPelletSubClass( manager, reasoner, estud, person ); testPelletSubClass( manager, reasoner, estud, person );
testPelletSubClass( manager, reasoner, estud, student ); testPelletSubClass( manager, reasoner, estud, student );
</pre> </pre>
<p>Such that:</p> <p>Such that:</p>
<pre> <pre>
public void testPelletSubClass( OWLOntologyManager manager, Reasoner reasoner, OWLDescription d1, OWLDescription d2 ) { private String clname( OWLClassExpression cl ) {
OWLAxiom axiom = manager.getOWLDataFactory().getOWLSubClassAxiom( d1, d2 ); return cl.asOWLClass().getIRI().getFragment();
boolean isit = reasoner.isEntailed( axiom ); }
if ( isit ) {
System.out.println( "Pellet(Merged): "+d1+" is subclass of "+d2 ); public void testPelletSubClass( OWLOntologyManager manager, OWLReasoner reasoner, OWLClassExpression d1, OWLClassExpression d2 ) {
} else { OWLAxiom axiom = manager.getOWLDataFactory().getOWLSubClassOfAxiom( d1, d2 );
System.out.println( "Pellet(Merged): "+d1+" is not necessarily subclass of "+d2 ); if ( reasoner.isEntailed( axiom ) ) {
} System.out.println( "Pellet(Merged): "+clname(d1)+" is subclass of "+clname(d2) );
} } else {
System.out.println( "Pellet(Merged): "+clname(d1)+" is not necessarily subclass of "+clname(d2) );
}
}
</pre> </pre>
</div> </div>
<div class="explain" id="qu9"> <div class="explain" id="qu9">
...@@ -382,8 +394,17 @@ ontologies instead of the merged one. ...@@ -382,8 +394,17 @@ ontologies instead of the merged one.
} }
</pre> </pre>
</div> </div>
The results for these execution are, for SPARQL:
The results for these execution are (for Pellet): <pre>
---------------------------------------------------------------------------------------
| fn | ln | t | s |
=======================================================================================
| "Miles" | "Davis" | "JOHANNISBEER RESEARCH" | "Univ.-Prof. Dr. Paolo Carciofo" |
| "Chet" | "Baker" | "University Pie XXIII" | |
| "McCoy" | "Tyner" | "University of Soupaloignon" | "Dr Nanni Girasole" |
...
</pre>
for Pellet:
<pre> <pre>
Pellet(Merged): There are 47 students http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#Estudiante Pellet(Merged): There are 47 students http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#Estudiante
Pellet(Merged): Estudiante is not necessarily subclass of Person Pellet(Merged): Estudiante is not necessarily subclass of Person
......
<rdf:RDF
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<owl:Ontology rdf:about="">
<rdfs:comment>Matched ontologies</rdfs:comment>
<rdfs:comment>Generated by fr.inrialpes.exmo.align.renderer.OWLAxiomsRendererVisitor</rdfs:comment>
<rdfs:comment>method: fr.inrialpes.exmo.align.impl.method.StringDistAlignment</rdfs:comment>
<owl:imports rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl"/>
<owl:imports rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl"/>
</owl:Ontology>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#supervisor">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#phd-advisor"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#city">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#city-of-study"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#affiliation">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#institution"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#topic">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#topics-of-interest"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#firstname">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#first-name"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#lastname">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#name"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#year">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#year-in-phd"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#gender">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#gender"/>
</owl:DatatypeProperty>
<owl:Class rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#Estudiante">
<owl:equivalentClass rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#Student"/>
</owl:Class>
<owl:DatatypeProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology1.owl#country">
<owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/tutorial4/ontology2.owl#country-of-study"/>
</owl:DatatypeProperty>
</rdf:RDF>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment