diff --git a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java index 8d8f5b7110039338ae6600bbab7cc0b1274619a2..f80d48df284b13a7f57a9d6a9bf864d6f1204387 100644 --- a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java @@ -144,13 +144,27 @@ public abstract class OntologyFactory { * Encapsulate an ontology already in the environment * These methods should rather be in a LoadableOntologyFactory */ - public abstract LoadedOntology newOntology( Object onto ) throws OntowrapException; + public abstract LoadedOntology newOntology( Object onto , boolean onlyLocalEntities ) throws OntowrapException; + + public LoadedOntology newOntology( Object onto ) throws OntowrapException { + return newOntology(onto,false); + } + + /** * Load an ontology, cache enabled * These methods should rather be in a LoadableOntologyFactory */ - public abstract LoadedOntology loadOntology( URI uri ) throws OntowrapException; + public LoadedOntology loadOntology( URI uri ) throws OntowrapException { + return loadOntology(uri,true); + } + + /** + * Load an ontology, cache enabled + * These methods should rather be in a LoadableOntologyFactory + */ + public abstract LoadedOntology loadOntology( URI uri , boolean onlyLocalEntities) throws OntowrapException; /** * Load an ontology, cache enabled if true, disabled otherwise diff --git a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java index 1bb6bbcff4337b902c882d9ea52140f3c5126d42..f7bec973b11e4f3cd54b5f17bb0d71efa2240c87 100644 --- a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java @@ -55,8 +55,15 @@ import fr.inrialpes.exmo.ontowrap.util.EntityFilter; public class JENAOntology extends BasicOntology<OntModel> implements HeavyLoadedOntology<OntModel>{ + private boolean onlyLocalEntities=true; // JE: this is not very Java 1.5... // This is because of the version of Jena we use apparently + + + + public JENAOntology(boolean onlyLocalEntities) { + this.onlyLocalEntities=onlyLocalEntities; + } public Object getEntity(URI u) throws OntowrapException { return onto.getOntResource(u.toString()); @@ -205,13 +212,22 @@ public class JENAOntology extends BasicOntology<OntModel> implements HeavyLoaded } }; }*/ + + private <K> Set<K> getFilteredOrNot(Set<K> s) { + if (onlyLocalEntities) + return new EntityFilter<K>(s,this); + else + return s; + } public Set<OntClass> getClasses() { - return new EntityFilter<OntClass>(onto.listNamedClasses().toSet(),this); + + return getFilteredOrNot(onto.listNamedClasses().toSet()); + } public Set<DatatypeProperty> getDataProperties() { - return new EntityFilter<DatatypeProperty>(onto.listDatatypeProperties().toSet(),this); + return getFilteredOrNot(onto.listDatatypeProperties().toSet()); //return getEntitySet(onto.listDatatypeProperties()); } @@ -222,22 +238,21 @@ public class JENAOntology extends BasicOntology<OntModel> implements HeavyLoaded public Set<OntResource> getEntities() { - return new EntityFilter<OntResource>((onto.listAllOntProperties().mapWith( mapProperty ) + return getFilteredOrNot((onto.listAllOntProperties().mapWith( mapProperty ) .andThen(onto.listNamedClasses().mapWith( mapClass )) - .andThen(onto.listIndividuals().mapWith( mapInd )).toSet()), - this); + .andThen(onto.listIndividuals().mapWith( mapInd )).toSet())); } public Set<Individual> getIndividuals() { - return new EntityFilter<Individual>(onto.listIndividuals().toSet(),this); + return getFilteredOrNot(onto.listIndividuals().toSet()); } public Set<ObjectProperty> getObjectProperties() { - return new EntityFilter<ObjectProperty>(onto.listObjectProperties().toSet(),this); + return getFilteredOrNot(onto.listObjectProperties().toSet()); } public Set<OntProperty> getProperties() { - return new EntityFilter<OntProperty>(onto.listAllOntProperties().toSet(),this); + return getFilteredOrNot(onto.listAllOntProperties().toSet()); /*return getEntitySet( onto.listAllOntProperties().filterDrop( new Filter () { public boolean accept( Object o ) { return (o instanceof AnnotationProperty); } }) );*/ @@ -308,7 +323,10 @@ public class JENAOntology extends BasicOntology<OntModel> implements HeavyLoaded public Set<OntProperty> getDataProperties(Object c, int local, int asserted, int named) { return new EntityFilter<OntProperty>( ((OntClass) c).listDeclaredProperties(asserted==OntologyFactory.DIRECT).toSet(),this) { protected boolean isFiltered(OntProperty obj) { - return super.isFiltered(obj) && !obj.isDatatypeProperty(); + if (JENAOntology.this.onlyLocalEntities) + return super.isFiltered(obj) && !obj.isDatatypeProperty(); + else + return !obj.isDatatypeProperty(); } }; @@ -329,12 +347,15 @@ public class JENAOntology extends BasicOntology<OntModel> implements HeavyLoaded public Set<OntProperty> getObjectProperties(Object c, int local, int asserted, int named) { return new EntityFilter<OntProperty>( ((OntClass) c).listDeclaredProperties(asserted==OntologyFactory.DIRECT).toSet(),this) { protected boolean isFiltered( OntProperty obj ) { - return super.isFiltered(obj) && !obj.isObjectProperty(); + if (JENAOntology.this.onlyLocalEntities) + return super.isFiltered(obj) && !obj.isObjectProperty(); + else + return !obj.isObjectProperty(); } }; } public Set<OntProperty> getProperties(Object c, int local, int asserted, int named) { - return new EntityFilter<OntProperty>( ((OntClass) c).listDeclaredProperties(asserted==OntologyFactory.DIRECT).toSet(),this); + return getFilteredOrNot(((OntClass) c).listDeclaredProperties(asserted==OntologyFactory.DIRECT).toSet()); } public Set<? extends OntResource> getRange(Object p, int asserted) { diff --git a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java index 4b6ca350330080b9ade89104b93872864c93703e..08e4286a88bca2bc00b3356b78bd83bb4efc759a 100644 --- a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java @@ -48,9 +48,9 @@ public class JENAOntologyFactory extends OntologyFactory { } catch (URISyntaxException ex) { ex.printStackTrace(); } // should not happen } - public JENAOntology newOntology( Object ontology ) throws OntowrapException { + public JENAOntology newOntology( Object ontology , boolean onlyLocalEntities ) throws OntowrapException { if ( ontology instanceof OntModel ) { - JENAOntology onto = new JENAOntology(); + JENAOntology onto = new JENAOntology(onlyLocalEntities); onto.setFormalism( formalismId ); onto.setFormURI( formalismUri ); onto.setOntology( (OntModel)ontology ); @@ -70,12 +70,14 @@ public class JENAOntologyFactory extends OntologyFactory { } cache.recordOntology( onto.getURI(), onto ); return onto; + } else { throw new OntowrapException( "Argument is not an OntModel: "+ontology ); } + } - public JENAOntology loadOntology( URI uri ) throws OntowrapException { + public JENAOntology loadOntology( URI uri , boolean onlyLocalEntities) throws OntowrapException { JENAOntology onto = null; onto = cache.getOntologyFromURI( uri ); if ( onto != null ) return onto; @@ -84,7 +86,7 @@ public class JENAOntologyFactory extends OntologyFactory { try { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ); m.read(uri.toString()); - onto = new JENAOntology(); + onto = new JENAOntology(onlyLocalEntities); onto.setFile(uri); // to be checked : why several ontologies in a model ??? // If no URI can be extracted from ontology, then we use the physical URI diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java index fc7ee6ea690d7ea36bcd7e80f9796a9248e1bb98..3039bd37c6832156e9fea1a5ae26135e7c6f5db0 100644 --- a/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java @@ -56,7 +56,7 @@ public class OWLAPIOntologyFactory extends OntologyFactory { cache.clear(); } - public OWLAPIOntology newOntology( Object ontology ) throws OntowrapException { + public OWLAPIOntology newOntology( Object ontology, boolean onlyLocalEntities ) throws OntowrapException { if ( ontology instanceof OWLOntology ) { OWLAPIOntology onto = new OWLAPIOntology(); onto.setFormalism( formalismId ); @@ -76,7 +76,7 @@ public class OWLAPIOntologyFactory extends OntologyFactory { } } - public OWLAPIOntology loadOntology( URI uri ) throws OntowrapException { + public OWLAPIOntology loadOntology( URI uri, boolean onlyLocalEntities) throws OntowrapException { OWLAPIOntology onto = null; onto = cache.getOntologyFromURI( uri ); if ( onto != null ) return onto; diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3Ontology.java b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3Ontology.java index fd3041d87399af46be5ceea7a2f6bcec0e460353..99377df67432aa9d906b02774255a1a10f4c54b0 100644 --- a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3Ontology.java +++ b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3Ontology.java @@ -62,25 +62,40 @@ import fr.inrialpes.exmo.ontowrap.util.EntityFilter; public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements HeavyLoadedOntology<OWLOntology> { - public OWLAPI3Ontology() { + private boolean onlyLocalEntities=true; + public OWLAPI3Ontology(boolean onlyLocalEntities) { + this.onlyLocalEntities=onlyLocalEntities; } + private <K> Set<K> getFilteredOrNot(Set<K> s) { + if (onlyLocalEntities) + return new EntityFilter<K>(s,this); + else + return s; + } + public Set<? extends Object> getClasses() { //return onto.getReferencedClasses(); //return onto.getClassesInSignature(); - return new EntityFilter<OWLClass>(onto.getClassesInSignature(),this); + return getFilteredOrNot(onto.getClassesInSignature()); } public Set<? extends Object> getDataProperties() { - return new EntityFilter<OWLDataProperty>(onto.getDataPropertiesInSignature(),this); + return getFilteredOrNot(onto.getDataPropertiesInSignature()); //return onto.getDataPropertiesInSignature(); } + + + public Set<? extends Object> getEntities() { //return onto.getSignature(); return new EntityFilter<OWLEntity>(onto.getSignature(),this) { protected final boolean isFiltered(OWLEntity obj) { - return super.isFiltered(obj) || obj instanceof OWLAnnotationProperty || obj instanceof OWLDatatype; + if (onlyLocalEntities) + return super.isFiltered(obj) || obj instanceof OWLAnnotationProperty || obj instanceof OWLDatatype; + else + return obj instanceof OWLAnnotationProperty || obj instanceof OWLDatatype; } }; } @@ -219,19 +234,23 @@ public class OWLAPI3Ontology extends BasicOntology<OWLOntology> implements Heavy public Set<? extends Object> getIndividuals() { //return onto.getIndividualsInSignature(); - return new EntityFilter<OWLNamedIndividual>(onto.getIndividualsInSignature(),this); + return getFilteredOrNot(onto.getIndividualsInSignature()); } public Set<? extends Object> getObjectProperties() { //System.err.println ( "ONTO: "+onto ); //return onto.getObjectPropertiesInSignature(); - return new EntityFilter<OWLObjectProperty>(onto.getObjectPropertiesInSignature(),this); + return getFilteredOrNot(onto.getObjectPropertiesInSignature()); } public Set<? extends Object> getProperties() { return new EntityFilter<OWLEntity>(onto.getSignature(),this) { protected final boolean isFiltered(OWLEntity obj) { - return super.isFiltered(obj) || !(obj instanceof OWLObjectProperty || obj instanceof OWLDataProperty); + if (onlyLocalEntities) + return super.isFiltered(obj) || !(obj instanceof OWLObjectProperty || obj instanceof OWLDataProperty); + else { + return !(obj instanceof OWLObjectProperty || obj instanceof OWLDataProperty); + } } }; diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java index 81382dc9e6c79f772ab64a2ca9ca63aab87385fc..788996dc837a03beefd6738b0cccfd5383dd29dd 100644 --- a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java @@ -58,9 +58,9 @@ public class OWLAPI3OntologyFactory extends OntologyFactory { } @Override - public OWLAPI3Ontology newOntology( Object ontology ) throws OntowrapException { + public OWLAPI3Ontology newOntology( Object ontology , boolean onlyLocalEntities) throws OntowrapException { if ( ontology instanceof OWLOntology ) { - OWLAPI3Ontology onto = new OWLAPI3Ontology(); + OWLAPI3Ontology onto = new OWLAPI3Ontology(onlyLocalEntities); onto.setFormalism( formalismId ); onto.setFormURI( formalismUri ); onto.setOntology( (OWLOntology)ontology ); @@ -74,7 +74,7 @@ public class OWLAPI3OntologyFactory extends OntologyFactory { } @Override - public HeavyLoadedOntology loadOntology( URI uri ) throws OntowrapException { + public HeavyLoadedOntology loadOntology( URI uri , boolean onlyLocalEntities) throws OntowrapException { OWLAPI3Ontology onto = null; //System.err.println( " Loading ontology "+uri ); // Cache seems to be implemented in API 3.0 anyway @@ -108,7 +108,7 @@ public class OWLAPI3OntologyFactory extends OntologyFactory { oocex.printStackTrace(); throw new OntowrapException("Cannot load " + uri, oocex ); } - onto = new OWLAPI3Ontology(); + onto = new OWLAPI3Ontology(onlyLocalEntities); onto.setFormalism( formalismId ); onto.setFormURI( formalismUri ); onto.setOntology( ontology ); diff --git a/src/fr/inrialpes/exmo/ontowrap/skosapi/SKOSOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/skosapi/SKOSOntologyFactory.java index 4d59f7e8815b70af136b80e0c17980791520383d..fa9fdf95abb2ee9bb3af2d43b5c1e7c99f5cf67e 100644 --- a/src/fr/inrialpes/exmo/ontowrap/skosapi/SKOSOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/skosapi/SKOSOntologyFactory.java @@ -57,7 +57,7 @@ public class SKOSOntologyFactory extends OntologyFactory { } @Override - public SKOSThesaurus newOntology( Object ontology ) throws OntowrapException { + public SKOSThesaurus newOntology( Object ontology , boolean onlyLocalEntities) throws OntowrapException { if ( ontology instanceof SKOSDataset ) { SKOSThesaurus onto = null; onto = new SKOSThesaurus(); @@ -76,7 +76,7 @@ public class SKOSOntologyFactory extends OntologyFactory { } @Override - public SKOSThesaurus loadOntology( URI uri ) throws OntowrapException { + public SKOSThesaurus loadOntology( URI uri , boolean onlyLocalEntities) throws OntowrapException { //System.err.println(" Loading "+uri ); SKOSThesaurus onto = null; onto = cache.getOntologyFromURI( uri ); diff --git a/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java index 1c9ab6217ee684a6582e58425bca8f803a132939..aefc35948b87ec34c97724a64039cde994516460 100644 --- a/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java @@ -50,7 +50,7 @@ public class SKOSLiteOntologyFactory extends OntologyFactory { } @Override - public SKOSLiteThesaurus loadOntology(URI uri) throws OntowrapException { + public SKOSLiteThesaurus loadOntology(URI uri, boolean onlyLocalEntities) throws OntowrapException { SKOSLiteThesaurus onto = cache.getOntologyFromURI( uri ); if ( onto != null ) return onto; onto = cache.getOntology( uri ); @@ -66,7 +66,7 @@ public class SKOSLiteOntologyFactory extends OntologyFactory { } @Override - public SKOSLiteThesaurus newOntology(Object m) throws OntowrapException { + public SKOSLiteThesaurus newOntology(Object m, boolean onlyLocalEntities) throws OntowrapException { if ( m instanceof Model ) { SKOSLiteThesaurus onto = new SKOSLiteThesaurus((Model) m); onto.setFormalism( formalismId ); diff --git a/src/fr/inrialpes/exmo/ontowrap/util/EntityFilter.java b/src/fr/inrialpes/exmo/ontowrap/util/EntityFilter.java index c9895e3fc1ab40e1a2a8f848e5d277710eab2ca6..d99f89826b90b5bb23ee47e7286dcc804cb661c3 100644 --- a/src/fr/inrialpes/exmo/ontowrap/util/EntityFilter.java +++ b/src/fr/inrialpes/exmo/ontowrap/util/EntityFilter.java @@ -29,6 +29,7 @@ import fr.inrialpes.exmo.ontowrap.OntowrapException; public class EntityFilter<T> extends FilteredSet<T> { private String ontoURI=null; private LoadedOntology<?> onto=null; + public EntityFilter(Set<T> s, LoadedOntology<?> onto) { super(s); ontoURI = onto.getURI().toString().replaceFirst("#.*", "");