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 2012/08/15 17:08:49 UTC
svn commit: r1373449 [3/3] - in /incubator/stanbol/trunk: commons/owl/
commons/owl/src/main/java/org/apache/stanbol/commons/owl/
commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/
commons/owl/src/test/java/org/apache/stanbol/commons/owl/tra...
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java Wed Aug 15 15:08:48 2012
@@ -1068,7 +1068,7 @@ public class ClerezzaOntologyProvider im
// XXX Force is ignored for the content, but the imports?
// TODO Profile this method. Are we getting rid of rdfData after adding its triples?
- OWLOntologyID publicKey = OWLUtils.guessOntologyIdentifier(rdfData);
+ OWLOntologyID publicKey = OWLUtils.extractOntologyID(rdfData);
if (publicKey == null) {
IRI z;
if (origins.length > 0 && origins[0] != null) {
@@ -1095,8 +1095,8 @@ public class ClerezzaOntologyProvider im
* ontology source. XXX note that anonymous ontologies should be considered a match... or
* should they not?
*/
- OWLOntologyID idFromSrc = OWLUtils.guessOntologyIdentifier(rdfData);
- OWLOntologyID idFromStore = OWLUtils.guessOntologyIdentifier(store.getTriples(ref));
+ OWLOntologyID idFromSrc = OWLUtils.extractOntologyID(rdfData);
+ OWLOntologyID idFromStore = OWLUtils.extractOntologyID(store.getTriples(ref));
condition &= (idFromSrc == null && idFromStore == null) || idFromSrc.equals(idFromStore);
// Finally, a size check
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java Wed Aug 15 15:08:48 2012
@@ -59,7 +59,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * A set of static utility methods for managing ontologies in KReS.
+ * A set of static utility methods for managing ontologies.
*
* @author alexdma
*
@@ -71,87 +71,9 @@ public class OntologyUtils {
private static String[] preferredFormats = {RDF_XML, TURTLE, X_TURTLE, RDF_JSON, N3, N_TRIPLE,
MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML};
- @Deprecated
- public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
- OntologyInputSource<OWLOntology> childSrc) {
- return appendOntology(parentSrc, childSrc, null, null);
- }
-
- @Deprecated
- public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
- OntologyInputSource<OWLOntology> childSrc,
- IRI rewritePrefix) {
- return appendOntology(parentSrc, childSrc, null, rewritePrefix);
- }
-
- @Deprecated
- public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
- OntologyInputSource<OWLOntology> childSrc,
- OWLOntologyManager ontologyManager) {
- return appendOntology(parentSrc, childSrc, ontologyManager, null);
- }
-
- /**
- * This method appends one ontology (the child) to another (the parent) by proceeding as follows. If a
- * physical URI can be obtained from the child source, an import statement using that physical URI will be
- * added to the parent ontology, otherwise all the axioms from the child ontology will be copied to the
- * parent. <br>
- * Note: the ontology manager will not load additional ontologies.
- *
- * @deprecated
- * @param parentSrc
- * must exist!
- * @param childSrc
- * @param ontologyManager
- * can be null (e.g. when one does not want changes to be immediately reflected in their
- * ontology manager), in which case a temporary ontology manager will be used.
- * @param rewritePrefix
- * . if not null, import statements will be generated in the form
- * <tt>rewritePrefix/child_ontology_logical_IRI</tt>. It can be used for relocating the
- * ontology document file elsewhere.
- * @return the parent with the appended child
- */
- public static OWLOntology appendOntology(OntologyInputSource<OWLOntology> parentSrc,
- OntologyInputSource<OWLOntology> childSrc,
- OWLOntologyManager ontologyManager,
- IRI rewritePrefix) {
-
- if (ontologyManager == null) ontologyManager = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = ontologyManager.getOWLDataFactory();
- OWLOntology oParent = parentSrc.getRootOntology();
- OWLOntology oChild = childSrc.getRootOntology();
-
- // Named ontology with a provided absolute prefix. Use name and prefix
- // for creating an new import statement.
- if (!oChild.isAnonymous() && rewritePrefix != null
- /* && rewritePrefix.isAbsolute() */) {
- IRI impIri = IRI.create(rewritePrefix + "/" + oChild.getOntologyID().getOntologyIRI());
- OWLImportsDeclaration imp = factory.getOWLImportsDeclaration(impIri);
- ontologyManager.applyChange(new AddImport(oParent, imp));
- }
- // Anonymous, with physicalIRI. A plain import statement is added.
- else if (childSrc.hasOrigin() && childSrc.getOrigin().getReference() instanceof IRI) {
- OWLImportsDeclaration imp = factory.getOWLImportsDeclaration((IRI) (childSrc.getOrigin()
- .getReference()));
- ontologyManager.applyChange(new AddImport(oParent, imp));
- }
-
- // Anonymous and no physical IRI (e.g. in memory). Copy all axioms and
- // import statements.
- else {
- ontologyManager.addAxioms(oParent, oChild.getAxioms());
- for (OWLImportsDeclaration imp : oChild.getImportsDeclarations())
- ontologyManager.applyChange(new AddImport(oParent, factory.getOWLImportsDeclaration(imp
- .getIRI())));
- }
- return oParent;
- }
-
public static OWLOntology buildImportTree(OntologyInputSource<OWLOntology> rootSrc,
Set<OWLOntology> subtrees) {
-
return buildImportTree(rootSrc.getRootOntology(), subtrees, OWLManager.createOWLOntologyManager());
-
}
/**
@@ -194,59 +116,7 @@ public class OntologyUtils {
* @return the same input ontology as defined in <code>root</code>, but with the added import statements.
*/
public static OWLOntology buildImportTree(OWLOntology root, Set<OWLOntology> subtrees) {
-
return buildImportTree(root, subtrees, OWLManager.createOWLOntologyManager());
-
- }
-
- /**
- * Provides a standardized string format for an OWL Ontology ID. The string returned is of type
- * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or
- * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/>
- * <br/>
- * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other
- * URL encoding occurs.
- *
- * @param id
- * the OWL ontology ID to encode
- * @return the string form of this ID.
- * @see URIUtils#sanitize(IRI)
- */
- public static String encode(OWLOntologyID id) {
- if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID.");
- if (id.getOntologyIRI() == null) throw new IllegalArgumentException(
- "Cannot encode an OWLOntologyID that is missing an ontologyIRI.");
- String s = "";
- s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A");
- if (id.getVersionIRI() != null) s += (":::")
- + URIUtils.sanitize(id.getVersionIRI()).toString()
- .replace(":::", "%3A%3A%3A");
- return s;
- }
-
- /**
- * Extracts an OWL Ontology ID from its standard string form. The string must be of type
- * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt>
- * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/>
- * <br/>
- * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process.
- *
- * @param stringForm
- * the string to decode
- * @return the string form of this ID.
- * @see URIUtils#desanitize(IRI)
- */
- public static OWLOntologyID decode(String stringForm) {
- if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException(
- "Supplied string form must be non-null and non-empty.");
- IRI oiri, viri;
- String[] split = stringForm.split(":::");
- if (split.length >= 1) {
- oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::")));
- viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::")))
- : null;
- return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri);
- } else return null; // Anonymous but versioned ontologies are not acceptable.
}
/**
@@ -337,31 +207,77 @@ public class OntologyUtils {
}
public static OWLOntology buildImportTree(Set<OWLOntology> subtrees) throws OWLOntologyCreationException {
-
return buildImportTree(subtrees, OWLManager.createOWLOntologyManager());
-
}
public static OWLOntology buildImportTree(Set<OWLOntology> subtrees, OWLOntologyManager mgr) throws OWLOntologyCreationException {
-
return buildImportTree(new RootOntologySource(mgr.createOntology()), subtrees, mgr);
+ }
+ /**
+ * Extracts an OWL Ontology ID from its standard string form. The string must be of type
+ * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt>
+ * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/>
+ * <br/>
+ * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process.
+ *
+ * @param stringForm
+ * the string to decode
+ * @return the string form of this ID.
+ * @see URIUtils#desanitize(IRI)
+ */
+ public static OWLOntologyID decode(String stringForm) {
+ if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException(
+ "Supplied string form must be non-null and non-empty.");
+ IRI oiri, viri;
+ String[] split = stringForm.split(":::");
+ if (split.length >= 1) {
+ oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::")));
+ viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::")))
+ : null;
+ return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri);
+ } else return null; // Anonymous but versioned ontologies are not acceptable.
}
- public static List<String> getPreferredSupportedFormats(Collection<String> supported) {
+ /**
+ * Provides a standardized string format for an OWL Ontology ID. The string returned is of type
+ * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or
+ * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/>
+ * <br/>
+ * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other
+ * URL encoding occurs.
+ *
+ * @param id
+ * the OWL ontology ID to encode
+ * @return the string form of this ID.
+ * @see URIUtils#sanitize(IRI)
+ */
+ public static String encode(OWLOntologyID id) {
+ if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID.");
+ if (id.getOntologyIRI() == null) throw new IllegalArgumentException(
+ "Cannot encode an OWLOntologyID that is missing an ontologyIRI.");
+ String s = "";
+ s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A");
+ if (id.getVersionIRI() != null) s += (":::")
+ + URIUtils.sanitize(id.getVersionIRI()).toString()
+ .replace(":::", "%3A%3A%3A");
+ return s;
+ }
+
+ public static List<String> getPreferredFormats() {
List<String> result = new ArrayList<String>();
for (String f : preferredFormats)
- if (supported.contains(f)) result.add(f);
- // The non-preferred supported formats on the tail in any order
- for (String f : supported)
- if (!result.contains(f)) result.add(f);
+ result.add(f);
return result;
}
- public static List<String> getPreferredFormats() {
+ public static List<String> getPreferredSupportedFormats(Collection<String> supported) {
List<String> result = new ArrayList<String>();
for (String f : preferredFormats)
- result.add(f);
+ if (supported.contains(f)) result.add(f);
+ // The non-preferred supported formats on the tail in any order
+ for (String f : supported)
+ if (!result.contains(f)) result.add(f);
return result;
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestClerezzaProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestClerezzaProvider.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestClerezzaProvider.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestClerezzaProvider.java Wed Aug 15 15:08:48 2012
@@ -64,8 +64,6 @@ public class TestClerezzaProvider {
private String fn1 = "/ontologies/versiontest_v1.owl", fn2 = "/ontologies/versiontest_v2.owl";
- private String oiri = "http://stanbol.apache.org/ontologies/versiontest";
-
private OntologyProvider<TcProvider> ontologyProvider;
private OfflineConfiguration offline = new OfflineConfigurationImpl(new Hashtable<String,Object>());
@@ -98,7 +96,7 @@ public class TestClerezzaProvider {
// Must be 2 different graphs
assertFalse(key1.equals(key2));
- assertEquals(2, ontologyProvider.getPublicKeys().size());
+ assertEquals(2, ontologyProvider.listOntologies().size());
// Ontologies must not be tainting each other
// Don't use keys any more here. They're not the real public keys!
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestStorage.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestStorage.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestStorage.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestStorage.java Wed Aug 15 15:08:48 2012
@@ -42,6 +42,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,7 +97,7 @@ public class TestStorage {
String ephemeralScopeId = "CaducousScope";
OntologyInputSource<OWLOntology> ois = new RootOntologyIRISource(IRI.create(getClass().getResource(
"/ontologies/nonexistentcharacters.owl")));
- IRI ontologyId = ois.getRootOntology().getOntologyID().getOntologyIRI();
+ OWLOntologyID ontologyId = ois.getRootOntology().getOntologyID();
OntologyScope scope = onManager.createOntologyScope(ephemeralScopeId);
// Initially, the ontology is not there
assertFalse(ontologyProvider.hasOntology(ontologyId));
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java Wed Aug 15 15:08:48 2012
@@ -28,14 +28,11 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.util.Hashtable;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
-import org.apache.stanbol.commons.owl.OWLOntologyManagerFactory;
import org.apache.stanbol.commons.owl.util.OWLUtils;
import org.apache.stanbol.ontologymanager.ontonet.Constants;
import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
@@ -64,8 +61,7 @@ import org.semanticweb.owlapi.model.OWLC
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
-import org.semanticweb.owlapi.model.OWLOntologyCreationException;
-import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.model.OWLOntologyID;
public class TestClerezzaSpaces {
@@ -87,15 +83,6 @@ public class TestClerezzaSpaces {
return new GraphSource(parser.parse(is, SupportedFormat.RDF_XML));
}
- private static OntologyInputSource<?> getLocalSource(String resourcePath, OWLOntologyManager mgr) throws OWLOntologyCreationException,
- URISyntaxException {
- URL url = TestOntologySpaces.class.getResource(resourcePath);
- File f = new File(url.toURI());
- return new ParentPathInputSource(f, mgr != null ? mgr
- : OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations()
- .toArray(new IRI[0])));
- }
-
@BeforeClass
public static void setup() throws Exception {
offline = new OfflineConfigurationImpl(new Hashtable<String,Object>());
@@ -130,7 +117,7 @@ public class TestClerezzaSpaces {
public void testAddOntology() throws Exception {
CustomOntologySpace space = null;
- IRI logicalId = OWLUtils.guessOntologyIdentifier(nonexSrc.getRootOntology()).getOntologyIRI();
+ OWLOntologyID logicalId = OWLUtils.extractOntologyID(nonexSrc.getRootOntology());
assertNotNull(logicalId);
space = factory.createCustomOntologySpace(scopeId, dropSrc, minorSrc);
@@ -138,7 +125,7 @@ public class TestClerezzaSpaces {
space.addOntology(nonexSrc);
assertTrue(space.hasOntology(logicalId));
- logicalId = OWLUtils.guessOntologyIdentifier(dropSrc.getRootOntology()).getOntologyIRI();
+ logicalId = OWLUtils.extractOntologyID(dropSrc.getRootOntology());
assertNotNull(logicalId);
assertTrue(space.hasOntology(logicalId));
}
@@ -158,12 +145,10 @@ public class TestClerezzaSpaces {
@Test
public void testCreateSpace() throws Exception {
CustomOntologySpace space = factory.createCustomOntologySpace(scopeId, dropSrc);
- IRI logicalId = null;
+ OWLOntologyID logicalId = null;
Object o = dropSrc.getRootOntology();
- if (o instanceof TripleCollection) logicalId = OWLUtils.guessOntologyIdentifier((TripleCollection) o)
- .getOntologyIRI();
- else if (o instanceof OWLOntology) logicalId = OWLUtils.guessOntologyIdentifier((OWLOntology) o)
- .getOntologyIRI();
+ if (o instanceof TripleCollection) logicalId = OWLUtils.extractOntologyID((TripleCollection) o);
+ else if (o instanceof OWLOntology) logicalId = OWLUtils.extractOntologyID((OWLOntology) o);
assertNotNull(logicalId);
assertTrue(space.hasOntology(logicalId));
}
@@ -259,8 +244,8 @@ public class TestClerezzaSpaces {
public void testRemoveCustomOntology() throws Exception {
CustomOntologySpace space = null;
space = factory.createCustomOntologySpace(scopeId, dropSrc);
- IRI dropId = OWLUtils.guessOntologyIdentifier(dropSrc.getRootOntology()).getOntologyIRI();
- IRI nonexId = OWLUtils.guessOntologyIdentifier(nonexSrc.getRootOntology()).getOntologyIRI();
+ OWLOntologyID dropId = OWLUtils.extractOntologyID(dropSrc.getRootOntology());
+ OWLOntologyID nonexId = OWLUtils.extractOntologyID(nonexSrc.getRootOntology());
space.addOntology(inMemorySrc);
space.addOntology(nonexSrc);