Mentions légales du service

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

- improved implementation of the algebraic manipulation

parent ba79ea2f
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,7 @@ with a warning: ...@@ -87,6 +87,7 @@ with a warning:
<li>Added httpcore library necessary for tutorial4 (tutorial/lib)</li> <li>Added httpcore library necessary for tutorial4 (tutorial/lib)</li>
<li>Added extensions to <tt>BasicOntologyNetwork</tt> (impl)</li> <li>Added extensions to <tt>BasicOntologyNetwork</tt> (impl)</li>
<li>Added read/write to <tt>BasicOntologyNetwork</tt> (impl)</li> <li>Added read/write to <tt>BasicOntologyNetwork</tt> (impl)</li>
<li>Added algebraic manipulation of <tt>BasicOntologyNetwork</tt> (impl)</li>
<li>Added storage support for networks of ontologies (serv)</li> <li>Added storage support for networks of ontologies (serv)</li>
<li>Genericised storage <tt>Cache</tt> and implemented <tt>VolatilCache</tt> which contains a full Cache implementation without storage (serv)</li> <li>Genericised storage <tt>Cache</tt> and implemented <tt>VolatilCache</tt> which contains a full Cache implementation without storage (serv)</li>
</ul></p> </ul></p>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
package fr.inrialpes.exmo.align.impl; package fr.inrialpes.exmo.align.impl;
import java.lang.Cloneable; //import java.lang.Cloneable; // JE: what happens when I do a clone() ??
import java.lang.Iterable; import java.lang.Iterable;
import java.util.Collections; import java.util.Collections;
import java.util.Collection; import java.util.Collection;
...@@ -135,13 +135,44 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -135,13 +135,44 @@ public class BasicOntologyNetwork implements OntologyNetwork {
return ontologies.keySet(); // ?? return ontologies.keySet(); // ??
}; };
public Set<Alignment> getTargetingAlignments( URI onto ){ public Set<Alignment> getTargetingAlignments( URI onto ){
if (!ontologies.containsKey(onto)) return Collections.emptySet(); OntologyTriple ot = ontologies.get( onto );
return ontologies.get( onto ).targettingAlignments; if ( ot == null ) return Collections.emptySet();
}; return ot.targettingAlignments;
}
public Set<Alignment> getSourceAlignments( URI onto ){ public Set<Alignment> getSourceAlignments( URI onto ){
if (!ontologies.containsKey(onto)) return Collections.emptySet(); OntologyTriple ot = ontologies.get( onto );
return ontologies.get( onto ).sourceAlignments; if ( ot == null ) return Collections.emptySet();
}; return ot.sourceAlignments;
}
/*
The one below is more efficient (as soon as the structure is maintained)
Thus structure is not necessary... it should have been put rather in ontoTriple!
public Set<Alignment> getAlignments( URI onto1, URI onto2 ){
OntologyTriple ot1 = ontologies.get( onto1 );
OntologyTriple ot2 = ontologies.get( onto2 );
if ( ot1 == null || ot2 == null ) return Collections.emptySet();
return intersectAlignments( ot1.sourceAlignments, ot2.targettingAlignments );
}
*/
public Set<Alignment> getAlignments(URI srcOnto, URI dstOnto) {
Map<URI,Set<Alignment>> m = onto2Align.get(srcOnto);
if (m!=null) {
Set<Alignment> aligns = m.get(dstOnto);
if (aligns!=null) return Collections.unmodifiableSet(aligns);
}
return Collections.emptySet();
}
/**
* Clone?
*/
//public BasicOntologyNetwork clone() {}
/**
* Normalizes an ontology network for it to have exactly one alignment between each pair of ontologies.
* Creates a new network
*/
public void invert() throws AlignmentException { public void invert() throws AlignmentException {
HashSet<Alignment> newal = new HashSet<Alignment>(); HashSet<Alignment> newal = new HashSet<Alignment>();
for ( Alignment al : alignments ) newal.add( al.inverse() ); for ( Alignment al : alignments ) newal.add( al.inverse() );
...@@ -155,7 +186,7 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -155,7 +186,7 @@ public class BasicOntologyNetwork implements OntologyNetwork {
public void normalize() throws AlignmentException { public void normalize() throws AlignmentException {
for ( OntologyTriple ot1 : ontologies.values() ) { for ( OntologyTriple ot1 : ontologies.values() ) {
for ( OntologyTriple ot2 : ontologies.values() ) { for ( OntologyTriple ot2 : ontologies.values() ) {
Set<Alignment> als = intersect( ot1.sourceAlignments, ot2.targettingAlignments ); Set<Alignment> als = intersectAlignments( ot1.sourceAlignments, ot2.targettingAlignments );
// Suppress them // Suppress them
if ( als.size() != 1 ) { if ( als.size() != 1 ) {
Alignment norm = normalizeAlignmentSet( als, ot1.onto, ot2.onto ); Alignment norm = normalizeAlignmentSet( als, ot1.onto, ot2.onto );
...@@ -169,7 +200,7 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -169,7 +200,7 @@ public class BasicOntologyNetwork implements OntologyNetwork {
} }
} }
protected Alignment normalizeAlignmentSet( Set<Alignment> als, URI onto1, URI onto2 ) { protected static Alignment normalizeAlignmentSet( Set<Alignment> als, URI onto1, URI onto2 ) throws AlignmentException {
Alignment result = null; Alignment result = null;
if ( als.size() == 0 ) { // If no element, create new if ( als.size() == 0 ) { // If no element, create new
result = new BasicAlignment(); result = new BasicAlignment();
...@@ -189,7 +220,7 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -189,7 +220,7 @@ public class BasicOntologyNetwork implements OntologyNetwork {
return result; return result;
} }
protected Set<Alignment> intersect( Set<Alignment> s1, Set<Alignment> s2 ) { protected static Set<Alignment> intersectAlignments( Set<Alignment> s1, Set<Alignment> s2 ) {
Set<Alignment> result = new HashSet<Alignment>(); Set<Alignment> result = new HashSet<Alignment>();
for ( Alignment x : s1 ) { for ( Alignment x : s1 ) {
if ( s2.contains( x ) ) result.add( x ); if ( s2.contains( x ) ) result.add( x );
...@@ -201,13 +232,16 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -201,13 +232,16 @@ public class BasicOntologyNetwork implements OntologyNetwork {
* Match ontologies in a network, using existing ontologies as input... * Match ontologies in a network, using existing ontologies as input...
* Modifies the network * Modifies the network
* TODO * TODO
* Alternative definition!
* public void match( Class<? extends AlignmentProcess> method, boolean reflexive ) throws AlignmentException {
}
*/ */
public void match( String method, boolean reflexive, boolean symmetric) throws AlignmentException { public void match( String method, boolean reflexive, boolean symmetric) throws AlignmentException {
for ( OntologyTriple ot1 : ontologies.values() ) { for ( OntologyTriple ot1 : ontologies.values() ) {
for ( OntologyTriple ot2 : ontologies.values() ) { for ( OntologyTriple ot2 : ontologies.values() ) {
if ( ( ot1 == ot2 && reflexive ) if ( ( ot1 == ot2 && reflexive )
|| symmetric ) { || symmetric ) {
Set<Alignment> als = intersect( ot1.sourceAlignments, ot2.targettingAlignments ); Set<Alignment> als = intersectAlignments( ot1.sourceAlignments, ot2.targettingAlignments );
Alignment init = normalizeAlignmentSet( als, ot1.onto, ot2.onto ); Alignment init = normalizeAlignmentSet( als, ot1.onto, ot2.onto );
for ( Alignment al : als ) { for ( Alignment al : als ) {
remAlignment( al ); remAlignment( al );
...@@ -224,10 +258,20 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -224,10 +258,20 @@ public class BasicOntologyNetwork implements OntologyNetwork {
} }
} }
/**
* Applies a threshold to all alignments in a network
* Modifies the network
*/
public void trim( String method, double threshold ) throws AlignmentException {
for ( Alignment al : alignments ) {
al.cut( method, threshold );
}
}
/** /**
* Intersection of two ontology networks... * Intersection of two ontology networks...
* Creates a new network * Creates a new network
* TODO * TODO: add extensions? i.e., partial clone as BasicAlignment
*/ */
public static BasicOntologyNetwork meet( OntologyNetwork on1, OntologyNetwork on2 ) throws AlignmentException { public static BasicOntologyNetwork meet( OntologyNetwork on1, OntologyNetwork on2 ) throws AlignmentException {
BasicOntologyNetwork result = new BasicOntologyNetwork(); BasicOntologyNetwork result = new BasicOntologyNetwork();
...@@ -242,8 +286,13 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -242,8 +286,13 @@ public class BasicOntologyNetwork implements OntologyNetwork {
for ( URI onto1 : result.getOntologies() ) { for ( URI onto1 : result.getOntologies() ) {
for ( URI onto2 : result.getOntologies() ) { for ( URI onto2 : result.getOntologies() ) {
// Get the alignments from both networks // Get the alignments from both networks
Set<Alignment> als1 = on1.getAlignments( onto1, onto2 );
Set<Alignment> als2 = on2.getAlignments( onto1, onto2 );
// Normalise them (yes because it is join) // Normalise them (yes because it is join)
Alignment init1 = normalizeAlignmentSet( als1, onto1, onto2 );
Alignment init2 = normalizeAlignmentSet( als2, onto1, onto2 );
// Meet them // Meet them
result.addAlignment( init1.meet( init2 ) );
} }
} }
return result; return result;
...@@ -252,25 +301,19 @@ public class BasicOntologyNetwork implements OntologyNetwork { ...@@ -252,25 +301,19 @@ public class BasicOntologyNetwork implements OntologyNetwork {
/** /**
* Union of two ontology networks... * Union of two ontology networks...
* Creates a new network * Creates a new network
* TODO * TODO: same as before
*/ */
public static BasicOntologyNetwork join( OntologyNetwork on1, OntologyNetwork on2 ) throws AlignmentException { public static BasicOntologyNetwork join( OntologyNetwork on1, OntologyNetwork on2 ) throws AlignmentException {
return (BasicOntologyNetwork)null; return (BasicOntologyNetwork)null;
} }
/** /**
* Add alignments only if there is no existing alignments * Difference between two ontology networks...
public void match( Class<? extends AlignmentProcess> method, boolean reflexive ) throws AlignmentException { * Creates a new network
} * TODO: same as before
*/ */
public static BasicOntologyNetwork diff( OntologyNetwork on1, OntologyNetwork on2 ) throws AlignmentException {
public Set<Alignment> getAlignments(URI srcOnto, URI dstOnto) { return (BasicOntologyNetwork)null;
Map<URI,Set<Alignment>> m = onto2Align.get(srcOnto);
if (m!=null) {
Set<Alignment> aligns = m.get(dstOnto);
if (aligns!=null) return Collections.unmodifiableSet(aligns);
}
return Collections.emptySet();
} }
public Collection<String[]> getExtensions(){ return extensions.getValues(); } public Collection<String[]> getExtensions(){ return extensions.getValues(); }
......
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