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 [1/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...
Author: alexdma
Date: Wed Aug 15 15:08:48 2012
New Revision: 1373449
URL: http://svn.apache.org/viewvc?rev=1373449&view=rev
Log:
Implemented necessary utilities for STANBOL-709. Lookahead Graph and ID guesser methods were moved from ontologymanager to commons.owl and improved to support owl:versionIRI, as well as cases where the ontology IRI and version IRI are displaced. Unit tests added for all standard cases.
Added:
incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/OntologyLookaheadMGraph.java
- copied, changed from r1372826, incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologyLookaheadMGraph.java
incubator/stanbol/trunk/commons/owl/src/test/resources/log4j.properties
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/named.owl
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/named_immediate.owl
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/nameless.owl
- copied unchanged from r1372826, incubator/stanbol/trunk/commons/owl/src/test/resources/owl/nameless_ontology.owl
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned.owl
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_distance-100-reversed.owl
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_distance-100.owl
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_immediate.owl
Removed:
incubator/stanbol/trunk/commons/owl/src/test/resources/owl/nameless_ontology.owl
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologyLookaheadMGraph.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/TestUtilities.java
Modified:
incubator/stanbol/trunk/commons/owl/pom.xml
incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/OWLUtils.java
incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/transformation/ConversionTester.java
incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/TestOWLUtils.java
incubator/stanbol/trunk/contrib/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/resources/ReengineerResource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologyContentInputSource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOWLUtils.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/util/OntologyUtils.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/TestClerezzaProvider.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestStorage.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java
Modified: incubator/stanbol/trunk/commons/owl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/owl/pom.xml?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/owl/pom.xml (original)
+++ incubator/stanbol/trunk/commons/owl/pom.xml Wed Aug 15 15:08:48 2012
@@ -119,6 +119,7 @@
<dependencies>
+
<!-- Stanbol deps -->
<dependency>
<groupId>org.apache.stanbol</groupId>
@@ -205,6 +206,12 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.testing.stanbol</artifactId>
+ <version>0.9.0-incubating</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.simple.storage</artifactId>
Copied: incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/OntologyLookaheadMGraph.java (from r1372826, incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologyLookaheadMGraph.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/OntologyLookaheadMGraph.java?p2=incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/OntologyLookaheadMGraph.java&p1=incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologyLookaheadMGraph.java&r1=1372826&r2=1373449&rev=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologyLookaheadMGraph.java (original)
+++ incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/OntologyLookaheadMGraph.java Wed Aug 15 15:08:48 2012
@@ -14,57 +14,129 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.stanbol.ontologymanager.ontonet.impl.clerezza;
+package org.apache.stanbol.commons.owl;
import java.util.Iterator;
import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.Triple;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.apache.stanbol.commons.owl.util.OWL2Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * An utility modifiable graph that only
+ * An utility modifiable graph that only accepts triples that deal with naming this graph as an ontology.
*
* @author alexdma
*
*/
public class OntologyLookaheadMGraph extends SimpleMGraph {
+ private Logger log = LoggerFactory.getLogger(getClass());
+
private UriRef ontologyIRI = null, versionIRI = null;
- @Override
- public boolean performAdd(Triple t) {
- boolean b = false;
+ private int tripleCount = 0, foundIndex = -1;
- // filter the interesting Triples
- if (RDF.type.equals(t.getPredicate()) && OWL.Ontology.equals(t.getObject())) b = super.performAdd(t);
- else if (new UriRef(OWL2Constants.OWL_VERSION_IRI).equals(t.getPredicate())) b = super.performAdd(t);
+ private int maxTriples, offset = 10;
- // check the currently available triples for the Ontology ID
- checkOntologyId();
+ private UriRef versionIriProperty = new UriRef(OWL2Constants.OWL_VERSION_IRI);
- if (ontologyIRI != null) throw new RuntimeException(); // stop importing
- // TODO: add a limit to the triples you read
+ public OntologyLookaheadMGraph() {
+ this(-1, -1);
+ }
- return b;
+ public OntologyLookaheadMGraph(int maxTriples) {
+ this(maxTriples, Math.max(10, maxTriples / 10));
}
- public UriRef getOntologyIRI() {
- return ontologyIRI;
+ public OntologyLookaheadMGraph(int maxTriples, int offset) {
+ if (maxTriples > 0 && offset > maxTriples) throw new IllegalArgumentException(
+ "Offset cannot be greater than the maximum triples to scan.");
+ this.maxTriples = maxTriples;
+ this.offset = offset;
}
- private void checkOntologyId() {
+ protected void checkOntologyId() {
for (Iterator<Triple> it = this.filter(null, RDF.type, OWL.Ontology); it.hasNext();) {
NonLiteral s = it.next().getSubject();
if (s instanceof UriRef) {
ontologyIRI = (UriRef) s;
+ if (foundIndex <= 0) foundIndex = tripleCount;
break;
}
}
+ /*
+ * TODO be more tolerant with versionIRI triples with no owl:Ontology typing?
+ */
+ for (Iterator<Triple> it = this.filter(null, versionIriProperty, null); it.hasNext();) {
+ Resource o = it.next().getObject();
+ if (o instanceof UriRef) {
+ versionIRI = (UriRef) o;
+ if (foundIndex <= 0) foundIndex = tripleCount;
+ break;
+ }
+ }
+ }
+
+ /**
+ * Returns the maximum distance allowed (in triples) between the ontology IRI and version IRI
+ * declarations. A negative value indicates no limit.
+ *
+ * @return
+ */
+ public int getOffset() {
+ return offset;
+ }
+
+ public UriRef getOntologyIRI() {
+ return ontologyIRI;
+ }
+
+ public int getScannedTripleCount() {
+ return tripleCount;
+ }
+
+ public UriRef getVersionIRI() {
+ return versionIRI;
+ }
+
+ @Override
+ public boolean performAdd(Triple t) {
+ // Check if the overall triple limit has been reached.
+ if (maxTriples > 0 && tripleCount == maxTriples) {
+ log.debug("Triple limit {} reached. Stopping triple addition.", maxTriples);
+ throw new RuntimeException();
+ }
+ // If one IRI was found, check if the allowed offset has been reached.
+ // (if foundIndex is positive, then tripleCount must be at least the same.)
+ if (foundIndex > 0 && tripleCount - foundIndex == offset) {
+ log.debug("Offset reached.");
+ log.debug("Triples scanned: {}", tripleCount);
+ log.debug("Found at: {}", foundIndex);
+ log.debug("Offset: {}", offset);
+ throw new RuntimeException();
+ }
+ boolean b = false;
+ tripleCount++;
+
+ // filter the interesting Triples
+ if (versionIriProperty.equals(t.getPredicate())
+ || (RDF.type.equals(t.getPredicate()) && OWL.Ontology.equals(t.getObject()))) b = super
+ .performAdd(t);
+
+ // check the currently available triples for the Ontology ID
+ checkOntologyId();
+ if (ontologyIRI != null && versionIRI != null) {
+ log.debug("Fully qualified OWL Ontology ID found. Aborting.");
+ throw new RuntimeException(); // stop importing
+ }
+ return b;
}
}
Modified: incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/OWLUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/OWLUtils.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/OWLUtils.java (original)
+++ incubator/stanbol/trunk/commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/OWLUtils.java Wed Aug 15 15:08:48 2012
@@ -16,14 +16,19 @@
*/
package org.apache.stanbol.commons.owl.util;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.Triple;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.stanbol.commons.owl.OntologyLookaheadMGraph;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyID;
@@ -35,6 +40,8 @@ import org.slf4j.LoggerFactory;
*/
public class OWLUtils {
+ private static int _LOOKAHEAD_LIMIT_DEFAULT = 1024;
+
private static Logger log = LoggerFactory.getLogger(OWLUtils.class);
public static final String NS_STANBOL = "http://stanbol.apache.org/";
@@ -46,7 +53,7 @@ public class OWLUtils {
* @param o
* @return
*/
- public static OWLOntologyID guessOntologyIdentifier(OWLOntology o) {
+ public static OWLOntologyID extractOntologyID(OWLOntology o) {
String oiri;
IRI viri = null;
// For named OWL ontologies it is their ontology ID.
@@ -71,7 +78,7 @@ public class OWLUtils {
* the RDF graph
* @return the OWL ontology ID of the supplied graph, or null if it denotes an anonymous ontology.
*/
- public static OWLOntologyID guessOntologyIdentifier(TripleCollection graph) {
+ public static OWLOntologyID extractOntologyID(TripleCollection graph) {
IRI ontologyIri = null, versionIri = null;
Iterator<Triple> it = graph.filter(null, RDF.type, OWL.Ontology);
if (it.hasNext()) {
@@ -97,4 +104,52 @@ public class OWLUtils {
else return new OWLOntologyID(ontologyIri, versionIri);
}
+ /**
+ * Performs lookahead with a 100 kB limit.
+ *
+ * @param content
+ * @param parser
+ * @param format
+ * @return
+ * @throws IOException
+ */
+ public static OWLOntologyID guessOntologyID(InputStream content, Parser parser, String format) throws IOException {
+ return guessOntologyID(content, parser, format, _LOOKAHEAD_LIMIT_DEFAULT);
+ }
+
+ public static OWLOntologyID guessOntologyID(InputStream content, Parser parser, String format, int limit) throws IOException {
+ return guessOntologyID(content, parser, format, limit, Math.max(10, limit / 10));
+ }
+
+ public static OWLOntologyID guessOntologyID(InputStream content,
+ Parser parser,
+ String format,
+ int limit,
+ int versionIriOffset) throws IOException {
+ long before = System.currentTimeMillis();
+ log.info("Guessing ontology ID. Read limit = {} triples; offset = {} triples.", limit,
+ versionIriOffset);
+ BufferedInputStream bIn = new BufferedInputStream(content);
+ bIn.mark(limit * 512); // set an appropriate limit
+ OntologyLookaheadMGraph graph = new OntologyLookaheadMGraph(limit, versionIriOffset);
+ try {
+ parser.parse(graph, bIn, format);
+ } catch (RuntimeException e) {}
+ OWLOntologyID result;
+
+ if (graph.getOntologyIRI() == null) { // No Ontology ID found
+ log.warn(" *** No ontology ID found, ontology has a chance of being anonymous.");
+ result = null;
+ } else {
+ // bIn.reset(); // reset set the stream to the start
+ IRI oiri = IRI.create(graph.getOntologyIRI().getUnicodeString());
+ result = graph.getVersionIRI() == null ? new OWLOntologyID(oiri) : new OWLOntologyID(oiri,
+ IRI.create(graph.getVersionIRI().getUnicodeString()));
+ log.info(" *** Guessed ID : {}", result);
+ }
+ log.info(" *** Triples scanned : {}, filtered : {}", graph.getScannedTripleCount(), graph.size());
+ log.info(" *** Time : {} ms", System.currentTimeMillis() - before);
+ return result;
+ }
+
}
Modified: incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/transformation/ConversionTester.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/transformation/ConversionTester.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/transformation/ConversionTester.java (original)
+++ incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/transformation/ConversionTester.java Wed Aug 15 15:08:48 2012
@@ -1,19 +1,19 @@
/*
-* 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.
+ */
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@@ -25,30 +25,34 @@ package org.apache.stanbol.commons.owl.t
*
* @author elvio
*/
-import com.hp.hpl.jena.ontology.AnnotationProperty;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
import java.net.URI;
import java.util.Set;
import junit.framework.TestCase;
-import org.apache.stanbol.commons.owl.transformation.JenaToOwlConvert;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDatatype;
+import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
+import org.semanticweb.owlapi.model.OWLIndividualAxiom;
+import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
+
+import com.hp.hpl.jena.ontology.AnnotationProperty;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty;
@@ -58,554 +62,539 @@ import com.hp.hpl.jena.rdf.model.Literal
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
-import org.semanticweb.owlapi.model.OWLAnnotation;
-import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
-import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
-import org.semanticweb.owlapi.model.OWLIndividualAxiom;
-import org.semanticweb.owlapi.model.OWLLiteral;
public class ConversionTester extends TestCase {
- private static final String RDFXML = "RDF/XML";
+ private static final String RDFXML = "RDF/XML";
- private static final String _BASE = "http://example.org/dummy";
+ private static final String _BASE = "http://example.org/dummy";
- private static final URI CLAZZ = URI.create(_BASE + "#" + "Peanut");
+ private static final URI CLAZZ = URI.create(_BASE + "#" + "Peanut");
- private static final URI SUBJECT = URI.create(_BASE + "#" + "Lucy");
+ private static final URI SUBJECT = URI.create(_BASE + "#" + "Lucy");
- private static final URI OP = URI.create(_BASE + "#" + "hasSibling");
+ private static final URI OP = URI.create(_BASE + "#" + "hasSibling");
- private static final URI DP = URI.create(_BASE + "#" + "hasAge");
+ private static final URI DP = URI.create(_BASE + "#" + "hasAge");
private static final URI label = URI.create("http://www.w3.org/2000/01/rdf-schema#label");
private static final String clazzlabel = "Peanut";
- private static final String VALUE = "8";
+ private static final String VALUE = "8";
- private static final URI DATATYPE = URI.create("http://www.w3.org/2001/XMLSchema#int");
+ private static final URI DATATYPE = URI.create("http://www.w3.org/2001/XMLSchema#int");
- private static final URI OBJECT = URI.create(_BASE + "#" + "Linus");
+ private static final URI OBJECT = URI.create(_BASE + "#" + "Linus");
- public void testAxiomOwlToJenaResource(){
+ public void testAxiomOwlToJenaResource() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
-
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLOntology ont = null;
- try{
- ont = mgr.createOntology();
- } catch(OWLOntologyCreationException e){
- e.printStackTrace();
- fail("Can not create ontology");
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLOntology ont = null;
+ try {
+ ont = mgr.createOntology();
+ } catch (OWLOntologyCreationException e) {
+ e.printStackTrace();
+ fail("Can not create ontology");
+ }
+
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+
+ StmtIterator resource = null;
+
+ OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
+ OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
+ OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
+ OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
+ OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
+ OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
+ OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
+ OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
+ OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
+ OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls); // Classe
+ OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op); // obj prop
+ OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp); // data prop
+ OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub); // subject
+ OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj); // object
+
+ OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub); // Istanza
+ OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj); // Istanza
+ OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj); // Obj
+ // prop
+ // tra
+ // individui
+ OWLDataPropertyAssertionAxiom axiomvalue = factory
+ .getOWLDataPropertyAssertionAxiom(dp, obj, literal1); // Dataprop all'istanza;
+ OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav); // Annotazione
+
+ mgr.addAxiom(ont, daxiomcls);
+ mgr.addAxiom(ont, daxiomop);
+ mgr.addAxiom(ont, daxiomdp);
+ mgr.addAxiom(ont, daxiomsub);
+ mgr.addAxiom(ont, daxiomobj);
+ mgr.addAxiom(ont, axiomsub);
+ mgr.addAxiom(ont, axiomobj);
+ mgr.addAxiom(ont, axiomop);
+ mgr.addAxiom(ont, axiomvalue);
+ mgr.addAxiom(ont, axioman);
+
+ Set<OWLAxiom> setaxiom = ont.getAxioms();
+
+ try {
+ resource = j2o.AxiomOwlToJenaResource(setaxiom, RDFXML);
+ if (resource == null) {
+ fail("Some errors occur");
+ } else {
+ String statment = "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/2000/01/rdf-schema#range, http://www.w3.org/2000/01/rdf-schema#Literal] "
+ + "[http://example.org/dummy#hasAge, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#DatatypeProperty] "
+ + "[http://example.org/dummy#Linus, http://example.org/dummy#hasAge, \"8\"^^http://www.w3.org/2001/XMLSchema#int] "
+ + "[http://example.org/dummy#Linus, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] "
+ + "[http://example.org/dummy#hasSibling, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#ObjectProperty] "
+ + "[http://example.org/dummy#Lucy, http://example.org/dummy#hasSibling, http://example.org/dummy#Linus] "
+ + "[http://example.org/dummy#Lucy, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] "
+ + "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#AnnotationProperty] "
+ + "[http://example.org/dummy#Peanut, http://www.w3.org/2000/01/rdf-schema#label, \"Peanut\"@en] "
+ + "[http://example.org/dummy#Peanut, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class]";
+
+ int size = setaxiom.size();
+ int count = 0;
+ while (resource.hasNext()) {
+ Statement stm = resource.nextStatement();
+ Resource jsubj = stm.getSubject();
+ if (jsubj.getURI().equals(OP.toString()) || jsubj.getURI().equals(DP.toString())
+ || jsubj.getURI().equals(CLAZZ.toString())
+ || jsubj.getURI().equals(OBJECT.toString())
+ || jsubj.getURI().equals(SUBJECT.toString())
+ || jsubj.getURI().equals(label.toString())) if (statment.contains(stm.toString())) count++;
}
- OWLDataFactory factory = mgr.getOWLDataFactory();
-
- StmtIterator resource = null;
-
- OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
- OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
- OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
- OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
- OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel,"en"));
- OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
- OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
- OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
- OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE,dt);
- OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls); //Classe
- OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op); //obj prop
- OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp); //data prop
- OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub); //subject
- OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj); //object
-
- OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls,sub); //Istanza
- OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls,obj); //Istanza
- OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj); //Obj prop tra individui
- OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, obj,literal1); //Dataprop all'istanza;
- OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav); //Annotazione
-
- mgr.addAxiom(ont,daxiomcls);
- mgr.addAxiom(ont,daxiomop);
- mgr.addAxiom(ont,daxiomdp);
- mgr.addAxiom(ont,daxiomsub);
- mgr.addAxiom(ont,daxiomobj);
- mgr.addAxiom(ont,axiomsub);
- mgr.addAxiom(ont,axiomobj);
- mgr.addAxiom(ont,axiomop);
- mgr.addAxiom(ont,axiomvalue);
- mgr.addAxiom(ont,axioman);
-
- Set<OWLAxiom> setaxiom = ont.getAxioms();
-
- try{
- resource = j2o.AxiomOwlToJenaResource(setaxiom, RDFXML);
- if(resource == null){
- fail("Some errors occur");
- }else{
- String statment = "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/2000/01/rdf-schema#range, http://www.w3.org/2000/01/rdf-schema#Literal] "+
- "[http://example.org/dummy#hasAge, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#DatatypeProperty] "+
- "[http://example.org/dummy#Linus, http://example.org/dummy#hasAge, \"8\"^^http://www.w3.org/2001/XMLSchema#int] "+
- "[http://example.org/dummy#Linus, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] "+
- "[http://example.org/dummy#hasSibling, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#ObjectProperty] "+
- "[http://example.org/dummy#Lucy, http://example.org/dummy#hasSibling, http://example.org/dummy#Linus] "+
- "[http://example.org/dummy#Lucy, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] "+
- "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#AnnotationProperty] "+
- "[http://example.org/dummy#Peanut, http://www.w3.org/2000/01/rdf-schema#label, \"Peanut\"@en] "+
- "[http://example.org/dummy#Peanut, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class]";
-
- int size = setaxiom.size();
- int count = 0;
- while(resource.hasNext()){
- Statement stm = resource.nextStatement();
- Resource jsubj = stm.getSubject();
- if(jsubj.getURI().equals(OP.toString())||jsubj.getURI().equals(DP.toString())||jsubj.getURI().equals(CLAZZ.toString())||jsubj.getURI().equals(OBJECT.toString())||jsubj.getURI().equals(SUBJECT.toString())||jsubj.getURI().equals(label.toString()))
- if(statment.contains(stm.toString()))
- count++;
- }
-
- assertEquals(size,count);
-
- }
- }catch (Exception e) {
- e.printStackTrace();
- fail("Exception caugth");
- }finally{
- assertNotNull(resource);
- }
- }
-
- public void testAnnotationPropJenaToOwl() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OntModel model = ModelFactory.createOntologyModel();
- AnnotationProperty jp = model.createAnnotationProperty(label.toString());
- OWLAnnotationProperty wp = null;
- try{
- wp = j2o.AnnotationPropJenaToOwl(jp, RDFXML);
- if(wp==null){
- fail("Some errors occur");
- }else{
- assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
- }
- }catch (Exception e){
- e.printStackTrace();
- fail("Exception caugth");
- } finally {
- assertNotNull(wp);
- }
- }
-
- public void testAnnotationPropOwlToJena() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = mgr.getOWLDataFactory();
- OWLAnnotationProperty wp = factory.getOWLAnnotationProperty(IRI.create(label));
- AnnotationProperty jp = null;
- try{
- jp = j2o.AnnotationPropOwlToJena(wp, RDFXML);
- if(jp==null){
- fail("Some errors occur");
- }else{
- assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
- }
- }catch (Exception e){
- e.printStackTrace();
- fail("Exception caugth");
- } finally {
- assertNotNull(jp);
- }
- }
-
- public void testClassJenaToOwl() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OntModel model = ModelFactory.createOntologyModel();
- OntClass jc = model.createClass(CLAZZ.toString());
- OWLClass wc = null;
- try{
- wc = j2o.ClassJenaToOwl(jc, RDFXML);
- if(wc==null)
- fail("Some problems accours");
- else{
- assertEquals(wc.getIRI().toURI().toString(), jc.getURI().toString());
- }
- }catch (Exception e) {
- e.printStackTrace();
- fail("Exception caugth");
- }finally {
- assertNotNull(wc);
- }
- }
-
- public void testClassOwlToJena() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = mgr.getOWLDataFactory();
- OWLClass c = factory.getOWLClass(IRI.create(CLAZZ));
- OntClass jc = null;
- try {
- jc = j2o.ClassOwlToJena(c, RDFXML);
- if(jc==null){
- fail("Some problem accours");
- }else{
- assertEquals(jc.getURI(), c.getIRI().toString());
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail("Exception caught");
- } finally {
- assertNotNull(jc);
- }
+ assertEquals(size, count);
- }
-
- public void testDataPropJenaToOwl() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OntModel model = ModelFactory.createOntologyModel();
- DatatypeProperty jp = model.createDatatypeProperty(DP.toString());
- OWLDataProperty wp = null;
- try{
- wp = j2o.DataPropJenaToOwl(jp, RDFXML);
- if(wp==null){
- fail("Some problem accours");
- }else{
- assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
- }
- }catch (Exception e) {
- e.printStackTrace();
- fail("Exception caugth");
- } finally {
- assertNotNull(wp);
- }
- }
-
- public void testDataPropOwlToJena() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = mgr.getOWLDataFactory();
- OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
- DatatypeProperty jdp = null;
- try {
- jdp = j2o.DataPropOwlToJena(dp, RDFXML);
- if(jdp == null){
- fail("Some errors accour");
- }else{
- assertEquals(jdp.getURI(), dp.getIRI().toString());
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail("Exception caught");
- } finally {
- assertNotNull(jdp);
- }
- }
-
- public void testModelJenaToOwlConvert() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OntModel model = ModelFactory.createOntologyModel();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = mgr.getOWLDataFactory();
- String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
- OWLOntology owl = null;
-
- try{
- model.read(dul,RDFXML);
- }catch (Exception e){
- e.printStackTrace();
- fail("Could not load ontology");
- }
-
- try{
- owl = j2o.ModelJenaToOwlConvert(model, RDFXML);
- if(owl == null){
- fail("Some errors occur");
- }else{
-
- ExtendedIterator<OntClass> jenaclass = model.listNamedClasses();
- int jenaclassset = jenaclass.toSet().size();
- jenaclass = model.listNamedClasses();
- Set<OWLClass> owlclass = owl.getClassesInSignature();
- int countclass = 0;
-
- while(jenaclass.hasNext())
- if(owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI()))))
- countclass++;
- if(countclass==jenaclassset)
- assertEquals(countclass,jenaclassset);
- else
- fail("Error in number of classes");
-
- ExtendedIterator<ObjectProperty> jenaprop = model.listObjectProperties();
- int jenapropset = jenaprop.toSet().size();
- jenaprop = model.listObjectProperties();
- Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
- int countprop = 0;
-
- while(jenaprop.hasNext())
- if(owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI()))))
- countprop++;
- if(countprop==jenapropset)
- assertEquals(countprop,jenapropset);
- else
- fail("Error in number of object properties");
-
- ExtendedIterator<DatatypeProperty> jenadata = model.listDatatypeProperties();
- int jenadataset = jenadata.toSet().size();
- jenadata = model.listDatatypeProperties();
- Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
- int countdata = 0;
-
- while(jenadata.hasNext())
- if(owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI()))))
- countdata++;
- if(countdata==jenadataset)
- assertEquals(countdata,jenadataset);
- else
- fail("Error in number of data properties");
- }
- }catch (Exception e){
- e.printStackTrace();
- fail("Exception caugth");
- }finally{
- assertNotNull(owl);
- }
- }
-
- public void testModelOwlToJenaConvert() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLOntologyManager mgrf = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = mgrf.getOWLDataFactory();
- String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
- OWLOntology owl = null;
- OntModel jena = null;
- try {
- owl = mgr.loadOntologyFromOntologyDocument(IRI.create(dul));
- } catch (OWLOntologyCreationException e) {
- e.printStackTrace();
- fail("Could not load ontology");
- }
- try {
- jena = j2o.ModelOwlToJenaConvert(owl, "RDF/XML");
- if(jena == null){
- fail("Some errors occur");
- }else{
-
- ExtendedIterator<OntClass> jenaclass = jena.listNamedClasses();
- int jenaclassset = jenaclass.toSet().size();
- jenaclass = jena.listNamedClasses();
- Set<OWLClass> owlclass = owl.getClassesInSignature();
- int countclass = 0;
-
- while(jenaclass.hasNext())
- if(owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI()))))
- countclass++;
- if(countclass==jenaclassset)
- assertEquals(countclass,jenaclassset);
- else
- fail("Error in number of classes");
-
- ExtendedIterator<ObjectProperty> jenaprop = jena.listObjectProperties();
- int jenapropset = jenaprop.toSet().size();
- jenaprop = jena.listObjectProperties();
- Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
- int countprop = 0;
-
- while(jenaprop.hasNext())
- if(owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI()))))
- countprop++;
- if(countprop==jenapropset)
- assertEquals(countprop,jenapropset);
- else
- fail("Error in number of object properties");
-
- ExtendedIterator<DatatypeProperty> jenadata = jena.listDatatypeProperties();
- int jenadataset = jenadata.toSet().size();
- jenadata = jena.listDatatypeProperties();
- Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
- int countdata = 0;
-
- while(jenadata.hasNext())
- if(owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI()))))
- countdata++;
- if(countdata==jenadataset)
- assertEquals(countdata,jenadataset);
- else
- fail("Error in number of data properties");
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail("Exception caugth");
- } finally{
- assertNotNull(jena);
- }
- }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(resource);
+ }
+ }
+
+ public void testAnnotationPropJenaToOwl() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OntModel model = ModelFactory.createOntologyModel();
+ AnnotationProperty jp = model.createAnnotationProperty(label.toString());
+ OWLAnnotationProperty wp = null;
+ try {
+ wp = j2o.AnnotationPropJenaToOwl(jp, RDFXML);
+ if (wp == null) {
+ fail("Some errors occur");
+ } else {
+ assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(wp);
+ }
+ }
+
+ public void testAnnotationPropOwlToJena() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+ OWLAnnotationProperty wp = factory.getOWLAnnotationProperty(IRI.create(label));
+ AnnotationProperty jp = null;
+ try {
+ jp = j2o.AnnotationPropOwlToJena(wp, RDFXML);
+ if (jp == null) {
+ fail("Some errors occur");
+ } else {
+ assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(jp);
+ }
+ }
+
+ public void testClassJenaToOwl() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OntModel model = ModelFactory.createOntologyModel();
+ OntClass jc = model.createClass(CLAZZ.toString());
+ OWLClass wc = null;
+ try {
+ wc = j2o.ClassJenaToOwl(jc, RDFXML);
+ if (wc == null) fail("Some problems accours");
+ else {
+ assertEquals(wc.getIRI().toURI().toString(), jc.getURI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(wc);
+ }
+ }
+
+ public void testClassOwlToJena() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+ OWLClass c = factory.getOWLClass(IRI.create(CLAZZ));
+ OntClass jc = null;
+ try {
+ jc = j2o.ClassOwlToJena(c, RDFXML);
+ if (jc == null) {
+ fail("Some problem accours");
+ } else {
+ assertEquals(jc.getURI(), c.getIRI().toString());
+ }
- public void testObjPropJenaToOwl() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OntModel model = ModelFactory.createOntologyModel();
- ObjectProperty jp = model.createObjectProperty(OP.toString());
- OWLObjectProperty wp = null;
- try{
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caught");
+ } finally {
+ assertNotNull(jc);
+ }
+
+ }
+
+ public void testDataPropJenaToOwl() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OntModel model = ModelFactory.createOntologyModel();
+ DatatypeProperty jp = model.createDatatypeProperty(DP.toString());
+ OWLDataProperty wp = null;
+ try {
+ wp = j2o.DataPropJenaToOwl(jp, RDFXML);
+ if (wp == null) {
+ fail("Some problem accours");
+ } else {
+ assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(wp);
+ }
+ }
+
+ public void testDataPropOwlToJena() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+ OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
+ DatatypeProperty jdp = null;
+ try {
+ jdp = j2o.DataPropOwlToJena(dp, RDFXML);
+ if (jdp == null) {
+ fail("Some errors accour");
+ } else {
+ assertEquals(jdp.getURI(), dp.getIRI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caught");
+ } finally {
+ assertNotNull(jdp);
+ }
+ }
+
+ public void testModelJenaToOwlConvert() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OntModel model = ModelFactory.createOntologyModel();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+ String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
+ OWLOntology owl = null;
+
+ try {
+ model.read(dul, RDFXML);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Could not load ontology");
+ }
+
+ try {
+ owl = j2o.ModelJenaToOwlConvert(model, RDFXML);
+ if (owl == null) {
+ fail("Some errors occur");
+ } else {
+
+ ExtendedIterator<OntClass> jenaclass = model.listNamedClasses();
+ int jenaclassset = jenaclass.toSet().size();
+ jenaclass = model.listNamedClasses();
+ Set<OWLClass> owlclass = owl.getClassesInSignature();
+ int countclass = 0;
+
+ while (jenaclass.hasNext())
+ if (owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI())))) countclass++;
+ if (countclass == jenaclassset) assertEquals(countclass, jenaclassset);
+ else fail("Error in number of classes");
+
+ ExtendedIterator<ObjectProperty> jenaprop = model.listObjectProperties();
+ int jenapropset = jenaprop.toSet().size();
+ jenaprop = model.listObjectProperties();
+ Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
+ int countprop = 0;
+
+ while (jenaprop.hasNext())
+ if (owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI())))) countprop++;
+ if (countprop == jenapropset) assertEquals(countprop, jenapropset);
+ else fail("Error in number of object properties");
+
+ ExtendedIterator<DatatypeProperty> jenadata = model.listDatatypeProperties();
+ int jenadataset = jenadata.toSet().size();
+ jenadata = model.listDatatypeProperties();
+ Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
+ int countdata = 0;
+
+ while (jenadata.hasNext())
+ if (owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI())))) countdata++;
+ if (countdata == jenadataset) assertEquals(countdata, jenadataset);
+ else fail("Error in number of data properties");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(owl);
+ }
+ }
+
+ public void testModelOwlToJenaConvert() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLOntologyManager mgrf = OWLManager.createOWLOntologyManager();
+ OWLDataFactory factory = mgrf.getOWLDataFactory();
+ String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
+ OWLOntology owl = null;
+ OntModel jena = null;
+ try {
+ owl = mgr.loadOntologyFromOntologyDocument(IRI.create(dul));
+ } catch (OWLOntologyCreationException e) {
+ e.printStackTrace();
+ fail("Could not load ontology");
+ }
+ try {
+ jena = j2o.ModelOwlToJenaConvert(owl, "RDF/XML");
+ if (jena == null) {
+ fail("Some errors occur");
+ } else {
+
+ ExtendedIterator<OntClass> jenaclass = jena.listNamedClasses();
+ int jenaclassset = jenaclass.toSet().size();
+ jenaclass = jena.listNamedClasses();
+ Set<OWLClass> owlclass = owl.getClassesInSignature();
+ int countclass = 0;
+
+ while (jenaclass.hasNext())
+ if (owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI())))) countclass++;
+ if (countclass == jenaclassset) assertEquals(countclass, jenaclassset);
+ else fail("Error in number of classes");
+
+ ExtendedIterator<ObjectProperty> jenaprop = jena.listObjectProperties();
+ int jenapropset = jenaprop.toSet().size();
+ jenaprop = jena.listObjectProperties();
+ Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
+ int countprop = 0;
+
+ while (jenaprop.hasNext())
+ if (owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI())))) countprop++;
+ if (countprop == jenapropset) assertEquals(countprop, jenapropset);
+ else fail("Error in number of object properties");
+
+ ExtendedIterator<DatatypeProperty> jenadata = jena.listDatatypeProperties();
+ int jenadataset = jenadata.toSet().size();
+ jenadata = jena.listDatatypeProperties();
+ Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
+ int countdata = 0;
+
+ while (jenadata.hasNext())
+ if (owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI())))) countdata++;
+ if (countdata == jenadataset) assertEquals(countdata, jenadataset);
+ else fail("Error in number of data properties");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(jena);
+ }
+ }
+
+ public void testObjPropJenaToOwl() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OntModel model = ModelFactory.createOntologyModel();
+ ObjectProperty jp = model.createObjectProperty(OP.toString());
+ OWLObjectProperty wp = null;
+ try {
wp = j2o.ObjPropJenaToOwl(jp, RDFXML);
- if(wp == null){
- fail("Some errors occurs");
- }else{
- assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
- }
- }catch(Exception e){
- e.printStackTrace();
- fail("Exception caugth");
- } finally {
- assertNotNull(wp);
- }
- }
-
- public void testObjPropOwlToJena() {
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLDataFactory factory = mgr.getOWLDataFactory();
- OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
- ObjectProperty jop = null;
- try {
- jop = j2o.ObjPropOwlToJena(op, RDFXML);
- if(jop == null){
- fail("Some errore occurs");
- }else{
- assertEquals(jop.getURI(), op.getIRI().toString());
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail("Exception caught");
- } finally{
- assertNotNull(jop);
- }
-
- }
-
- public void testResourceJenaToOwlAxiom() {
-
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OntModel model = ModelFactory.createOntologyModel();
-
- OntClass jenaclass = model.createClass(CLAZZ.toString());
- ObjectProperty jenaobprop = model.createObjectProperty(OP.toString());
- DatatypeProperty jenadataprop = model.createDatatypeProperty(DP.toString());
- Individual jenasub = model.createIndividual(SUBJECT.toString(), jenaclass);
- Individual jenaobj = model.createIndividual(OBJECT.toString(), jenaclass);
- AnnotationProperty jenaanno = model.createAnnotationProperty(label.toString());
- Literal value = model.createTypedLiteral(VALUE,DATATYPE.toString());
-
- model.add(jenasub, jenaobprop, jenaobj);
- model.add(jenasub,jenadataprop,value);
- model.add(jenasub,jenaanno,"Lucy","en");
-
- Set<OWLAxiom> owlaxiom = null;
-
- try{
- owlaxiom = j2o.ResourceJenaToOwlAxiom(jenasub, RDFXML);
- if(owlaxiom==null){
- fail("Some errors occur");
- }else{
+ if (wp == null) {
+ fail("Some errors occurs");
+ } else {
+ assertEquals(wp.getIRI().toURI().toString(), jp.getURI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(wp);
+ }
+ }
+
+ public void testObjPropOwlToJena() {
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+ OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
+ ObjectProperty jop = null;
+ try {
+ jop = j2o.ObjPropOwlToJena(op, RDFXML);
+ if (jop == null) {
+ fail("Some errore occurs");
+ } else {
+ assertEquals(jop.getURI(), op.getIRI().toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caught");
+ } finally {
+ assertNotNull(jop);
+ }
+
+ }
+
+ public void testResourceJenaToOwlAxiom() {
+
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OntModel model = ModelFactory.createOntologyModel();
+
+ OntClass jenaclass = model.createClass(CLAZZ.toString());
+ ObjectProperty jenaobprop = model.createObjectProperty(OP.toString());
+ DatatypeProperty jenadataprop = model.createDatatypeProperty(DP.toString());
+ Individual jenasub = model.createIndividual(SUBJECT.toString(), jenaclass);
+ Individual jenaobj = model.createIndividual(OBJECT.toString(), jenaclass);
+ AnnotationProperty jenaanno = model.createAnnotationProperty(label.toString());
+ Literal value = model.createTypedLiteral(VALUE, DATATYPE.toString());
+
+ model.add(jenasub, jenaobprop, jenaobj);
+ model.add(jenasub, jenadataprop, value);
+ model.add(jenasub, jenaanno, "Lucy", "en");
+
+ Set<OWLAxiom> owlaxiom = null;
+
+ try {
+ owlaxiom = j2o.ResourceJenaToOwlAxiom(jenasub, RDFXML);
+ if (owlaxiom == null) {
+ fail("Some errors occur");
+ } else {
StmtIterator str = model.listStatements();
- int count=0;
- while(str.hasNext()){
- Statement stm = str.next();
- Resource subject = stm.getSubject();
- if(SUBJECT.toString().equals(subject.getURI().toString()))
- count++;
+ int count = 0;
+ while (str.hasNext()) {
+ Statement stm = str.next();
+ Resource subject = stm.getSubject();
+ if (SUBJECT.toString().equals(subject.getURI().toString())) count++;
}
- if(count==owlaxiom.size()){
- assertEquals(count,owlaxiom.size());
- }else{
+ if (count == owlaxiom.size()) {
+ assertEquals(count, owlaxiom.size());
+ } else {
fail("The number of axioms don't match the number of statement");
- }}
- }catch (Exception e){
- e.printStackTrace();
- fail("Exception caugth");
- }finally{
- assertNotNull(owlaxiom);
- }
- }
-
- public void testEntityOwlToJenaResource() {
-
- JenaToOwlConvert j2o = new JenaToOwlConvert();
- OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
- OWLOntology ont = null;
- StmtIterator resource = null;
-
- try{
- ont = mgr.createOntology();
- } catch (OWLOntologyCreationException e) {
- e.printStackTrace();
- fail("Could not load ontology");
- }
-
- OWLDataFactory factory = mgr.getOWLDataFactory();
-
- OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
- OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
- OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
- OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
- OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel,"en"));
- OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
- OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
- OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
- OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE,dt);
- OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls); //Classe
- OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op); //obj prop
- OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp); //data prop
- OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub); //subject
- OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj); //object
-
- OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls,sub); //Istanza
- OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls,obj); //Istanza
- OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj); //Obj prop tra individui
- OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, sub,literal1); //Dataprop all'istanza;
- OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav); //Annotazione
-
- mgr.addAxiom(ont,daxiomcls);
- mgr.addAxiom(ont,daxiomop);
- mgr.addAxiom(ont,daxiomdp);
- mgr.addAxiom(ont,daxiomsub);
- mgr.addAxiom(ont,daxiomobj);
- mgr.addAxiom(ont,axiomsub);
- mgr.addAxiom(ont,axiomobj);
- mgr.addAxiom(ont,axiomop);
- mgr.addAxiom(ont,axiomvalue);
- mgr.addAxiom(ont,axioman);
-
- Set<OWLIndividualAxiom> ind = ont.getAxioms(sub);
-
- try{
- resource = j2o.EntityOwlToJenaResource(daxiomsub.getEntity(), ont, RDFXML);
- if(resource == null){
- fail("Some errors accour");
- }else{
-
- int cont = 0;
- while(resource.hasNext()){
- Statement stm = resource.nextStatement();
- IRI subres = IRI.create(stm.getSubject().getURI());
- if(("<"+subres+">").equals(daxiomsub.getEntity().toString()))
- cont++;
- }
-
- assertEquals(ind.size(),(cont-1));
-
- }
- }catch (Exception e){
- e.printStackTrace();
- fail("Exception caugth");
- } finally{
- assertNotNull(resource);
}
- }
-}
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(owlaxiom);
+ }
+ }
+
+ public void testEntityOwlToJenaResource() {
+
+ JenaToOwlConvert j2o = new JenaToOwlConvert();
+ OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
+ OWLOntology ont = null;
+ StmtIterator resource = null;
+
+ try {
+ ont = mgr.createOntology();
+ } catch (OWLOntologyCreationException e) {
+ e.printStackTrace();
+ fail("Could not load ontology");
+ }
+
+ OWLDataFactory factory = mgr.getOWLDataFactory();
+
+ OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
+ OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
+ OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
+ OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
+ OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
+ OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
+ OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
+ OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
+ OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
+ OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls); // Classe
+ OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op); // obj prop
+ OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp); // data prop
+ OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub); // subject
+ OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj); // object
+
+ OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub); // Istanza
+ OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj); // Istanza
+ OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj); // Obj
+ // prop
+ // tra
+ // individui
+ OWLDataPropertyAssertionAxiom axiomvalue = factory
+ .getOWLDataPropertyAssertionAxiom(dp, sub, literal1); // Dataprop all'istanza;
+ OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav); // Annotazione
+
+ mgr.addAxiom(ont, daxiomcls);
+ mgr.addAxiom(ont, daxiomop);
+ mgr.addAxiom(ont, daxiomdp);
+ mgr.addAxiom(ont, daxiomsub);
+ mgr.addAxiom(ont, daxiomobj);
+ mgr.addAxiom(ont, axiomsub);
+ mgr.addAxiom(ont, axiomobj);
+ mgr.addAxiom(ont, axiomop);
+ mgr.addAxiom(ont, axiomvalue);
+ mgr.addAxiom(ont, axioman);
+
+ Set<OWLIndividualAxiom> ind = ont.getAxioms(sub);
+
+ try {
+ resource = j2o.EntityOwlToJenaResource(daxiomsub.getEntity(), ont, RDFXML);
+ if (resource == null) {
+ fail("Some errors accour");
+ } else {
+
+ int cont = 0;
+ while (resource.hasNext()) {
+ Statement stm = resource.nextStatement();
+ IRI subres = IRI.create(stm.getSubject().getURI());
+ if (("<" + subres + ">").equals(daxiomsub.getEntity().toString())) cont++;
+ }
+ assertEquals(ind.size(), (cont - 1));
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception caugth");
+ } finally {
+ assertNotNull(resource);
+ }
+ }
+}
Modified: incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/TestOWLUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/TestOWLUtils.java?rev=1373449&r1=1373448&r2=1373449&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/TestOWLUtils.java (original)
+++ incubator/stanbol/trunk/commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/TestOWLUtils.java Wed Aug 15 15:08:48 2012
@@ -16,6 +16,9 @@
*/
package org.apache.stanbol.commons.owl.util;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_XML;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.TURTLE;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -24,43 +27,208 @@ import java.io.InputStream;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.rdf.core.serializedform.ParsingProvider;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
import org.apache.clerezza.rdf.jena.parser.JenaParserProvider;
import org.apache.clerezza.rdf.simple.storage.SimpleTcProvider;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
-
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntologyID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test suite for the OWL language utility methods.
+ *
+ * @author alexdma
+ *
+ */
public class TestOWLUtils {
+ /*
+ * I need a new Parser because if I use getInsance() I keep getting an annoying exception on a
+ * RdfJsonParsing Provider that I don't need.
+ */
+ private static Parser parser = new Parser();
+
@BeforeClass
public static void setupTests() throws Exception {
TcManager.getInstance().addWeightedTcProvider(new SimpleTcProvider());
+ parser.bindParsingProvider(new JenaParserProvider());
}
- private ParsingProvider pp = new JenaParserProvider();
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ private IRI ontologyIri = IRI.create("http://stanbol.apache.org/ontologies/test");
private UriRef uri = new UriRef("ontonet:http://stanbol.apache.org/prova");
+ /*
+ * Guessing the ID of a named ontology whose IRI is near the end of the graph.
+ */
+ @Test
+ public void lookaheadNamed() throws Exception {
+ String location = "/owl/named.owl";
+ log.info("Testing lookahead for location {}", location);
+
+ // Try a low triple limit (the ontology IRI triple is much further).
+ InputStream content = getClass().getResourceAsStream(location);
+ OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
+ assertNull(id);
+
+ // Try again with no limit
+ content = getClass().getResourceAsStream(location);
+ id = OWLUtils.guessOntologyID(content, parser, RDF_XML);
+ assertNotNull(id);
+ assertEquals(new OWLOntologyID(ontologyIri), id);
+ }
+
+ /*
+ * Guessing the ID of a named ontology whose IRI is at the beginning of the graph.
+ */
+ @Test
+ public void lookaheadNamedImmediate() throws Exception {
+ String location = "/owl/named_immediate.owl";
+ log.info("Testing lookahead for location {}", location);
+
+ // Try a low triple limit (the ontology IRI triple is much further).
+ InputStream content = getClass().getResourceAsStream(location);
+ OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
+ assertNotNull(id);
+ assertEquals(new OWLOntologyID(ontologyIri), id);
+ }
+
+ /*
+ * Guessing the ID of a versioned ontology whose IRIs are grouped at the end of the graph.
+ */
+ @Test
+ public void lookaheadVersioned() throws Exception {
+ // Identifiers are at position > 10 . Triples are grouped.
+ // Minimum offset required is 2 because of an owl:versionInfo triple in-between.
+ String location = "/owl/versioned.owl";
+ log.info("Testing lookahead for location {}", location);
+ IRI incubatedVersion = IRI
+ .create("http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned.owl");
+ OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
+
+ // Low triple limit: guessing should fail.
+ InputStream content = getClass().getResourceAsStream(location);
+ OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
+ assertNull(id);
+
+ // Reasonable triple limit with low offset: guessing should return the unversioned ID.
+ content = getClass().getResourceAsStream(location);
+ id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 256, 1);
+ assertNotNull(id);
+ assertEquals(new OWLOntologyID(ontologyIri), id);
+
+ // Reasonable triple limit with auto offset: guessing should succeed.
+ content = getClass().getResourceAsStream(location);
+ id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 256);
+ assertNotNull(id);
+ assertEquals(expectedOntId, id);
+
+ // No triple limit: guessing should succeed.
+ content = getClass().getResourceAsStream(location);
+ id = OWLUtils.guessOntologyID(content, parser, RDF_XML);
+ assertNotNull(id);
+ assertEquals(expectedOntId, id);
+ }
+
+ /*
+ * Guessing the ID of a versioned ontology whose ontology IRI is declared >100 triples before its version
+ * IRI.
+ */
+ @Test
+ public void lookaheadVersionedDistance100() throws Exception {
+ // Actual distance is 102
+ String location = "/owl/versioned_distance-100.owl";
+ log.info("Testing lookahead for location {}", location);
+ IRI incubatedVersion = IRI
+ .create("http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_distance-100.owl");
+ OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
+
+ // No triple limit but offset < 102 : guessing should return the unversioned ID.
+ InputStream content = getClass().getResourceAsStream(location);
+ OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, TURTLE, -1, 99);
+ assertNotNull(id);
+ assertEquals(new OWLOntologyID(ontologyIri), id);
+
+ // Try again, setting limit = 1024 (offset = 102) should work.
+ content = getClass().getResourceAsStream(location);
+ id = OWLUtils.guessOntologyID(content, parser, TURTLE, 1024);
+ assertNotNull(id);
+ assertEquals(expectedOntId, id);
+ }
+
+ /*
+ * Guessing the ID of an ontology whose ontology IRI is declared >100 triples after its version IRI.
+ */
+ @Test
+ public void lookaheadVersionedDistance100Reversed() throws Exception {
+ // Actual distance is 102
+ String location = "/owl/versioned_distance-100-reversed.owl";
+ log.info("Testing lookahead for location {}", location);
+ IRI incubatedVersion = IRI
+ .create("http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_distance-100-reversed.owl");
+ OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
+
+ // No triple limit but offset < 102 : guessing should fail.
+ InputStream content = getClass().getResourceAsStream(location);
+ OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, TURTLE, -1, 99);
+ assertNull(id);
+
+ // Try again, setting limit = 1024 (offset = 102) should work.
+ content = getClass().getResourceAsStream(location);
+ id = OWLUtils.guessOntologyID(content, parser, TURTLE, 1024);
+ assertNotNull(id);
+ assertEquals(expectedOntId, id);
+ }
+
+ /*
+ * Guessing the ID of a versioned ontology whose ID is at the beginning of the graph.
+ */
+ @Test
+ public void lookaheadVersionedImmediate() throws Exception {
+ String location = "/owl/versioned_immediate.owl";
+ log.info("Testing lookahead for location {}", location);
+ IRI incubatedVersion = IRI
+ .create("http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_immediate.owl");
+ OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
+
+ // Try a low triple limit (the ontology IRI triple is much further).
+ InputStream content = getClass().getResourceAsStream(location);
+ OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
+ assertNotNull(id);
+ assertEquals(expectedOntId, id);
+ }
+
+ /*
+ * Extracting the OWL ontology identifier on a *whole* ontology.
+ */
@Test
public void namedUriRef() throws Exception {
InputStream inputStream = getClass().getResourceAsStream("/owl/maincharacters.owl");
MGraph mg = TcManager.getInstance().createMGraph(uri);
- pp.parse(mg, inputStream, "application/rdf+xml", uri);
- assertNotNull(OWLUtils.guessOntologyIdentifier(mg.getGraph()));
+ parser.parse(mg, inputStream, "application/rdf+xml", uri);
+ assertNotNull(OWLUtils.extractOntologyID(mg.getGraph()));
}
+ /*
+ * Extracting the OWL ontology identifier on a *whole* nameless ontology must return a null value.
+ */
@Test
public void namelessUriRef() throws Exception {
- InputStream inputStream = getClass().getResourceAsStream("/owl/nameless_ontology.owl");
+ InputStream inputStream = getClass().getResourceAsStream("/owl/nameless.owl");
MGraph mg = TcManager.getInstance().createMGraph(uri);
- pp.parse(mg, inputStream, "application/rdf+xml", uri);
- assertNull(OWLUtils.guessOntologyIdentifier(mg.getGraph()));
+ parser.parse(mg, inputStream, "application/rdf+xml", uri);
+ assertNull(OWLUtils.extractOntologyID(mg.getGraph()));
}
@After
public void reset() throws Exception {
- TcManager.getInstance().deleteTripleCollection(uri);
+ if (TcManager.getInstance().listTripleCollections().contains(uri)) TcManager.getInstance()
+ .deleteTripleCollection(uri);
}
-
}
Added: incubator/stanbol/trunk/commons/owl/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/owl/src/test/resources/log4j.properties?rev=1373449&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/owl/src/test/resources/log4j.properties (added)
+++ incubator/stanbol/trunk/commons/owl/src/test/resources/log4j.properties Wed Aug 15 15:08:48 2012
@@ -0,0 +1,23 @@
+# 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.
+
+
+log4j.rootLogger=WARN, CONSOLE
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+#log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%C{1}] %m%n
+log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] [%C{1}] %m%n
+
+log4j.category.org.apache.stanbol.ontologymanager.ontonet=INFO
\ No newline at end of file