You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by en...@apache.org on 2011/06/28 11:17:58 UTC
svn commit: r1140492 - in /incubator/stanbol/trunk/ontologymanager/ontonet:
./
src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/
src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/
src/test/resources/onto...
Author: enridaga
Date: Tue Jun 28 09:17:57 2011
New Revision: 1140492
URL: http://svn.apache.org/viewvc?rev=1140492&view=rev
Log:
This commit speed up tests and should avoid lookup on on-line resources (STANBOL-177, STANBOL-178). Problem was related both to a not efficient implementation of the test initialization. Also testing the handling of non existent and anonymous ontologies resulted in an on-line lookup. Those kind of resources have been commented in the onology registry used by RegistryTest (krestest.owl).
Modified:
incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestRegistry.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/registry/krestest.owl
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml?rev=1140492&r1=1140491&r2=1140492&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml Tue Jun 28 09:17:57 2011
@@ -171,20 +171,20 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
- </dependency>
+ </dependency-->
</dependencies>
<repositories>
- <repository>
+ <!--repository>
<id>stlab-cnr-repo</id>
<url>http://stlab.istc.cnr.it/software/maven/repo</url>
- </repository>
+ </repository-->
<repository>
<id>com.hp.hpl.jena</id>
<name>jena maven repository</name>
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java?rev=1140492&r1=1140491&r2=1140492&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java Tue Jun 28 09:17:57 2011
@@ -52,29 +52,33 @@ import org.slf4j.LoggerFactory;
public class RegistryLoaderImpl implements RegistryLoader {
- private final OWLClass cRegistryLibrary;
+ private final OWLClass cRegistryLibrary;
- private final OWLObjectProperty isPartOf, isOntologyOf;
+ private final OWLObjectProperty isPartOf, isOntologyOf;
- private Logger log = LoggerFactory.getLogger(getClass());
+ private Logger log = LoggerFactory.getLogger(getClass());
- private final IRI mergedOntologyIRI = IRI.create(CODOVocabulary.REPOSITORY_MERGED_ONTOLOGY);
+ private final IRI mergedOntologyIRI = IRI
+ .create(CODOVocabulary.REPOSITORY_MERGED_ONTOLOGY);
- private ONManager onm;
+ private ONManager onm;
- private Map<URI,OWLOntology> registryOntologiesCache = new HashMap<URI,OWLOntology>();
+ private Map<URI, OWLOntology> registryOntologiesCache = new HashMap<URI, OWLOntology>();
- /**
+ /**
*/
- public RegistryLoaderImpl(ONManager onm) {
- this.onm = onm;
- OWLDataFactory factory = OWLManager.getOWLDataFactory();
- cRegistryLibrary = factory.getOWLClass(IRI.create(CODOVocabulary.CODD_OntologyLibrary));
- isPartOf = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.PARTOF_IsPartOf));
- isOntologyOf = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.ODPM_IsOntologyOf));
- }
+ public RegistryLoaderImpl(ONManager onm) {
+ this.onm = onm;
+ OWLDataFactory factory = OWLManager.getOWLDataFactory();
+ cRegistryLibrary = factory.getOWLClass(IRI
+ .create(CODOVocabulary.CODD_OntologyLibrary));
+ isPartOf = factory.getOWLObjectProperty(IRI
+ .create(CODOVocabulary.PARTOF_IsPartOf));
+ isOntologyOf = factory.getOWLObjectProperty(IRI
+ .create(CODOVocabulary.ODPM_IsOntologyOf));
+ }
- public Set<OWLOntology> gatherOntologies(RegistryItem registryItem,
+ public Set<OWLOntology> gatherOntologies(RegistryItem registryItem,
OWLOntologyManager manager,
boolean recurseRegistries) throws OWLOntologyCreationException {
@@ -82,7 +86,8 @@ public class RegistryLoaderImpl implemen
Set<OWLOntology> result = new HashSet<OWLOntology>();
- if (registryItem instanceof Registry) for (RegistryItem item : ((Registry) registryItem)
+ if (registryItem instanceof Registry){
+ for (RegistryItem item : ((Registry) registryItem)
.getChildren())
try {
result.addAll(gatherOntologies(item, manager, recurseRegistries));
@@ -92,388 +97,468 @@ public class RegistryLoaderImpl implemen
+ ". Skipping.", e);
continue;
}
- else if (registryItem.isOntology()) try {
- result.add(manager.loadOntologyFromOntologyDocument(IRI.create(((RegistryOntology) registryItem)
- .getURL())));
- } catch (OWLOntologyAlreadyExistsException ex) {
- // E chissenefrega, ce la aggiungiamo lo stesso.
- result.add(manager.getOntology(ex.getOntologyID()));
- } catch (OWLOntologyCreationIOException ex) {
- // Che ce potemo fa'?
- } catch (URISyntaxException e) {
- log.warn("[NONFATAL] Malformed URI for ontology " + registryItem.getName()
- + ". Skipping.", e);
}
- else if (registryItem.isLibrary()) for (RegistryItem item : ((RegistryLibrary) registryItem)
- .getChildren()) {
- result.addAll(gatherOntologies(item, manager, recurseRegistries));
+ else if (registryItem.isOntology()){
+ IRI locationIri = null;
+ try {
+ locationIri = IRI.create(((RegistryOntology) registryItem)
+ .getURL());
+ result.add(manager.loadOntology(locationIri));
+ } catch (OWLOntologyAlreadyExistsException ex) {
+ // We are trying to oad an alread existing ontology,
+ // we take it from the manager directly
+ result.add(manager.getOntology(ex.getOntologyID()));
+
+ } catch (OWLOntologyCreationIOException ex) {
+ // FIXME Log error here
+ log.error("[NONFATAL] Cannot load ontology from "+locationIri);
+ } catch (URISyntaxException e) {
+ log.warn("[NONFATAL] Malformed URI for ontology " + registryItem.getName()
+ + ". Skipping.", e);
+ }
+ } else if (registryItem.isLibrary()){
+ for (RegistryItem item : ((RegistryLibrary) registryItem).getChildren()) {
+ result.addAll(gatherOntologies(item, manager, recurseRegistries));
+ }
}
return result;
}
- public RegistryLibrary getLibrary(Registry reg, IRI libraryID) {
- for (RegistryItem child : reg.getChildren()) {
- try {
- if (child.isLibrary() && IRI.create(child.getURL()).equals(libraryID)) return (RegistryLibrary) child;
- } catch (URISyntaxException e) {
- // If some URL is not well-formed here and there, sticazzi
- continue;
- }
- }
- return null;
- }
-
- private OWLOntology getMergedOntology(IRI registryLocation) throws RegistryContentException {
- try {
- return getMergedOntology(registryLocation.toURI().toURL());
- } catch (MalformedURLException e) {
- log.warn(
- "KReS :: [NONFATAL] Malformed URI for merged ontology from registry " + registryLocation, e);
- return null;
- }
- }
-
- private OWLOntology getMergedOntology(URL registryLocation) throws RegistryContentException {
- OWLOntology ontology = null;
-
- try {
- IRI mergedOntology = mergedOntologyIRI.resolve("#"
- + URLEncoder.encode(registryLocation.toString(),
- "UTF-8"));
- if (!ODPRegistryCacheManager.registryContains(mergedOntology.toURI())) {
-
- // final OWLOntology ont =
- // getOntologyForRegistryLocation(registryLocation
- // .toURI());
-
- final OWLOntology ont = getOntologyForRegistryLocationNoCached(registryLocation.toURI());
- if (ont == null) throw new RegistryContentException(new NullPointerException(
- "Registry unavailable: " + registryLocation.toURI()));
-
- OWLOntologySetProvider provider = new OWLOntologySetProvider() {
- public Set<OWLOntology> getOntologies() {
- return ODPRegistryCacheManager.getManager().getImportsClosure(ont);
- }
- };
- final OWLDataFactory factory = ODPRegistryCacheManager.getManager().getOWLDataFactory();
-
- // We filter only interesting axioms
- OWLAxiomFilter filter = new OWLAxiomFilter() {
- public boolean passes(OWLAxiom arg0) {
- if (arg0.getSignature().contains(
- factory.getOWLClass(IRI.create(CODOVocabulary.CODD_OntologyLibrary)))
- || arg0.getSignature().contains(
- factory.getOWLClass(IRI.create(CODOVocabulary.CODK_Ontology)))
- || arg0.getSignature().contains(
- factory.getOWLObjectProperty(IRI.create(CODOVocabulary.ODPM_IsOntologyOf)))
- || arg0.getSignature().contains(
- factory.getOWLObjectProperty(IRI.create(CODOVocabulary.PARTOF_IsPartOf)))
- || arg0.getSignature().contains(
- factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()))) {
- return true;
- }
- return false;
- }
- };
-
- OWLOntologyMerger merger = new OWLOntologyMerger(provider, filter);
- OWLOntology merged = merger.createMergedOntology(ODPRegistryCacheManager.getManager(),
- mergedOntology);
- ODPRegistryCacheManager.addResource(merged, mergedOntology.toURI());
- ontology = merged;
- } else {
- ontology = ODPRegistryCacheManager.getOntology(mergedOntology.toURI());
- }
- } catch (URIUnresolvableException e) {
- throw new RegistryContentException(e);
- } catch (OWLOntologyCreationException e) {
- throw new RegistryContentException(e);
- } catch (OWLOntologyChangeException e) {
- throw new RegistryContentException(e);
- } catch (ODPRegistryCacheException e) {
- throw new RegistryContentException(e);
- } catch (UnsupportedEncodingException e) {
- throw new RegistryContentException(e);
- } catch (URISyntaxException e) {
- throw new RegistryContentException(e);
- }
- return ontology;
- }
-
- private OWLOntology getOntologyForRegistryLocation(URI location) {
- return registryOntologiesCache.get(location);
- }
-
- private OWLOntology getOntologyForRegistryLocationNoCached(URI location) {
- OWLOntologyManagerFactoryImpl factory = onm.getOntologyManagerFactory();
- IRI iri = IRI.create(location);
- try {
- if (factory != null) return factory.createOntologyManager(true).loadOntologyFromOntologyDocument(
- iri);
- else return OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(iri);
- } catch (OWLOntologyCreationException e) {
- log.error("KReS :: Registry loader failed to load ontology at " + location, e);
- return null;
- }
- }
-
- public Object getParent(Object child) {
- if (child instanceof AbstractRegistryItem) {
- return ((RegistryItem) child).getParent();
- }
- return null;
- }
-
- private Set<OWLIndividual> getParentContainer(OWLNamedIndividual child, OWLOntology ontology) {
-
- if (child.getObjectPropertyValues(ontology).containsKey(isPartOf)
- || child.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
- Set<OWLIndividual> partOfSet = child.getObjectPropertyValues(ontology).get(isPartOf);
- Set<OWLIndividual> ontologyOfSet = child.getObjectPropertyValues(ontology).get(isOntologyOf);
-
- Set<OWLIndividual> mergedSet = new HashSet<OWLIndividual>();
- if (partOfSet != null) mergedSet.addAll(partOfSet);
- if (ontologyOfSet != null) mergedSet.addAll(ontologyOfSet);
- return mergedSet;
- } else return new HashSet<OWLIndividual>();
- }
-
- private Set<OWLNamedIndividual> getParts(OWLIndividual parent, OWLOntology ontology) {
- Set<OWLNamedIndividual> indies = ontology.getIndividualsInSignature();
- Iterator<OWLNamedIndividual> iter = indies.iterator();
- Set<OWLNamedIndividual> tor = new HashSet<OWLNamedIndividual>();
- // For each individual in this ontology
- while (iter.hasNext()) {
- OWLNamedIndividual n = iter.next();
- // Get its parent wrt to isPartOf or isOntologyOf relationships
- for (OWLIndividual i : this.getParentContainer(n, ontology)) {
- if (i.equals(parent)) {
- tor.add(n);
- break;
- }
- }
- }
- return tor;
- }
-
- private List<Registry> getRegistries() {
- List<Registry> registries = new ArrayList<Registry>();
- // String storedStringValue = XDRegistryPlugin.getDefault()
- // .getPreferenceStore().getString(
- // PreferenceConstants.P_ODP_REGISTRIES);
- String[] regs = new String[] {}/*
- * URLListEditor .parsePreferenceStoreValue (storedStringValue)
- */;
-
- for (int i = 0; i < regs.length; i++) {
- Registry registry1 = null;
- try {
- // TODO Find a way to obtain registry names
- String registryName = ""/*
- * URLListEditor .parseNameValueString(regs[i])[0]
- */;
- // TODO Find a way to obtain registry locations
- String registryLocation = ""/*
- * URLListEditor .parseNameValueString(regs[i])[1]
- */;
- registry1 = new Registry(registryName);
- registry1.setURL(new URL(registryLocation));
- } catch (Exception e) {
- if (registry1 != null) {
- registry1.setError(e.getLocalizedMessage());
- log.error("KReS :: Error on ODP registry: " + registry1.getName(), e);
- }
- }
- if (registry1 != null) registries.add(registry1);
- else log.error("KReS :: Cannot load ODP registry: " + regs[i]);
- }
- return registries;
- }
-
- private List<Registry> getRegistries(XDRegistrySource source) {
-
- List<Registry> registries = new ArrayList<Registry>();
-
- if (source.getPhysicalIRI() != null) {
-
- } else if (source.isInputStreamAvailable()) {
-
- } else if (source.isReaderAvailable()) {
-
- }
-
- return registries;
- }
-
- private RegistryLibrary getTree(OWLNamedIndividual i, OWLOntology ontology) {
-
- RegistryLibrary to = new RegistryLibrary(
- new RDFSLabelGetter(ontology, i.getIRI(), false).getPreferred());
- try {
- Set<OWLNamedIndividual> children = this.getParts(i, ontology);
- if (children.size() == 0) return to;
- for (OWLNamedIndividual childIndividual : children) {
- if (isLibrary(childIndividual, ontology)) {
- RegistryLibrary t = this.getTree(childIndividual, ontology);
- to.addChild(t);
- } else if (isOntology(childIndividual, ontology)) {
- RegistryOntology t = new RegistryOntology(new RDFSLabelGetter(ontology,
- childIndividual.getIRI(), false).getPreferred());
- t.setURL(childIndividual.getIRI().toURI().toURL());
- to.addChild(t);
- }
- }
- } catch (MalformedURLException e) {
- log.error("KReS :: MalformedURLException caught while getting tree for " + i.getIRI(), e);
-
- }
- return to;
- }
-
- public boolean hasChildren(Object parent) {
- if (parent instanceof RegistryLibrary) return ((RegistryLibrary) parent).hasChildren();
- return false;
- }
-
- public boolean hasLibrary(Registry reg, IRI libraryID) {
- for (RegistryItem child : reg.getChildren()) {
- try {
- if (child.isLibrary() && IRI.create(child.getURL()).equals(libraryID)) return true;
- } catch (URISyntaxException e) {
- // If some URL is not well-formed here and there, sticazzi
- continue;
- }
- }
- return false;
- }
-
- private boolean isLibrary(OWLIndividual indy, OWLOntology ontology) {
- OWLClass folderClass = OWLManager.getOWLDataFactory().getOWLClass(
- IRI.create(CODOVocabulary.CODD_OntologyLibrary));
- return (folderClass.getIndividuals(ontology).contains(indy));
- }
-
- private boolean isOntology(OWLIndividual indy, OWLOntology ontology) {
- OWLClass ontologyClass = OWLManager.getOWLDataFactory().getOWLClass(
- IRI.create(CODOVocabulary.CODK_Ontology));
- return (ontologyClass.getIndividuals(ontology).contains(indy));
- }
-
- public void loadLocations() throws RegistryContentException {
-
- try {
-
- registryOntologiesCache.clear();
- List<Registry> registries = getRegistries();
+ public RegistryLibrary getLibrary(Registry reg, IRI libraryID) {
+ for (RegistryItem child : reg.getChildren()) {
+ try {
+ if (child.isLibrary()
+ && IRI.create(child.getURL()).equals(libraryID))
+ return (RegistryLibrary) child;
+ } catch (URISyntaxException e) {
+ // If some URL is not well-formed here and there, sticazzi
+ continue;
+ }
+ }
+ return null;
+ }
+
+ private OWLOntology getMergedOntology(IRI registryLocation)
+ throws RegistryContentException {
+ try {
+ return getMergedOntology(registryLocation.toURI().toURL());
+ } catch (MalformedURLException e) {
+ log.warn(
+ "KReS :: [NONFATAL] Malformed URI for merged ontology from registry "
+ + registryLocation, e);
+ return null;
+ }
+ }
+
+ private OWLOntology getMergedOntology(URL registryLocation)
+ throws RegistryContentException {
+ OWLOntology ontology = null;
+
+ try {
+ IRI mergedOntology = mergedOntologyIRI.resolve("#"
+ + URLEncoder.encode(registryLocation.toString(), "UTF-8"));
+ if (!ODPRegistryCacheManager.registryContains(mergedOntology
+ .toURI())) {
+
+ // final OWLOntology ont =
+ // getOntologyForRegistryLocation(registryLocation
+ // .toURI());
+
+ final OWLOntology ont = getOntologyForRegistryLocationNoCached(registryLocation
+ .toURI());
+ if (ont == null)
+ throw new RegistryContentException(
+ new NullPointerException("Registry unavailable: "
+ + registryLocation.toURI()));
+
+ OWLOntologySetProvider provider = new OWLOntologySetProvider() {
+ public Set<OWLOntology> getOntologies() {
+ return ODPRegistryCacheManager.getManager()
+ .getImportsClosure(ont);
+ }
+ };
+ final OWLDataFactory factory = ODPRegistryCacheManager
+ .getManager().getOWLDataFactory();
+
+ // We filter only interesting axioms
+ OWLAxiomFilter filter = new OWLAxiomFilter() {
+ public boolean passes(OWLAxiom arg0) {
+ if (arg0.getSignature()
+ .contains(
+ factory.getOWLClass(IRI
+ .create(CODOVocabulary.CODD_OntologyLibrary)))
+ || arg0.getSignature()
+ .contains(
+ factory.getOWLClass(IRI
+ .create(CODOVocabulary.CODK_Ontology)))
+ || arg0.getSignature()
+ .contains(
+ factory.getOWLObjectProperty(IRI
+ .create(CODOVocabulary.ODPM_IsOntologyOf)))
+ || arg0.getSignature()
+ .contains(
+ factory.getOWLObjectProperty(IRI
+ .create(CODOVocabulary.PARTOF_IsPartOf)))
+ || arg0.getSignature()
+ .contains(
+ factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL
+ .getIRI()))) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ OWLOntologyMerger merger = new OWLOntologyMerger(provider,
+ filter);
+ OWLOntology merged = merger.createMergedOntology(
+ ODPRegistryCacheManager.getManager(), mergedOntology);
+ ODPRegistryCacheManager.addResource(merged,
+ mergedOntology.toURI());
+ ontology = merged;
+ } else {
+ ontology = ODPRegistryCacheManager.getOntology(mergedOntology
+ .toURI());
+ }
+ } catch (URIUnresolvableException e) {
+ throw new RegistryContentException(e);
+ } catch (OWLOntologyCreationException e) {
+ throw new RegistryContentException(e);
+ } catch (OWLOntologyChangeException e) {
+ throw new RegistryContentException(e);
+ } catch (ODPRegistryCacheException e) {
+ throw new RegistryContentException(e);
+ } catch (UnsupportedEncodingException e) {
+ throw new RegistryContentException(e);
+ } catch (URISyntaxException e) {
+ throw new RegistryContentException(e);
+ }
+ return ontology;
+ }
+
+ private OWLOntology getOntologyForRegistryLocation(URI location) {
+ return registryOntologiesCache.get(location);
+ }
+
+ private OWLOntology getOntologyForRegistryLocationNoCached(URI location) {
+ OWLOntologyManagerFactoryImpl factory = onm.getOntologyManagerFactory();
+ IRI iri = IRI.create(location);
+ try {
+ if (factory != null)
+ return factory.createOntologyManager(true)
+ .loadOntologyFromOntologyDocument(iri);
+ else
+ return OWLManager.createOWLOntologyManager()
+ .loadOntologyFromOntologyDocument(iri);
+ } catch (OWLOntologyCreationException e) {
+ log.error("KReS :: Registry loader failed to load ontology at "
+ + location, e);
+ return null;
+ }
+ }
+
+ public Object getParent(Object child) {
+ if (child instanceof AbstractRegistryItem) {
+ return ((RegistryItem) child).getParent();
+ }
+ return null;
+ }
+
+ private Set<OWLIndividual> getParentContainer(OWLNamedIndividual child,
+ OWLOntology ontology) {
+
+ if (child.getObjectPropertyValues(ontology).containsKey(isPartOf)
+ || child.getObjectPropertyValues(ontology).containsKey(
+ isOntologyOf)) {
+ Set<OWLIndividual> partOfSet = child.getObjectPropertyValues(
+ ontology).get(isPartOf);
+ Set<OWLIndividual> ontologyOfSet = child.getObjectPropertyValues(
+ ontology).get(isOntologyOf);
+
+ Set<OWLIndividual> mergedSet = new HashSet<OWLIndividual>();
+ if (partOfSet != null)
+ mergedSet.addAll(partOfSet);
+ if (ontologyOfSet != null)
+ mergedSet.addAll(ontologyOfSet);
+ return mergedSet;
+ } else
+ return new HashSet<OWLIndividual>();
+ }
+
+ private Set<OWLNamedIndividual> getParts(OWLIndividual parent,
+ OWLOntology ontology) {
+ Set<OWLNamedIndividual> indies = ontology.getIndividualsInSignature();
+ Iterator<OWLNamedIndividual> iter = indies.iterator();
+ Set<OWLNamedIndividual> tor = new HashSet<OWLNamedIndividual>();
+ // For each individual in this ontology
+ while (iter.hasNext()) {
+ OWLNamedIndividual n = iter.next();
+ // Get its parent wrt to isPartOf or isOntologyOf relationships
+ for (OWLIndividual i : this.getParentContainer(n, ontology)) {
+ if (i.equals(parent)) {
+ tor.add(n);
+ break;
+ }
+ }
+ }
+ return tor;
+ }
+
+ private List<Registry> getRegistries() {
+ List<Registry> registries = new ArrayList<Registry>();
+ // String storedStringValue = XDRegistryPlugin.getDefault()
+ // .getPreferenceStore().getString(
+ // PreferenceConstants.P_ODP_REGISTRIES);
+ String[] regs = new String[] {}/*
+ * URLListEditor
+ * .parsePreferenceStoreValue
+ * (storedStringValue)
+ */;
+
+ for (int i = 0; i < regs.length; i++) {
+ Registry registry1 = null;
+ try {
+ // TODO Find a way to obtain registry names
+ String registryName = ""/*
+ * URLListEditor
+ * .parseNameValueString(regs[i])[0]
+ */;
+ // TODO Find a way to obtain registry locations
+ String registryLocation = ""/*
+ * URLListEditor
+ * .parseNameValueString(regs[i])[1]
+ */;
+ registry1 = new Registry(registryName);
+ registry1.setURL(new URL(registryLocation));
+ } catch (Exception e) {
+ if (registry1 != null) {
+ registry1.setError(e.getLocalizedMessage());
+ log.error(
+ "KReS :: Error on ODP registry: "
+ + registry1.getName(), e);
+ }
+ }
+ if (registry1 != null)
+ registries.add(registry1);
+ else
+ log.error("KReS :: Cannot load ODP registry: " + regs[i]);
+ }
+ return registries;
+ }
+
+ private List<Registry> getRegistries(XDRegistrySource source) {
+
+ List<Registry> registries = new ArrayList<Registry>();
+
+ if (source.getPhysicalIRI() != null) {
+
+ } else if (source.isInputStreamAvailable()) {
+
+ } else if (source.isReaderAvailable()) {
+
+ }
+
+ return registries;
+ }
+
+ private RegistryLibrary getTree(OWLNamedIndividual i, OWLOntology ontology) {
+
+ RegistryLibrary to = new RegistryLibrary(new RDFSLabelGetter(ontology,
+ i.getIRI(), false).getPreferred());
+ try {
+ Set<OWLNamedIndividual> children = this.getParts(i, ontology);
+ if (children.size() == 0)
+ return to;
+ for (OWLNamedIndividual childIndividual : children) {
+ if (isLibrary(childIndividual, ontology)) {
+ RegistryLibrary t = this.getTree(childIndividual, ontology);
+ to.addChild(t);
+ } else if (isOntology(childIndividual, ontology)) {
+ RegistryOntology t = new RegistryOntology(
+ new RDFSLabelGetter(ontology, childIndividual
+ .getIRI(), false).getPreferred());
+ t.setURL(childIndividual.getIRI().toURI().toURL());
+ to.addChild(t);
+ }
+ }
+ } catch (MalformedURLException e) {
+ log.error(
+ "KReS :: MalformedURLException caught while getting tree for "
+ + i.getIRI(), e);
+
+ }
+ return to;
+ }
+
+ public boolean hasChildren(Object parent) {
+ if (parent instanceof RegistryLibrary)
+ return ((RegistryLibrary) parent).hasChildren();
+ return false;
+ }
+
+ public boolean hasLibrary(Registry reg, IRI libraryID) {
+ for (RegistryItem child : reg.getChildren()) {
+ try {
+ if (child.isLibrary()
+ && IRI.create(child.getURL()).equals(libraryID))
+ return true;
+ } catch (URISyntaxException e) {
+ // If some URL is not well-formed here and there, sticazzi
+ continue;
+ }
+ }
+ return false;
+ }
+
+ private boolean isLibrary(OWLIndividual indy, OWLOntology ontology) {
+ OWLClass folderClass = OWLManager.getOWLDataFactory().getOWLClass(
+ IRI.create(CODOVocabulary.CODD_OntologyLibrary));
+ return (folderClass.getIndividuals(ontology).contains(indy));
+ }
+
+ private boolean isOntology(OWLIndividual indy, OWLOntology ontology) {
+ OWLClass ontologyClass = OWLManager.getOWLDataFactory().getOWLClass(
+ IRI.create(CODOVocabulary.CODK_Ontology));
+ return (ontologyClass.getIndividuals(ontology).contains(indy));
+ }
+
+ public void loadLocations() throws RegistryContentException {
+
+ try {
+
+ registryOntologiesCache.clear();
+ List<Registry> registries = getRegistries();
+
+ int regsize = registries.size();
+ int c = 0;
+ for (Registry current : registries) {
+ c++;
+ log.debug("Loading " + current.toString() + " [" + c + "/"
+ + regsize + "]");
+ if (!ODPRegistryCacheManager.registryContains(current.getURL()
+ .toURI())) {
+ try {
+ log.debug("Fetching: " + current.getURL().toURI());
+ registryOntologiesCache.put(current.getURL().toURI(),
+ ODPRegistryCacheManager.getOntology(current
+ .getURL().toURI()));
+ } catch (URIUnresolvableException e) {
+ log.error("KReS :: could not resolve URI "
+ + current.getURL().toURI(), e);
+ registryOntologiesCache.put(current.getURL().toURI(),
+ null);
+ } catch (ODPRegistryCacheException e) {
+ log.error("KReS :: failed to cache ontology "
+ + current.getURL().toURI(), e);
+ registryOntologiesCache.put(current.getURL().toURI(),
+ null);
+ }
+ }
+ }
+ c = 0;
+ for (Registry registry : registries) {
+ c++;
+ try {
+ registry = setupRegistry(registry);
+ } catch (RegistryContentException e) {
+ registry.setError(" [Unable to load from location "
+ + registry.getURL().toString() + "]");
+ }
+ }
+ } catch (Throwable th) {
+ log.error(
+ "KreS :: Exception occurred while trying to get registry locations.",
+ th);
+ }
+ }
+
+ /**
+ * The ontology at <code>physicalIRI</code> may in turn include more than
+ * one registry.
+ *
+ * @param physicalIRI
+ * @return
+ */
+ public Set<Registry> loadRegistriesEager(IRI physicalIRI) {
- int regsize = registries.size();
- int c = 0;
- for (Registry current : registries) {
- c++;
- log.debug("Loading " + current.toString() + " [" + c + "/" + regsize + "]");
- if (!ODPRegistryCacheManager.registryContains(current.getURL().toURI())) {
- try {
- log.debug("Fetching: " + current.getURL().toURI());
- registryOntologiesCache.put(current.getURL().toURI(),
- ODPRegistryCacheManager.getOntology(current.getURL().toURI()));
- } catch (URIUnresolvableException e) {
- log.error("KReS :: could not resolve URI " + current.getURL().toURI(), e);
- registryOntologiesCache.put(current.getURL().toURI(), null);
- } catch (ODPRegistryCacheException e) {
- log.error("KReS :: failed to cache ontology " + current.getURL().toURI(), e);
- registryOntologiesCache.put(current.getURL().toURI(), null);
- }
- }
- }
- c = 0;
- for (Registry registry : registries) {
- c++;
- try {
- registry = setupRegistry(registry);
- } catch (RegistryContentException e) {
- registry.setError(" [Unable to load from location " + registry.getURL().toString() + "]");
- }
- }
- } catch (Throwable th) {
- log.error("KreS :: Exception occurred while trying to get registry locations.", th);
- }
- }
+ Set<Registry> results = new HashSet<Registry>();
+ OWLOntologyManager mgr = onm.getOwlCacheManager();// getManager();
- /**
- * The ontology at <code>physicalIRI</code> may in turn include more than one registry.
- *
- * @param physicalIRI
- * @return
- */
- public Set<Registry> loadRegistriesEager(IRI physicalIRI) {
-
- Set<Registry> results = new HashSet<Registry>();
- OWLOntologyManager mgr = onm.getOwlCacheManager();// getManager();
-
- try {
- OWLOntology ontology = mgr.loadOntology(physicalIRI);
- for (OWLIndividual ind : cRegistryLibrary.getIndividuals(ontology))
- if (ind.isNamed()) {
- OWLNamedIndividual nind = ind.asOWLNamedIndividual();
- IRI regiri = nind.getIRI();
- Registry registry = new Registry(regiri.getFragment());
- try {
- // TODO: avoid using toURL crap
- registry.setURL(regiri.toURI().toURL());
- } catch (MalformedURLException e) {
- // Why should a well-formed IRI be a malformed URL
- // anyway ?
- log.warn("KReS :: ontology document IRI " + physicalIRI
- + " matches a malformed URI pattern.", e);
- }
- // Find the ontologies in this registry
- // If this is individual is not "ontology of" or "part of",
- // then proceed.
- if (!nind.getObjectPropertyValues(ontology).containsKey(isPartOf)
- && !nind.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
- registry.addChild(this.getTree((OWLNamedIndividual) nind, ontology));
- }
- results.add(registry);
- }
- } catch (OWLOntologyAlreadyExistsException e) {
- log.warn("KReS :: ontology " + e.getOntologyID() + " exists and will not be reloaded.", e);
- // Do nothing. Existing ontologies are fine.
- } catch (OWLOntologyCreationException e) {
- log.error("KReS :: Could not load ontology " + physicalIRI + " .", e);
- } finally {}
- return results;
- }
+ try {
+ OWLOntology ontology = mgr.loadOntology(physicalIRI);
+ for (OWLIndividual ind : cRegistryLibrary.getIndividuals(ontology))
+ if (ind.isNamed()) {
+ OWLNamedIndividual nind = ind.asOWLNamedIndividual();
+ IRI regiri = nind.getIRI();
+ Registry registry = new Registry(regiri.getFragment());
+ try {
+ // TODO: avoid using toURL crap
+ registry.setURL(regiri.toURI().toURL());
+ } catch (MalformedURLException e) {
+ // Why should a well-formed IRI be a malformed URL
+ // anyway ?
+ log.warn("KReS :: ontology document IRI " + physicalIRI
+ + " matches a malformed URI pattern.", e);
+ }
+ // Find the ontologies in this registry
+ // If this is individual is not "ontology of" or "part of",
+ // then proceed.
+ if (!nind.getObjectPropertyValues(ontology).containsKey(
+ isPartOf)
+ && !nind.getObjectPropertyValues(ontology)
+ .containsKey(isOntologyOf)) {
+ registry.addChild(this.getTree(
+ (OWLNamedIndividual) nind, ontology));
+ }
+ results.add(registry);
+ }
+ } catch (OWLOntologyAlreadyExistsException e) {
+ log.warn("KReS :: ontology " + e.getOntologyID()
+ + " exists and will not be reloaded.", e);
+ // Do nothing. Existing ontologies are fine.
+ } catch (OWLOntologyCreationException e) {
+ log.error("KReS :: Could not load ontology " + physicalIRI + " .",
+ e);
+ } finally {
+ }
+ return results;
+ }
+
+ /**
+ * Requires that Registry objects are created earlier. Problem is, we might
+ * not know their names a priori.
+ *
+ * @param registry
+ * @return
+ * @throws RegistryContentException
+ */
+ private Registry setupRegistry(Registry registry)
+ throws RegistryContentException {
- /**
- * Requires that Registry objects are created earlier. Problem is, we might not know their names a priori.
- *
- * @param registry
- * @return
- * @throws RegistryContentException
- */
- private Registry setupRegistry(Registry registry) throws RegistryContentException {
-
- // For each registry:
- registry.removeChildren();
- OWLOntology ontology = getMergedOntology(registry.getURL());
-
- // TODO: Restore ODP cache manager.
- // setManager(ODPRegistryCacheManager.getManager());
- Set<OWLIndividual> folderSet = cRegistryLibrary.getIndividuals(ontology);
-
- // Look for first level elements;
- Iterator<OWLIndividual> iter = folderSet.iterator();
- while (iter.hasNext()) {
- OWLIndividual i = iter.next();
- if (i instanceof OWLNamedIndividual) {
- if (!i.getObjectPropertyValues(ontology).containsKey(isPartOf)
- && !i.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
- registry.addChild(this.getTree((OWLNamedIndividual) i, ontology));
- }
- }
- }
+ // For each registry:
+ registry.removeChildren();
+ OWLOntology ontology = getMergedOntology(registry.getURL());
+
+ // TODO: Restore ODP cache manager.
+ // setManager(ODPRegistryCacheManager.getManager());
+ Set<OWLIndividual> folderSet = cRegistryLibrary
+ .getIndividuals(ontology);
+
+ // Look for first level elements;
+ Iterator<OWLIndividual> iter = folderSet.iterator();
+ while (iter.hasNext()) {
+ OWLIndividual i = iter.next();
+ if (i instanceof OWLNamedIndividual) {
+ if (!i.getObjectPropertyValues(ontology).containsKey(isPartOf)
+ && !i.getObjectPropertyValues(ontology).containsKey(
+ isOntologyOf)) {
+ registry.addChild(this.getTree((OWLNamedIndividual) i,
+ ontology));
+ }
+ }
+ }
- return registry;
- }
+ return registry;
+ }
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestRegistry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestRegistry.java?rev=1140492&r1=1140491&r2=1140492&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestRegistry.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestRegistry.java Tue Jun 28 09:17:57 2011
@@ -1,25 +1,39 @@
package org.apache.stanbol.ontologymanager.ontonet.registry;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.File;
+import java.net.URL;
+import java.util.Dictionary;
import java.util.Hashtable;
import org.apache.stanbol.ontologymanager.ontonet.api.DuplicateIDException;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManagerConfiguration;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.ParentPathInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologySpaceException;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryLoader;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.io.OntologyRegistryIRISource;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.junit.BeforeClass;
import org.junit.Test;
import org.semanticweb.owlapi.model.IRI;
-
+import org.semanticweb.owlapi.model.OWLOntologyIRIMapper;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.util.AutoIRIMapper;
public class TestRegistry {
-
+ private static OWLOntologyManager ontologyManager;
+ private static RegistryLoader loader;
+ private static OntologyRegistryIRISource ontologySource;
+ private static ONManagerConfiguration configuration;
private static ONManager onm;
private static IRI testRegistryIri = IRI
@@ -32,19 +46,39 @@ public class TestRegistry {
@BeforeClass
public static void setup() {
// An ONManagerImpl with no store and default settings
- onm = new ONManagerImpl(null,null, new Hashtable<String, Object>());
+ configuration = new ONManagerConfigurationImpl(
+ new Hashtable<String, Object>());
+ onm = new ONManagerImpl(null, null, configuration,
+ new Hashtable<String, Object>());
+ ontologyManager = onm.getOwlCacheManager();
+ loader = onm.getRegistryLoader();
+
+
+ }
+
+ private static boolean mapperIsSet = false;
+
+ public void setupOfflineMapper() {
+ if (mapperIsSet) {
+ } else {
+ ontologySource = new OntologyRegistryIRISource(testRegistryIri,
+ ontologyManager, loader);
+ mapperIsSet = true;
+ }
}
@Test
public void testAddRegistryToSessionSpace() {
+ setupOfflineMapper();
IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
SessionOntologySpace space = null;
space = onm.getOntologySpaceFactory().createSessionOntologySpace(
scopeIri);
-
space.setUp();
try {
- space.addOntology(new OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
+ // space.addOntology(new
+ // OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
+ space.addOntology(ontologySource);
} catch (UnmodifiableOntologySpaceException e) {
fail("Adding libraries to session space failed. "
+ "This should not happen for active session spaces.");
@@ -56,13 +90,14 @@ public class TestRegistry {
@Test
public void testScopeCreationWithRegistry() {
+ setupOfflineMapper();
IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
OntologyScope scope = null;
// The factory call also invokes loadRegistriesEager() and
// gatherOntologies() so no need to test them individually.
try {
- scope = onm.getOntologyScopeFactory().createOntologyScope(
- scopeIri, new OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
+ scope = onm.getOntologyScopeFactory().createOntologyScope(scopeIri,
+ ontologySource);
} catch (DuplicateIDException e) {
fail("DuplicateID exception caught when creating test scope.");
}
@@ -75,13 +110,13 @@ public class TestRegistry {
@Test
public void testSpaceCreationWithRegistry() {
+ setupOfflineMapper();
IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
CoreOntologySpace space = null;
// The factory call also invokes loadRegistriesEager() and
// gatherOntologies() so no need to test them individually.
- space = onm.getOntologySpaceFactory().createCoreOntologySpace(
- scopeIri, new OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
-
+ space = onm.getOntologySpaceFactory().createCoreOntologySpace(scopeIri,
+ ontologySource);
assertTrue(space != null && space.getTopOntology() != null);
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/registry/krestest.owl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/registry/krestest.owl?rev=1140492&r1=1140491&r2=1140492&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/registry/krestest.owl (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/registry/krestest.owl Tue Jun 28 09:17:57 2011
@@ -26,11 +26,11 @@
</rdf:Description>
<!-- For testing ontologies that do not exist -->
- <rdf:Description rdf:about="http://www.ontologydesignpatterns.org/cp/owl/doesnotexist.owl">
+ <!--rdf:Description rdf:about="http://www.ontologydesignpatterns.org/cp/owl/doesnotexist.owl">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Does not exist</rdfs:label>
<meta:isOntologyOf rdf:resource="#TestRegistry"/>
<rdf:type rdf:resource="http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl#Ontology"/>
- </rdf:Description>
+ </rdf:Description-->
<!-- For testing already loaded ontologies -->
<rdf:Description rdf:about="http://www.ontologydesignpatterns.org/cp/owl/objectrole.owl">
@@ -40,11 +40,11 @@
</rdf:Description>
<!-- For testing anonymous ontologies -->
- <rdf:Description rdf:about="http://www.ontologydesignpatterns.org/ont/iks/nameless_ontology.owl">
+ <!--rdf:Description rdf:about="http://www.ontologydesignpatterns.org/ont/iks/nameless_ontology.owl">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Nameless</rdfs:label>
<meta:isOntologyOf rdf:resource="#TestRegistry"/>
<rdf:type rdf:resource="http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl#Ontology"/>
- </rdf:Description>
+ </rdf:Description-->
<!-- For testing undefined registries -->
<rdf:Description rdf:about="http://www.ontologydesignpatterns.org/cp/owl/classification.owl">