Mentions légales du service

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

- Added working tutorial2

parent b3b5ee38
No related branches found
No related tags found
No related merge requests found
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
change your code; minor release numbers bring bug fixes and new change your code; minor release numbers bring bug fixes and new
functionnalities but should not require change in existing code.</p> functionnalities but should not require change in existing code.</p>
<h2>Plan for release 4 (you can comment)</h2> <h2>Plan for release 5 (you can comment)</h2>
<p> <p>
The next major release, release 4, is now in sight due to various The next major release, release 5, is now in sight due to various
constraints and needs that have arousen in the past months. Here are constraints and needs that have arousen in the past months. Here are
the main ruptures that will appear: the main ruptures that will appear:
<ul compact="1"> <ul compact="1">
...@@ -27,25 +27,16 @@ the main ruptures that will appear: ...@@ -27,25 +27,16 @@ the main ruptures that will appear:
will provide the opportunity to define everyone owns relation (and will provide the opportunity to define everyone owns relation (and
generalise the use of relation algebras). (api/impl)</li> generalise the use of relation algebras). (api/impl)</li>
<li>The <tt>onto</tt> package will be fully externalised from the <li>The <tt>onto</tt> package will be fully externalised from the
Alignment API. This means in particular (a) the full disappearance Alignment API. This means in particular (a) virtualisation of the Ontology
of the the <tt>OWLAPICell</tt> and <tt>OWLAPIAlignment</tt> support from OMWGAlignments which are currently based on Jena, (b)
deprecated since version 3.3, (b) virtualisation of the Ontology
support from OMWGAlignments which are currently based on Jena, (c)
release of separated subpackages offering OWL API 1.0, OWL API 2.0, release of separated subpackages offering OWL API 1.0, OWL API 2.0,
Jena 2.5, OLGraph and SKOS. (onto)</li> Jena 2.5, and SKOS. (onto)</li>
<li>Creation of a different project, OntoSim, for supporting distances
and similarities across ontologies. This project will adopt several
parts of the current implementation part. It will have no impact on
the API.</li>
</ul> </ul>
Other less radical changes include: Other less radical changes include:
<ul compact="1"> <ul compact="1">
<li>Replacement of <tt>Parameters</tt> by Java <tt>Property</tt> (api/impl)</li>
<li>Implementation of <tt>Relation</tt> and <tt>Confidence</tt> interfaces </li> <li>Implementation of <tt>Relation</tt> and <tt>Confidence</tt> interfaces </li>
<li>Implement <tt>onto</tt> support in database store (server)</li> <li>Implement <tt>onto</tt> support in database store (server)</li>
<!--li>Move <tt>OLgraphs</tt> as HeavyLoadedOntology (onto)</li--> <!--li>Move <tt>OLgraphs</tt> as HeavyLoadedOntology (onto)</li-->
<li>Integrate OWMG as part of the Alignment API code (impl)</li>
<li>Implement database store for OMWG Language (server)</li>
</ul> </ul>
Currently the development and maintainance of 3 versions continue. Currently the development and maintainance of 3 versions continue.
</p> </p>
...@@ -60,6 +51,8 @@ Currently the development and maintainance of 3 versions continue. ...@@ -60,6 +51,8 @@ Currently the development and maintainance of 3 versions continue.
<li>Improve HTML interface layout and usability (server)</li> <li>Improve HTML interface layout and usability (server)</li>
<li>Implement metadata edition (server)</li> <li>Implement metadata edition (server)</li>
<li>Implement correspondence selection (server)</li> <li>Implement correspondence selection (server)</li>
<li>Implement semantic precision and recall (impl)</li>
<li>Implement fully relaxed precision and recall (impl)</li>
<li>Render alignments as module descriptions (impl)</li> <li>Render alignments as module descriptions (impl)</li>
<li>Implement extensive evaluation framework (impl)</li> <li>Implement extensive evaluation framework (impl)</li>
<li>Implement debug options with log4j</li> <li>Implement debug options with log4j</li>
...@@ -67,16 +60,21 @@ Currently the development and maintainance of 3 versions continue. ...@@ -67,16 +60,21 @@ Currently the development and maintainance of 3 versions continue.
<li>Add more tests</li> <li>Add more tests</li>
</ul></p> </ul></p>
<h2>Next version (3.7: Rouquine carm&eacute;lite)</h2> <h2>Next version (4.0: Rouquine carm&eacute;lite)</h2>
<p> <p>
This version under development is planned for next September. It is This version under development is planned for next September. It is
likely to include: likely to include:
<ul> <ul>
<li>Integration of OMWG alignments</li>
<li>Migration to OWL API 2 as the default Ontology implementation</li>
<li>Separation from <a href="http://ontosim.gforge.inria.fr">OntoSim</a></li>
<li>Integrate some basic reasoning.</li> <li>Integrate some basic reasoning.</li>
<li>Implementing semantic precision and recall /bug (impl).</li>
<li>Added a parameter to the OWLAxiomsRenderer so that it could render
heterogeneous axioms, like Class sameAs Property (impl).</li>
<li>Bug in triming, maybe leaves one item to much (impl)</li>
<li>Integration of OMWG alignments (impl)</li>
<li>Replacement of <tt>Parameters</tt> by Java <tt>Property</tt> (api/impl)</li>
<li>Implement database store for OMWG Language (server)</li>
<li>Addition of advanced tutorial (doc)</li>
</ul> </ul>
</p> </p>
...@@ -88,9 +86,24 @@ likely to include: ...@@ -88,9 +86,24 @@ likely to include:
<p> <p>
<ul compact="1"> <ul compact="1">
<li>Separated the Alignment API from <a href="http://ontosim.gforge.inria.fr">OntoSim</a> (impl/ling)</li>
<li>Reintegrated <tt>JWNLAlignment</tt> in implementation (procalign)</li>
<li>Migrated to OWL API 2 as the default Ontology implementation (onto)</li>
<li>Lifted OWL API 2 as <tt>HeavyLoadedOntology</tt> (onto)</li>
<li>Added computation of MAP (Mean Average Precision)
in <tt>PRGraphEvaluator</tt> (impl).</li>
<li>Added pretty-printing of names in server (server)</li> <li>Added pretty-printing of names in server (server)</li>
<li>Added initialisation through initial alignment
in <tt>MatrixMeasure</tt> (impl)</li>
<li>Suppressed of the <tt>OWLAPICell</tt> and <tt>OWLAPIAlignment</tt>
(deprecated since version 3.3) (impl)</li>
<li>Reorganised the lib directory hierarchically (build)</li> <li>Reorganised the lib directory hierarchically (build)</li>
<li>Corrected a bug when the server is launched without -S (server)</li> <li>Corrected a bug when the server is launched without -S
(server)</li>
<li>Corrected a bug in retrieving alignments from ontologies when the
two ontologies are the same (server)</li>
<li>Corrected a bug when <tt>StringDistAignment<tt> fail to raise
exception when bad method given (impl)</tt>
<!--li>Suppressed the capability to export alignments in WSML (impl/omwg)</li--> <!--li>Suppressed the capability to export alignments in WSML (impl/omwg)</li-->
</ul> </ul>
</p> </p>
......
File added
...@@ -43,6 +43,7 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser; ...@@ -43,6 +43,7 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser;
// Jena // Jena
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
...@@ -50,7 +51,14 @@ import com.hp.hpl.jena.query.ResultSetFormatter; ...@@ -50,7 +51,14 @@ 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;
// Pellet // Pellet and OWL API
import org.mindswap.pellet.owlapi.Reasoner;
import org.semanticweb.owl.model.OWLOntologyManager;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyCreationException;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLAxiom;
import org.semanticweb.owl.apibinding.OWLManager;
// IDDL // IDDL
import fr.inrialpes.exmo.iddl.IDDLReasoner; import fr.inrialpes.exmo.iddl.IDDLReasoner;
...@@ -78,6 +86,7 @@ import javax.xml.xpath.XPathExpressionException; ...@@ -78,6 +86,7 @@ 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.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.BufferedWriter; import java.io.BufferedWriter;
...@@ -101,7 +110,7 @@ import java.net.URISyntaxException; ...@@ -101,7 +110,7 @@ import java.net.URISyntaxException;
/** /**
* MyApp * MyApp
* *
* Takes two files as arguments and align them. * Reconcile two ontologies in various ways
*/ */
public class MyApp { public class MyApp {
...@@ -117,9 +126,12 @@ public class MyApp { ...@@ -117,9 +126,12 @@ public class MyApp {
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/tutorial/edu.mit.visus.bibtex.owl"; //String u1 = "http://alignapi.gforge.inria.fr/tutorial2/ontology1.owl";
// String u2 = "http://alignapi.gforge.inria.fr/tutorial/myOnto.owl"; //String u2 = "http://alignapi.gforge.inria.fr/tutorial2/ontology2.owl";
String u1 = "file:ontology1.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";
Parameters params = new BasicParameters(); Parameters params = new BasicParameters();
try { try {
uri1 = new URI( u1 ); uri1 = new URI( u1 );
...@@ -127,77 +139,89 @@ public class MyApp { ...@@ -127,77 +139,89 @@ public class MyApp {
} catch (URISyntaxException use) { use.printStackTrace(); } } catch (URISyntaxException use) { use.printStackTrace(); }
// ***** First exercise: matching ***** // ***** First exercise: matching *****
// 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
String found = getFromURLString( RESTServ+"find?onto1="+u1+"&onto2="+u2, false ); String found = getFromURLString( RESTServ+"find?onto1="+u1+"&onto2="+u2, false );
// 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 );
// Alternative: match the ontologies from the server // (Sol3) Match the ontologies on the server
if ( alset.getLength() == -1 ) { if ( alset.getLength() == 0 ) {
// call for matching
// * tested (must add force = true) // * tested (must add force = true)
//String match = getFromURLString( RESTServ+"match?onto1="+u1+"&onto2="+u2+"&method="+method+"&pretty="+myId+"&action=Match", true ); //String match = getFromURLString( RESTServ+"match?onto1="+u1+"&onto2="+u2+"&method="+method+"&pretty="+myId+"&action=Match", true );
// This returns a URI // This returns a URI
} }
// Ask it if ( alset.getLength() > 0 ) {
String alid = alset.item(0).getNodeValue(); // Ask it
found = getFromURLString( RESTServ+"retrieve?method=fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor&id="+alid, false ); String alid = alset.item(0).getNodeValue();
alset = extractFromResult( found, "//retrieveResponse/result/*[1]",true ); found = getFromURLString( RESTServ+"retrieve?method=fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor&id="+alid, false );
alset = extractFromResult( found, "//retrieveResponse/result/*[1]",true );
// This code is heavy as hell // This code is heavy as hell
String xmlString = null; String xmlString = null;
try { try {
// Set up the output transformer // Set up the output transformer
TransformerFactory transfac = TransformerFactory.newInstance(); TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer(); Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes");
// Print the DOM node // Print the DOM node
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
DOMSource source = new DOMSource( alset.item(0) ); DOMSource source = new DOMSource( alset.item(0) );
trans.transform(source, new StreamResult(sw)); trans.transform(source, new StreamResult(sw));
xmlString = sw.toString(); xmlString = sw.toString();
//System.out.println(xmlString);
//System.out.println(xmlString); } catch (TransformerException e) {
} catch (TransformerException e) { e.printStackTrace();
e.printStackTrace(); }
}
// Parse it (better passing to the SAXHandler) // parse it as an alignment
try { // (better passing to the SAXHandler)
AlignmentParser aparser = new AlignmentParser(0); try {
Alignment alu = aparser.parseString( xmlString ); AlignmentParser aparser = new AlignmentParser(0);
al = ObjectAlignment.toObjectAlignment((URIAlignment)alu); Alignment alu = aparser.parseString( xmlString );
} catch (ParserConfigurationException pce) { al = ObjectAlignment.toObjectAlignment((URIAlignment)alu);
pce.printStackTrace(); } catch (ParserConfigurationException pce) {
} catch (SAXException saxe) { pce.printStackTrace();
saxe.printStackTrace(); } catch (SAXException saxe) {
} catch (IOException ioe) { saxe.printStackTrace();
ioe.printStackTrace(); } catch (IOException ioe) {
} catch (AlignmentException ae) { ioe.printStackTrace();
ae.printStackTrace(); } catch (AlignmentException ae) {
ae.printStackTrace();
}
} }
// (Sol2) Match the ontologies with a local algorithm
if ( al == null ){ // Unfortunatelly no alignment was available if ( al == null ){ // Unfortunatelly no alignment was available
// Match the ontologies with a local algorithm
AlignmentProcess ap = new StringDistAlignment(); AlignmentProcess ap = new StringDistAlignment();
try { try {
ap.init( uri1, uri2 ); ap.init( uri1, uri2 );
params.setParameter("stringFunction","smoaDistance"); params.setParameter("stringFunction","smoaDistance");
params.setParameter("noinst","1");
ap.align( (Alignment)null, params ); ap.align( (Alignment)null, params );
al = ap; al = ap;
// Supplementary:
// upload the result on the server
// store it
} catch (AlignmentException ae) { ae.printStackTrace(); } } catch (AlignmentException ae) { ae.printStackTrace(); }
} }
// Alternative: find an intermediate ontology between which there is matching + Compose it! // Alternative: find an intermediate ontology between which there are alignments
// find (basically a graph traversal operation)
// retrieve them
// parse them
// compose them
// ***** Second exercise: merging/transforming ***** // ***** Second exercise: merging/transforming *****
// generate a merged ontology between the ontologies (OWLAxioms) // (Sol1) generate a merged ontology between the ontologies (OWLAxioms)
// @@@@@@@@@@@@@@@@TODO => Set in a file...
PrintWriter writer = null; PrintWriter writer = null;
File merged = new File( "/tmp/myresult.owl" ); File merged = new File( tempOntoFileName );
try { try {
writer = new PrintWriter ( new FileWriter( merged, false ), true ); writer = new PrintWriter ( new FileWriter( merged, false ), true );
AlignmentVisitor renderer = new OWLAxiomsRendererVisitor(writer); AlignmentVisitor renderer = new OWLAxiomsRendererVisitor(writer);
...@@ -215,31 +239,35 @@ public class MyApp { ...@@ -215,31 +239,35 @@ public class MyApp {
} }
} }
// Alternative: import the data from one ontology into the other // (Sol2) import the data from one ontology into the other
// ***** Third exercise: querying ***** // ***** Third exercise: querying/reasoning *****
// Use SPARQL to answer queries // (Sol1) Use SPARQL to answer queries (at the data level)
// @@@@@@@@@@@@@@@@TOTEST
InputStream in = null; InputStream in = null;
QueryExecution qe = null; QueryExecution qe = null;
try { try {
// Open the bloggers RDF graph from the filesystem in = new FileInputStream( merged );
in = new FileInputStream( merged ); //in = new URL("http://alignapi.gforge.inria.fr/tutorial2/ontology1.owl").openStream();
//OntModelSpec.OWL_MEM_RDFS_INF or no arguments to see the difference...
// Create an empty in-memory model and populate it from the graph Model model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF,null);
Model model = ModelFactory.createDefaultModel(); model.read(in,"file:///tmp/myresult.owl");
//Model model = ModelFactory.createMemModelMaker().createModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close(); in.close();
// Create a new query // Create a new query
// Could also be selected by supervisor ???
String queryString = String queryString =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT ?url " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX aa: <http://alignapi.gforge.inria.fr/tutorial2/ontology1.owl#> " +
"SELECT ?fn ?ln ?t ?s " +
//"SELECT ?fn ?ln " +
"WHERE {" + "WHERE {" +
" ?contributor foaf:name \"Jon Foobar\" . " + " ?student rdf:type aa:Estudiante . " +
" ?contributor foaf:weblog ?url . " + " ?student aa:firstname ?fn. " +
" ?student aa:lastname ?ln. " +
"OPTIONAL { ?student aa:affiliation ?t . } " +
"OPTIONAL { ?student aa:supervisor ?s . } " +
" }"; " }";
Query query = QueryFactory.create(queryString); Query query = QueryFactory.create(queryString);
...@@ -260,33 +288,49 @@ public class MyApp { ...@@ -260,33 +288,49 @@ public class MyApp {
} }
// Alternative: Use Pellet to answer queries // Alternative: Use Pellet to answer queries
// @@@@@@@@@@@@@@@@TODO
// ***** Fourth exercise: reasoning ***** // ***** Fourth exercise: reasoning *****
PelletReasoner reasoner = new PelletReasoner();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// should not be a file Reasoner reasoner = new Reasoner( manager );
OWLOntology ontology = manager.loadOntology( merged );
OWLAxiom axiom = df.getOWLSubClassAxiom( headache, pain ); // ontology that will be used
String file = "http://www.mindswap.org/2004/owl/mindswappers";
// Load the ontology
try {
OWLOntology ontology = manager.loadOntology( URI.create( "file://"+tempOntoFileName ) );
reasoner.loadOntology( ontology );
} catch (OWLOntologyCreationException ooce) { ooce.printStackTrace(); }
// get the instances of a class
OWLClass person = manager.getOWLDataFactory().getOWLClass( URI.create( "http://alignapi.gforge.inria.fr/tutorial2/ontology1.owl#Estudiante" ) );
Set instances = reasoner.getIndividuals( person, false );
System.err.println("There are "+instances.size()+" students "+person.getURI());
/*
OWLClass person2 = manager.getOWLDataFactory().getOWLClass( URI.create( "http://alignapi.gforge.inria.fr/tutorial2/ontology2.owl#Person" ) );
OWLAxiom axiom = manager.getOWLSubClassAxiom( person, person2 );
boolean isit = reasoner.isEntailed( axiom );
*/
/* /*
// test consistency of aligned ontologies // test consistency of aligned ontologies
IDDLReasoner reasoner = new IDDLReasoner( Semantics.DL ); IDDLReasoner reasoner = new IDDLReasoner( Semantics.IDDL );
reasoner.addOntology( uri1 ); reasoner.addOntology( uri1 );
reasoner.addOntology( uri2 ); reasoner.addOntology( uri2 );
reasoner.addAlignment( align1 ); reasoner.addAlignment( al );
// What to do if not consistent? // What to do if not consistent?
if ( reasoner.isConsistent() ) { if ( reasoner.isConsistent() ) {
Alignment al2 = new URIAlignment(); Alignment al2 = new URIAlignment();
al2.init( uri1, uri2 ); try {
al2.init( uri1, uri2 );
// add the cell // add the cell
//al2.addAlignCell( c2.getObject1(), c2.getObject2(), c2.getRelation().getRelation(), 1. ); //al2.addAlignCell( c2.getObject1(), c2.getObject2(), c2.getRelation().getRelation(), 1. );
} catch (AlignmentException ae) { ae.printStackTrace(); }
reasoner.isEntailed( al2 ); reasoner.isEntailed( al2 );
} else { } else {
System.err.println( "your alignment is inconsistent"); System.err.println( "your alignment is inconsistent");
} }
*/ */
//
} }
public String getFromURLString( String u, boolean print ){ public String getFromURLString( String u, boolean print ){
......
/*
* $Id$
*
* Copyright (C) INRIA, 2009
*
* Modifications to the initial code base are copyright of their
* respective authors, or their employers as appropriate. Authorship
* of the modifications may be determined from the ChangeLog placed at
* the end of this file.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
// Alignment API classes
import org.semanticweb.owl.align.Alignment;
import org.semanticweb.owl.align.AlignmentException;
import org.semanticweb.owl.align.AlignmentProcess;
import org.semanticweb.owl.align.AlignmentVisitor;
import org.semanticweb.owl.align.Parameters;
// Alignment API implementation classes
import fr.inrialpes.exmo.align.impl.BasicParameters;
import fr.inrialpes.exmo.align.impl.ObjectAlignment;
import fr.inrialpes.exmo.align.impl.URIAlignment;
import fr.inrialpes.exmo.align.impl.BasicAlignment;
import fr.inrialpes.exmo.align.impl.method.StringDistAlignment;
import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor;
import fr.inrialpes.exmo.align.parser.AlignmentParser;
// Jena
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
// Pellet
// IDDL
import fr.inrialpes.exmo.iddl.IDDLReasoner;
import fr.inrialpes.exmo.iddl.conf.Semantics;
// SAX standard classes
import org.xml.sax.SAXException;
// DOM Standard classes
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathConstants;
// Java standard classes
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.File;
import java.io.FileWriter;
import java.net.URI;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
/**
* MyApp
*
* Reconcile two ontologies in various ways
*/
public class MyApp {
String RESTServ = "http://aserv.inrialpes.fr/rest/";
public static void main( String[] args ) {
new MyApp().run( args );
}
public void run( String[] args ) {
// Setting variables
String myId = "JETest";
Alignment al = null;
URI uri1 = null;
URI uri2 = null;
//String u1 = "http://alignapi.gforge.inria.fr/tutorial2/ontology1.owl";
//String u2 = "http://alignapi.gforge.inria.fr/tutorial2/ontology2.owl";
String u1 = "file:ontology1.owl";
String u2 = "file:ontology2.owl";
String method = "fr.inrialpes.exmo.align.impl.method.StringDistAlignment";
Parameters params = new BasicParameters();
try {
uri1 = new URI( u1 );
uri2 = new URI( u2 );
} catch (URISyntaxException use) { use.printStackTrace(); exit(); }
try {
// ***** First exercise: matching *****
// (Sol1) Try to find an alignment between two ontologies from the server
// ask for it
// retrieve it
// parse it as an alignment
// (Sol2) Match the ontologies with a local algorithm
// match
// (Sol3) Match the ontologies on the server
// call for matching
// retrieve it
// parse it as an alignment
// Alternative: find an intermediate ontology between which there are alignments
// find (basically a graph traversal operation)
// retrieve them
// parse them
// compose them
// Supplementary:
// upload the result on the server
// store it
// ***** Second exercise: merging/transforming *****
// (Sol1) generate a merged ontology between the ontologies (OWLAxioms)
// (Sol2) import the data from one ontology into the other
// ***** Third exercise: querying and reasoning *****
// (Sol1) Use SPARQL to answer queries (at the data level)
// (Sol2) Use Pellet to answer queries (at the ontology level)
} catch (Exception e) { e.printStackTrace(); exit(); }
}
public String getFromURLString( String u, boolean print ){
URL url = null;
String result = "<?xml version='1.0'?>";
try {
url = new URL( u );
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
if (print) System.out.println(inputLine);
result += inputLine;
}
in.close();
}
catch ( MalformedURLException mue ) { mue.printStackTrace(); }
catch ( IOException mue ) { mue.printStackTrace(); }
return result;
}
public NodeList extractFromResult( String found, String path, boolean print ){
Document document = null;
NodeList nodes = null;
try { // Parse the returned string as XML
DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = parser.parse(new ByteArrayInputStream( found.getBytes() ));
} catch ( ParserConfigurationException pce ) { pce.printStackTrace(); }
catch ( SAXException se ) { se.printStackTrace(); }
catch ( IOException ioe ) { ioe.printStackTrace(); }
try { // Apply the Xpath expression
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile( path );
Object result = expr.evaluate( document, XPathConstants.NODESET );
nodes = (NodeList)result;
if ( print ) {
for ( int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}
}
} catch (XPathExpressionException xpee) { xpee.printStackTrace(); }
return nodes;
}
}
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