Here is a small tutorial for the alignment API. Most of the tutorial is based on command-lines invocations. Of course, it is not the natural way to use this API: it is made for being embedded in some application programme and we are working towards implementing an alignment server that can help programmes to use the API remotely. The complete tutorial is also available as a self-contained script.sh or script.bat
A small companion tutorial has been designed for the Alignment Server. It follows, as much as possible, the reasoning of this tutorial but provides input and output through a web browser.
This tutorial has been designed for the Alignment API version 2.4 (it has been updated to work with version 3.2).For running the alignment API, you must have a Java interpreter available. We wil call it java.
Download the last version of the Alignment API from http://gforge.inria.fr/frs/?group_id=117. Unzip it and go to the created directory:
You can check that everything works by only typing:
usage: Procalign [options] URI1 URI2 options are: --impl=className -i classname Use the given alignment implementation. --renderer=className -r className Specifies the alignment renderer --output=filename -o filename Output the alignment in filename --params=filename -p filename Reads parameters from filename --alignment=filename -a filename Start from an XML alignment file --threshold=double -t double Filters the similarities under threshold --cutmethod=hard|perc|prop|best|span -T hard|perc|prop|best|span method for computing the threshold --debug[=n] -d [n] Report debug info at level n -Dparam=value Set parameter --help -h Print this message Alignment API implementation 3.2 ($Id: index.html 742 2008-07-07 23:20:07Z euzenat $)
The above command outputs the command line usage of the Procalign class. We do not detail it here, this tutorial will present it entirelly.
You can modify the Alignment API and its implementation. In this tutorial, we will simply learn how to use it.
You will then go to the tutorial directory by doing:
You can clean up previous trials by:
The goal of this tutorial is only to help you realize the possibilities of the Alignment API and implementation. It can be played by invoking each command line from the command-line interpreter. In this example we use the tcsh syntax but the main specific syntax is the first one:
which puts in variable $CWD the name of the current directory.
Your mission, if you accept it, will be to find the best alignment between two bibliographic ontologies. They can be seen here:
These two ontologies have been used for a few years in the Ontology Alignment Evaluation Initiative.
For demonstrating the use of our implementation of the Alignment API, we implemented a particular processor (fr.inrialpes.exmo.align.util.Procalign) which:
Let's try to match these two ontologies:
The result is displayed on the standard output. Since the output is too long we send it to a file by using the -o switch:
Additional options are available:
Hence, it is possible to display the alignment in HTML by using the adequate renderer:
See the output in RDF/XML or HTML.
The result is expressed in the Alignment format. This format, in RDF/XML, is made of a header containing "metadata" about the alignment:
<?xml version='1.0' encoding='utf-8' standalone='no'?> <rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:xsd='http://www.w3.org/2001/XMLSchema#' xmlns:align='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'> <Alignment> <xml>yes</xml> <level>0</level> <type>**</type> <method>fr.inrialpes.exmo.align.impl.method.StringDistAlignment</method> <time>18</time> <onto1> <Ontology rdf:about="http://alignapi.gforge.inria.fr/tutorial/myOnto.owl"> <location>file:///Java/alignapi/html/tutorial/myOnto.owl</location> <formalism> <Formalism align:name="OWL1.0" align:uri="http://www.w3.org/2002/07/owl#"/> </formalism> </Ontology> </onto1> <onto2> <Ontology rdf:about="http://alignapi.gforge.inria.fr/tutorial/edu.mit.visus.bibtex.owl"> <location>file:///Java/alignapi/html/tutorial/edu.mit.visus.bibtex.owl</location> <formalism> <Formalism align:name="OWL1.0" align:uri="http://www.w3.org/2002/07/owl#"/> </formalism> </Ontology> </onto2>
and the corresponding set of correspondences:
<map> <Cell> <entity1 rdf:resource="http://alignapi.gforge.inria.fr/tutorial/myOnto.owl#Article"/> <entity2 rdf:resource="http://alignapi.gforge.inria.fr/tutorial/edu.mit.visus.bibtex.owl#Article"/> <measure rdf:datatype="http://www.w3.org/2001/XMLSchema#float">1.0</measure> <relation>=</relation> </Cell> </map>
each correspondence is made of two references to the aligned entities, the relation holding between the entities (=) and a confidence measure (1.0) in this correspondence. Here, because the default method that has been used for aligning the ontologies is so simple (it only compares the labels of the entities and find that there is a correspondence if their labels are equal), the correspondences are always that simple. But it is too simple so we will use a more sophisticated method based on an edit distance:
See the output in RDF/XML or HTML.
This is achieved by specifying the class of Alignment to be used (through the -i switch) and the distance function to be used (-DstringFunction=levenshteinDistance).
Look at the results: how are they different from before?
We can see that the correspondences now contain confidence factors different than 1.0, they also match strings which are not the same and indeed far more correspondences are available.
We do the same with another measure (smoaDistance):
More work: you can apply other available alignments classes. Look in the ../../src/fr/inrialpes/exmo/align/impl/method directory for more simple alignment methods. Also look in the StringDistances class the possible values for stringFunction (they are the names of methods).
Advanced: You can also look at the instructions for installing WordNet and its Java interface and use a WordNet based distance provided with the API implementation by ($WNDIR is the directory where wordnet is installed):
As can be seen there are some correspondences that do not really make sense. Fortunately, they also have very low confidence values. It is thus interesting to use a threshold for eliminating these values. Let's try a threshold of .33 over the alignment (with the -t switch):
See the output in RDF/XML or HTML.
As expected we have suppressed some of these inaccurate correspondences. But did we also suppressed accurate ones?
This operation has contributed eliminating a number of innacurate correspondences like Journal-Conference or Composite-Conference. However, there remains some unaccurate correspondences like Institution-InCollection and Published-UnPublished!
We can also apply this treatment to other methods available:
See the output in RDF/XML or HTML.
Other manipulations: It is possible to invert an alignment with the following command:
See the output in RDF/XML or HTML. The results is an alignment from the source to the target. Inverting alignment is only the exchange of the order of the elements in the alignment file. This can be useful when you have an alignment of A to B, an alignment from C to B and you want to go from A to C. The solution is then to invert the second alignment and to compose them.
More work: There is another switch (-T) in Procalign that specifies the way a threshold is applied (hard|perc|prop|best|span) the default being "hard". The curious reader can apply these and see the difference in results. How they work is explained in the Alignment API documentation.
More work: Try to play with the thresholds in order to find the best values for levenshteinDistance and smoaDistance.
Once a good alignment has been found, only half of the work has been done. In order to actually use our result it is necessary to transform it into some processable format. For instance, if one wants to merge two OWL ontologies, the alignment can be changed into as set of OWL "bridging" axioms. This is achieved by "rendering" the alignment in OWL (through the -r switch):
The result is a set of OWL assertions of the form:
<owl:Class rdf:about="http://alignapi.gforge.inria.fr/tutorial/myOnto.owl#Techreport"> <owl:equivalentClass rdf:resource="http://alignapi.gforge.inria.fr/tutorial/edu.mit.visus.bibtex.owl#Techreport"/> </owl:Class> <owl:ObjectProperty rdf:about="http://alignapi.gforge.inria.fr/tutorial/myOnto.owl#copyright"> <owl:equivalentProperty rdf:resource="http://alignapi.gforge.inria.fr/tutorial/edu.mit.visus.bibtex.owl#hasCopyright"/> </owl:ObjectProperty>
If one wants to use the alignments only for infering on instances without actually merging the classes, she can generate SWRL rules:
which brings for the same assertions:
<ruleml:imp> <ruleml:_body> <swrl:classAtom> <owllx:Class owllx:name="http://alignapi.gforge.inria.fr/tutorial/myOnto.owl#Techreport"/> <ruleml:var>x</ruleml:var> </swrl:classAtom> </ruleml:_body> <ruleml:_head> <swrlx:classAtom> <owllx:Class owllx:name="http://alignapi.gforge.inria.fr/tutorial/edu.mit.visus.bibtex.owl#Techreport"/> <ruleml:var>x</ruleml:var> </swrl:classAtom> </ruleml:_head> </ruleml:imp> <ruleml:imp> <ruleml:_body> <swrl:individualPropertyAtom swrlx:property="http://alignapi.gforge.inria.fr/tutorial/myOnto.owl#copyright"/> <ruleml:var>x</ruleml:var> <ruleml:var>y</ruleml:var> </swrl:individualPropertyAtom> </ruleml:_body> <ruleml:_head> <swrl:datavaluedPropertyAtom swrlx:property="http://alignapi.gforge.inria.fr/tutorial/edu.mit.visus.bibtex.owl#hasCopyright"/> <ruleml:var>x</ruleml:var> <ruleml:var>y</ruleml:var> </swrl:datavaluedPropertyAtom> </ruleml:_head> </ruleml:imp>
Exchanging data can also be achieved more simply through XSLT transformations which will transform the OWL instance files from one ontology to another:
this transformation can be applied to the data of data.xml:
for giving the results/data.xml file.
We will evaluate alignments by comparing them to some reference alignment which is supposed to express what is expected from an alignment of these two ontologies. The reference alignment is refalign.rdf (or HTML).
For evaluating we use another class than Procalign. It is called EvalAlign we should specify this to java. By default, it computes precision, recall and associated measures. It can be invoked this way:
The first argument is always the reference alignment, the second one is the alignment to be evaluated. The result is given here:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:map="http://www.atl.external.lmco.com/projects/ontology/ResultsOntology.n3#"> <map:output rdf:about=""> <map:reference rdf:resource="file://localhost/JAVA/alignapi/html/tutorial/results/refalign.rdf"> <map:input rdf:resource="file://localhost/JAVA/alignapi/html/tutorial/results/equal.rdf"> <map:precision>1.0</map:precision> <map:recall>0.22916666666666666</map:recall> <fallout>0.0</fallout> <map:fMeasure>0.37288135593220334</map:fMeasure> <map:oMeasure>0.22916666666666666</map:oMeasure> <result>0.22916666666666666</result> </map:output> </rdf:RDF>
Of course, since that method only match objects with the same name, it is accurate, yielding a high precision. However, it has poor recall.
We can now evaluate the edit distance. What to expect from the evaluation of this alignment?
Since it returns more correspondences by loosening the constraints for being a correspondence, it is expected that the recall will increase at the expense of precision.
We can see the results of:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:map="http://www.atl.external.lmco.com/projects/ontology/ResultsOntology.n3#"> <map:output rdf:about=""> <map:reference rdf:resource="file://localhost/JAVA/alignapi/html/tutorial/results/refalign.rdf"> <map:input rdf:resource="file://localhost/JAVA/alignapi/html/tutorial/results/levenshtein33.rdf"> <map:precision>0.6811594202898551</map:precision> <map:recall>0.9791666666666666</map:recall> <fallout>0.3188405797101449</fallout> <map:fMeasure>0.8034188034188035</map:fMeasure> <map:oMeasure>0.5208333333333333</map:oMeasure> <result>1.4374999999999998</result> </map:output> </rdf:RDF>
It is possible to summarize these results by comparing them to each others. This can be achieved by the GroupEval class. This class can output several formats (by default html) and takes all the alignments in the subdirectories of the current directory. Here we only have the results directory:
The results are displayed in the results/eval.html file whose main content is the table:
algo | refalign | equal | SMOA | SMOA5 | levenshtein | levenshtein33 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
test | Prec. | Rec. | FMeas. | Prec. | Rec. | FMeas. | Prec. | Rec. | FMeas. | Prec. | Rec. | FMeas. | Prec. | Rec. | FMeas. | Prec. | Rec. | FMeas. |
results | 1.00 | 1.00 | 1.00 | 1.00 | 0.23 | 0.37 | 0.55 | 0.96 | 0.70 | 0.69 | 0.96 | 0.80 | 0.53 | 1.00 | 0.69 | 0.68 | 0.98 | 0.80 |
H-mean | 1.00 | 1.00 | 1.00 | 1.00 | 0.23 | 0.37 | 0.55 | 0.96 | 0.70 | 0.69 | 0.96 | 0.80 | 0.53 | 1.00 | 0.69 | 0.68 | 0.98 | 0.80 |
More work: As you can see, the PRecEvaluator does not only provide precision and recall but also provides F-measure. F-measure is usually used as an "absolute" trade-off between precision and recall (i.e., the optimum F-measure is considered the best precision and recall). Can you establish this point for SMOA and levenshtein and tell which algorithm is more adapted?
Of course, the goal of this API is not to be used at the command line level (even if it can be very useful). So if you are ready for it, you can develop in Java your own application that takes advantage of the API.
A skeleton of program using the Alignment API is Skeleton.java. It can be compiled by invoking:
and run by:
Now considering the API (that can be consulted through its thin Javadoc for instance), can you modify the Skeleton program in order for it performs the following:
Of course, you can do it progressively.
Do you want to see a possible solution?
The main piece of code in Skeleton.java is replaced by:
// Run two different alignment methods (e.g., ngram distance and smoa) AlignmentProcess a1 = new StringDistAlignment(); a1.init( onto1, onto2 ); params.setParameter("stringFunction","smoaDistance"); a1.align( (Alignment)null, params ); AlignmentProcess a2 = new StringDistAlignment(); a2.init( onto1, onto2 ); params = new BasicParameters(); params.setParameter("stringFunction","ngramDistance"); a2.align( (Alignment)null, params ); // Merge the two results. ((BasicAlignment)a1).ingest(a2); // Threshold at various thresholds // Evaluate them against the references // and choose the one with the best F-Measure AlignmentParser aparser = new AlignmentParser(0); Alignment reference = aparser.parse( "file://"+(new File ( "refalign.rdf" ) . getAbsolutePath()) ); Evaluator evaluator = new PRecEvaluator( reference, a1 ); double best = 0.; Alignment result = null; for ( int i = 0; i <= 10 ; i = i+2 ){ a1.cut( ((double)i)/10 ); evaluator.eval( new BasicParameters() ); System.err.println("Threshold "+(((double)i)/10)+" : "+((PRecEvaluator)evaluator).getFmeasure()); if ( ((PRecEvaluator)evaluator).getFmeasure() > best ) { result = (BasicAlignment)((BasicAlignment)a1).clone(); best = ((PRecEvaluator)evaluator).getFmeasure(); } } // Displays it as SWRL Rules PrintWriter writer = new PrintWriter ( new BufferedWriter( new OutputStreamWriter( System.out, "UTF-8" )), true); AlignmentVisitor renderer = new SWRLRendererVisitor(writer); result.render(renderer); writer.flush(); writer.close();
A full working solution is MyApp.java.
More work: Can you add a switch like the -i switch of Procalign so that the main class of the application can be passed at commant-line.
Advanced: You can develop a specialized matching algorithm by subclassing the Java programs provided in the Alignment API implementation (like BasicAlignment or DistanceAlignment).
Advanced: What about writing an editor for the alignment API?
More info: http://alignapi.gforge.inria.fr
The format of this tutorial has been shamelessly borrowed from Sean Bechhofer's OWL tutorial.
http://alignapi.gforge.inria.fr/tutorial/
$Id: index.html 742 2008-07-07 23:20:07Z euzenat $