You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2011/07/22 20:37:17 UTC
svn commit: r1149687 [2/2] - in
/incubator/stanbol/trunk/ontologymanager/ontonet/src:
main/java/org/apache/stanbol/ontologymanager/ontonet/api/
main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/
main/java/org/apache/stanbol/ontologymana...
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/RegistryManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/RegistryManagerImpl.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/RegistryManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/RegistryManagerImpl.java Fri Jul 22 18:37:10 2011
@@ -16,7 +16,6 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.registry;
-import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -32,6 +31,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.PropertyOption;
import org.apache.felix.scr.annotations.Service;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryContentException;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryContentListener;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryItemFactory;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryManager;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Library;
@@ -44,21 +44,32 @@ import org.apache.stanbol.ontologymanage
import org.osgi.service.component.ComponentContext;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLAxiomVisitor;
import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.util.OWLAxiomVisitorAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Default implementation of the registry manager, that listens to requests on its referenced resources and
+ * issues loading requests accordingly.
+ */
@Component(immediate = true, metatype = true)
@Service(RegistryManager.class)
-public class RegistryManagerImpl implements RegistryManager {
+public class RegistryManagerImpl implements RegistryManager, RegistryContentListener {
private static final boolean _LAZY_LOADING_DEFAULT = false;
@@ -88,6 +99,7 @@ public class RegistryManagerImpl impleme
@Property(name = RegistryManager.LAZY_LOADING, boolValue = _LAZY_LOADING_DEFAULT)
private boolean lazyLoading = _LAZY_LOADING_DEFAULT;
+ /* Maps registries to libraries */
private Map<IRI,Set<IRI>> libraryIndex = new HashMap<IRI,Set<IRI>>();
@Property(name = RegistryManager.REGISTRY_LOCATIONS, cardinality = 1000)
@@ -95,11 +107,12 @@ public class RegistryManagerImpl impleme
private Logger log = LoggerFactory.getLogger(getClass());
+ /* Maps libraries to ontologies */
private Map<IRI,Set<IRI>> ontologyIndex = new HashMap<IRI,Set<IRI>>();
private Map<IRI,RegistryItem> population = new TreeMap<IRI,RegistryItem>();
- private Map<IRI,Registry> registries = new HashMap<IRI,Registry>();
+ private Set<IRI> registries = new HashSet<IRI>();
private RegistryItemFactory riFactory;
@@ -148,9 +161,10 @@ public class RegistryManagerImpl impleme
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
// Load registries
+ Set<OWLOntology> regOnts = new HashSet<OWLOntology>();
for (String loc : locations) {
try {
- OWLOntology o = mgr.loadOntology(IRI.create(loc));
+ regOnts.add(mgr.loadOntology(IRI.create(loc)));
} catch (OWLOntologyAlreadyExistsException e) {
log.info("Skipping cached ontology {}.", e.getOntologyID());
continue;
@@ -159,25 +173,131 @@ public class RegistryManagerImpl impleme
continue;
}
}
-
+ // Build the model!
+ createModel(regOnts);
}
@Override
public void addRegistry(Registry registry) {
try {
- registries.put(IRI.create(registry.getURL()), registry);
+ population.put(registry.getIRI(), registry);
+ registries.add(registry.getIRI());
updateLocations();
- } catch (URISyntaxException e) {
+ } catch (Exception e) {
log.error("Failed to add ontology registry.", e);
}
}
@Override
public void clearRegistries() {
- registries.clear();
+ for (IRI id : registries)
+ if (registries.remove(id)) population.remove(id);
updateLocations();
}
+ @Override
+ public Set<Registry> createModel(Set<OWLOntology> registryOntologies) {
+
+ Set<Registry> results = new HashSet<Registry>();
+ // Reset population
+ population.clear();
+
+ // Build the transitive imports closure of the union.
+ Set<OWLOntology> closure = new HashSet<OWLOntology>();
+ for (OWLOntology rego : registryOntologies)
+ closure.addAll(rego.getOWLOntologyManager().getImportsClosure(rego));
+
+ final Map<IRI,int[]> candidateTypes = new HashMap<IRI,int[]>();
+
+ OWLAxiomVisitor v = new OWLAxiomVisitorAdapter() {
+
+ private int[] checkScores(IRI key) {
+ int[] scores;
+ if (candidateTypes.containsKey(key)) scores = candidateTypes.get(key);
+ else {
+ scores = new int[] {0, 0};
+ candidateTypes.put(key, scores);
+ }
+ return scores;
+ }
+
+ @Override
+ public void visit(OWLClassAssertionAxiom axiom) {
+ OWLIndividual ind = axiom.getIndividual();
+ if (ind.isAnonymous()) return;
+ IRI iri = ind.asOWLNamedIndividual().getIRI();
+ int[] scores = checkScores(iri);
+
+ OWLClassExpression type = axiom.getClassExpression();
+ if (cRegistryLibrary.equals(type)) {
+ scores[0]++;
+ } else if (cOntology.equals(type)) {
+ scores[1]++;
+ }
+
+ }
+
+ @Override
+ public void visit(OWLObjectPropertyAssertionAxiom axiom) {
+ OWLObjectPropertyExpression prop = axiom.getProperty();
+
+ if (hasOntology.equals(prop)) {
+ IRI iri;
+ OWLIndividual ind = axiom.getSubject();
+ if (!ind.isAnonymous()) {
+ iri = ind.asOWLNamedIndividual().getIRI();
+ checkScores(iri)[0]++;
+ }
+ ind = axiom.getObject();
+ if (!ind.isAnonymous()) {
+ iri = ind.asOWLNamedIndividual().getIRI();
+ checkScores(iri)[1]++;
+ }
+ } else if (isOntologyOf.equals(prop)) {
+ IRI iri;
+ OWLIndividual ind = axiom.getSubject();
+ if (!ind.isAnonymous()) {
+ iri = ind.asOWLNamedIndividual().getIRI();
+ checkScores(iri)[1]++;
+ }
+ ind = axiom.getObject();
+ if (!ind.isAnonymous()) {
+ iri = ind.asOWLNamedIndividual().getIRI();
+ checkScores(iri)[0]++;
+ }
+ }
+
+ }
+
+ };
+
+ // First pass to determine the types.
+ for (OWLOntology o : closure)
+ for (OWLAxiom ax : o.getAxioms())
+ ax.accept(v);
+
+ // Then populate on the registry
+ OWLDataFactory df = OWLManager.getOWLDataFactory();
+ for (IRI iri : candidateTypes.keySet()) {
+ int[] scores = candidateTypes.get(iri);
+ if (scores != null && (scores[0] > 0 || scores[1] > 0)) {
+ if (scores[0] > 0 && scores[1] == 0) population.put(iri,
+ riFactory.createLibrary(df.getOWLNamedIndividual(iri)));
+ else if (scores[0] == 0 && scores[1] > 0) population.put(iri,
+ riFactory.createRegistryOntology(df.getOWLNamedIndividual(iri)));
+ } else log.warn("Unable to determine type for registry item {}", iri);
+ }
+
+ for (OWLOntology oReg : registryOntologies) {
+ try {
+ results.add(populateRegistry(oReg));
+ } catch (RegistryContentException e) {
+ log.error("An error occurred while populating an ontology registry.", e);
+ }
+ }
+ return results;
+ }
+
@Deactivate
protected void deactivate(ComponentContext context) {
lazyLoading = _LAZY_LOADING_DEFAULT;
@@ -193,7 +313,12 @@ public class RegistryManagerImpl impleme
@Override
public Set<Registry> getRegistries() {
- return new HashSet<Registry>(registries.values());
+ Set<Registry> results = new HashSet<Registry>();
+ for (IRI key : population.keySet()) {
+ RegistryItem item = population.get(key);
+ if (item instanceof Registry) results.add((Registry) item);
+ }
+ return results;
}
@Override
@@ -204,7 +329,8 @@ public class RegistryManagerImpl impleme
@Override
public Registry getRegistry(IRI id) {
- return registries.get(id);
+ RegistryItem item = population.get(id);
+ return item != null && item instanceof Registry ? (Registry) item : null;
}
@Override
@@ -212,7 +338,7 @@ public class RegistryManagerImpl impleme
return lazyLoading;
}
- public Library populateLibrary(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
+ protected Library populateLibrary(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI id = ind.getIRI();
RegistryItem lib = null;
if (population.containsKey(id)) {
@@ -224,8 +350,8 @@ public class RegistryManagerImpl impleme
} else {
lib = riFactory.createLibrary(ind.asOWLNamedIndividual());
try {
- population.put(IRI.create(lib.getURL()), lib);
- } catch (URISyntaxException e) {
+ population.put(lib.getIRI(), lib);
+ } catch (Exception e) {
log.error("Invalid identifier for library item " + lib, e);
return null;
}
@@ -240,7 +366,7 @@ public class RegistryManagerImpl impleme
return (Library) lib;
}
- public RegistryOntology populateOntology(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
+ protected RegistryOntology populateOntology(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI id = ind.getIRI();
RegistryItem ront = null;
if (population.containsKey(id)) {
@@ -252,8 +378,8 @@ public class RegistryManagerImpl impleme
} else {
ront = riFactory.createRegistryOntology(ind);
try {
- population.put(IRI.create(ront.getURL()), ront);
- } catch (URISyntaxException e) {
+ population.put(ront.getIRI(), ront);
+ } catch (Exception e) {
log.error("Invalid identifier for library item " + ront, e);
return null;
}
@@ -263,12 +389,12 @@ public class RegistryManagerImpl impleme
for (OWLOntology o : registries)
libs.addAll(ind.getObjectPropertyValues(isOntologyOf, o));
for (OWLIndividual ilib : libs) {
- if (ilib.isNamed()) ront.addContainer(populateLibrary(ilib.asOWLNamedIndividual(), registries));
+ if (ilib.isNamed()) ront.addParent(populateLibrary(ilib.asOWLNamedIndividual(), registries));
}
return (RegistryOntology) ront;
}
- public Registry populateRegistry(OWLOntology registry) throws RegistryContentException {
+ protected Registry populateRegistry(OWLOntology registry) throws RegistryContentException {
Registry reg = riFactory.createRegistry(registry);
Set<OWLOntology> closure = registry.getOWLOntologyManager().getImportsClosure(registry);
@@ -286,23 +412,38 @@ public class RegistryManagerImpl impleme
}
switch (t) {
case LIBRARY:
- // // Create the library and attach to parent and children
+ // Create the library and attach to parent and children
item = populateLibrary(ind.asOWLNamedIndividual(), closure);
reg.addChild(item);
+ item.addRegistryContentListener(this);
break;
case ONTOLOGY:
// Create the ontology and attach to parent
item = populateOntology(ind.asOWLNamedIndividual(), closure);
- // We don't know where to attach it to in this method.
+ item.addRegistryContentListener(this);
+ // We don't know where to attach it within this method.
break;
default:
break;
}
}
+ try {
+ reg.addRegistryContentListener(this);
+ population.put(reg.getIRI(), reg);
+ } catch (Exception e) {
+ log.error("Invalid identifier for library item " + reg, e);
+ return null;
+ }
return reg;
}
@Override
+ public void registryContentRequested(RegistryItem requestTarget) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
public void removeRegistry(IRI registryId) {
registries.remove(registryId);
updateLocations();
@@ -314,7 +455,7 @@ public class RegistryManagerImpl impleme
}
protected synchronized void updateLocations() {
- Set<IRI> locations = Collections.unmodifiableSet(registries.keySet());
+ Set<IRI> locations = Collections.unmodifiableSet(registries);
this.locations = locations.toArray(new String[0]);
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/cache/RegistryUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/cache/RegistryUtils.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/cache/RegistryUtils.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/cache/RegistryUtils.java Fri Jul 22 18:37:10 2011
@@ -16,30 +16,28 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.registry.cache;
-import java.net.URISyntaxException;
-import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
-import java.util.TreeMap;
-import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryContentException;
-import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryItemFactory;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Library;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Registry;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem.Type;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryOntology;
-import org.apache.stanbol.ontologymanager.ontonet.impl.registry.RegistryItemFactoryImpl;
import org.apache.stanbol.ontologymanager.ontonet.xd.vocabulary.CODOVocabulary;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLAxiomVisitor;
import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
-import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.util.OWLAxiomVisitorAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,14 +47,10 @@ public class RegistryUtils {
private static final OWLObjectProperty hasPart, hasOntology, isPartOf, isOntologyOf;
+ @SuppressWarnings("unused")
private static Logger log = LoggerFactory.getLogger(RegistryUtils.class);
- private static Map<IRI,RegistryItem> population = new TreeMap<IRI,RegistryItem>();
-
- private static RegistryItemFactory riFactory;
-
static {
- riFactory = new RegistryItemFactoryImpl();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
cOntology = factory.getOWLClass(IRI.create(CODOVocabulary.CODK_Ontology));
cRegistryLibrary = factory.getOWLClass(IRI.create(CODOVocabulary.CODD_OntologyLibrary));
@@ -81,7 +75,7 @@ public class RegistryUtils {
if (item instanceof RegistryOntology) {
// An Ontology MUST have a non-null URI.
try {
- IRI iri = IRI.create(item.getURL());
+ IRI iri = item.getIRI();
result |= iri.equals(ontologyId);
} catch (Exception e) {
return false;
@@ -96,115 +90,65 @@ public class RegistryUtils {
}
- /**
- * Simulates a classifier.
- *
- * @param ind
- * @param o
- * @return
- */
- public static Type getType(OWLIndividual ind, Set<OWLOntology> ontologies) {
- // TODO also use property values
- Set<OWLClassExpression> types = ind.getTypes(ontologies);
- if (types.contains(cOntology) && !types.contains(cRegistryLibrary))
- return Type.ONTOLOGY;
- if (!types.contains(cOntology) && types.contains(cRegistryLibrary))
- return Type.LIBRARY;
+ @Deprecated
+ public static Type getType(final OWLIndividual ind, Set<OWLOntology> ontologies) {
+
+ // 0 is for library, 1 is for ontology (more in the future?)
+ final int[] pointsFor = new int[] {0, 0};
+ final int[] pointsAgainst = new int[] {0, 0};
+
+ OWLAxiomVisitor v = new OWLAxiomVisitorAdapter() {
+
+ @Override
+ public void visit(OWLClassAssertionAxiom axiom) {
+ if (ind.equals(axiom.getIndividual())) {
+ OWLClassExpression type = axiom.getClassExpression();
+ if (cRegistryLibrary.equals(type)) {
+ pointsFor[0]++;
+ pointsAgainst[1]++;
+ } else if (cOntology.equals(type)) {
+ pointsFor[1]++;
+ pointsAgainst[0]++;
+ }
+ }
+ }
+
+ @Override
+ public void visit(OWLObjectPropertyAssertionAxiom axiom) {
+ OWLObjectPropertyExpression prop = axiom.getProperty();
+ if (ind.equals(axiom.getSubject())) {
+
+ if (hasOntology.equals(prop)) {
+ pointsFor[0]++;
+ pointsAgainst[1]++;
+ } else if (isOntologyOf.equals(prop)) {
+ pointsFor[1]++;
+ pointsAgainst[0]++;
+ }
+
+ } else if (ind.equals(axiom.getObject())) {
+ if (isOntologyOf.equals(prop)) {
+ pointsFor[0]++;
+ pointsAgainst[1]++;
+ } else if (hasOntology.equals(prop)) {
+ pointsFor[1]++;
+ pointsAgainst[0]++;
+ }
+ }
+ }
+
+ };
+
+ // TODO use this strategy in the single pass algorithm for constructing the model.
+ for (OWLOntology o : ontologies)
+ for (OWLAxiom ax : o.getAxioms())
+ ax.accept(v);
+
+ if (pointsFor[0] > 0 && pointsAgainst[0] == 0) return Type.LIBRARY;
+ if (pointsFor[1] > 0 && pointsAgainst[1] == 0) return Type.ONTOLOGY;
+ // Cannot determine registries, since they have no associated individual.
return null;
+
}
-
-// public static Library populateLibrary(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
-// IRI id = ind.getIRI();
-// RegistryItem lib = null;
-// if (population.containsKey(id)) {
-// // We are not allowing multityping either.
-// lib = population.get(id);
-// if (!(lib instanceof Library)) throw new RegistryContentException(
-// "Inconsistent multityping: for item " + id + " : {" + Library.class + ", "
-// + lib.getClass() + "}");
-// } else {
-// lib = riFactory.createLibrary(ind.asOWLNamedIndividual());
-// try {
-// population.put(IRI.create(lib.getURL()), lib);
-// } catch (URISyntaxException e) {
-// log.error("Invalid identifier for library item " + lib, e);
-// return null;
-// }
-// }
-// // EXIT nodes.
-// Set<OWLIndividual> ronts = new HashSet<OWLIndividual>();
-// for (OWLOntology o : registries)
-// ronts.addAll(ind.getObjectPropertyValues(hasOntology, o));
-// for (OWLIndividual iont : ronts) {
-// if (iont.isNamed())
-// lib.addChild(populateOntology(iont.asOWLNamedIndividual(), registries));
-// }
-// return (Library) lib;
-// }
-//
-// public static RegistryOntology populateOntology(OWLNamedIndividual ind, Set<OWLOntology> registries) throws RegistryContentException {
-// IRI id = ind.getIRI();
-// RegistryItem ront = null;
-// if (population.containsKey(id)) {
-// // We are not allowing multityping either.
-// ront = population.get(id);
-// if (!(ront instanceof RegistryOntology)) throw new RegistryContentException(
-// "Inconsistent multityping: for item " + id + " : {" + RegistryOntology.class + ", "
-// + ront.getClass() + "}");
-// } else {
-// ront = riFactory.createRegistryOntology(ind);
-// try {
-// population.put(IRI.create(ront.getURL()), ront);
-// } catch (URISyntaxException e) {
-// log.error("Invalid identifier for library item " + ront, e);
-// return null;
-// }
-// }
-// // EXIT nodes.
-// Set<OWLIndividual> libs = new HashSet<OWLIndividual>();
-// for (OWLOntology o : registries)
-// libs.addAll(ind.getObjectPropertyValues(isOntologyOf, o));
-// for (OWLIndividual ilib : libs) {
-// if (ilib.isNamed())
-// ront.addContainer(populateLibrary(ilib.asOWLNamedIndividual(), registries));
-// }
-// return (RegistryOntology) ront;
-// }
-//
-// public static Registry populateRegistry(OWLOntology registry) throws RegistryContentException {
-//
-// Registry reg = riFactory.createRegistry(registry);
-// Set<OWLOntology> closure = registry.getOWLOntologyManager().getImportsClosure(registry);
-//
-// // Just scan all individuals. Recurse in case the registry imports more registries.
-// for (OWLIndividual ind : registry.getIndividualsInSignature(true)) {
-// // We do not allow anonymous registry items.
-// if (ind.isAnonymous()) continue;
-// RegistryItem item = null;
-// // IRI id = ind.asOWLNamedIndividual().getIRI();
-// Type t = getType(ind, closure);
-// if (t==null) {
-// log.warn("Undetermined type for registry ontology individual {}",ind);
-// continue;
-// }
-// switch (getType(ind, closure)) {
-// case LIBRARY:
-// // // Create the library and attach to parent and children
-// item = populateLibrary(ind.asOWLNamedIndividual(), closure);
-// reg.addChild(item);
-// break;
-// case ONTOLOGY:
-// // Create the ontology and attach to parent
-// item = populateOntology(ind.asOWLNamedIndividual(), closure);
-// // We don't know where to attach it to in this method.
-// break;
-// default:
-// break;
-// }
-// }
-//
-// population = new TreeMap<IRI,RegistryItem>();
-// return reg;
-// }
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/AbstractRegistryItem.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/AbstractRegistryItem.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/AbstractRegistryItem.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/AbstractRegistryItem.java Fri Jul 22 18:37:10 2011
@@ -16,22 +16,23 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.registry.model;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.IllegalRegistryCycleException;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryContentException;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryContentListener;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryOperation;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem;
import org.semanticweb.owlapi.model.IRI;
public abstract class AbstractRegistryItem implements RegistryItem {
- /* Two-way adjacency TODO use maps instead? */
- protected Set<RegistryItem> children = new HashSet<RegistryItem>(),
- parents = new HashSet<RegistryItem>();
+ /* Two-way adjacency index TODO use maps instead? */
+ protected Map<IRI,RegistryItem> children = new HashMap<IRI,RegistryItem>(),
+ parents = new HashMap<IRI,RegistryItem>();
private IRI iri;
@@ -39,28 +40,23 @@ public abstract class AbstractRegistryIt
private String name;
- public AbstractRegistryItem(String name) {
- setName(name);
- }
-
- public AbstractRegistryItem(String name, URL url) throws URISyntaxException {
- this(name);
- setURL(url);
+ public AbstractRegistryItem(IRI iri) {
+ setIRI(iri);
}
- protected void fireContentRequested(RegistryItem item) {
- for (RegistryContentListener listener : getRegistryContentListeners())
- listener.registryContentRequested(item);
+ public AbstractRegistryItem(IRI iri, String name) {
+ this(iri);
+ setName(name);
}
@Override
public void addChild(RegistryItem child) throws RegistryContentException {
- if (parents.contains(child)) throw new RegistryContentException("Cannot add parent item " + child
- + " as a child.");
- if (!children.contains(child)) {
- children.add(child);
+ if (this.equals(child) || parents.values().contains(child)) throw new IllegalRegistryCycleException(
+ this, child, RegistryOperation.ADD_CHILD);
+ if (!children.values().contains(child)) {
+ children.put(child.getIRI(), child);
try {
- child.addContainer(this);
+ child.addParent(this);
} catch (RegistryContentException e) {
// Shouldn't happen. null is always legal.
}
@@ -68,17 +64,19 @@ public abstract class AbstractRegistryIt
}
@Override
- public void addContainer(RegistryItem container) throws RegistryContentException {
- if (children.contains(container)) throw new RegistryContentException("Cannot set child item "
- + container + " as a parent.");
- if (!parents.contains(container)) {
- parents.add(container);
- container.addChild(this);
+ public void addParent(RegistryItem parent) throws RegistryContentException {
+ if (this.equals(parent) || children.values().contains(parent)) throw new IllegalRegistryCycleException(
+ this, parent, RegistryOperation.ADD_PARENT);
+ if (!parents.values().contains(parent)) {
+ parents.put(parent.getIRI(), parent);
+ try {
+ parent.addChild(this);
+ } catch (RegistryContentException e) {
+ // Shouldn't happen. null is always legal.
+ }
}
}
- // private RegistryItem parent;
-
@Override
public void addRegistryContentListener(RegistryContentListener listener) {
listeners.add(listener);
@@ -86,23 +84,39 @@ public abstract class AbstractRegistryIt
@Override
public void clearChildren() {
- for (RegistryItem child : children)
+ for (RegistryItem child : children.values())
removeChild(child);
}
@Override
+ public void clearParents() {
+ for (RegistryItem parent : parents.values())
+ removeParent(parent);
+ }
+
+ @Override
public void clearRegistryContentListeners() {
listeners.clear();
}
+ protected void fireContentRequested(RegistryItem item) {
+ for (RegistryContentListener listener : getRegistryContentListeners())
+ listener.registryContentRequested(item);
+ }
+
+ @Override
+ public RegistryItem getChild(IRI id) {
+ return children.get(id);
+ }
+
@Override
public RegistryItem[] getChildren() {
- return children.toArray(new RegistryItem[children.size()]);
+ return children.values().toArray(new RegistryItem[children.size()]);
}
@Override
- public RegistryItem[] getContainers() {
- return parents.toArray(new RegistryItem[parents.size()]);
+ public IRI getIRI() {
+ return iri;
}
public String getName() {
@@ -110,17 +124,18 @@ public abstract class AbstractRegistryIt
}
@Override
- public Set<RegistryContentListener> getRegistryContentListeners() {
- return listeners;
+ public RegistryItem getParent(IRI id) {
+ return parents.get(id);
}
- public URL getURL() {
- try {
- return iri.toURI().toURL();
- } catch (MalformedURLException e) {
- // Will be obsolete once we replace URLs with IRIs
- return null;
- }
+ @Override
+ public RegistryItem[] getParents() {
+ return parents.values().toArray(new RegistryItem[parents.size()]);
+ }
+
+ @Override
+ public Set<RegistryContentListener> getRegistryContentListeners() {
+ return listeners;
}
@Override
@@ -129,6 +144,11 @@ public abstract class AbstractRegistryIt
}
@Override
+ public boolean hasParents() {
+ return !parents.isEmpty();
+ }
+
+ @Override
public boolean isLibrary() {
return Type.LIBRARY.equals(getType());
}
@@ -139,18 +159,24 @@ public abstract class AbstractRegistryIt
}
@Override
+ public void prune() {
+ clearChildren();
+ clearParents();
+ }
+
+ @Override
public void removeChild(RegistryItem child) {
- if (children.contains(child)) {
- children.remove(child);
- child.removeContainer(this);
+ if (children.values().contains(child)) {
+ children.remove(child.getIRI());
+ child.removeParent(this);
}
}
@Override
- public void removeContainer(RegistryItem container) {
- if (parents.contains(container)) {
- parents.remove(container);
- container.removeChild(this);
+ public void removeParent(RegistryItem parent) {
+ if (parents.values().contains(parent)) {
+ parents.remove(parent.getIRI());
+ parent.removeChild(this);
}
}
@@ -160,13 +186,13 @@ public abstract class AbstractRegistryIt
}
@Override
- public void setName(String string) {
- this.name = string;
+ public void setIRI(IRI iri) {
+ this.iri = iri;
}
@Override
- public void setURL(URL url) throws URISyntaxException {
- this.iri = IRI.create(url);
+ public void setName(String string) {
+ this.name = string;
}
@Override
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/LibraryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/LibraryImpl.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/LibraryImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/LibraryImpl.java Fri Jul 22 18:37:10 2011
@@ -16,8 +16,6 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.registry.model;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.util.HashSet;
import java.util.Set;
@@ -27,6 +25,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Library;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryOntology;
+import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
@@ -37,12 +36,12 @@ public class LibraryImpl extends Abstrac
private boolean loaded = false;
- public LibraryImpl(String name) {
- super(name);
+ public LibraryImpl(IRI iri) {
+ super(iri);
}
- public LibraryImpl(String name, URL url) throws URISyntaxException {
- super(name, url);
+ public LibraryImpl(IRI iri, String name) {
+ super(iri, name);
}
@Override
@@ -80,6 +79,7 @@ public class LibraryImpl extends Abstrac
@Override
public void loadOntologies(OWLOntologyManager mgr) {
+ if (mgr == null) throw new IllegalArgumentException("A null ontology manager is not allowed.");
// TODO Auto-generated method stub
loaded = true;
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryImpl.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryImpl.java Fri Jul 22 18:37:10 2011
@@ -16,11 +16,9 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.registry.model;
-import java.net.URISyntaxException;
-import java.net.URL;
-
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Registry;
import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class RegistryImpl extends AbstractRegistryItem implements Registry {
@@ -29,21 +27,21 @@ public class RegistryImpl extends Abstra
private String message = "";
- public RegistryImpl(String name) {
- this(name, OWLManager.createOWLOntologyManager());
+ public RegistryImpl(IRI iri) {
+ this(iri, OWLManager.createOWLOntologyManager());
}
- public RegistryImpl(String name, OWLOntologyManager cache) {
- super(name);
+ public RegistryImpl(IRI iri, OWLOntologyManager cache) {
+ super(iri);
setCache(cache);
}
- public RegistryImpl(String name, URL url) throws URISyntaxException {
- this(name, url, OWLManager.createOWLOntologyManager());
+ public RegistryImpl(IRI iri, String name) {
+ this(iri, name, OWLManager.createOWLOntologyManager());
}
- public RegistryImpl(String name, URL url, OWLOntologyManager cache) throws URISyntaxException {
- super(name, url);
+ public RegistryImpl(IRI iri, String name, OWLOntologyManager cache) {
+ super(iri, name);
setCache(cache);
}
@@ -65,19 +63,24 @@ public class RegistryImpl extends Abstra
return type;
}
+ @Deprecated
public boolean isError() {
return !isOK();
}
+ @Deprecated
public boolean isOK() {
return this.getError().equals("");
}
@Override
public void setCache(OWLOntologyManager cache) {
+ // TODO use the ontology manager factory.
+ if (cache == null) cache = OWLManager.createOWLOntologyManager();
this.cache = cache;
}
+ @Deprecated
public void setError(String message) {
this.message = message;
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryOntologyImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryOntologyImpl.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryOntologyImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/RegistryOntologyImpl.java Fri Jul 22 18:37:10 2011
@@ -16,26 +16,25 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.registry.model;
-import java.net.URISyntaxException;
-import java.net.URL;
-
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryOntologyNotLoadedException;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryOntology;
+import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
public class RegistryOntologyImpl extends AbstractRegistryItem implements RegistryOntology {
private OWLOntology owl;
- public RegistryOntologyImpl(String name) {
- super(name);
+ public RegistryOntologyImpl(IRI iri) {
+ super(iri);
}
- public RegistryOntologyImpl(String name, URL url) throws URISyntaxException {
- super(name, url);
+ public RegistryOntologyImpl(IRI iri, String name) {
+ super(iri, name);
}
@Override
- public OWLOntology asOWLOntology() {
+ public OWLOntology asOWLOntology() throws RegistryOntologyNotLoadedException {
fireContentRequested(this);
return owl;
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/Locations.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/Locations.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/Locations.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/Locations.java Fri Jul 22 18:37:10 2011
@@ -64,5 +64,10 @@ public class Locations {
* Identifier of test ontology library 2.
*/
public static final IRI LIBRARY_TEST2 = IRI.create(_REGISTRY_TEST + "#Library2");
+
+ /**
+ * Identifier of test ontology library 1.
+ */
+ public static final IRI ONT_TEST1 = IRI.create(__STANBOL_ONT_NAMESPACE + "test1.owl");
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/StructureTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/StructureTest.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/StructureTest.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/StructureTest.java Fri Jul 22 18:37:10 2011
@@ -1,23 +1,26 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet;
import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+
import org.junit.BeforeClass;
import org.junit.Test;
import org.semanticweb.owlapi.apibinding.OWLManager;
@@ -27,48 +30,41 @@ import org.semanticweb.owlapi.model.OWLO
public class StructureTest {
- private static IRI baseIri = IRI.create(Constants.PEANUTS_MAIN_BASE);
+ private static IRI baseIri = IRI.create(Constants.PEANUTS_MAIN_BASE);
- private static OWLOntologyManager ontMgr = null;
+ private static OWLOntologyManager ontMgr = null;
- @BeforeClass
- public static void setUp() {
- try {
- //new Activator().start(null);
- ontMgr = OWLManager.createOWLOntologyManager();
- } catch (Exception e) {
- fail("Bundle activator could not be started");
- }
- }
-
- @Test
- public void testOWLManagerCreation() {
- assertNotNull(ontMgr);
- }
-
- @Test
- public void testOntologyCreation() {
- try {
- assertNotNull(ontMgr.createOntology(baseIri));
- } catch (OWLOntologyCreationException e) {
- fail("An empty ontology manager failed to create ontology with base IRI "
- + baseIri + " !");
- }
- }
-
- // @Test
- // public void testReasoner() {
- // OWLOntology ont = null;
- // ;
- // try {
- // ont = ontMgr.createOntology(baseIri);
- // } catch (OWLOntologyCreationException e) {
- // fail("Could not create ontology with base IRI " + Constants.base);
- // }
- // OWLReasoner reasoner = ManagerContext.get().getReasonerFactory()
- // .createReasoner(ont);
- // assertNotNull(reasoner.getRootOntology());
- // assertTrue(true);
- // }
+ @BeforeClass
+ public static void setUp() {
+ try {
+ // new Activator().start(null);
+ ontMgr = OWLManager.createOWLOntologyManager();
+ } catch (Exception e) {
+ fail("Bundle activator could not be started");
+ }
+ }
+
+ @Test
+ public void testHashMapImplementation() {
+ Map<String,int[]> map = new HashMap<String,int[]>();
+ int[] prova1 = new int[] {0, 0};
+ map.put("test", prova1);
+ prova1[0]++;
+ assertTrue(map.get("test")[0] > 0);
+ }
+
+ @Test
+ public void testOntologyCreation() {
+ try {
+ assertNotNull(ontMgr.createOntology(baseIri));
+ } catch (OWLOntologyCreationException e) {
+ fail("An empty ontology manager failed to create ontology with base IRI " + baseIri + " !");
+ }
+ }
+
+ @Test
+ public void testOWLManagerCreation() {
+ assertNotNull(ontMgr);
+ }
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestIndexing.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestIndexing.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestIndexing.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestIndexing.java Fri Jul 22 18:37:10 2011
@@ -34,7 +34,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryManager;
-import org.apache.stanbol.ontologymanager.ontonet.api.registry.io.OntologyRegistryIRISource;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.io.RegistryIRISource;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.ontologymanager.ontonet.impl.registry.RegistryManagerImpl;
@@ -85,7 +85,7 @@ public class TestIndexing {
try {
scope = onm.getOntologyScopeFactory().createOntologyScope(
scopeIri,
- new OntologyRegistryIRISource(testRegistryIri, onm.getOwlCacheManager(), onm
+ new RegistryIRISource(testRegistryIri, onm.getOwlCacheManager(), onm
.getRegistryLoader(), null
// new RootOntologySource(oParent
));
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyLibrary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyLibrary.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyLibrary.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyLibrary.java Fri Jul 22 18:37:10 2011
@@ -110,7 +110,7 @@ public class TestOntologyLibrary {
Library lib = null;
// Look for test #Library2
for (RegistryItem item : reg.getChildren()) {
- if (Locations.LIBRARY_TEST2.toURI().toURL().equals(item.getURL())) {
+ if (Locations.LIBRARY_TEST2.equals(item.getIRI())) {
lib = (Library) item;
break;
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyRegistry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyRegistry.java?rev=1149687&r1=1149686&r2=1149687&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyRegistry.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyRegistry.java Fri Jul 22 18:37:10 2011
@@ -16,15 +16,15 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.registry;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.io.File;
import java.net.URL;
+import java.util.Collections;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Set;
import org.apache.stanbol.ontologymanager.ontonet.Locations;
import org.apache.stanbol.ontologymanager.ontonet.api.DuplicateIDException;
@@ -34,11 +34,11 @@ import org.apache.stanbol.ontologymanage
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.RegistryManager;
-import org.apache.stanbol.ontologymanager.ontonet.api.registry.io.OntologyRegistryIRISource;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.io.RegistryIRISource;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Registry;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryOntology;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.ontologymanager.ontonet.impl.registry.RegistryManagerImpl;
@@ -52,9 +52,7 @@ import org.semanticweb.owlapi.util.AutoI
public class TestOntologyRegistry {
- private static OWLOntologyManager ontologyManager;
- private static RegistryLoader loader;
- private static OntologyRegistryIRISource ontologySource;
+ private static RegistryIRISource ontologySource;
private static ONManagerConfiguration configuration;
private static ONManager onm;
@@ -65,9 +63,6 @@ public class TestOntologyRegistry {
RegistryManager regman = new RegistryManagerImpl(emptyConfig);
// An ONManagerImpl with no store and default settings
onm = new ONManagerImpl(null, null, configuration, regman, emptyConfig);
- ontologyManager = onm.getOwlCacheManager();
- loader = onm.getRegistryLoader();
-
}
// private static boolean mapperIsSet = false;
@@ -86,11 +81,19 @@ public class TestOntologyRegistry {
assertNotNull(url);
virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
// Population is lazy; no need to add other mappers.
+
OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
- Registry r = onm.getRegistryManager().populateRegistry(oReg);
- assertNotNull(r);
- int count = 2;
+ Set<Registry> rs = onm.getRegistryManager().createModel(Collections.singleton(oReg));
+
+ assertEquals(1, rs.size());
+ Registry r = rs.iterator().next();
+ assertTrue(r.hasChildren());
+ // The nonexistent library should also be included, if using the more powerful algorithm.
+ int count = 3; // set to 2 if using the less powerful algorithm.
assertEquals(count, r.getChildren().length);
+
+ for (RegistryItem ri : r.getChildren())
+ assertTrue(ri.hasChildren());
}
/**
@@ -106,26 +109,41 @@ public class TestOntologyRegistry {
assertNotNull(url);
virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
// Population is lazy; no need to add other mappers.
- OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
- Registry r1 = onm.getRegistryManager().populateRegistry(oReg);
- // Now the second registry.
- oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS);
- Registry r2 = onm.getRegistryManager().populateRegistry(oReg);
- assertNotNull(r2);
- int count = 2;
- assertEquals(count, r1.getChildren().length);
-// for (RegistryItem lib : r1.getChildren()) {
-// System.out.println("\t"+lib);
-// for (RegistryItem ont : lib.getChildren()) {
-// System.out.println("\t\t"+ont);
-// }
-// }
-// for (RegistryItem lib : r2.getChildren()) {
-// System.out.println("\t"+lib);
-// for (RegistryItem ont : lib.getChildren()) {
-// System.out.println("\t\t"+ont);
-// }
-// }
+
+ // Create the model from two overlapping registries.
+ Set<OWLOntology> regs = new HashSet<OWLOntology>();
+ regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST));
+ regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS));
+ Set<Registry> rs = onm.getRegistryManager().createModel(regs);
+
+ for (Registry r : rs) {
+ // The nonexistent library should also be included, if using the more powerful algorithm.
+ if (Locations._REGISTRY_TEST.equals(r.getIRI())) assertEquals(3, r.getChildren().length); // set
+ // to 2
+ // if
+ // using
+ // the
+ // less
+ // powerful
+ // algorithm.
+ else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI())) assertEquals(1,
+ r.getChildren().length);
+ // check
+ for (RegistryItem lib : r.getChildren()) {
+ if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
+ boolean found = false;
+ for (RegistryItem child : lib.getChildren()) {
+ if (child instanceof RegistryOntology && Locations.ONT_TEST1.equals(child.getIRI())) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue(found);
+ break;
+ }
+
+ }
+ }
}
@Test