Mentions légales du service

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

- Fixed #9681 OWL API 3.0 interface is not fully implemented

- Implemented cache cleaning correctly
- ontowrap has been made independent from align (exception)
parent 22b9d794
No related branches found
No related tags found
No related merge requests found
...@@ -25,9 +25,9 @@ import java.util.HashSet; ...@@ -25,9 +25,9 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.Iterator; import java.util.Iterator;
import org.semanticweb.owl.align.AlignmentException;
import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationValue;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLDatatype; import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLLiteral; import org.semanticweb.owlapi.model.OWLLiteral;
...@@ -49,6 +49,7 @@ import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; ...@@ -49,6 +49,7 @@ import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
import fr.inrialpes.exmo.ontowrap.BasicOntology; import fr.inrialpes.exmo.ontowrap.BasicOntology;
import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.OntologyFactory;
import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology;
import fr.inrialpes.exmo.ontowrap.OntowrapException;
public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
HeavyLoadedOntology<OWLOntology> { HeavyLoadedOntology<OWLOntology> {
...@@ -69,7 +70,7 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements ...@@ -69,7 +70,7 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
return onto.getSignature(); return onto.getSignature();
} }
public Object getEntity(URI u) throws AlignmentException { public Object getEntity(URI u) throws OntowrapException {
// There is better in OWLAPI3: getEntitiesInSignature( IRI ) // There is better in OWLAPI3: getEntitiesInSignature( IRI )
for (OWLEntity e : onto.getSignature()) { for (OWLEntity e : onto.getSignature()) {
if (e.getIRI().toURI().equals(u)) if (e.getIRI().toURI().equals(u))
...@@ -78,73 +79,76 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements ...@@ -78,73 +79,76 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
return null; return null;
} }
protected Set<String> getEntityAnnotations(Object o, URI type, String lang) { /**
OWLEntity ent = (OWLEntity) o; * type and lang can be null
Set<String> annots = new HashSet<String>(); */
// JE: total mess in OWL API 3 protected Set<String> getEntityAnnotations( Object o, URI type, String lang ) {
/* OWLEntity entity = (OWLEntity) o;
Set<OWLAnnotation> owlAnnots; Set<String> annotations = new HashSet<String>();
if ( type == null ) // JE: This had to be rewritten for OWL API 3. Too bad.
owlAnnots = ent.getAnnotations(onto); for ( OWLAnnotation annot : entity.getAnnotations( onto ) ) {
else OWLAnnotationValue c = annot.getValue();
owlAnnots = ent.getAnnotations( onto, type ); OWLAnnotationProperty p = annot.getProperty();
for (OWLAnnotation annot : owlAnnots) { if ( c instanceof OWLLiteral ) {
OWLLiteral c = annot.getAnnotationValueAsLiteral(); if ( lang == null || ((OWLLiteral)c).hasLang(lang) ) {
if (lang == null || c.asOWLUntypedLiteral().hasLang(lang)) if ( type == null ||
annots.add(c.getLiteral()); ( type.equals(OWLRDFVocabulary.RDFS_LABEL.getURI()) && p.isLabel() ) ||
( type.equals(OWLRDFVocabulary.RDFS_COMMENT.getURI()) && p.isComment() ) )
annotations.add( ((OWLLiteral)c).getLiteral() );
}
}
} }
*/ return annotations;
return annots;
} }
public Set<String> getEntityAnnotations(Object o) throws AlignmentException { public Set<String> getEntityAnnotations(Object o) throws OntowrapException {
return getEntityAnnotations(o, null, null); return getEntityAnnotations(o, null, null);
} }
public Set<String> getEntityComments(Object o, String lang) public Set<String> getEntityComments(Object o, String lang)
throws AlignmentException { throws OntowrapException {
return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_COMMENT.getURI(), lang); return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_COMMENT.getURI(), lang);
} }
public Set<String> getEntityComments(Object o) throws AlignmentException { public Set<String> getEntityComments(Object o) throws OntowrapException {
return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_COMMENT.getURI(), null); return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_COMMENT.getURI(), null);
} }
public String getEntityName(Object o) throws AlignmentException { public String getEntityName( Object o ) throws OntowrapException {
try { try {
// Should try to get the label first // Should try to get the label first
return getFragmentAsLabel( ((OWLEntity) o).getIRI().toURI() ); return getFragmentAsLabel( ((OWLEntity) o).getIRI().toURI() );
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new AlignmentException(o+" is not an entity for "+ onto.getOntologyID().getOntologyIRI().toURI()); throw new OntowrapException(o+" is not an entity for "+ onto.getOntologyID().getOntologyIRI().toURI());
} }
} }
public String getEntityName( Object o, String lang ) throws AlignmentException { public String getEntityName( Object o, String lang ) throws OntowrapException {
// Should first get the label in the language // Should first get the label in the language (but see below)
return getEntityName( o ); return getEntityName( o );
} }
public Set<String> getEntityNames(Object o, String lang) throws AlignmentException { public Set<String> getEntityNames(Object o, String lang) throws OntowrapException {
return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), lang); return getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), lang);
} }
public Set<String> getEntityNames(Object o) throws AlignmentException { public Set<String> getEntityNames(Object o) throws OntowrapException {
Set<String> result = getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), null); Set<String> result = getEntityAnnotations(o, OWLRDFVocabulary.RDFS_LABEL.getURI(), null);
if ( result == null ) { if ( result == null ) {
String label = getEntityName( o ); String label = getEntityName( o );
if ( label != null ) { if ( label != null ) {
result = new HashSet(); result = new HashSet<String>();
result.add( label ); result.add( label );
} }
} }
return result; return result;
} }
public URI getEntityURI(Object o) throws AlignmentException { public URI getEntityURI(Object o) throws OntowrapException {
try { try {
return ((OWLEntity) o).getIRI().toURI(); return ((OWLEntity) o).getIRI().toURI();
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new AlignmentException(o + " is not an entity for " throw new OntowrapException(o + " is not an entity for "
+onto.getOntologyID().getOntologyIRI().toURI()); +onto.getOntologyID().getOntologyIRI().toURI());
// + onto.getURI()); // + onto.getURI());
} }
...@@ -325,7 +329,7 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements ...@@ -325,7 +329,7 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
return supers; return supers;
}; };
public Set<Object> getRange( Object p, int asserted ){ public Set<Object> getRange( Object p, int asserted ){
Set resultSet = new HashSet(); Set<Object> resultSet = new HashSet<Object>();
for ( Object ent : ((OWLProperty)p).getRanges( getOntology() ) ){ for ( Object ent : ((OWLProperty)p).getRanges( getOntology() ) ){
// Not correct // Not correct
// Could be something else than class // Could be something else than class
...@@ -336,7 +340,7 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements ...@@ -336,7 +340,7 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
return resultSet; return resultSet;
}; };
public Set<Object> getDomain( Object p, int asserted ){ public Set<Object> getDomain( Object p, int asserted ){
Set resultSet = new HashSet(); Set<Object> resultSet = new HashSet<Object>();
for ( Object ent : ((OWLProperty)p).getDomains( getOntology() ) ){ for ( Object ent : ((OWLProperty)p).getDomains( getOntology() ) ){
// Not correct // Not correct
// Could be something else than class // Could be something else than class
...@@ -371,8 +375,8 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements ...@@ -371,8 +375,8 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
* Inherits all properties of a class * Inherits all properties of a class
*/ */
private Set<Object> getInheritedProperties( OWLClass cl ) { private Set<Object> getInheritedProperties( OWLClass cl ) {
Set resultSet = new HashSet(); Set<Object> resultSet = new HashSet<Object>();
try { getProperties( cl, resultSet, new HashSet()); } try { getProperties( cl, resultSet, new HashSet<Object>()); }
catch (OWLException ex) {}; catch (OWLException ex) {};
return resultSet; return resultSet;
} }
...@@ -413,7 +417,10 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements ...@@ -413,7 +417,10 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements
// JD: it is hazardous... // JD: it is hazardous...
public void unload() { public void unload() {
onto = null; if ( onto != null ) {
onto.getOWLOntologyManager().removeOntology( onto );
onto = null;
}
} }
......
...@@ -33,6 +33,8 @@ import fr.inrialpes.exmo.ontowrap.BasicOntology; ...@@ -33,6 +33,8 @@ import fr.inrialpes.exmo.ontowrap.BasicOntology;
import fr.inrialpes.exmo.ontowrap.LoadedOntology; import fr.inrialpes.exmo.ontowrap.LoadedOntology;
import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology;
import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.OntologyFactory;
import fr.inrialpes.exmo.ontowrap.OntowrapException;
import fr.inrialpes.exmo.ontowrap.owlapi10.OWLAPIOntology; import fr.inrialpes.exmo.ontowrap.owlapi10.OWLAPIOntology;
import fr.inrialpes.exmo.ontowrap.owlapi10.OWLAPIOntologyFactory; import fr.inrialpes.exmo.ontowrap.owlapi10.OWLAPIOntologyFactory;
import fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3Ontology; import fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3Ontology;
...@@ -79,7 +81,7 @@ public class OntoTest { ...@@ -79,7 +81,7 @@ public class OntoTest {
assertEquals( factory, OntologyFactory.getFactory() ); assertEquals( factory, OntologyFactory.getFactory() );
} }
@Test(expectedExceptions = AlignmentException.class, groups = { "full", "onto", "raw" }, dependsOnMethods = {"factoryTest"}) @Test(expectedExceptions = OntowrapException.class, groups = { "full", "onto", "raw" }, dependsOnMethods = {"factoryTest"})
public void concreteFactoryTest() throws Exception { public void concreteFactoryTest() throws Exception {
// not really useful // not really useful
factory.newOntology( null ); factory.newOntology( null );
......
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