You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2015/03/19 22:34:35 UTC
[1/6] clerezza git commit: CLEREZZA-963: using and rdf-commons from
clerezza-rdf-core repository
Repository: clerezza
Updated Branches:
refs/heads/rdf-commons 4cb0b5240 -> de5881d42
CLEREZZA-963: using and rdf-commons from clerezza-rdf-core repository
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/340cdcaf
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/340cdcaf
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/340cdcaf
Branch: refs/heads/rdf-commons
Commit: 340cdcafd3026a5d5a7dfc6a31d925ae813967b4
Parents: 4cb0b52
Author: Reto Gmuer <re...@apache.org>
Authored: Thu Mar 19 17:41:59 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Thu Mar 19 17:41:59 2015 +0000
----------------------------------------------------------------------
maven-ontologies-plugin/pom.xml | 4 +-
rdf.ontologies/pom.xml | 8 +-
rdf.schemagen/pom.xml | 15 ++-
.../clerezza/rdf/schemagen/SchemaGen.java | 118 ++++++++++---------
4 files changed, 76 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/340cdcaf/maven-ontologies-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/maven-ontologies-plugin/pom.xml b/maven-ontologies-plugin/pom.xml
index c04cf20..f4884a1 100644
--- a/maven-ontologies-plugin/pom.xml
+++ b/maven-ontologies-plugin/pom.xml
@@ -24,7 +24,7 @@
<parent>
<artifactId>clerezza</artifactId>
<groupId>org.apache.clerezza</groupId>
- <version>0.5</version>
+ <version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<groupId>org.apache.clerezza</groupId>
@@ -49,7 +49,7 @@
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.schemagen</artifactId>
- <version>0.11</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/340cdcaf/rdf.ontologies/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.ontologies/pom.xml b/rdf.ontologies/pom.xml
index 7dbf888..d9a7a7e 100644
--- a/rdf.ontologies/pom.xml
+++ b/rdf.ontologies/pom.xml
@@ -37,9 +37,9 @@
<description>Some java classes with constants for common ontologies.</description>
<dependencies>
<dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.core</artifactId>
- <version>0.14</version>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-api</artifactId>
+ <version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
@@ -47,6 +47,7 @@
<plugin>
<groupId>org.apache.clerezza</groupId>
<artifactId>maven-ontologies-plugin</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<phase>generate-sources</phase>
@@ -71,7 +72,6 @@
</goals>
</execution>
</executions>
- <version>0.4</version>
</plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/340cdcaf/rdf.schemagen/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.schemagen/pom.xml b/rdf.schemagen/pom.xml
index 70a208a..af8820c 100644
--- a/rdf.schemagen/pom.xml
+++ b/rdf.schemagen/pom.xml
@@ -24,7 +24,7 @@
<parent>
<artifactId>clerezza</artifactId>
<groupId>org.apache.clerezza</groupId>
- <version>0.5</version>
+ <version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<groupId>org.apache.clerezza</groupId>
@@ -43,14 +43,19 @@
<artifactId>wymiwyg-commons-core</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>rdf.core</artifactId>
- <version>0.14</version>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-api</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-impl-utils</artifactId>
+ <version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.jena.parser</artifactId>
- <version>0.12</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/340cdcaf/rdf.schemagen/src/main/java/org/apache/clerezza/rdf/schemagen/SchemaGen.java
----------------------------------------------------------------------
diff --git a/rdf.schemagen/src/main/java/org/apache/clerezza/rdf/schemagen/SchemaGen.java b/rdf.schemagen/src/main/java/org/apache/clerezza/rdf/schemagen/SchemaGen.java
index ce4f720..adbfbeb 100644
--- a/rdf.schemagen/src/main/java/org/apache/clerezza/rdf/schemagen/SchemaGen.java
+++ b/rdf.schemagen/src/main/java/org/apache/clerezza/rdf/schemagen/SchemaGen.java
@@ -31,16 +31,18 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-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.core.serializedform.Parser;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
import org.wymiwyg.commons.util.arguments.AnnotatedInterfaceArguments;
import org.wymiwyg.commons.util.arguments.ArgumentHandler;
import org.wymiwyg.commons.util.arguments.InvalidArgumentsException;
@@ -102,7 +104,7 @@ public class SchemaGen {
Iterator<Triple> ontologyTriples = schemaGraph.filter(null, RDF.type, OWL.Ontology);
String result;
if(ontologyTriples.hasNext()) {
- result = ((UriRef) ontologyTriples.next().getSubject()).getUnicodeString();
+ result = ((Iri) ontologyTriples.next().getSubject()).getUnicodeString();
} else {
throw new RuntimeException("No OWL Ontology found!");
}
@@ -131,7 +133,7 @@ public class SchemaGen {
out.println(';');
}
out.println();
- out.println("import org.apache.clerezza.rdf.core.UriRef;");
+ out.println("import org.apache.commons.rdf.Iri;");
out.println();
out.print("public class ");
out.print(getSimpleName());
@@ -186,16 +188,16 @@ public class SchemaGen {
out.println(description);
out.println("\t */");
}
- out.print("\tpublic static final UriRef ");
+ out.print("\tpublic static final Iri ");
out.print(ontologyResource.getLocalName());
- out.print(" = new UriRef(\"");
+ out.print(" = new Iri(\"");
out.print(ontologyResource.getUriString());
out.println("\");");
}
}
- private Collection<OntologyResource> getResourcesOfType(UriRef type) {
+ private Collection<OntologyResource> getResourcesOfType(Iri type) {
return getResourcesOfType(type, null);
}
@@ -205,14 +207,14 @@ public class SchemaGen {
* @param ignore a set things to ignore
* @return
*/
- private Collection<OntologyResource> getResourcesOfType(UriRef type, Collection<OntologyResource> ignore) {
+ private Collection<OntologyResource> getResourcesOfType(Iri type, Collection<OntologyResource> ignore) {
Set<OntologyResource> result = new HashSet<OntologyResource>();
Iterator<Triple> classStatemente = schemaGraph.filter(null, RDF.type,
type);
while (classStatemente.hasNext()) {
Triple triple = classStatemente.next();
- NonLiteral classResource = triple.getSubject();
- if (classResource instanceof BNode) {
+ BlankNodeOrIri classResource = triple.getSubject();
+ if (classResource instanceof BlankNode) {
if (type !=null) System.err.println("Ignoring anonymous resource of type " + type.getUnicodeString());
else System.err.println("Ignoring anonymous resource");
for (Triple contextTriple : getNodeContext(classResource, schemaGraph)) {
@@ -222,7 +224,7 @@ public class SchemaGen {
}
// Test if the given resource belongs to the ontology
- final UriRef classUri = (UriRef) classResource;
+ final Iri classUri = (Iri) classResource;
final String strClassUri = classUri.getUnicodeString();
if (strClassUri.startsWith(namespace)) {
// The remaining part of the class URI must not contain
@@ -246,25 +248,25 @@ public class SchemaGen {
return result;
}
- private Graph getNodeContext(NonLiteral resource, Graph graph) {
- final HashSet<BNode> dontExpand = new HashSet<BNode>();
- if (resource instanceof BNode) {
- dontExpand.add((BNode) resource);
+ private ImmutableGraph getNodeContext(BlankNodeOrIri resource, Graph graph) {
+ final HashSet<BlankNode> dontExpand = new HashSet<BlankNode>();
+ if (resource instanceof BlankNode) {
+ dontExpand.add((BlankNode) resource);
}
- return getContextOf(resource, dontExpand, graph).getGraph();
+ return getContextOf(resource, dontExpand, graph).getImmutableGraph();
}
- private MGraph getContextOf(NonLiteral node, Set<BNode> dontExpand,
+ private Graph getContextOf(BlankNodeOrIri node, Set<BlankNode> dontExpand,
Graph graph) {
- MGraph result = new SimpleMGraph();
+ Graph result = new SimpleGraph();
Iterator<Triple> forwardProperties = graph.filter(node, null, null);
while (forwardProperties.hasNext()) {
Triple triple = forwardProperties.next();
result.add(triple);
- Resource object = triple.getObject();
- if (object instanceof BNode) {
- BNode bNodeObject = (BNode) object;
+ RdfTerm object = triple.getObject();
+ if (object instanceof BlankNode) {
+ BlankNode bNodeObject = (BlankNode) object;
if (!dontExpand.contains(bNodeObject)) {
dontExpand.add(bNodeObject);
result.addAll(getContextOf(bNodeObject, dontExpand, graph));
@@ -275,9 +277,9 @@ public class SchemaGen {
while (backwardProperties.hasNext()) {
Triple triple = backwardProperties.next();
result.add(triple);
- NonLiteral subject = triple.getSubject();
- if (subject instanceof BNode) {
- BNode bNodeSubject = (BNode) subject;
+ BlankNodeOrIri subject = triple.getSubject();
+ if (subject instanceof BlankNode) {
+ BlankNode bNodeSubject = (BlankNode) subject;
if (!dontExpand.contains(bNodeSubject)) {
dontExpand.add(bNodeSubject);
result.addAll(getContextOf(bNodeSubject, dontExpand, graph));
@@ -307,7 +309,7 @@ public class SchemaGen {
Comparable<OntologyResource> {
final Graph graph;
- final UriRef uri;
+ final Iri uri;
static final List<String> reservedWords = Arrays.asList(
"abstract", "assert", "boolean", "break", "byte", "case",
@@ -320,7 +322,7 @@ public class SchemaGen {
"synchronized", "this", "throw", "throws", "transient",
"true", "try", "void", "volatile", "while");
- OntologyResource(UriRef uri, Graph graph) {
+ OntologyResource(Iri uri, Graph graph) {
this.uri = uri;
this.graph = graph;
}
@@ -346,7 +348,7 @@ public class SchemaGen {
Iterator<Triple> titleStatements = graph.filter(
uri, DCTERMS.title, null);
while (titleStatements.hasNext()) {
- Resource object = titleStatements.next().getObject();
+ RdfTerm object = titleStatements.next().getObject();
if (object instanceof Literal) {
result.append("title: ");
result.append (((Literal) object).getLexicalForm());
@@ -356,7 +358,7 @@ public class SchemaGen {
Iterator<Triple> descriptionStatements = graph.filter(
uri, DCTERMS.description, null);
while (descriptionStatements.hasNext()) {
- Resource object = descriptionStatements.next().getObject();
+ RdfTerm object = descriptionStatements.next().getObject();
if (object instanceof Literal) {
result.append("description: ");
result.append (((Literal) object).getLexicalForm());
@@ -366,7 +368,7 @@ public class SchemaGen {
Iterator<Triple> skosDefStatements = graph.filter(
uri, SKOS.definition, null);
while (skosDefStatements.hasNext()) {
- Resource object = skosDefStatements.next().getObject();
+ RdfTerm object = skosDefStatements.next().getObject();
if (object instanceof Literal) {
result.append("definition: ");
result.append (((Literal) object).getLexicalForm());
@@ -376,7 +378,7 @@ public class SchemaGen {
Iterator<Triple> rdfsCommentStatements = graph.filter(
uri, RDFS.comment, null);
while (rdfsCommentStatements.hasNext()) {
- Resource object = rdfsCommentStatements.next().getObject();
+ RdfTerm object = rdfsCommentStatements.next().getObject();
if (object instanceof Literal) {
result.append("comment: ");
result.append(((Literal) object).getLexicalForm());
@@ -386,7 +388,7 @@ public class SchemaGen {
Iterator<Triple> skosNoteStatements = graph.filter(
uri, SKOS.note, null);
while (skosNoteStatements.hasNext()) {
- Resource object = skosNoteStatements.next().getObject();
+ RdfTerm object = skosNoteStatements.next().getObject();
if (object instanceof Literal) {
result.append("note: ");
result.append (((Literal) object).getLexicalForm());
@@ -396,13 +398,13 @@ public class SchemaGen {
Iterator<Triple> skosExampleStatements = graph.filter(
uri, SKOS.example, null);
while (skosExampleStatements.hasNext()) {
- Resource object = skosExampleStatements.next().getObject();
+ RdfTerm object = skosExampleStatements.next().getObject();
if (object instanceof Literal) {
result.append("example: ");
result.append (((Literal) object).getLexicalForm());
result.append("\n");
- } else if (object instanceof UriRef) {
- result.append("see <a href="+((UriRef)object).getUnicodeString()+">example</a>");
+ } else if (object instanceof Iri) {
+ result.append("see <a href="+((Iri)object).getUnicodeString()+">example</a>");
result.append("\n");
}
}
@@ -442,13 +444,13 @@ public class SchemaGen {
private static final String NS = "http://www.w3.org/2002/07/owl#";
- private static final UriRef Class =
- new UriRef(NS + "Class");
- public static final Resource Ontology = new UriRef(NS + "Ontology");
- private static final UriRef DatatypeProperty =
- new UriRef(NS + "DatatypeProperty");
- private static final UriRef ObjectProperty =
- new UriRef(NS + "ObjectProperty");
+ private static final Iri Class =
+ new Iri(NS + "Class");
+ public static final RdfTerm Ontology = new Iri(NS + "Ontology");
+ private static final Iri DatatypeProperty =
+ new Iri(NS + "DatatypeProperty");
+ private static final Iri ObjectProperty =
+ new Iri(NS + "ObjectProperty");
}
/** RDFS Ontology. */
@@ -456,9 +458,9 @@ public class SchemaGen {
private static final String NS =
"http://www.w3.org/2000/01/rdf-schema#";
- private static final UriRef Class = new UriRef(NS + "Class");
- private static final UriRef Datatype = new UriRef(NS + "Datatype");
- private static final UriRef comment = new UriRef(NS + "comment");
+ private static final Iri Class = new Iri(NS + "Class");
+ private static final Iri Datatype = new Iri(NS + "Datatype");
+ private static final Iri comment = new Iri(NS + "comment");
}
/** RDF Ontology. */
@@ -466,19 +468,19 @@ public class SchemaGen {
private static final String NS =
"http://www.w3.org/1999/02/22-rdf-syntax-ns#";
- private static final UriRef Property = new UriRef(NS + "Property");
- private static final UriRef type = new UriRef(NS + "type");
+ private static final Iri Property = new Iri(NS + "Property");
+ private static final Iri type = new Iri(NS + "type");
}
private static class SKOS {
- static final UriRef definition = new UriRef("http://www.w3.org/2008/05/skos#definition");
- static final UriRef note = new UriRef("http://www.w3.org/2004/02/skos/core#note");
- static final UriRef example = new UriRef("http://www.w3.org/2004/02/skos/core#example");
+ static final Iri definition = new Iri("http://www.w3.org/2008/05/skos#definition");
+ static final Iri note = new Iri("http://www.w3.org/2004/02/skos/core#note");
+ static final Iri example = new Iri("http://www.w3.org/2004/02/skos/core#example");
}
private static class DCTERMS {
- public static final UriRef title = new UriRef("http://purl.org/dc/terms/title");
- public static final UriRef description = new UriRef("http://purl.org/dc/terms/description");
+ public static final Iri title = new Iri("http://purl.org/dc/terms/title");
+ public static final Iri description = new Iri("http://purl.org/dc/terms/description");
}
}
[5/6] clerezza git commit: CLEREZZA-964: using rdf-commons from
clerezza-rdf-core repository
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
new file mode 100644
index 0000000..4b0a4dc
--- /dev/null
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingGraph.java
@@ -0,0 +1,223 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.AbstractGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
+
+/**
+ * This wrapps a Triplecollection changing a prefix for the Iris contained
+ * in subject or object position.
+ *
+ * Currently it only supports read opearations.
+ *
+ * @author reto
+ */
+public class UriMutatingGraph implements Graph {
+
+ private final Graph base;
+ private final String sourcePrefix;
+ private final String targetPrefix;
+ private final int sourcePrefixLength;
+ private final int targetPrefixLength;
+
+ public UriMutatingGraph(Graph base, String sourcePrefix,
+ String targetPrefix) {
+ this.base = base;
+ this.sourcePrefix = sourcePrefix;
+ sourcePrefixLength= sourcePrefix.length();
+ this.targetPrefix = targetPrefix;
+ targetPrefixLength= targetPrefix.length();
+ }
+
+ private <R extends RdfTerm> R toTargetRdfTerm(final R sourceRdfTerm) {
+ if (sourceRdfTerm instanceof Iri) {
+ final Iri sourceIri = (Iri) sourceRdfTerm;
+ if (sourceIri.getUnicodeString().startsWith(sourcePrefix)) {
+ final String uriRest = sourceIri.getUnicodeString()
+ .substring(sourcePrefixLength);
+ return (R) new Iri(targetPrefix+uriRest);
+ }
+ }
+ return sourceRdfTerm;
+ }
+
+ private Triple toTargetTriple(Triple triple) {
+ if (triple == null) {
+ return null;
+ }
+ return new TripleImpl(toTargetRdfTerm(triple.getSubject()),
+ triple.getPredicate(), toTargetRdfTerm(triple.getObject()));
+ }
+
+ private <R extends RdfTerm> R toSourceRdfTerm(final R targetRdfTerm) {
+ if (targetRdfTerm instanceof Iri) {
+ final Iri sourceIri = (Iri) targetRdfTerm;
+ if (sourceIri.getUnicodeString().startsWith(targetPrefix)) {
+ final String uriRest = sourceIri.getUnicodeString()
+ .substring(targetPrefixLength);
+ return (R) new Iri(sourcePrefix+uriRest);
+ }
+ }
+ return targetRdfTerm;
+ }
+
+ private Triple toSourceTriple(Triple triple) {
+ if (triple == null) {
+ return null;
+ }
+ return new TripleImpl(toSourceRdfTerm(triple.getSubject()),
+ triple.getPredicate(), toSourceRdfTerm(triple.getObject()));
+ }
+
+ @Override
+ public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
+ final Iterator<Triple> baseIter = base.filter(toSourceRdfTerm(subject),
+ predicate, toSourceRdfTerm(object));
+ return new WrappedIteraror(baseIter);
+
+
+ }
+
+
+ @Override
+ public int size() {
+ return base.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return base.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return base.contains(toSourceTriple((Triple)o));
+ }
+
+ @Override
+ public Iterator<Triple> iterator() {
+ return filter(null, null, null);
+ }
+
+ @Override
+ public Object[] toArray() {
+ Object[] result = base.toArray();
+ for (int i = 0; i < result.length; i++) {
+ Triple triple = (Triple) result[i];
+ result[i] = toTargetTriple(triple);
+ }
+ return result;
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ T[] result = base.toArray(a);
+ for (int i = 0; i < result.length; i++) {
+ Triple triple = (Triple) result[i];
+ result[i] = (T) toTargetTriple(triple);
+ }
+ return result;
+ }
+
+ @Override
+ public boolean add(Triple e) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ for (Object object : c) {
+ if (!contains(object)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Triple> c) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public ImmutableGraph getImmutableGraph() {
+ return new SimpleImmutableGraph(this);
+ }
+
+ @Override
+ public ReadWriteLock getLock() {
+ return base.getLock();
+ }
+
+ class WrappedIteraror implements Iterator<Triple>{
+ private final Iterator<Triple> baseIter;
+
+ private WrappedIteraror(Iterator<Triple> baseIter) {
+ this.baseIter = baseIter;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return baseIter.hasNext();
+ }
+
+ @Override
+ public Triple next() {
+ return toTargetTriple(baseIter.next());
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingTripleCollection.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingTripleCollection.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingTripleCollection.java
deleted file mode 100644
index fa4f732..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriMutatingTripleCollection.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * 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.clerezza.rdf.utils;
-
-import java.util.Collection;
-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.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-
-/**
- * This wrapps a Triplecollection changing a prefix for the UriRefs contained
- * in subject or object position.
- *
- * Currently it only supports read opearations.
- *
- * @author reto
- */
-public class UriMutatingTripleCollection implements TripleCollection {
-
- private final TripleCollection base;
- private final String sourcePrefix;
- private final String targetPrefix;
- private final int sourcePrefixLength;
- private final int targetPrefixLength;
-
- public UriMutatingTripleCollection(TripleCollection base, String sourcePrefix,
- String targetPrefix) {
- this.base = base;
- this.sourcePrefix = sourcePrefix;
- sourcePrefixLength= sourcePrefix.length();
- this.targetPrefix = targetPrefix;
- targetPrefixLength= targetPrefix.length();
- }
-
- private <R extends Resource> R toTargetResource(final R sourceResource) {
- if (sourceResource instanceof UriRef) {
- final UriRef sourceUriRef = (UriRef) sourceResource;
- if (sourceUriRef.getUnicodeString().startsWith(sourcePrefix)) {
- final String uriRest = sourceUriRef.getUnicodeString()
- .substring(sourcePrefixLength);
- return (R) new UriRef(targetPrefix+uriRest);
- }
- }
- return sourceResource;
- }
-
- private Triple toTargetTriple(Triple triple) {
- if (triple == null) {
- return null;
- }
- return new TripleImpl(toTargetResource(triple.getSubject()),
- triple.getPredicate(), toTargetResource(triple.getObject()));
- }
-
- private <R extends Resource> R toSourceResource(final R targetResource) {
- if (targetResource instanceof UriRef) {
- final UriRef sourceUriRef = (UriRef) targetResource;
- if (sourceUriRef.getUnicodeString().startsWith(targetPrefix)) {
- final String uriRest = sourceUriRef.getUnicodeString()
- .substring(targetPrefixLength);
- return (R) new UriRef(sourcePrefix+uriRest);
- }
- }
- return targetResource;
- }
-
- private Triple toSourceTriple(Triple triple) {
- if (triple == null) {
- return null;
- }
- return new TripleImpl(toSourceResource(triple.getSubject()),
- triple.getPredicate(), toSourceResource(triple.getObject()));
- }
-
- @Override
- public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
- final Iterator<Triple> baseIter = base.filter(toSourceResource(subject),
- predicate, toSourceResource(object));
- return new WrappedIteraror(baseIter);
-
-
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- }
-
- @Override
- public int size() {
- return base.size();
- }
-
- @Override
- public boolean isEmpty() {
- return base.isEmpty();
- }
-
- @Override
- public boolean contains(Object o) {
- return base.contains(toSourceTriple((Triple)o));
- }
-
- @Override
- public Iterator<Triple> iterator() {
- return filter(null, null, null);
- }
-
- @Override
- public Object[] toArray() {
- Object[] result = base.toArray();
- for (int i = 0; i < result.length; i++) {
- Triple triple = (Triple) result[i];
- result[i] = toTargetTriple(triple);
- }
- return result;
- }
-
- @Override
- public <T> T[] toArray(T[] a) {
- T[] result = base.toArray(a);
- for (int i = 0; i < result.length; i++) {
- Triple triple = (Triple) result[i];
- result[i] = (T) toTargetTriple(triple);
- }
- return result;
- }
-
- @Override
- public boolean add(Triple e) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- @Override
- public boolean remove(Object o) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- for (Object object : c) {
- if (!contains(object)) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public boolean addAll(Collection<? extends Triple> c) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- class WrappedIteraror implements Iterator<Triple>{
- private final Iterator<Triple> baseIter;
-
- private WrappedIteraror(Iterator<Triple> baseIter) {
- this.baseIter = baseIter;
- }
-
- @Override
- public boolean hasNext() {
- return baseIter.hasNext();
- }
-
- @Override
- public Triple next() {
- return toTargetTriple(baseIter.next());
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriRefUtil.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriRefUtil.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriRefUtil.java
deleted file mode 100644
index 4aed365..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UriRefUtil.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.clerezza.rdf.utils;
-
-
-/**
- * A utility class for UriRef and String manipulations.
- *
- * @author tio
- */
-public class UriRefUtil {
-
- /**
- * Strips #x00 - #x1F and #x7F-#x9F from a Unicode string
- * @see <a href="http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference">
- * http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference</a> and
- * replaces all US-ASCII space character with a "+".
- *
- * @param inputChars
- * @return the stripped string
- *
- */
- public static String stripNonUriRefChars(CharSequence inputChars) {
-
- if (inputChars == null) {
- return "";
- }
-
- StringBuffer buffer = new StringBuffer();
-
- for (int i = 0; i < inputChars.length(); i++) {
- char c = inputChars.charAt(i);
-
- if (!isIllegal(c)) {
- buffer.append(c);
- }
- }
- return buffer.toString().replaceAll("\\s+", "+");
- }
-
- private static boolean isIllegal(char ch) {
- if ((ch >= 0x7F) && (ch <= 0x9F)) {
- return true;
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
index 3f839e9..03c73a5 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/graphnodeprovider/GraphNodeProvider.java
@@ -18,7 +18,7 @@ package org.apache.clerezza.rdf.utils.graphnodeprovider;
* specific language governing permissions and limitations
* under the License.
*/
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.utils.GraphNode;
/**
@@ -34,18 +34,18 @@ public interface GraphNodeProvider {
* Get a GraphNode for the specified resource, see class comments for
* details.
*/
- GraphNode get(UriRef uriRef);
+ GraphNode get(Iri uriRef);
/**
* Get a GraphNode for the specified resource, The resource is assumed to be
- * local, i.e. the method behaves like get(UriRef) for a Uri with an
+ * local, i.e. the method behaves like get(Iri) for a Uri with an
* authority section contained in the Set retuned by
* <code>org.apache.clerezza.platform.config.PlatformConfig#getBaseUris()</code>
*/
- GraphNode getLocal(UriRef uriRef);
+ GraphNode getLocal(Iri uriRef);
/**
* return true iff getLocal(uriRef).getNodeContext.size > 0
*/
- boolean existsLocal(UriRef uriRef);
+ boolean existsLocal(Iri uriRef);
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
index ad03681..1841cd1 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/BaseSmusher.java
@@ -21,15 +21,14 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.MGraph;
-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.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.rdf.ontologies.OWL;
/**
@@ -50,12 +49,12 @@ public class BaseSmusher {
* @param equivalenceSets sets of equivalent resources
* @param addOwlSameAs whether owl:sameAs statements should be added
*/
- public void smush(LockableMGraph mGraph, Set<Set<NonLiteral>> equivalenceSets, boolean addOwlSameAs) {
- Map<NonLiteral, NonLiteral> current2ReplacementMap = new HashMap<NonLiteral, NonLiteral>();
- final MGraph owlSameAsGraph = new SimpleMGraph();
- for (Set<NonLiteral> equivalenceSet : equivalenceSets) {
- final NonLiteral replacement = getReplacementFor(equivalenceSet, owlSameAsGraph);
- for (NonLiteral current : equivalenceSet) {
+ public void smush(Graph mGraph, Set<Set<BlankNodeOrIri>> equivalenceSets, boolean addOwlSameAs) {
+ Map<BlankNodeOrIri, BlankNodeOrIri> current2ReplacementMap = new HashMap<BlankNodeOrIri, BlankNodeOrIri>();
+ final Graph owlSameAsGraph = new SimpleGraph();
+ for (Set<BlankNodeOrIri> equivalenceSet : equivalenceSets) {
+ final BlankNodeOrIri replacement = getReplacementFor(equivalenceSet, owlSameAsGraph);
+ for (BlankNodeOrIri current : equivalenceSet) {
if (!current.equals(replacement)) {
current2ReplacementMap.put(current, replacement);
}
@@ -67,11 +66,11 @@ public class BaseSmusher {
try {
for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
final Triple triple = it.next();
- final NonLiteral subject = triple.getSubject();
- NonLiteral subjectReplacement = current2ReplacementMap.get(subject);
- final Resource object = triple.getObject();
+ final BlankNodeOrIri subject = triple.getSubject();
+ BlankNodeOrIri subjectReplacement = current2ReplacementMap.get(subject);
+ final RdfTerm object = triple.getObject();
@SuppressWarnings(value = "element-type-mismatch")
- Resource objectReplacement = current2ReplacementMap.get(object);
+ RdfTerm objectReplacement = current2ReplacementMap.get(object);
if ((subjectReplacement != null) || (objectReplacement != null)) {
it.remove();
if (subjectReplacement == null) {
@@ -92,24 +91,24 @@ public class BaseSmusher {
}
}
- private NonLiteral getReplacementFor(Set<NonLiteral> equivalenceSet,
- MGraph owlSameAsGraph) {
- final Set<UriRef> uriRefs = new HashSet<UriRef>();
- for (NonLiteral nonLiteral : equivalenceSet) {
- if (nonLiteral instanceof UriRef) {
- uriRefs.add((UriRef) nonLiteral);
+ private BlankNodeOrIri getReplacementFor(Set<BlankNodeOrIri> equivalenceSet,
+ Graph owlSameAsGraph) {
+ final Set<Iri> uriRefs = new HashSet<Iri>();
+ for (BlankNodeOrIri nonLiteral : equivalenceSet) {
+ if (nonLiteral instanceof Iri) {
+ uriRefs.add((Iri) nonLiteral);
}
}
switch (uriRefs.size()) {
case 1:
return uriRefs.iterator().next();
case 0:
- return new BNode();
+ return new BlankNode();
}
- final UriRef preferedIri = getPreferedIri(uriRefs);
- final Iterator<UriRef> uriRefIter = uriRefs.iterator();
+ final Iri preferedIri = getPreferedIri(uriRefs);
+ final Iterator<Iri> uriRefIter = uriRefs.iterator();
while (uriRefIter.hasNext()) {
- UriRef uriRef = uriRefIter.next();
+ Iri uriRef = uriRefIter.next();
if (!uriRef.equals(preferedIri)) {
owlSameAsGraph.add(new TripleImpl(uriRef, OWL.sameAs, preferedIri));
}
@@ -126,8 +125,8 @@ public class BaseSmusher {
* @param uriRefs
* @return
*/
- protected UriRef getPreferedIri(Set<UriRef> uriRefs) {
- final Iterator<UriRef> uriRefIter = uriRefs.iterator();
+ protected Iri getPreferedIri(Set<Iri> uriRefs) {
+ final Iterator<Iri> uriRefIter = uriRefs.iterator();
//instead of an arbitrary one we might either decide lexicographically
//or look at their frequency in mGraph
return uriRefIter.next();
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
index 0e1d380..fad1d6b 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/IfpSmusher.java
@@ -18,7 +18,6 @@
*/
package org.apache.clerezza.rdf.utils.smushing;
-import org.apache.clerezza.rdf.utils.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -26,16 +25,11 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.MGraph;
-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.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
import org.slf4j.Logger;
@@ -61,35 +55,35 @@ public class IfpSmusher extends BaseSmusher {
* @param mGraph
* @param tBox
*/
- public void smush(LockableMGraph mGraph, TripleCollection tBox) {
- final Set<UriRef> ifps = getIfps(tBox);
- final Map<PredicateObject, Set<NonLiteral>> ifp2nodesMap = new HashMap<PredicateObject, Set<NonLiteral>>();
+ public void smush(Graph mGraph, Graph tBox) {
+ final Set<Iri> ifps = getIfps(tBox);
+ final Map<PredicateObject, Set<BlankNodeOrIri>> ifp2nodesMap = new HashMap<PredicateObject, Set<BlankNodeOrIri>>();
for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
final Triple triple = it.next();
- final UriRef predicate = triple.getPredicate();
+ final Iri predicate = triple.getPredicate();
if (!ifps.contains(predicate)) {
continue;
}
final PredicateObject po = new PredicateObject(predicate, triple.getObject());
- Set<NonLiteral> equivalentNodes = ifp2nodesMap.get(po);
+ Set<BlankNodeOrIri> equivalentNodes = ifp2nodesMap.get(po);
if (equivalentNodes == null) {
- equivalentNodes = new HashSet<NonLiteral>();
+ equivalentNodes = new HashSet<BlankNodeOrIri>();
ifp2nodesMap.put(po, equivalentNodes);
}
equivalentNodes.add(triple.getSubject());
}
- Set<Set<NonLiteral>> unitedEquivalenceSets = uniteSetsWithCommonElement(ifp2nodesMap.values());
+ Set<Set<BlankNodeOrIri>> unitedEquivalenceSets = uniteSetsWithCommonElement(ifp2nodesMap.values());
smush(mGraph, unitedEquivalenceSets, true);
}
- private Set<UriRef> getIfps(TripleCollection tBox) {
+ private Set<Iri> getIfps(Graph tBox) {
final Iterator<Triple> ifpDefinitions = tBox.filter(null, RDF.type,
OWL.InverseFunctionalProperty);
- final Set<UriRef> ifps = new HashSet<UriRef>();
+ final Set<Iri> ifps = new HashSet<Iri>();
while (ifpDefinitions.hasNext()) {
final Triple triple = ifpDefinitions.next();
- ifps.add((UriRef) triple.getSubject());
+ ifps.add((Iri) triple.getSubject());
}
return ifps;
}
@@ -136,10 +130,10 @@ public class IfpSmusher extends BaseSmusher {
class PredicateObject {
- final UriRef predicate;
- final Resource object;
+ final Iri predicate;
+ final RdfTerm object;
- public PredicateObject(UriRef predicate, Resource object) {
+ public PredicateObject(Iri predicate, RdfTerm object) {
this.predicate = predicate;
this.object = object;
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
index e9ccbe0..e656a42 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
@@ -24,11 +24,10 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-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.access.LockableMGraph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,43 +49,43 @@ public class SameAsSmusher extends BaseSmusher {
* @param owlSameStatements
* @param addCanonicalSameAsStatements if true owl:sameAsStatements with the preferedIri as object will be added
*/
- public void smush(LockableMGraph mGraph,
- TripleCollection owlSameStatements,
+ public void smush(Graph mGraph,
+ Graph owlSameStatements,
boolean addCanonicalSameAsStatements) {
log.info("Starting smushing");
// This hashmap contains a uri (key) and the set of equivalent uris (value)
- final Map<NonLiteral, Set<NonLiteral>> node2EquivalenceSet = new HashMap<NonLiteral, Set<NonLiteral>>();
+ final Map<BlankNodeOrIri, Set<BlankNodeOrIri>> node2EquivalenceSet = new HashMap<BlankNodeOrIri, Set<BlankNodeOrIri>>();
log.info("Creating the sets of equivalent uris of each subject or object in the owl:sameAs statements");
// Determines for each subject and object in all the owl:sameAs statements the set of ewquivalent uris
for (Iterator<Triple> it = owlSameStatements.iterator(); it.hasNext();) {
final Triple triple = it.next();
- final UriRef predicate = triple.getPredicate();
+ final Iri predicate = triple.getPredicate();
if (!predicate.equals(OWL.sameAs)) {
throw new RuntimeException("Statements must use only <http://www.w3.org/2002/07/owl#sameAs> predicate.");
}
- final NonLiteral subject = triple.getSubject();
+ final BlankNodeOrIri subject = triple.getSubject();
//literals not yet supported
- final NonLiteral object = (NonLiteral)triple.getObject();
+ final BlankNodeOrIri object = (BlankNodeOrIri)triple.getObject();
- Set<NonLiteral> equivalentNodes = node2EquivalenceSet.get(subject);
+ Set<BlankNodeOrIri> equivalentNodes = node2EquivalenceSet.get(subject);
// if there is not a set of equivalent uris then create a new set
if (equivalentNodes == null) {
equivalentNodes = node2EquivalenceSet.get(object);
if (equivalentNodes == null) {
- equivalentNodes = new HashSet<NonLiteral>();
+ equivalentNodes = new HashSet<BlankNodeOrIri>();
}
} else {
- Set<NonLiteral> objectSet = node2EquivalenceSet.get(object);
+ Set<BlankNodeOrIri> objectSet = node2EquivalenceSet.get(object);
if ((objectSet != null) && (objectSet != equivalentNodes)) {
//merge two sets
- for (NonLiteral res : objectSet) {
+ for (BlankNodeOrIri res : objectSet) {
node2EquivalenceSet.remove(res);
}
- for (NonLiteral res : objectSet) {
+ for (BlankNodeOrIri res : objectSet) {
node2EquivalenceSet.put(res,equivalentNodes);
}
equivalentNodes.addAll(objectSet);
@@ -106,7 +105,7 @@ public class SameAsSmusher extends BaseSmusher {
}
// This set contains the sets of equivalent uris
- Set<Set<NonLiteral>> unitedEquivalenceSets = new HashSet<Set<NonLiteral>>(node2EquivalenceSet.values());
+ Set<Set<BlankNodeOrIri>> unitedEquivalenceSets = new HashSet<Set<BlankNodeOrIri>>(node2EquivalenceSet.values());
smush(mGraph, unitedEquivalenceSets, addCanonicalSameAsStatements);
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
new file mode 100644
index 0000000..fa14977
--- /dev/null
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/GraphUtilsTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class GraphUtilsTest {
+
+ final Iri u1 = new Iri("http://ex.org/1");
+ final Iri u2 = new Iri("http://ex.org/2");
+ final Iri u3 = new Iri("http://ex.org/3");
+
+ @Test
+ public void removeSubGraph() throws NoSuchSubGraphException {
+ Graph baseGraph = createBaseGraph();
+
+ Graph subGraph = new SimpleGraph();
+ {
+ BlankNode bNode1 = new BlankNode();
+ BlankNode bNode2 = new BlankNode();
+ subGraph.add(new TripleImpl(u1, u2, bNode2));
+ subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+ subGraph.add(new TripleImpl(bNode2, u2, bNode1));
+ }
+ GraphUtils.removeSubGraph(baseGraph, subGraph);
+ Assert.assertEquals(1, baseGraph.size());
+ }
+
+ private Graph createBaseGraph() {
+ Graph baseGraph = new SimpleGraph();
+ {
+ BlankNode bNode1 = new BlankNode();
+ BlankNode bNode2 = new BlankNode();
+ baseGraph.add(new TripleImpl(u1, u2, bNode2));
+ baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
+ baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+ baseGraph.add(new TripleImpl(u3, u2, u1));
+ }
+ return baseGraph;
+ }
+
+ /** It is required that the subgraph comprises the whole context of the Bnodes it ioncludes
+ *
+ * @throws org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException
+ */
+ @Test(expected=NoSuchSubGraphException.class)
+ public void removeIncompleteSubGraph() throws NoSuchSubGraphException {
+ Graph baseGraph = createBaseGraph();
+
+ Graph subGraph = new SimpleGraph();
+ {
+ BlankNode bNode1 = new BlankNode();
+ BlankNode bNode2 = new BlankNode();
+ subGraph.add(new TripleImpl(u1, u2, bNode2));
+ subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+ }
+ GraphUtils.removeSubGraph(baseGraph, subGraph);
+ }
+
+ @Test(expected=NoSuchSubGraphException.class)
+ public void removeInvalidSubGraph() throws NoSuchSubGraphException {
+ Graph baseGraph = createBaseGraph();
+
+ Graph subGraph = new SimpleGraph();
+ {
+ BlankNode bNode1 = new BlankNode();
+ BlankNode bNode2 = new BlankNode();
+ subGraph.add(new TripleImpl(u1, u2, bNode2));
+ subGraph.add(new TripleImpl(bNode2, u2, bNode2));
+ baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
+ baseGraph.add(new TripleImpl(bNode2, u2, new BlankNode()));
+ }
+ GraphUtils.removeSubGraph(baseGraph, subGraph);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
index 1094b51..d7a2b81 100644
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
@@ -18,12 +18,12 @@
*/
package org.apache.clerezza.rdf.utils;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.rdf.ontologies.FOAF;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
@@ -37,20 +37,20 @@ import org.junit.Test;
*/
public class IfpSmushTest {
- private MGraph ontology = new SimpleMGraph();
+ private Graph ontology = new SimpleGraph();
{
ontology.add(new TripleImpl(FOAF.mbox, RDF.type, OWL.InverseFunctionalProperty));
}
@Test
- public void simpleBNode() {
- MGraph mGraph = new SimpleMGraph();
- UriRef mbox1 = new UriRef("mailto:foo@example.org");
- final BNode bNode1 = new BNode();
+ public void simpleBlankNode() {
+ Graph mGraph = new SimpleGraph();
+ Iri mbox1 = new Iri("mailto:foo@example.org");
+ final BlankNode bNode1 = new BlankNode();
mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(bNode1, RDFS.comment,
new PlainLiteralImpl("a comment")));
- final BNode bNode2 = new BNode();
+ final BlankNode bNode2 = new BlankNode();
mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(bNode2, RDFS.comment,
new PlainLiteralImpl("another comment")));
@@ -60,19 +60,19 @@ public class IfpSmushTest {
@Test
public void overlappingEquivalenceClasses() {
- MGraph mGraph = new SimpleMGraph();
- UriRef mbox1 = new UriRef("mailto:foo@example.org");
- final BNode bNode1 = new BNode();
+ Graph mGraph = new SimpleGraph();
+ Iri mbox1 = new Iri("mailto:foo@example.org");
+ final BlankNode bNode1 = new BlankNode();
mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(bNode1, RDFS.comment,
new PlainLiteralImpl("a comment")));
- final BNode bNode2 = new BNode();
- UriRef mbox2 = new UriRef("mailto:bar@example.org");
+ final BlankNode bNode2 = new BlankNode();
+ Iri mbox2 = new Iri("mailto:bar@example.org");
mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox2));
mGraph.add(new TripleImpl(bNode2, RDFS.comment,
new PlainLiteralImpl("another comment")));
- final BNode bNode3 = new BNode();
+ final BlankNode bNode3 = new BlankNode();
mGraph.add(new TripleImpl(bNode3, FOAF.mbox, mbox2));
mGraph.add(new TripleImpl(bNode3, RDFS.comment,
new PlainLiteralImpl("yet another comment")));
@@ -81,14 +81,14 @@ public class IfpSmushTest {
}
@Test
- public void oneUriRef() {
- MGraph mGraph = new SimpleMGraph();
- UriRef mbox1 = new UriRef("mailto:foo@example.org");
- final UriRef resource = new UriRef("http://example.org/");
+ public void oneIri() {
+ Graph mGraph = new SimpleGraph();
+ Iri mbox1 = new Iri("mailto:foo@example.org");
+ final Iri resource = new Iri("http://example.org/");
mGraph.add(new TripleImpl(resource, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(resource, RDFS.comment,
new PlainLiteralImpl("a comment")));
- final BNode bNode2 = new BNode();
+ final BlankNode bNode2 = new BlankNode();
mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(bNode2, RDFS.comment,
new PlainLiteralImpl("another comment")));
@@ -97,14 +97,14 @@ public class IfpSmushTest {
}
@Test
- public void twoUriRefs() {
- MGraph mGraph = new SimpleMGraph();
- UriRef mbox1 = new UriRef("mailto:foo@example.org");
- final UriRef resource1 = new UriRef("http://example.org/");
+ public void twoIris() {
+ Graph mGraph = new SimpleGraph();
+ Iri mbox1 = new Iri("mailto:foo@example.org");
+ final Iri resource1 = new Iri("http://example.org/");
mGraph.add(new TripleImpl(resource1, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(resource1, RDFS.comment,
new PlainLiteralImpl("a comment")));
- final UriRef resource2 = new UriRef("http://2.example.org/");
+ final Iri resource2 = new Iri("http://2.example.org/");
mGraph.add(new TripleImpl(resource2, FOAF.mbox, mbox1));
mGraph.add(new TripleImpl(resource2, RDFS.comment,
new PlainLiteralImpl("another comment")));
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java
deleted file mode 100644
index 19a85f9..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/MGraphUtilsTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.clerezza.rdf.utils;
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.utils.MGraphUtils.NoSuchSubGraphException;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class MGraphUtilsTest {
-
- final UriRef u1 = new UriRef("http://ex.org/1");
- final UriRef u2 = new UriRef("http://ex.org/2");
- final UriRef u3 = new UriRef("http://ex.org/3");
-
- @Test
- public void removeSubGraph() throws NoSuchSubGraphException {
- MGraph baseGraph = createBaseGraph();
-
- MGraph subGraph = new SimpleMGraph();
- {
- BNode bNode1 = new BNode();
- BNode bNode2 = new BNode();
- subGraph.add(new TripleImpl(u1, u2, bNode2));
- subGraph.add(new TripleImpl(bNode2, u2, bNode2));
- subGraph.add(new TripleImpl(bNode2, u2, bNode1));
- }
- MGraphUtils.removeSubGraph(baseGraph, subGraph);
- Assert.assertEquals(1, baseGraph.size());
- }
-
- private MGraph createBaseGraph() {
- MGraph baseGraph = new SimpleMGraph();
- {
- BNode bNode1 = new BNode();
- BNode bNode2 = new BNode();
- baseGraph.add(new TripleImpl(u1, u2, bNode2));
- baseGraph.add(new TripleImpl(bNode2, u2, bNode2));
- baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
- baseGraph.add(new TripleImpl(u3, u2, u1));
- }
- return baseGraph;
- }
-
- /** It is required that the subgraph comprises the whole context of the Bnodes it ioncludes
- *
- * @throws org.apache.clerezza.rdf.utils.MGraphUtils.NoSuchSubGraphException
- */
- @Test(expected=NoSuchSubGraphException.class)
- public void removeIncompleteSubGraph() throws NoSuchSubGraphException {
- MGraph baseGraph = createBaseGraph();
-
- MGraph subGraph = new SimpleMGraph();
- {
- BNode bNode1 = new BNode();
- BNode bNode2 = new BNode();
- subGraph.add(new TripleImpl(u1, u2, bNode2));
- subGraph.add(new TripleImpl(bNode2, u2, bNode2));
- }
- MGraphUtils.removeSubGraph(baseGraph, subGraph);
- }
-
- @Test(expected=NoSuchSubGraphException.class)
- public void removeInvalidSubGraph() throws NoSuchSubGraphException {
- MGraph baseGraph = createBaseGraph();
-
- MGraph subGraph = new SimpleMGraph();
- {
- BNode bNode1 = new BNode();
- BNode bNode2 = new BNode();
- subGraph.add(new TripleImpl(u1, u2, bNode2));
- subGraph.add(new TripleImpl(bNode2, u2, bNode2));
- baseGraph.add(new TripleImpl(bNode2, u2, bNode1));
- baseGraph.add(new TripleImpl(bNode2, u2, new BNode()));
- }
- MGraphUtils.removeSubGraph(baseGraph, subGraph);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
index 2097975..cd4045d 100644
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/RdfListTest.java
@@ -24,13 +24,13 @@ import java.util.Set;
import junit.framework.Assert;
import org.junit.Test;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Resource;
-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.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
import static org.junit.Assert.*;
/**
@@ -41,8 +41,8 @@ public class RdfListTest {
@Test
public void listCreationAndAccess() {
- TripleCollection tc = new SimpleMGraph();
- List<Resource> list = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ Graph tc = new SimpleGraph();
+ List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
assertEquals(0, list.size());
list.add(new PlainLiteralImpl("hello"));
list.add(new PlainLiteralImpl("world"));
@@ -61,7 +61,7 @@ public class RdfListTest {
assertEquals(5, list.size());
assertEquals(new PlainLiteralImpl("hello"), list.get(1));
assertEquals(new PlainLiteralImpl("interesting"), list.get(2));
- List<Resource> list2 = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ List<RdfTerm> list2 = new RdfList(new Iri("http://example.org/mytest"), tc);
assertEquals(5, list2.size());
assertEquals(new PlainLiteralImpl("hello"), list2.get(1));
assertEquals(new PlainLiteralImpl("interesting"), list2.get(2));
@@ -86,13 +86,13 @@ public class RdfListTest {
@Test
public void listCreationAndAccess2() {
- TripleCollection tc = new SimpleMGraph();
- List<Resource> list = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ Graph tc = new SimpleGraph();
+ List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
assertEquals(0, list.size());
list.add(0,new PlainLiteralImpl("world"));
- list = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ list = new RdfList(new Iri("http://example.org/mytest"), tc);
list.add(0,new PlainLiteralImpl("beautifuly"));
- list = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ list = new RdfList(new Iri("http://example.org/mytest"), tc);
list.add(0,new PlainLiteralImpl("hello"));
assertEquals(new PlainLiteralImpl("hello"), list.get(0));
assertEquals(new PlainLiteralImpl("beautifuly"), list.get(1));
@@ -101,12 +101,12 @@ public class RdfListTest {
@Test
public void listCreationAndAccess3() {
- TripleCollection tc = new SimpleMGraph();
- List<Resource> list = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ Graph tc = new SimpleGraph();
+ List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
assertEquals(0, list.size());
- BNode node0 = new BNode() {};
- BNode node1 = new BNode() {};
- BNode node2 = new BNode() {};
+ BlankNode node0 = new BlankNode() {};
+ BlankNode node1 = new BlankNode() {};
+ BlankNode node2 = new BlankNode() {};
list.add(0,node2);
list.add(0,node1);
list.add(0,node0);
@@ -117,8 +117,8 @@ public class RdfListTest {
@Test
public void secondButLastElementAccessTest() {
- TripleCollection tc = new SimpleMGraph();
- List<Resource> list = new RdfList(new UriRef("http://example.org/mytest2"), tc);
+ Graph tc = new SimpleGraph();
+ List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest2"), tc);
list.add(new PlainLiteralImpl("hello"));
list.add(new PlainLiteralImpl("world"));
list.remove(1);
@@ -127,8 +127,8 @@ public class RdfListTest {
@Test
public void cleanGraphAfterRemoval() {
- TripleCollection tc = new SimpleMGraph();
- List<Resource> list = new RdfList(new UriRef("http://example.org/mytest"), tc);
+ Graph tc = new SimpleGraph();
+ List<RdfTerm> list = new RdfList(new Iri("http://example.org/mytest"), tc);
list.add(new PlainLiteralImpl("hello"));
list.add(new PlainLiteralImpl("world"));
list.remove(1);
@@ -138,14 +138,14 @@ public class RdfListTest {
@Test
public void findContainingListNodesAndfindContainingListsTest() {
- TripleCollection tc = new SimpleMGraph();
- GraphNode listA = new GraphNode(new UriRef("http:///listA"), tc);
- GraphNode listB = new GraphNode(new UriRef("http:///listB"), tc);
- BNode element1 = new BNode();
- BNode element2 = new BNode();
- BNode element3 = new BNode();
- BNode element4 = new BNode();
- BNode element5 = new BNode();
+ Graph tc = new SimpleGraph();
+ GraphNode listA = new GraphNode(new Iri("http:///listA"), tc);
+ GraphNode listB = new GraphNode(new Iri("http:///listB"), tc);
+ BlankNode element1 = new BlankNode();
+ BlankNode element2 = new BlankNode();
+ BlankNode element3 = new BlankNode();
+ BlankNode element4 = new BlankNode();
+ BlankNode element5 = new BlankNode();
RdfList rdfListA = new RdfList(listA);
rdfListA.add(element1);
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
index d32034c..66c4005 100644
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
@@ -19,16 +19,14 @@
package org.apache.clerezza.rdf.utils;
import java.util.Iterator;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.PlainLiteral;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.rdf.ontologies.FOAF;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
@@ -42,16 +40,16 @@ import org.junit.Test;
*/
public class SameAsSmushTest {
- private final UriRef uriA = new UriRef("http://example.org/A");
- private final UriRef uriB = new UriRef("http://example.org/B");
+ private final Iri uriA = new Iri("http://example.org/A");
+ private final Iri uriB = new Iri("http://example.org/B");
private final Literal lit = new PlainLiteralImpl("That's me (and you)");
- private MGraph sameAsStatements = new SimpleMGraph();
+ private Graph sameAsStatements = new SimpleGraph();
{
sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
}
- private MGraph dataGraph = new SimpleMGraph();
+ private Graph dataGraph = new SimpleGraph();
{
dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
index c8f8cf9..af8434a 100644
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/TestGraphNode.java
@@ -25,16 +25,16 @@ import java.util.Set;
import junit.framework.Assert;
import org.junit.Test;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-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.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.test.RandomMGraph;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.clerezza.rdf.core.test.RandomGraph;
/**
*
@@ -44,11 +44,11 @@ public class TestGraphNode {
@Test
public void nodeContext() {
- MGraph g = new SimpleMGraph();
- BNode bNode1 = new BNode() {};
- BNode bNode2 = new BNode() {};
- UriRef property1 = new UriRef("http://example.org/property1");
- UriRef property2 = new UriRef("http://example.org/property2");
+ Graph g = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode() {};
+ BlankNode bNode2 = new BlankNode() {};
+ Iri property1 = new Iri("http://example.org/property1");
+ Iri property2 = new Iri("http://example.org/property2");
g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
g.add(new TripleImpl(bNode1, property2, property1));
g.add(new TripleImpl(bNode2, property2, bNode1));
@@ -63,10 +63,10 @@ public class TestGraphNode {
@Test
public void addNode() {
- MGraph g = new SimpleMGraph();
- BNode bNode1 = new BNode() {};
- BNode bNode2 = new BNode() {};
- UriRef property1 = new UriRef("http://example.org/property1");
+ Graph g = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode() {};
+ BlankNode bNode2 = new BlankNode() {};
+ Iri property1 = new Iri("http://example.org/property1");
GraphNode n = new GraphNode(bNode1, g);
n.addProperty(property1, bNode2);
Assert.assertEquals(1, g.size());
@@ -74,14 +74,14 @@ public class TestGraphNode {
@Test
public void testGetSubjectAndObjectNodes() {
- RandomMGraph graph = new RandomMGraph(500, 20, new SimpleMGraph());
+ RandomGraph graph = new RandomGraph(500, 20, new SimpleGraph());
for (int j = 0; j < 200; j++) {
Triple randomTriple = graph.getRandomTriple();
GraphNode node = new GraphNode(randomTriple.getSubject(), graph);
- Iterator<UriRef> properties = node.getProperties();
+ Iterator<Iri> properties = node.getProperties();
while (properties.hasNext()) {
- UriRef property = properties.next();
- Set<Resource> objects = createSet(node.getObjects(property));
+ Iri property = properties.next();
+ Set<RdfTerm> objects = createSet(node.getObjects(property));
Iterator<GraphNode> objectNodes = node.getObjectNodes(property);
while (objectNodes.hasNext()) {
GraphNode graphNode = objectNodes.next();
@@ -93,10 +93,10 @@ public class TestGraphNode {
for (int j = 0; j < 200; j++) {
Triple randomTriple = graph.getRandomTriple();
GraphNode node = new GraphNode(randomTriple.getObject(), graph);
- Iterator<UriRef> properties = node.getProperties();
+ Iterator<Iri> properties = node.getProperties();
while (properties.hasNext()) {
- UriRef property = properties.next();
- Set<Resource> subjects = createSet(node.getSubjects(property));
+ Iri property = properties.next();
+ Set<RdfTerm> subjects = createSet(node.getSubjects(property));
Iterator<GraphNode> subjectNodes = node.getSubjectNodes(property);
while (subjectNodes.hasNext()) {
GraphNode graphNode = subjectNodes.next();
@@ -108,14 +108,14 @@ public class TestGraphNode {
@Test
public void getAvailableProperties(){
- MGraph g = new SimpleMGraph();
- BNode bNode1 = new BNode() {};
- BNode bNode2 = new BNode() {};
- UriRef property1 = new UriRef("http://example.org/property1");
- UriRef property2 = new UriRef("http://example.org/property2");
- UriRef property3 = new UriRef("http://example.org/property3");
- UriRef property4 = new UriRef("http://example.org/property4");
- ArrayList<UriRef> props = new ArrayList<UriRef>();
+ Graph g = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode() {};
+ BlankNode bNode2 = new BlankNode() {};
+ Iri property1 = new Iri("http://example.org/property1");
+ Iri property2 = new Iri("http://example.org/property2");
+ Iri property3 = new Iri("http://example.org/property3");
+ Iri property4 = new Iri("http://example.org/property4");
+ ArrayList<Iri> props = new ArrayList<Iri>();
props.add(property1);
props.add(property2);
props.add(property3);
@@ -125,11 +125,11 @@ public class TestGraphNode {
n.addProperty(property2, bNode2);
n.addProperty(property3, bNode2);
n.addProperty(property4, bNode2);
- Iterator<UriRef> properties = n.getProperties();
+ Iterator<Iri> properties = n.getProperties();
int i = 0;
while(properties.hasNext()){
i++;
- UriRef prop = properties.next();
+ Iri prop = properties.next();
Assert.assertTrue(props.contains(prop));
props.remove(prop);
}
@@ -140,11 +140,11 @@ public class TestGraphNode {
@Test
public void deleteAll() {
- MGraph g = new SimpleMGraph();
- BNode bNode1 = new BNode() {};
- BNode bNode2 = new BNode() {};
- UriRef property1 = new UriRef("http://example.org/property1");
- UriRef property2 = new UriRef("http://example.org/property2");
+ Graph g = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode() {};
+ BlankNode bNode2 = new BlankNode() {};
+ Iri property1 = new Iri("http://example.org/property1");
+ Iri property2 = new Iri("http://example.org/property2");
//the two properties two be deleted
g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("bla bla")));
@@ -159,11 +159,11 @@ public class TestGraphNode {
@Test
public void deleteSingleProperty() {
- MGraph g = new SimpleMGraph();
- BNode bNode1 = new BNode() {};
- BNode bNode2 = new BNode() {};
- UriRef property1 = new UriRef("http://example.org/property1");
- UriRef property2 = new UriRef("http://example.org/property2");
+ Graph g = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode() {};
+ BlankNode bNode2 = new BlankNode() {};
+ Iri property1 = new Iri("http://example.org/property1");
+ Iri property2 = new Iri("http://example.org/property2");
//the properties two be deleted
g.add(new TripleImpl(bNode1, property1, new PlainLiteralImpl("literal")));
//this 4 properties should stay
@@ -178,13 +178,13 @@ public class TestGraphNode {
@Test
public void replaceWith() {
- MGraph initialGraph = new SimpleMGraph();
- BNode bNode1 = new BNode();
- BNode bNode2 = new BNode();
- BNode newBnode = new BNode();
- UriRef property1 = new UriRef("http://example.org/property1");
- UriRef property2 = new UriRef("http://example.org/property2");
- UriRef newUriRef = new UriRef("http://example.org/newName");
+ Graph initialGraph = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode();
+ BlankNode bNode2 = new BlankNode();
+ BlankNode newBnode = new BlankNode();
+ Iri property1 = new Iri("http://example.org/property1");
+ Iri property2 = new Iri("http://example.org/property2");
+ Iri newIri = new Iri("http://example.org/newName");
Literal literal1 = new PlainLiteralImpl("literal");
Literal literal2 = new PlainLiteralImpl("bla bla");
@@ -199,14 +199,14 @@ public class TestGraphNode {
initialGraph.add(triple4);
initialGraph.add(triple5);
GraphNode node = new GraphNode(property1,
- new SimpleMGraph(initialGraph.iterator()));
+ new SimpleGraph(initialGraph.iterator()));
- node.replaceWith(newUriRef, true);
+ node.replaceWith(newIri, true);
Assert.assertEquals(5, node.getGraph().size());
- Triple expectedTriple1 = new TripleImpl(bNode1, newUriRef, literal1);
- Triple expectedTriple2 = new TripleImpl(bNode1, property2, newUriRef);
- Triple expectedTriple3 = new TripleImpl(newUriRef, newUriRef, bNode2);
- Triple expectedTriple4 = new TripleImpl(newUriRef, newUriRef, literal2);
+ Triple expectedTriple1 = new TripleImpl(bNode1, newIri, literal1);
+ Triple expectedTriple2 = new TripleImpl(bNode1, property2, newIri);
+ Triple expectedTriple3 = new TripleImpl(newIri, newIri, bNode2);
+ Triple expectedTriple4 = new TripleImpl(newIri, newIri, literal2);
Assert.assertTrue(node.getGraph().contains(expectedTriple1));
Assert.assertTrue(node.getGraph().contains(expectedTriple2));
@@ -218,7 +218,7 @@ public class TestGraphNode {
Assert.assertFalse(node.getGraph().contains(triple4));
Assert.assertFalse(node.getGraph().contains(triple5));
- node = new GraphNode(property1, new SimpleMGraph(initialGraph.iterator()));
+ node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator()));
node.replaceWith(newBnode);
Triple expectedTriple5 = new TripleImpl(bNode1, property2, newBnode);
Triple expectedTriple6 = new TripleImpl(newBnode, property1, bNode2);
@@ -229,16 +229,16 @@ public class TestGraphNode {
Assert.assertTrue(node.getGraph().contains(expectedTriple6));
Assert.assertTrue(node.getGraph().contains(expectedTriple7));
- node = new GraphNode(literal1, new SimpleMGraph(initialGraph.iterator()));
+ node = new GraphNode(literal1, new SimpleGraph(initialGraph.iterator()));
node.replaceWith(newBnode);
Triple expectedTriple8 = new TripleImpl(bNode1, property1, newBnode);
Assert.assertTrue(node.getGraph().contains(expectedTriple8));
- node = new GraphNode(property1, new SimpleMGraph(initialGraph.iterator()));
- node.replaceWith(newUriRef);
- Triple expectedTriple9 = new TripleImpl(bNode1, property2, newUriRef);
- Triple expectedTriple10 = new TripleImpl(newUriRef, property1, bNode2);
- Triple expectedTriple11 = new TripleImpl(newUriRef, property1, literal2);
+ node = new GraphNode(property1, new SimpleGraph(initialGraph.iterator()));
+ node.replaceWith(newIri);
+ Triple expectedTriple9 = new TripleImpl(bNode1, property2, newIri);
+ Triple expectedTriple10 = new TripleImpl(newIri, property1, bNode2);
+ Triple expectedTriple11 = new TripleImpl(newIri, property1, literal2);
Assert.assertTrue(node.getGraph().contains(triple1));
Assert.assertTrue(node.getGraph().contains(expectedTriple9));
Assert.assertTrue(node.getGraph().contains(expectedTriple10));
@@ -247,10 +247,10 @@ public class TestGraphNode {
@Test
public void equality() {
- MGraph g = new SimpleMGraph();
- BNode bNode1 = new BNode() {};
- BNode bNode2 = new BNode() {};
- UriRef property1 = new UriRef("http://example.org/property1");
+ Graph g = new SimpleGraph();
+ BlankNode bNode1 = new BlankNode() {};
+ BlankNode bNode2 = new BlankNode() {};
+ Iri property1 = new Iri("http://example.org/property1");
GraphNode n = new GraphNode(bNode1, g);
n.addProperty(property1, bNode2);
Assert.assertTrue(n.equals(new GraphNode(bNode1, g)));
@@ -259,10 +259,10 @@ public class TestGraphNode {
Assert.assertFalse(n.equals(n2));
}
- private Set<Resource> createSet(Iterator<? extends Resource> resources) {
- Set<Resource> set = new HashSet<Resource>();
+ private Set<RdfTerm> createSet(Iterator<? extends RdfTerm> resources) {
+ Set<RdfTerm> set = new HashSet<RdfTerm>();
while (resources.hasNext()) {
- Resource resource = resources.next();
+ RdfTerm resource = resources.next();
set.add(resource);
}
return set;
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
new file mode 100644
index 0000000..2881eb4
--- /dev/null
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionGraphTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+import java.util.Iterator;
+import org.junit.Test;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.junit.Assert;
+
+/**
+ *
+ * @author hasan
+ */
+public class UnionGraphTest {
+
+ private final Iri uriRef1 =
+ new Iri("http://example.org/ontology#res1");
+ private final Iri uriRef2 =
+ new Iri("http://example.org/ontology#res2");
+ private final Iri uriRef3 =
+ new Iri("http://example.org/ontology#res3");
+ private final Iri uriRef4 =
+ new Iri("http://example.org/ontology#res4");
+
+ @Test
+ public void readAccess() {
+ Graph graph = new SimpleGraph();
+ Graph graph2 = new SimpleGraph();
+ BlankNode bnode = new BlankNode() {
+ };
+ graph.add(new TripleImpl(uriRef1, uriRef2, uriRef1));
+ graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
+ Graph unionGraph = new UnionGraph(graph, graph2);
+ Iterator<Triple> unionTriples = unionGraph.iterator();
+ Assert.assertTrue(unionTriples.hasNext());
+ unionTriples.next();
+ Assert.assertTrue(unionTriples.hasNext());
+ unionTriples.next();
+ Assert.assertFalse(unionTriples.hasNext());
+ Assert.assertEquals(2, unionGraph.size());
+ }
+
+ @Test
+ public void writeAccess() {
+ Graph graph = new SimpleGraph();
+ Graph graph2 = new SimpleGraph();
+ BlankNode bnode = new BlankNode() {
+ };
+ graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
+ Graph unionGraph = new UnionGraph(graph, graph2);
+ Assert.assertEquals(1, unionGraph.size());
+ unionGraph.add(new TripleImpl(uriRef4, uriRef1, uriRef3));
+ Assert.assertEquals(1, graph.size());
+ Assert.assertEquals(2, unionGraph.size());
+ Assert.assertEquals(1, graph2.size());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionMGraphTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionMGraphTest.java
deleted file mode 100644
index 1c72497..0000000
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/UnionMGraphTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.clerezza.rdf.utils;
-
-import java.util.Iterator;
-import junit.framework.Assert;
-import org.junit.Test;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.MGraph;
-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.core.impl.TripleImpl;
-
-/**
- *
- * @author hasan
- */
-public class UnionMGraphTest {
-
- private final UriRef uriRef1 =
- new UriRef("http://example.org/ontology#res1");
- private final UriRef uriRef2 =
- new UriRef("http://example.org/ontology#res2");
- private final UriRef uriRef3 =
- new UriRef("http://example.org/ontology#res3");
- private final UriRef uriRef4 =
- new UriRef("http://example.org/ontology#res4");
-
- @Test
- public void readAccess() {
- MGraph graph = new SimpleMGraph();
- MGraph graph2 = new SimpleMGraph();
- BNode bnode = new BNode() {
- };
- graph.add(new TripleImpl(uriRef1, uriRef2, uriRef1));
- graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
- MGraph unionGraph = new UnionMGraph(graph, graph2);
- Iterator<Triple> unionTriples = unionGraph.iterator();
- Assert.assertTrue(unionTriples.hasNext());
- unionTriples.next();
- Assert.assertTrue(unionTriples.hasNext());
- unionTriples.next();
- Assert.assertFalse(unionTriples.hasNext());
- Assert.assertEquals(2, unionGraph.size());
- }
-
- @Test
- public void writeAccess() {
- MGraph graph = new SimpleMGraph();
- MGraph graph2 = new SimpleMGraph();
- BNode bnode = new BNode() {
- };
- graph2.add(new TripleImpl(bnode, uriRef1, uriRef3));
- MGraph unionGraph = new UnionMGraph(graph, graph2);
- Assert.assertEquals(1, unionGraph.size());
- unionGraph.add(new TripleImpl(uriRef4, uriRef1, uriRef3));
- Assert.assertEquals(1, graph.size());
- Assert.assertEquals(2, unionGraph.size());
- Assert.assertEquals(1, graph2.size());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
index 6bb1688..bab58e9 100644
--- a/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
+++ b/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmushTest.java
@@ -20,17 +20,14 @@ package org.apache.clerezza.rdf.utils.smushing;
import java.util.Iterator;
import java.util.Set;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.PlainLiteral;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.rdf.ontologies.FOAF;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
@@ -44,18 +41,18 @@ import org.junit.Test;
*/
public class SameAsSmushTest {
- private final UriRef uriA = new UriRef("http://example.org/A");
- private final UriRef uriB = new UriRef("http://example.org/B");
- private final UriRef uriC = new UriRef("http://example.org/C");
+ private final Iri uriA = new Iri("http://example.org/A");
+ private final Iri uriB = new Iri("http://example.org/B");
+ private final Iri uriC = new Iri("http://example.org/C");
private final Literal lit = new PlainLiteralImpl("That's me (and you)");
- private MGraph sameAsStatements = new SimpleMGraph();
+ private Graph sameAsStatements = new SimpleGraph();
{
sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
}
- private LockableMGraph dataGraph = new LockableMGraphWrapper(new SimpleMGraph());
+ private Graph dataGraph = new SimpleGraph();
{
dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
@@ -67,7 +64,7 @@ public class SameAsSmushTest {
SameAsSmusher smusher = new SameAsSmusher() {
@Override
- protected UriRef getPreferedIri(Set<UriRef> uriRefs) {
+ protected Iri getPreferedIri(Set<Iri> uriRefs) {
if (!uriRefs.contains(uriA)) throw new RuntimeException("not the set we excpect");
if (!uriRefs.contains(uriB)) throw new RuntimeException("not the set we excpect");
return uriC;
[3/6] clerezza git commit: CLEREZZA-964: using rdf-commons from
clerezza-rdf-core repository
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
index 34fc25c..b839c37 100644
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
+++ b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
@@ -23,19 +23,18 @@ import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-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.commons.rdf.BlankNode;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import static org.junit.Assert.*;
/**
@@ -44,22 +43,22 @@ import static org.junit.Assert.*;
*/
public abstract class TcProviderTest {
- protected final UriRef uriRefA = generateUri("a");
- protected final UriRef uriRefA1 = generateUri("a1");
- protected final UriRef uriRefB = generateUri("b");
- protected final UriRef uriRefB1 = generateUri("b1");
- protected final UriRef uriRefC = generateUri("c");
+ protected final Iri uriRefA = generateUri("a");
+ protected final Iri uriRefA1 = generateUri("a1");
+ protected final Iri uriRefB = generateUri("b");
+ protected final Iri uriRefB1 = generateUri("b1");
+ protected final Iri uriRefC = generateUri("c");
- protected final UriRef graphUriRef = generateUri("myGraph");
- protected final UriRef otherGraphUriRef = new UriRef(graphUriRef.getUnicodeString());
+ protected final Iri graphIri = generateUri("myGraph");
+ protected final Iri otherGraphIri = new Iri(graphIri.getUnicodeString());
@Test
- public void testCreateGraph() {
+ public void testCreateImmutableGraph() {
TcProvider simpleTcmProvider = getInstance();
- MGraph mGraph = new SimpleMGraph();
+ Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
- Graph createdGraph = simpleTcmProvider.createGraph(uriRefA, mGraph);
+ ImmutableGraph createdGraph = simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
Iterator<Triple> iteratorInput = mGraph.iterator();
Iterator<Triple> iteratorCreated = createdGraph.iterator();
@@ -67,80 +66,80 @@ public abstract class TcProviderTest {
assertFalse(iteratorCreated.hasNext());
try {
- simpleTcmProvider.createGraph(uriRefA, mGraph);
+ simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
assertTrue(false);
} catch (EntityAlreadyExistsException e) {
assertTrue(true);
}
- simpleTcmProvider.deleteTripleCollection(uriRefA);
+ simpleTcmProvider.deleteGraph(uriRefA);
}
@Test
- public void testCreateMGraph() {
+ public void testCreateGraph() {
TcProvider simpleTcmProvider = getInstance();
- MGraph mGraph = simpleTcmProvider.createMGraph(uriRefA);
+ Graph mGraph = simpleTcmProvider.createGraph(uriRefA);
assertTrue(mGraph.isEmpty());
try {
- simpleTcmProvider.createMGraph(uriRefA);
+ simpleTcmProvider.createGraph(uriRefA);
assertTrue(false);
} catch (EntityAlreadyExistsException e) {
assertTrue(true);
}
- simpleTcmProvider.deleteTripleCollection(uriRefA);
+ simpleTcmProvider.deleteGraph(uriRefA);
}
@Test
- public void testGetGraph() {
+ public void testGetImmutableGraph() {
TcProvider simpleTcmProvider = getInstance();
// add Graphs
- MGraph mGraph = new SimpleMGraph();
+ Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
- simpleTcmProvider.createGraph(uriRefA, mGraph);
- mGraph = new SimpleMGraph();
+ simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
+ mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
- simpleTcmProvider.createGraph(uriRefA1, mGraph);
- mGraph = new SimpleMGraph();
+ simpleTcmProvider.createImmutableGraph(uriRefA1, mGraph);
+ mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
- simpleTcmProvider.createGraph(uriRefB, mGraph);
- mGraph = new SimpleMGraph();
+ simpleTcmProvider.createImmutableGraph(uriRefB, mGraph);
+ mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));
- simpleTcmProvider.createGraph(uriRefB1, mGraph);
+ simpleTcmProvider.createImmutableGraph(uriRefB1, mGraph);
- Graph bGraph = simpleTcmProvider.getGraph(uriRefB);
+ ImmutableGraph bGraph = simpleTcmProvider.getImmutableGraph(uriRefB);
Iterator<Triple> iterator = bGraph.iterator();
assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
assertFalse(iterator.hasNext());
- simpleTcmProvider.deleteTripleCollection(uriRefA);
- simpleTcmProvider.deleteTripleCollection(uriRefA1);
- simpleTcmProvider.deleteTripleCollection(uriRefB);
- simpleTcmProvider.deleteTripleCollection(uriRefB1);
+ simpleTcmProvider.deleteGraph(uriRefA);
+ simpleTcmProvider.deleteGraph(uriRefA1);
+ simpleTcmProvider.deleteGraph(uriRefB);
+ simpleTcmProvider.deleteGraph(uriRefB1);
}
@Test
- public void testGetMGraph() {
+ public void testGetGraph() {
TcProvider simpleTcmProvider = getInstance();
- // add MGraphs
- MGraph mGraph = simpleTcmProvider.createMGraph(uriRefA);
+ // add Graphs
+ Graph mGraph = simpleTcmProvider.createGraph(uriRefA);
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
- mGraph = simpleTcmProvider.createMGraph(uriRefA1);
+ mGraph = simpleTcmProvider.createGraph(uriRefA1);
mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
- mGraph = simpleTcmProvider.createMGraph(uriRefB);
+ mGraph = simpleTcmProvider.createGraph(uriRefB);
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefA));
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
mGraph.remove(new TripleImpl(uriRefB, uriRefB, uriRefA));
assertEquals(1, mGraph.size());
- mGraph = simpleTcmProvider.createMGraph(uriRefB1);
+ mGraph = simpleTcmProvider.createGraph(uriRefB1);
mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));
- MGraph bGraph = simpleTcmProvider.getMGraph(uriRefB);
+ Graph bGraph = simpleTcmProvider.getGraph(uriRefB);
Iterator<Triple> iterator = bGraph.iterator();
assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
assertFalse(iterator.hasNext());
- simpleTcmProvider.deleteTripleCollection(uriRefA);
- simpleTcmProvider.deleteTripleCollection(uriRefA1);
- simpleTcmProvider.deleteTripleCollection(uriRefB);
- simpleTcmProvider.deleteTripleCollection(uriRefB1);
+ simpleTcmProvider.deleteGraph(uriRefA);
+ simpleTcmProvider.deleteGraph(uriRefA1);
+ simpleTcmProvider.deleteGraph(uriRefB);
+ simpleTcmProvider.deleteGraph(uriRefB1);
}
@@ -148,22 +147,22 @@ public abstract class TcProviderTest {
public void testGetTriples() {
TcProvider simpleTcmProvider = getInstance();
// add Graphs
- MGraph mGraph = new SimpleMGraph();
+ Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
- simpleTcmProvider.createGraph(uriRefA, mGraph);
- mGraph = new SimpleMGraph();
+ simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
+ mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
- simpleTcmProvider.createGraph(uriRefB, mGraph);
- // add MGraphs
- mGraph = simpleTcmProvider.createMGraph(uriRefA1);
+ simpleTcmProvider.createImmutableGraph(uriRefB, mGraph);
+ // add Graphs
+ mGraph = simpleTcmProvider.createGraph(uriRefA1);
mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
- mGraph = simpleTcmProvider.createMGraph(uriRefB1);
+ mGraph = simpleTcmProvider.createGraph(uriRefB1);
mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));
+ // get a ImmutableGraph
+ Graph tripleCollection = simpleTcmProvider.getGraph(uriRefA);
// get a Graph
- TripleCollection tripleCollection = simpleTcmProvider.getTriples(uriRefA);
- // get a MGraph
- TripleCollection tripleCollection2 = simpleTcmProvider.getTriples(uriRefB1);
+ Graph tripleCollection2 = simpleTcmProvider.getGraph(uriRefB1);
Iterator<Triple> iterator = tripleCollection.iterator();
assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
@@ -172,22 +171,22 @@ public abstract class TcProviderTest {
iterator = tripleCollection2.iterator();
assertEquals(new TripleImpl(uriRefB1, uriRefB1, uriRefB1), iterator.next());
assertFalse(iterator.hasNext());
- simpleTcmProvider.deleteTripleCollection(uriRefA);
- simpleTcmProvider.deleteTripleCollection(uriRefA1);
- simpleTcmProvider.deleteTripleCollection(uriRefB);
- simpleTcmProvider.deleteTripleCollection(uriRefB1);
+ simpleTcmProvider.deleteGraph(uriRefA);
+ simpleTcmProvider.deleteGraph(uriRefA1);
+ simpleTcmProvider.deleteGraph(uriRefB);
+ simpleTcmProvider.deleteGraph(uriRefB1);
}
@Test
public void testDeleteEntity() {
TcProvider simpleTcmProvider = getInstance();
- MGraph mGraph = new SimpleMGraph();
+ Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
- Graph graph = mGraph.getGraph();
- simpleTcmProvider.createGraph(uriRefA, graph);
- simpleTcmProvider.createGraph(uriRefC, graph);
+ ImmutableGraph graph = mGraph.getImmutableGraph();
+ simpleTcmProvider.createImmutableGraph(uriRefA, graph);
+ simpleTcmProvider.createImmutableGraph(uriRefC, graph);
- simpleTcmProvider.deleteTripleCollection(uriRefA);
+ simpleTcmProvider.deleteGraph(uriRefA);
try {
simpleTcmProvider.getGraph(uriRefA);
assertTrue(false);
@@ -196,9 +195,9 @@ public abstract class TcProviderTest {
}
// Check that graph is still available under uriRefC
- Graph cGraph = simpleTcmProvider.getGraph(uriRefC);
+ ImmutableGraph cGraph = simpleTcmProvider.getImmutableGraph(uriRefC);
assertNotNull(cGraph);
- simpleTcmProvider.deleteTripleCollection(uriRefC);
+ simpleTcmProvider.deleteGraph(uriRefC);
}
/**
@@ -214,17 +213,17 @@ public abstract class TcProviderTest {
// @Test
// public void testGetNames() {
-// MGraph mGraph = new SimpleMGraph();
+// Graph mGraph = new SimpleGraph();
// mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
// simpleTcmProvider.createGraph(uriRefB, mGraph.getGraph());
//
-// mGraph = new SimpleMGraph();
+// mGraph = new SimpleGraph();
// mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
-// Graph graph = mGraph.getGraph();
+// ImmutableGraph graph = mGraph.getGraph();
// simpleTcmProvider.createGraph(uriRefA, graph);
// simpleTcmProvider.createGraph(uriRefC, graph);
//
-// Set<UriRef> names = simpleTcmProvider.getNames(graph);
+// Set<Iri> names = simpleTcmProvider.getNames(graph);
//
// assertTrue(names.contains(uriRefA));
// assertTrue(names.contains(uriRefC));
@@ -234,83 +233,83 @@ public abstract class TcProviderTest {
// }
@Test
- public void testCreateMGraphExtended() throws Exception {
+ public void testCreateGraphExtended() throws Exception {
TcProvider provider = getInstance();
- MGraph graph = provider.createMGraph(graphUriRef);
+ Graph graph = provider.createGraph(graphIri);
assertNotNull(graph);
//get a new provider and check that graph is there
provider = getInstance();
- graph = provider.getMGraph(graphUriRef);
+ graph = provider.getGraph(graphIri);
assertNotNull(graph);
//check that there is no such graph, but only the mgraph
boolean expThrown = false;
try {
- Graph g = provider.getGraph(graphUriRef);
+ ImmutableGraph g = provider.getImmutableGraph(graphIri);
} catch(NoSuchEntityException e) {
expThrown = true;
}
assertTrue(expThrown);
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
@Test
- public void testCreateGraphExtended() throws Exception {
+ public void testCreateImmutableGraphExtended() throws Exception {
TcProvider provider = getInstance();
- Graph graph = provider.createGraph(graphUriRef, null);
+ ImmutableGraph graph = provider.createImmutableGraph(graphIri, null);
assertNotNull(graph);
//get a new provider and check that graph is there
provider = getInstance();
- graph = provider.getGraph(graphUriRef);
+ graph = provider.getImmutableGraph(graphIri);
assertNotNull(graph);
//check that there is no such mgraph, but only the graph
boolean expThrown = false;
try {
- MGraph g = provider.getMGraph(graphUriRef);
+ Graph g = provider.getGraph(graphIri);
} catch(NoSuchEntityException e) {
expThrown = true;
}
assertTrue(expThrown);
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
@Test
public void testCreateGraphNoDuplicateNames() throws Exception {
TcProvider provider = getInstance();
- Graph graph = provider.createGraph(graphUriRef, null);
+ ImmutableGraph graph = provider.createImmutableGraph(graphIri, null);
assertNotNull(graph);
boolean expThrown = false;
try {
- Graph other = provider.createGraph(otherGraphUriRef, null);
+ ImmutableGraph other = provider.createImmutableGraph(otherGraphIri, null);
} catch(EntityAlreadyExistsException eaee) {
expThrown = true;
}
assertTrue(expThrown);
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
@Test
- public void testCreateMGraphNoDuplicateNames() throws Exception {
+ public void testCreateGraphNoDuplicateNames2() throws Exception {
TcProvider provider = getInstance();
- MGraph graph = provider.createMGraph(graphUriRef);
+ Graph graph = provider.createGraph(graphIri);
assertNotNull(graph);
boolean expThrown = false;
try {
- MGraph other = provider.createMGraph(otherGraphUriRef);
+ Graph other = provider.createGraph(otherGraphIri);
} catch(EntityAlreadyExistsException eaee) {
expThrown = true;
}
assertTrue(expThrown);
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
@Test
@@ -320,11 +319,11 @@ public abstract class TcProviderTest {
TcProvider provider = getInstance();
- Graph graph = provider.createGraph(graphUriRef, createTestTripleCollection(t1));
+ ImmutableGraph graph = provider.createImmutableGraph(graphIri, createTestTripleCollection(t1));
assertEquals(1, graph.size());
assertTrue(graph.contains(t1));
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
@Test
@@ -336,7 +335,7 @@ public abstract class TcProviderTest {
TcProvider provider = getInstance();
- Graph graph = provider.createGraph(graphUriRef, createTestTripleCollection(t1));
+ ImmutableGraph graph = provider.createImmutableGraph(graphIri, createTestTripleCollection(t1));
boolean expThrown = false;
@@ -385,7 +384,7 @@ public abstract class TcProviderTest {
}
assertTrue(expThrown);
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
// This tests can not pass, because equals in AbstractGraph is not implemented
@@ -395,27 +394,27 @@ public abstract class TcProviderTest {
//
// TcProvider provider = getInstance();
//
-// TripleCollection triples = createTestTripleCollection(createTestTriple());
-// Graph graph = provider.createGraph(graphUriRef, triples);
+// Graph triples = createTestTripleCollection(createTestTriple());
+// ImmutableGraph graph = provider.createGraph(graphIri, triples);
//
// provider = getInstance();
-// Set<UriRef> names = provider.getNames(graph);
-// assertTrue(names.contains(graphUriRef));
+// Set<Iri> names = provider.getNames(graph);
+// assertTrue(names.contains(graphIri));
// }
//
// @Test
// public void testCreateSameGraphWithDifferentNames() throws Exception {
//
-// TripleCollection triples = createTestTripleCollection(createTestTriple());
+// Graph triples = createTestTripleCollection(createTestTriple());
//
// TcProvider provider = getInstance();
-// UriRef name1 = new UriRef("http://myGraph1");
-// Graph graph = provider.createGraph(name1, triples);
+// Iri name1 = new Iri("http://myGraph1");
+// ImmutableGraph graph = provider.createGraph(name1, triples);
//
-// UriRef name2 = new UriRef("http://myGraph2");
-// Graph secondGraph = provider.createGraph(name2, triples);
+// Iri name2 = new Iri("http://myGraph2");
+// ImmutableGraph secondGraph = provider.createGraph(name2, triples);
//
-// Set<UriRef> names = provider.getNames(graph);
+// Set<Iri> names = provider.getNames(graph);
// assertNotNull(names);
// assertEquals(2, names.size());
// }
@@ -423,72 +422,63 @@ public abstract class TcProviderTest {
@Test
public void testGraphDeletion() throws Exception {
- TripleCollection triples = createTestTripleCollection(createTestTriple());
+ Graph triples = createTestTripleCollection(createTestTriple());
TcProvider provider = getInstance();
- UriRef name1 = new UriRef("http://myGraph1");
- Graph graph = provider.createGraph(name1, triples);
+ Iri name1 = new Iri("http://myGraph1");
+ ImmutableGraph graph = provider.createImmutableGraph(name1, triples);
- UriRef name2 = new UriRef("http://myGraph2");
- Graph secondGraph = provider.createGraph(name2, triples);
+ Iri name2 = new Iri("http://myGraph2");
+ ImmutableGraph secondGraph = provider.createImmutableGraph(name2, triples);
//if we delete graph with name1, the second graph should still be there
- provider.deleteTripleCollection(name1);
+ provider.deleteGraph(name1);
provider = getInstance();
- Graph firstGraph = provider.getGraph(name2);
+ ImmutableGraph firstGraph = provider.getImmutableGraph(name2);
assertNotNull(firstGraph);
//check second name is not there
boolean expThrown = false;
try {
- Graph g = provider.getGraph(name1);
+ ImmutableGraph g = provider.getImmutableGraph(name1);
} catch(NoSuchEntityException nses) {
expThrown = true;
}
assertTrue(expThrown);
- provider.deleteTripleCollection(name2);
+ provider.deleteGraph(name2);
}
- @Test
- public void testGetTriplesGraph() throws Exception {
- TcProvider provider = getInstance();
- Graph graph = provider.createGraph(graphUriRef,
- createTestTripleCollection(createTestTriple()));
- TripleCollection tc = provider.getTriples(graphUriRef);
- assertNotNull(tc);
- provider.deleteTripleCollection(graphUriRef);
- }
@Test
- public void testGetTriplesMGraph() throws Exception {
+ public void testGetTriplesGraph() throws Exception {
TcProvider provider = getInstance();
- MGraph graph = provider.createMGraph(graphUriRef);
+ Graph graph = provider.createGraph(graphIri);
- TripleCollection tc = provider.getTriples(graphUriRef);
+ Graph tc = provider.getGraph(graphIri);
assertNotNull(tc);
- provider.deleteTripleCollection(graphUriRef);
+ provider.deleteGraph(graphIri);
}
private Triple createTestTriple() {
- NonLiteral subject = new BNode() {};
- UriRef predicate = new UriRef("http://test.com/");
- NonLiteral object = new UriRef("http://test.com/myObject");
+ BlankNodeOrIri subject = new BlankNode() {};
+ Iri predicate = new Iri("http://test.com/");
+ BlankNodeOrIri object = new Iri("http://test.com/myObject");
return new TripleImpl(subject, predicate, object);
}
- private TripleCollection createTestTripleCollection(Triple t) {
+ private Graph createTestTripleCollection(Triple t) {
Set<Triple> ts = new HashSet<Triple>();
ts.add(t);
- return new SimpleMGraph(ts);
+ return new SimpleGraph(ts);
}
- protected UriRef generateUri(String name) {
- return new UriRef("http://example.org/" + name);
+ protected Iri generateUri(String name) {
+ return new Iri("http://example.org/" + name);
}
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TripleCollectionWrapper.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TripleCollectionWrapper.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TripleCollectionWrapper.java
deleted file mode 100644
index 0cceae7..0000000
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TripleCollectionWrapper.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.clerezza.rdf.core.test;
-
-import java.util.Collection;
-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.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-
-/**
- *
- * @author mir
- */
-class TripleCollectionWrapper implements TripleCollection {
-
- protected TripleCollection wrapped;
-
- public TripleCollectionWrapper(TripleCollection tc) {
- this.wrapped = tc;
- }
-
- @Override
- public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
- return wrapped.filter(subject, predicate, object);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
- wrapped.addGraphListener(listener, filter, delay);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- wrapped.addGraphListener(listener, filter);
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- wrapped.removeGraphListener(listener);
- }
-
- @Override
- public int size() {
- return wrapped.size();
- }
-
- @Override
- public boolean isEmpty() {
- return wrapped.isEmpty();
- }
-
- @Override
- public boolean contains(Object o) {
- return wrapped.contains(o);
- }
-
- @Override
- public Iterator<Triple> iterator() {
- return wrapped.iterator();
- }
-
- @Override
- public Object[] toArray() {
- return wrapped.toArray();
- }
-
- @Override
- public <T> T[] toArray(T[] a) {
- return wrapped.toArray(a);
- }
-
- @Override
- public boolean add(Triple e) {
- return wrapped.add(e);
- }
-
- @Override
- public boolean remove(Object o) {
- return wrapped.remove(o);
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- return wrapped.containsAll(c);
- }
-
- @Override
- public boolean addAll(Collection<? extends Triple> c) {
- return wrapped.addAll(c);
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- return wrapped.removeAll(c);
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- return wrapped.retainAll(c);
- }
-
- @Override
- public void clear() {
- wrapped.clear();
- }
-
-}
[4/6] clerezza git commit: CLEREZZA-964: using rdf-commons from
clerezza-rdf-core repository
Posted by re...@apache.org.
CLEREZZA-964: using rdf-commons from clerezza-rdf-core repository
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/4bc320a8
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/4bc320a8
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/4bc320a8
Branch: refs/heads/rdf-commons
Commit: 4bc320a87f0fd8c5f52b9153924a09d114d9ea01
Parents: 47cc373
Author: Reto Gmuer <re...@apache.org>
Authored: Thu Mar 19 21:34:00 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Thu Mar 19 21:34:00 2015 +0000
----------------------------------------------------------------------
rdf.core.test/pom.xml | 4 +-
.../clerezza/rdf/core/test/GraphTest.java | 580 ++++++++++++++++++
.../clerezza/rdf/core/test/GraphWrapper.java | 126 ++++
.../test/LockableMGraphWrapperForTesting.java | 29 +-
.../core/test/LockingIteratorForTesting.java | 2 +-
.../clerezza/rdf/core/test/MGraphTest.java | 581 -------------------
.../clerezza/rdf/core/test/MGraphWrapper.java | 40 --
.../clerezza/rdf/core/test/RandomGraph.java | 237 ++++++++
.../clerezza/rdf/core/test/RandomMGraph.java | 237 --------
.../clerezza/rdf/core/test/TcProviderTest.java | 260 ++++-----
.../rdf/core/test/TripleCollectionWrapper.java | 129 ----
11 files changed, 1085 insertions(+), 1140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.core.test/pom.xml b/rdf.core.test/pom.xml
index ae07e20..c8d76b8 100644
--- a/rdf.core.test/pom.xml
+++ b/rdf.core.test/pom.xml
@@ -24,7 +24,7 @@
<parent>
<artifactId>clerezza</artifactId>
<groupId>org.apache.clerezza</groupId>
- <version>0.5</version>
+ <version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<groupId>org.apache.clerezza</groupId>
@@ -41,7 +41,7 @@
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.core</artifactId>
- <version>0.14</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
new file mode 100644
index 0000000..4741e2e
--- /dev/null
+++ b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphTest.java
@@ -0,0 +1,580 @@
+/*
+ * 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.clerezza.rdf.core.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.junit.Test;
+import org.apache.commons.rdf.Language;
+import org.apache.commons.rdf.event.AddEvent;
+import org.apache.commons.rdf.event.FilterTriple;
+import org.apache.commons.rdf.event.GraphEvent;
+import org.apache.commons.rdf.event.GraphListener;
+import org.apache.commons.rdf.event.RemoveEvent;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TypedLiteralImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.junit.Assert;
+
+
+
+/**
+ * A generic abstract test class, implementations overwrite this class,
+ * providing an implementation of the getEmptyGraph method.
+ *
+ * @author reto, szalay, mir, hhn
+ */
+public abstract class GraphTest {
+
+ private final Iri uriRef1 =
+ new Iri("http://example.org/ontology#res1");
+ private final Iri uriRef2 =
+ new Iri("http://example.org/ontology#res2");
+ private final Iri uriRef3 =
+ new Iri("http://example.org/ontology#res3");
+ private final Iri uriRef4 =
+ new Iri("http://example.org/ontology#res4");
+ private final Iri xmlLiteralType =
+ new Iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
+ private Literal literal1 = new PlainLiteralImpl("literal1");
+ private Literal literal2 = new PlainLiteralImpl("literal2");
+ private BlankNode bnode1 = new BlankNode();
+ private BlankNode bnode2 = new BlankNode();
+ private Triple trpl1 = new TripleImpl(uriRef2, uriRef2, literal1);
+ private Triple trpl2 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+ private Triple trpl3 = new TripleImpl(bnode2, uriRef3, literal2);
+ private Triple trpl4 = new TripleImpl(uriRef3, uriRef4, literal2);
+
+ /**
+ * Subclasses implement this method to provide implementation instances of
+ * Graph. This method may be called an arbitrary amount of time,
+ * independently whether previously returned Graph are still in use or not.
+ *
+ * @return an empty Graph of the implementation to be tested
+ */
+ protected abstract Graph getEmptyGraph();
+
+ @Test
+ public void testAddCountAndGetTriples() {
+ Graph graph = getEmptyGraph();
+ Assert.assertEquals(0, graph.size());
+ final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+ graph.add(triple1);
+ Assert.assertEquals(1, graph.size());
+ Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, uriRef1);
+ Assert.assertTrue(tripleIter.hasNext());
+ Triple tripleGot = tripleIter.next();
+ Assert.assertEquals(triple1, tripleGot);
+ Assert.assertFalse(tripleIter.hasNext());
+ BlankNode bnode = new BlankNode() {};
+ graph.add(new TripleImpl(bnode, uriRef1, uriRef3));
+ graph.add(new TripleImpl(bnode, uriRef1, uriRef4));
+ tripleIter = graph.filter(null, uriRef1, null);
+ Set<BlankNodeOrIri> subjectInMatchingTriples = new HashSet<BlankNodeOrIri>();
+ Set<RdfTerm> objectsInMatchingTriples = new HashSet<RdfTerm>();
+ while (tripleIter.hasNext()) {
+ Triple triple = tripleIter.next();
+ subjectInMatchingTriples.add(triple.getSubject());
+ objectsInMatchingTriples.add(triple.getObject());
+ }
+ Assert.assertEquals(1, subjectInMatchingTriples.size());
+ Assert.assertEquals(2, objectsInMatchingTriples.size());
+ Set<RdfTerm> expectedObjects = new HashSet<RdfTerm>();
+ expectedObjects.add(uriRef3);
+ expectedObjects.add(uriRef4);
+ Assert.assertEquals(expectedObjects, objectsInMatchingTriples);
+ graph.add(new TripleImpl(bnode, uriRef4, bnode));
+ tripleIter = graph.filter(null, uriRef4, null);
+ Assert.assertTrue(tripleIter.hasNext());
+ Triple retrievedTriple = tripleIter.next();
+ Assert.assertFalse(tripleIter.hasNext());
+ Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
+ tripleIter = graph.filter(uriRef1, uriRef2, null);
+ Assert.assertTrue(tripleIter.hasNext());
+ retrievedTriple = tripleIter.next();
+ Assert.assertFalse(tripleIter.hasNext());
+ Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
+ }
+
+ @Test
+ public void testRemoveAllTriples() {
+ Graph graph = getEmptyGraph();
+ Assert.assertEquals(0, graph.size());
+ graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3));
+ graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4));
+ Assert.assertEquals(2, graph.size());
+ graph.clear();
+ Assert.assertEquals(0, graph.size());
+ }
+
+ @Test
+ public void testUseTypedLiterals() {
+ Graph graph = getEmptyGraph();
+ Assert.assertEquals(0, graph.size());
+ Literal value = new TypedLiteralImpl("<elem>value</elem>",xmlLiteralType);
+ final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
+ graph.add(triple1);
+ Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
+ Assert.assertTrue(tripleIter.hasNext());
+ RdfTerm gotValue = tripleIter.next().getObject();
+ Assert.assertEquals(value, gotValue);
+ }
+
+ @Test
+ public void testUseLanguageLiterals() {
+ Graph graph = getEmptyGraph();
+ Assert.assertEquals(0, graph.size());
+ Language language = new Language("it");
+ Literal value = new PlainLiteralImpl("<elem>value</elem>",language);
+ final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
+ graph.add(triple1);
+ Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
+ Assert.assertTrue(tripleIter.hasNext());
+ RdfTerm gotValue = tripleIter.next().getObject();
+ Assert.assertEquals(value, gotValue);
+ Assert.assertEquals(language, ((Literal)gotValue).getLanguage());
+ }
+
+ @Test
+ public void testRemoveViaIterator() {
+ Graph graph = getEmptyGraph();
+ Assert.assertEquals(0, graph.size());
+ final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+ graph.add(triple1);
+ final TripleImpl triple2 = new TripleImpl(uriRef1, uriRef2, uriRef4);
+ graph.add(triple2);
+ Assert.assertEquals(2, graph.size());
+ Iterator<Triple> iterator = graph.iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ iterator.remove();
+ }
+ Assert.assertEquals(0, graph.size());
+ }
+
+ @Test
+ public void testGetSize() throws Exception {
+ Graph graph = getEmptyGraph();
+ // The test graph must always be empty after test fixture setup
+ Assert.assertEquals(0, graph.size());
+ }
+
+
+ @Test
+ public void testAddSingleTriple() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple triple= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ Assert.assertEquals(0, graph.size());
+ Assert.assertTrue(graph.add(triple));
+ Assert.assertEquals(1, graph.size());
+ }
+
+
+ @Test
+ public void testAddSameTripleTwice() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple triple= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ Assert.assertEquals(0, graph.size());
+ Assert.assertTrue(graph.add(triple));
+ Assert.assertFalse(graph.add(triple)); // ImmutableGraph does not change
+ Assert.assertEquals(1, graph.size());
+ }
+
+
+ @Test
+ public void testRemoveSingleTriple() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple triple= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ Assert.assertTrue(graph.add(triple));
+ Assert.assertTrue(graph.remove(triple));
+ Assert.assertEquals(0, graph.size());
+ }
+
+ @Test
+ public void testRemoveSameTripleTwice() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple tripleAlice= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ final Triple tripleBob= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/bob");
+ Assert.assertTrue(graph.add(tripleAlice));
+ Assert.assertTrue(graph.add(tripleBob));
+ Assert.assertTrue(graph.remove(tripleAlice));
+ Assert.assertFalse(graph.remove(tripleAlice));
+ Assert.assertEquals(1, graph.size());
+ }
+
+ @Test
+ public void testGetSameBlankNode() throws Exception {
+ Graph graph = getEmptyGraph();
+ BlankNode bNode = new BlankNode();
+ final Iri HAS_NAME = new Iri("http://example.org/ontology/hasName");
+ final PlainLiteralImpl name = new PlainLiteralImpl("http://example.org/people/alice");
+ final PlainLiteralImpl name2 = new PlainLiteralImpl("http://example.org/people/bob");
+ final Triple tripleAlice = new TripleImpl(bNode, HAS_NAME, name);
+ final Triple tripleBob = new TripleImpl(bNode, HAS_NAME, name2);
+ Assert.assertTrue(graph.add(tripleAlice));
+ Assert.assertTrue(graph.add(tripleBob));
+ Iterator<Triple> result = graph.filter(null, HAS_NAME, name);
+ Assert.assertEquals(bNode, result.next().getSubject());
+ }
+
+ @Test
+ public void testContainsIfContained() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple triple= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ Assert.assertTrue(graph.add(triple));
+ Assert.assertTrue(graph.contains(triple));
+ }
+
+
+ @Test
+ public void testContainsIfEmpty() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple triple= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ Assert.assertFalse(graph.contains(triple));
+ }
+
+
+ @Test
+ public void testContainsIfNotContained() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple tripleAdd= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ final Triple tripleTest= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/bob");
+ Assert.assertTrue(graph.add(tripleAdd));
+ Assert.assertFalse(graph.contains(tripleTest));
+ }
+
+
+ @Test
+ public void testFilterEmptyGraph() throws Exception {
+ Graph graph = getEmptyGraph();
+ Iterator<Triple> i = graph.filter(null, null, null);
+ Assert.assertFalse(i.hasNext());
+ }
+
+
+ @Test
+ public void testFilterSingleEntry() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple triple= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ Assert.assertTrue(graph.add(triple));
+
+ Iterator<Triple> i = graph.filter(null, null, null);
+ Collection<Triple> resultSet= toCollection(i);
+ Assert.assertEquals(1, resultSet.size());
+ Assert.assertTrue(resultSet.contains(triple));
+ }
+
+
+ @Test
+ public void testFilterByObject() throws Exception {
+ Graph graph = getEmptyGraph();
+ final Triple tripleAlice= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/alice");
+ final Triple tripleBob= createTriple(
+ "http://example.org/ontology/Person",
+ "http://example.org/ontology/hasName",
+ "http://example.org/people/bob");
+ Assert.assertTrue(graph.add(tripleAlice));
+ Assert.assertTrue(graph.add(tripleBob));
+
+ Iterator<Triple> iterator;
+ Collection<Triple> resultSet;
+
+ // Find bob
+ iterator = graph.filter(null, null,
+ new Iri("http://example.org/people/bob"));
+ resultSet= toCollection(iterator);
+ Assert.assertEquals(1, resultSet.size());
+ Assert.assertTrue(resultSet.contains(tripleBob));
+
+ // Find alice
+ iterator = graph.filter(null, null,
+ new Iri("http://example.org/people/alice"));
+ resultSet= toCollection(iterator);
+ Assert.assertEquals(1, resultSet.size());
+ Assert.assertTrue(resultSet.contains(tripleAlice));
+
+ // Find both
+ iterator = graph.filter(null, null, null);
+ resultSet= toCollection(iterator);
+ Assert.assertEquals(2, resultSet.size());
+ Assert.assertTrue(resultSet.contains(tripleAlice));
+ Assert.assertTrue(resultSet.contains(tripleBob));
+ }
+/*
+ @Test
+ public void graphEventTestAddRemove() {
+ Graph mGraph = getEmptyGraph();
+ TestGraphListener listener = new TestGraphListener();
+ mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+ mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+ mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+ mGraph.add(trpl1);
+ Assert.assertNull(listener.getEvents());
+ mGraph.add(trpl2);
+ Assert.assertEquals(1, listener.getEvents().size());
+ Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
+ Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+ listener.resetEvents();
+ mGraph.remove(trpl2);
+ Assert.assertEquals(1, listener.getEvents().size());
+ Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
+ Assert.assertTrue(listener.getEvents().get(0) instanceof RemoveEvent);
+ listener.resetEvents();
+ mGraph.add(trpl3);
+ Assert.assertEquals(1, listener.getEvents().size());
+ Assert.assertEquals(trpl3, listener.getEvents().get(0).getTriple());
+ Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+ listener.resetEvents();
+ mGraph.remove(trpl4);
+ Assert.assertNull(listener.getEvents());
+ }
+
+ @Test
+ public void graphEventTestAddAllRemoveAll() {
+ Graph mGraph = getEmptyGraph();
+ TestGraphListener listener = new TestGraphListener();
+ mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+ mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+ mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+ Graph triples = new SimpleGraph();
+ triples.add(trpl1);
+ triples.add(trpl2);
+ triples.add(trpl3);
+ triples.add(trpl4);
+ mGraph.addAll(triples);
+ List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+ Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+ Assert.assertEquals(3, cumulatedEvents.size());
+ Assert.assertTrue(cumulatedEvents.get(0) instanceof AddEvent);
+ Assert.assertTrue(cumulatedTriples.contains(trpl2));
+ Assert.assertTrue(cumulatedTriples.contains(trpl3));
+ Assert.assertTrue(cumulatedTriples.contains(trpl4));
+ listener.resetCumulatedEvents();
+ mGraph.removeAll(triples);
+ cumulatedEvents = listener.getCumulatedEvents();
+ cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+ Assert.assertEquals(3, cumulatedEvents.size());
+ Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+ Assert.assertTrue(cumulatedTriples.contains(trpl2));
+ Assert.assertTrue(cumulatedTriples.contains(trpl3));
+ Assert.assertTrue(cumulatedTriples.contains(trpl4));
+ }
+
+ @Test
+ public void graphEventTestFilterRemove() {
+ Graph mGraph = getEmptyGraph();
+ TestGraphListener listener = new TestGraphListener();
+ mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+ mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+ mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+ mGraph.add(trpl1);
+ mGraph.add(trpl2);
+ mGraph.add(trpl3);
+ mGraph.add(trpl4);
+ listener.resetCumulatedEvents();
+ Iterator<Triple> result = mGraph.filter(null, uriRef2, null);
+ while (result.hasNext()) {
+ result.next();
+ result.remove();
+ }
+ List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+ Assert.assertEquals(1, cumulatedEvents.size());
+ Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+ Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
+ }
+
+ @Test
+ public void graphEventTestIteratorRemove() {
+ Graph mGraph = getEmptyGraph();
+ TestGraphListener listener = new TestGraphListener();
+ mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+ mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+ mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+ mGraph.add(trpl1);
+ mGraph.add(trpl2);
+ mGraph.add(trpl3);
+ mGraph.add(trpl4);
+ listener.resetCumulatedEvents();
+ Iterator<Triple> result = mGraph.iterator();
+ while (result.hasNext()) {
+ result.next();
+ result.remove();
+ }
+ List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+ Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+ Assert.assertEquals(3, cumulatedEvents.size());
+ Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+ Assert.assertTrue(cumulatedTriples.contains(trpl2));
+ Assert.assertTrue(cumulatedTriples.contains(trpl3));
+ Assert.assertTrue(cumulatedTriples.contains(trpl4));
+ }
+
+ @Test
+ public void graphEventTestClear() {
+ Graph mGraph = getEmptyGraph();
+ TestGraphListener listener = new TestGraphListener();
+ mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
+ mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
+ mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
+ mGraph.add(trpl1);
+ mGraph.add(trpl2);
+ mGraph.add(trpl3);
+ mGraph.add(trpl4);
+ listener.resetCumulatedEvents();
+ mGraph.clear();
+ List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
+ Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
+ Assert.assertEquals(3, cumulatedEvents.size());
+ Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
+ Assert.assertTrue(cumulatedTriples.contains(trpl2));
+ Assert.assertTrue(cumulatedTriples.contains(trpl3));
+ Assert.assertTrue(cumulatedTriples.contains(trpl4));
+ }
+
+ private Set<Triple> getCumulatedTriples(List<GraphEvent> cumulatedEvents) {
+ Set<Triple> triples = new HashSet<Triple>();
+ for(GraphEvent event: cumulatedEvents) {
+ triples.add(event.getTriple());
+ }
+ return triples;
+ }
+
+ @Test
+ public void graphEventTestWithDelay() throws Exception{
+ Graph mGraph = getEmptyGraph();
+ TestGraphListener listener = new TestGraphListener();
+ mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null),
+ 1000);
+
+ Triple triple0 = new TripleImpl(uriRef2, uriRef2, literal1);
+ Triple triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
+ Triple triple2 = new TripleImpl(uriRef1, uriRef2, literal1);
+ Triple triple3 = new TripleImpl(uriRef1, uriRef2, bnode1);
+ mGraph.add(triple0);
+ mGraph.add(triple1);
+ mGraph.add(triple2);
+ mGraph.add(triple3);
+ Thread.sleep(1500);
+ Assert.assertEquals(3, listener.getEvents().size());
+ Assert.assertEquals(triple1, listener.getEvents().get(0).getTriple());
+ Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+ Assert.assertEquals(triple2, listener.getEvents().get(1).getTriple());
+ Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+ Assert.assertEquals(triple3, listener.getEvents().get(2).getTriple());
+ Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
+ }
+
+ private static class TestGraphListener implements GraphListener {
+ private List<GraphEvent> events = null;
+ private List<GraphEvent> cumulatedEvents = new ArrayList<GraphEvent>();
+
+ @Override
+ public void graphChanged(List<GraphEvent> events) {
+ this.events = events;
+ Iterator<GraphEvent> eventIter = events.iterator();
+ while (eventIter.hasNext()) {
+ GraphEvent graphEvent = eventIter.next();
+ this.cumulatedEvents.add(graphEvent);
+ }
+ }
+
+ public List<GraphEvent> getEvents() {
+ return events;
+ }
+
+ public List<GraphEvent> getCumulatedEvents() {
+ return cumulatedEvents;
+ }
+
+ public void resetEvents() {
+ events = null;
+ }
+
+ public void resetCumulatedEvents() {
+ cumulatedEvents = new ArrayList<GraphEvent>();
+ }
+ }
+*/
+ private Collection<Triple> toCollection(Iterator<Triple> iterator) {
+ Collection<Triple> result = new ArrayList<Triple>();
+ while (iterator.hasNext()) {
+ result.add(iterator.next());
+ }
+ return result;
+ }
+
+ /**
+ * Creates a new <code>Triple</code>.
+ * @param subject the subject.
+ * @param predicate the predicate.
+ * @param object the object.
+ * @throws IllegalArgumentException If an attribute is <code>null</code>.
+ */
+ private Triple createTriple(String subject, String predicate,
+ String object) {
+ return new TripleImpl(new Iri(subject), new Iri(predicate),
+ new Iri(object));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphWrapper.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphWrapper.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphWrapper.java
new file mode 100644
index 0000000..57fd89a
--- /dev/null
+++ b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/GraphWrapper.java
@@ -0,0 +1,126 @@
+/*
+ * 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.clerezza.rdf.core.test;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+
+
+/**
+ *
+ * @author mir
+ */
+class GraphWrapper implements Graph {
+
+ protected Graph wrapped;
+
+ public GraphWrapper(Graph tc) {
+ this.wrapped = tc;
+ }
+
+ @Override
+ public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
+ return wrapped.filter(subject, predicate, object);
+ }
+
+
+ @Override
+ public int size() {
+ return wrapped.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return wrapped.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return wrapped.contains(o);
+ }
+
+ @Override
+ public Iterator<Triple> iterator() {
+ return wrapped.iterator();
+ }
+
+ @Override
+ public Object[] toArray() {
+ return wrapped.toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return wrapped.toArray(a);
+ }
+
+ @Override
+ public boolean add(Triple e) {
+ return wrapped.add(e);
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return wrapped.remove(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return wrapped.containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Triple> c) {
+ return wrapped.addAll(c);
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ return wrapped.removeAll(c);
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ return wrapped.retainAll(c);
+ }
+
+ @Override
+ public void clear() {
+ wrapped.clear();
+ }
+
+ @Override
+ public ImmutableGraph getImmutableGraph() {
+ return wrapped.getImmutableGraph();
+ }
+
+ @Override
+ public ReadWriteLock getLock() {
+ return wrapped.getLock();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockableMGraphWrapperForTesting.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockableMGraphWrapperForTesting.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockableMGraphWrapperForTesting.java
index 1869787..3f009cc 100644
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockableMGraphWrapperForTesting.java
+++ b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockableMGraphWrapperForTesting.java
@@ -21,38 +21,37 @@ package org.apache.clerezza.rdf.core.test;
import java.util.Iterator;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.clerezza.rdf.core.MGraph;
-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.access.LockableMGraphWrapper;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
/**
- * Wrappes an MGraph as a LockableMGraph. If a method is called that reads
+ * Wrappes an Graph as a LockableGraph. If a method is called that reads
* or modifies the wrapped graph and the appropriate lock is not set, then a
* RuntimeException is thrown.
*
* @author rbn, mir
*/
-public class LockableMGraphWrapperForTesting extends LockableMGraphWrapper {
+public class LockableMGraphWrapperForTesting extends GraphWrapper {
private final ReentrantReadWriteLock lock = (ReentrantReadWriteLock) getLock();
private final Lock readLock = lock.readLock();
- private final MGraph wrapped;
+ private final Graph wrapped;
/**
- * Constructs a LocalbleMGraph for an MGraph.
+ * Constructs a LocalbleGraph for an Graph.
*
- * @param providedMGraph a non-lockable mgraph
+ * @param providedGraph a non-lockable mgraph
*/
- public LockableMGraphWrapperForTesting(final MGraph providedMGraph) {
- super(providedMGraph);
- this.wrapped = providedMGraph;
+ public LockableMGraphWrapperForTesting(final Graph providedGraph) {
+ super(providedGraph);
+ this.wrapped = providedGraph;
}
@Override
- public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
+ public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
LockChecker.checkIfReadLocked(lock);
readLock.lock();
try {
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockingIteratorForTesting.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockingIteratorForTesting.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockingIteratorForTesting.java
index d8bbc9a..ae911d4 100644
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockingIteratorForTesting.java
+++ b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/LockingIteratorForTesting.java
@@ -21,7 +21,7 @@ package org.apache.clerezza.rdf.core.test;
import java.util.Iterator;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.clerezza.rdf.core.Triple;
+import org.apache.commons.rdf.Triple;
/**
* Wrapps an iterator<Triple> reading all elements to a cache on construction
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphTest.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphTest.java
deleted file mode 100644
index 5b43e65..0000000
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphTest.java
+++ /dev/null
@@ -1,581 +0,0 @@
-/*
- * 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.clerezza.rdf.core.test;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-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.TripleImpl;
-import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
-import org.junit.Test;
-import junit.framework.Assert;
-import org.apache.clerezza.rdf.core.Language;
-import org.apache.clerezza.rdf.core.PlainLiteral;
-import org.apache.clerezza.rdf.core.event.AddEvent;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphEvent;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-import org.apache.clerezza.rdf.core.event.RemoveEvent;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-
-
-
-/**
- * A generic abstract test class, implementations overwrite this class,
- * providing an implementation of the getEmptyMGraph method.
- *
- * @author reto, szalay, mir, hhn
- */
-public abstract class MGraphTest {
-
- private final UriRef uriRef1 =
- new UriRef("http://example.org/ontology#res1");
- private final UriRef uriRef2 =
- new UriRef("http://example.org/ontology#res2");
- private final UriRef uriRef3 =
- new UriRef("http://example.org/ontology#res3");
- private final UriRef uriRef4 =
- new UriRef("http://example.org/ontology#res4");
- private final UriRef xmlLiteralType =
- new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
- private Literal literal1 = new PlainLiteralImpl("literal1");
- private Literal literal2 = new PlainLiteralImpl("literal2");
- private BNode bnode1 = new BNode();
- private BNode bnode2 = new BNode();
- private Triple trpl1 = new TripleImpl(uriRef2, uriRef2, literal1);
- private Triple trpl2 = new TripleImpl(uriRef1, uriRef2, uriRef1);
- private Triple trpl3 = new TripleImpl(bnode2, uriRef3, literal2);
- private Triple trpl4 = new TripleImpl(uriRef3, uriRef4, literal2);
-
- /**
- * Subclasses implement this method to provide implementation instances of
- * MGraph. This method may be called an arbitrary amount of time,
- * independently whether previously returned MGraph are still in use or not.
- *
- * @return an empty MGraph of the implementation to be tested
- */
- protected abstract MGraph getEmptyMGraph();
-
- @Test
- public void testAddCountAndGetTriples() {
- MGraph graph = getEmptyMGraph();
- Assert.assertEquals(0, graph.size());
- final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
- graph.add(triple1);
- Assert.assertEquals(1, graph.size());
- Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, uriRef1);
- Assert.assertTrue(tripleIter.hasNext());
- Triple tripleGot = tripleIter.next();
- Assert.assertEquals(triple1, tripleGot);
- Assert.assertFalse(tripleIter.hasNext());
- BNode bnode = new BNode() {};
- graph.add(new TripleImpl(bnode, uriRef1, uriRef3));
- graph.add(new TripleImpl(bnode, uriRef1, uriRef4));
- tripleIter = graph.filter(null, uriRef1, null);
- Set<NonLiteral> subjectInMatchingTriples = new HashSet<NonLiteral>();
- Set<Resource> objectsInMatchingTriples = new HashSet<Resource>();
- while (tripleIter.hasNext()) {
- Triple triple = tripleIter.next();
- subjectInMatchingTriples.add(triple.getSubject());
- objectsInMatchingTriples.add(triple.getObject());
- }
- Assert.assertEquals(1, subjectInMatchingTriples.size());
- Assert.assertEquals(2, objectsInMatchingTriples.size());
- Set<Resource> expectedObjects = new HashSet<Resource>();
- expectedObjects.add(uriRef3);
- expectedObjects.add(uriRef4);
- Assert.assertEquals(expectedObjects, objectsInMatchingTriples);
- graph.add(new TripleImpl(bnode, uriRef4, bnode));
- tripleIter = graph.filter(null, uriRef4, null);
- Assert.assertTrue(tripleIter.hasNext());
- Triple retrievedTriple = tripleIter.next();
- Assert.assertFalse(tripleIter.hasNext());
- Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
- tripleIter = graph.filter(uriRef1, uriRef2, null);
- Assert.assertTrue(tripleIter.hasNext());
- retrievedTriple = tripleIter.next();
- Assert.assertFalse(tripleIter.hasNext());
- Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
- }
-
- @Test
- public void testRemoveAllTriples() {
- MGraph graph = getEmptyMGraph();
- Assert.assertEquals(0, graph.size());
- graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3));
- graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4));
- Assert.assertEquals(2, graph.size());
- graph.clear();
- Assert.assertEquals(0, graph.size());
- }
-
- @Test
- public void testUseTypedLiterals() {
- MGraph graph = getEmptyMGraph();
- Assert.assertEquals(0, graph.size());
- Literal value = new TypedLiteralImpl("<elem>value</elem>",xmlLiteralType);
- final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
- graph.add(triple1);
- Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
- Assert.assertTrue(tripleIter.hasNext());
- Resource gotValue = tripleIter.next().getObject();
- Assert.assertEquals(value, gotValue);
- }
-
- @Test
- public void testUseLanguageLiterals() {
- MGraph graph = getEmptyMGraph();
- Assert.assertEquals(0, graph.size());
- Language language = new Language("it");
- Literal value = new PlainLiteralImpl("<elem>value</elem>",language);
- final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
- graph.add(triple1);
- Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
- Assert.assertTrue(tripleIter.hasNext());
- Resource gotValue = tripleIter.next().getObject();
- Assert.assertEquals(value, gotValue);
- Assert.assertEquals(language, ((PlainLiteral)gotValue).getLanguage());
- }
-
- @Test
- public void testRemoveViaIterator() {
- MGraph graph = getEmptyMGraph();
- Assert.assertEquals(0, graph.size());
- final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
- graph.add(triple1);
- final TripleImpl triple2 = new TripleImpl(uriRef1, uriRef2, uriRef4);
- graph.add(triple2);
- Assert.assertEquals(2, graph.size());
- Iterator<Triple> iterator = graph.iterator();
- while (iterator.hasNext()) {
- iterator.next();
- iterator.remove();
- }
- Assert.assertEquals(0, graph.size());
- }
-
- @Test
- public void testGetSize() throws Exception {
- MGraph graph = getEmptyMGraph();
- // The test graph must always be empty after test fixture setup
- Assert.assertEquals(0, graph.size());
- }
-
-
- @Test
- public void testAddSingleTriple() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple triple= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- Assert.assertEquals(0, graph.size());
- Assert.assertTrue(graph.add(triple));
- Assert.assertEquals(1, graph.size());
- }
-
-
- @Test
- public void testAddSameTripleTwice() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple triple= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- Assert.assertEquals(0, graph.size());
- Assert.assertTrue(graph.add(triple));
- Assert.assertFalse(graph.add(triple)); // Graph does not change
- Assert.assertEquals(1, graph.size());
- }
-
-
- @Test
- public void testRemoveSingleTriple() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple triple= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- Assert.assertTrue(graph.add(triple));
- Assert.assertTrue(graph.remove(triple));
- Assert.assertEquals(0, graph.size());
- }
-
- @Test
- public void testRemoveSameTripleTwice() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple tripleAlice= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- final Triple tripleBob= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/bob");
- Assert.assertTrue(graph.add(tripleAlice));
- Assert.assertTrue(graph.add(tripleBob));
- Assert.assertTrue(graph.remove(tripleAlice));
- Assert.assertFalse(graph.remove(tripleAlice));
- Assert.assertEquals(1, graph.size());
- }
-
- @Test
- public void testGetSameBNode() throws Exception {
- MGraph graph = getEmptyMGraph();
- BNode bNode = new BNode();
- final UriRef HAS_NAME = new UriRef("http://example.org/ontology/hasName");
- final PlainLiteralImpl name = new PlainLiteralImpl("http://example.org/people/alice");
- final PlainLiteralImpl name2 = new PlainLiteralImpl("http://example.org/people/bob");
- final Triple tripleAlice = new TripleImpl(bNode, HAS_NAME, name);
- final Triple tripleBob = new TripleImpl(bNode, HAS_NAME, name2);
- Assert.assertTrue(graph.add(tripleAlice));
- Assert.assertTrue(graph.add(tripleBob));
- Iterator<Triple> result = graph.filter(null, HAS_NAME, name);
- Assert.assertEquals(bNode, result.next().getSubject());
- }
-
- @Test
- public void testContainsIfContained() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple triple= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- Assert.assertTrue(graph.add(triple));
- Assert.assertTrue(graph.contains(triple));
- }
-
-
- @Test
- public void testContainsIfEmpty() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple triple= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- Assert.assertFalse(graph.contains(triple));
- }
-
-
- @Test
- public void testContainsIfNotContained() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple tripleAdd= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- final Triple tripleTest= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/bob");
- Assert.assertTrue(graph.add(tripleAdd));
- Assert.assertFalse(graph.contains(tripleTest));
- }
-
-
- @Test
- public void testFilterEmptyGraph() throws Exception {
- MGraph graph = getEmptyMGraph();
- Iterator<Triple> i = graph.filter(null, null, null);
- Assert.assertFalse(i.hasNext());
- }
-
-
- @Test
- public void testFilterSingleEntry() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple triple= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- Assert.assertTrue(graph.add(triple));
-
- Iterator<Triple> i = graph.filter(null, null, null);
- Collection<Triple> resultSet= toCollection(i);
- Assert.assertEquals(1, resultSet.size());
- Assert.assertTrue(resultSet.contains(triple));
- }
-
-
- @Test
- public void testFilterByObject() throws Exception {
- MGraph graph = getEmptyMGraph();
- final Triple tripleAlice= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/alice");
- final Triple tripleBob= createTriple(
- "http://example.org/ontology/Person",
- "http://example.org/ontology/hasName",
- "http://example.org/people/bob");
- Assert.assertTrue(graph.add(tripleAlice));
- Assert.assertTrue(graph.add(tripleBob));
-
- Iterator<Triple> iterator;
- Collection<Triple> resultSet;
-
- // Find bob
- iterator = graph.filter(null, null,
- new UriRef("http://example.org/people/bob"));
- resultSet= toCollection(iterator);
- Assert.assertEquals(1, resultSet.size());
- Assert.assertTrue(resultSet.contains(tripleBob));
-
- // Find alice
- iterator = graph.filter(null, null,
- new UriRef("http://example.org/people/alice"));
- resultSet= toCollection(iterator);
- Assert.assertEquals(1, resultSet.size());
- Assert.assertTrue(resultSet.contains(tripleAlice));
-
- // Find both
- iterator = graph.filter(null, null, null);
- resultSet= toCollection(iterator);
- Assert.assertEquals(2, resultSet.size());
- Assert.assertTrue(resultSet.contains(tripleAlice));
- Assert.assertTrue(resultSet.contains(tripleBob));
- }
-
- @Test
- public void graphEventTestAddRemove() {
- MGraph mGraph = getEmptyMGraph();
- TestGraphListener listener = new TestGraphListener();
- mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
- mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
- mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
- mGraph.add(trpl1);
- Assert.assertNull(listener.getEvents());
- mGraph.add(trpl2);
- Assert.assertEquals(1, listener.getEvents().size());
- Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
- Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
- listener.resetEvents();
- mGraph.remove(trpl2);
- Assert.assertEquals(1, listener.getEvents().size());
- Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
- Assert.assertTrue(listener.getEvents().get(0) instanceof RemoveEvent);
- listener.resetEvents();
- mGraph.add(trpl3);
- Assert.assertEquals(1, listener.getEvents().size());
- Assert.assertEquals(trpl3, listener.getEvents().get(0).getTriple());
- Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
- listener.resetEvents();
- mGraph.remove(trpl4);
- Assert.assertNull(listener.getEvents());
- }
-
- @Test
- public void graphEventTestAddAllRemoveAll() {
- MGraph mGraph = getEmptyMGraph();
- TestGraphListener listener = new TestGraphListener();
- mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
- mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
- mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
- MGraph triples = new SimpleMGraph();
- triples.add(trpl1);
- triples.add(trpl2);
- triples.add(trpl3);
- triples.add(trpl4);
- mGraph.addAll(triples);
- List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
- Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
- Assert.assertEquals(3, cumulatedEvents.size());
- Assert.assertTrue(cumulatedEvents.get(0) instanceof AddEvent);
- Assert.assertTrue(cumulatedTriples.contains(trpl2));
- Assert.assertTrue(cumulatedTriples.contains(trpl3));
- Assert.assertTrue(cumulatedTriples.contains(trpl4));
- listener.resetCumulatedEvents();
- mGraph.removeAll(triples);
- cumulatedEvents = listener.getCumulatedEvents();
- cumulatedTriples = getCumulatedTriples(cumulatedEvents);
- Assert.assertEquals(3, cumulatedEvents.size());
- Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
- Assert.assertTrue(cumulatedTriples.contains(trpl2));
- Assert.assertTrue(cumulatedTriples.contains(trpl3));
- Assert.assertTrue(cumulatedTriples.contains(trpl4));
- }
-
- @Test
- public void graphEventTestFilterRemove() {
- MGraph mGraph = getEmptyMGraph();
- TestGraphListener listener = new TestGraphListener();
- mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
- mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
- mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
- mGraph.add(trpl1);
- mGraph.add(trpl2);
- mGraph.add(trpl3);
- mGraph.add(trpl4);
- listener.resetCumulatedEvents();
- Iterator<Triple> result = mGraph.filter(null, uriRef2, null);
- while (result.hasNext()) {
- result.next();
- result.remove();
- }
- List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
- Assert.assertEquals(1, cumulatedEvents.size());
- Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
- Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
- }
-
- @Test
- public void graphEventTestIteratorRemove() {
- MGraph mGraph = getEmptyMGraph();
- TestGraphListener listener = new TestGraphListener();
- mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
- mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
- mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
- mGraph.add(trpl1);
- mGraph.add(trpl2);
- mGraph.add(trpl3);
- mGraph.add(trpl4);
- listener.resetCumulatedEvents();
- Iterator<Triple> result = mGraph.iterator();
- while (result.hasNext()) {
- result.next();
- result.remove();
- }
- List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
- Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
- Assert.assertEquals(3, cumulatedEvents.size());
- Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
- Assert.assertTrue(cumulatedTriples.contains(trpl2));
- Assert.assertTrue(cumulatedTriples.contains(trpl3));
- Assert.assertTrue(cumulatedTriples.contains(trpl4));
- }
-
- @Test
- public void graphEventTestClear() {
- MGraph mGraph = getEmptyMGraph();
- TestGraphListener listener = new TestGraphListener();
- mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
- mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
- mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
- mGraph.add(trpl1);
- mGraph.add(trpl2);
- mGraph.add(trpl3);
- mGraph.add(trpl4);
- listener.resetCumulatedEvents();
- mGraph.clear();
- List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
- Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
- Assert.assertEquals(3, cumulatedEvents.size());
- Assert.assertTrue(cumulatedEvents.get(0) instanceof RemoveEvent);
- Assert.assertTrue(cumulatedTriples.contains(trpl2));
- Assert.assertTrue(cumulatedTriples.contains(trpl3));
- Assert.assertTrue(cumulatedTriples.contains(trpl4));
- }
-
- private Set<Triple> getCumulatedTriples(List<GraphEvent> cumulatedEvents) {
- Set<Triple> triples = new HashSet<Triple>();
- for(GraphEvent event: cumulatedEvents) {
- triples.add(event.getTriple());
- }
- return triples;
- }
-
- @Test
- public void graphEventTestWithDelay() throws Exception{
- MGraph mGraph = getEmptyMGraph();
- TestGraphListener listener = new TestGraphListener();
- mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null),
- 1000);
-
- Triple triple0 = new TripleImpl(uriRef2, uriRef2, literal1);
- Triple triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
- Triple triple2 = new TripleImpl(uriRef1, uriRef2, literal1);
- Triple triple3 = new TripleImpl(uriRef1, uriRef2, bnode1);
- mGraph.add(triple0);
- mGraph.add(triple1);
- mGraph.add(triple2);
- mGraph.add(triple3);
- Thread.sleep(1500);
- Assert.assertEquals(3, listener.getEvents().size());
- Assert.assertEquals(triple1, listener.getEvents().get(0).getTriple());
- Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
- Assert.assertEquals(triple2, listener.getEvents().get(1).getTriple());
- Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
- Assert.assertEquals(triple3, listener.getEvents().get(2).getTriple());
- Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
- }
-
- private static class TestGraphListener implements GraphListener {
- private List<GraphEvent> events = null;
- private List<GraphEvent> cumulatedEvents = new ArrayList<GraphEvent>();
-
- @Override
- public void graphChanged(List<GraphEvent> events) {
- this.events = events;
- Iterator<GraphEvent> eventIter = events.iterator();
- while (eventIter.hasNext()) {
- GraphEvent graphEvent = eventIter.next();
- this.cumulatedEvents.add(graphEvent);
- }
- }
-
- public List<GraphEvent> getEvents() {
- return events;
- }
-
- public List<GraphEvent> getCumulatedEvents() {
- return cumulatedEvents;
- }
-
- public void resetEvents() {
- events = null;
- }
-
- public void resetCumulatedEvents() {
- cumulatedEvents = new ArrayList<GraphEvent>();
- }
- }
-
- private Collection<Triple> toCollection(Iterator<Triple> iterator) {
- Collection<Triple> result = new ArrayList<Triple>();
- while (iterator.hasNext()) {
- result.add(iterator.next());
- }
- return result;
- }
-
- /**
- * Creates a new <code>Triple</code>.
- * @param subject the subject.
- * @param predicate the predicate.
- * @param object the object.
- * @throws IllegalArgumentException If an attribute is <code>null</code>.
- */
- private Triple createTriple(String subject, String predicate,
- String object) {
- return new TripleImpl(new UriRef(subject), new UriRef(predicate),
- new UriRef(object));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphWrapper.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphWrapper.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphWrapper.java
deleted file mode 100644
index 0eedb0d..0000000
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/MGraphWrapper.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.clerezza.rdf.core.test;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-
-/**
- *
- * @author mir
- */
-class MGraphWrapper extends TripleCollectionWrapper implements MGraph{
-
- public MGraphWrapper(MGraph mGraph) {
- super(mGraph);
- }
-
- @Override
- public Graph getGraph() {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomGraph.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomGraph.java
new file mode 100644
index 0000000..b478b4e
--- /dev/null
+++ b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomGraph.java
@@ -0,0 +1,237 @@
+/*
+ * 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.clerezza.rdf.core.test;
+
+import java.util.Iterator;
+import java.util.UUID;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.commons.lang.RandomStringUtils;
+
+/**
+ * A <code>Graph</code> wrapper that allows growing and shrinking of
+ * the wrapped mgraph.
+ *
+ * @author mir
+ */
+public class RandomGraph extends GraphWrapper {
+
+ private int interconnectivity = 2;
+
+ public RandomGraph(Graph mGraph, int interconnectivity) {
+ super(mGraph);
+ this.interconnectivity = interconnectivity;
+ }
+
+ /**
+ * Creates a new random mutual graph.
+ *
+ * @param initialSize Determines the initial size of the content graph
+ * @param interconnectivity Determines the probability of using already existing
+ * resource when creating a new triple. The probability of using an existing
+ * resource over creating a new resouce is 1-(1/interconnectivity).
+ * @param mGraph
+ */
+ public RandomGraph(int initialSize, int interconnectivity, Graph mGraph) {
+ super(mGraph);
+ if (interconnectivity <= 0) {
+ throw new IllegalArgumentException("growth speed and the interconnectivity "
+ + "value have to be equals or highter one");
+ }
+ this.interconnectivity = interconnectivity;
+
+ setupInitialSize(initialSize);
+ }
+
+ /**
+ * Add or removes randomly a triple.
+ *
+ * @return the triple that was added or removed.
+ */
+ public Triple evolve() {
+ Triple triple;
+ int random = rollDice(2);
+ if (random == 0 && size() != 0) {
+ triple = getRandomTriple();
+ remove(triple);
+ } else {
+ triple = createRandomTriple();
+ add(triple);
+ }
+ return triple;
+ }
+
+ /**
+ * Removes a random triple.
+ *
+ * @return the triple that was removed.
+ */
+ public Triple removeRandomTriple() {
+ Triple randomTriple = getRandomTriple();
+ remove(randomTriple);
+ return randomTriple;
+ }
+
+ /**
+ * Adds a random triple.
+ *
+ * @return the triple that was added.
+ */
+ public Triple addRandomTriple() {
+ Triple randomTriple;
+ do {
+ randomTriple = createRandomTriple();
+ } while(contains(randomTriple));
+
+ add(randomTriple);
+ return randomTriple;
+ }
+
+ private Triple createRandomTriple() {
+ return new TripleImpl(getSubject(), getPredicate(), getObject());
+ }
+
+ private BlankNodeOrIri getSubject() {
+ int random = rollDice(interconnectivity);
+ if (size() == 0) {
+ random = 0;
+ }
+ switch (random) {
+ case 0: // create new BlankNodeOrIri
+ RdfTerm newRdfTerm;
+ do {
+ newRdfTerm = createRandomRdfTerm();
+ } while (!(newRdfTerm instanceof BlankNodeOrIri));
+ return (BlankNodeOrIri) newRdfTerm;
+ default: // get existing BlankNodeOrIri
+ RdfTerm existingRdfTerm;
+ do {
+ existingRdfTerm = getExistingRdfTerm();
+ if (existingRdfTerm == null) {
+ random = 0;
+ }
+ } while (!(existingRdfTerm instanceof BlankNodeOrIri));
+
+ return (BlankNodeOrIri) existingRdfTerm;
+ }
+ }
+
+ private Iri getPredicate() {
+ int random = rollDice(interconnectivity);
+ if (size() == 0) {
+ random = 0;
+ }
+ switch (random) {
+ case 0: // create new Iri
+ return createRandomIri();
+ default: // get existing Iri
+ RdfTerm existingRdfTerm;
+ do {
+ existingRdfTerm = getExistingRdfTerm();
+ if (existingRdfTerm == null) {
+ random = 0;
+ }
+ } while (!(existingRdfTerm instanceof Iri));
+ return (Iri) existingRdfTerm;
+ }
+ }
+
+ private RdfTerm getObject() {
+ int random = rollDice(interconnectivity);
+ if (size() == 0) {
+ random = 0;
+ }
+ switch (random) {
+ case 0: // create new resource
+ return createRandomRdfTerm();
+ default: // get existing resource
+ RdfTerm existingRdfTerm = getExistingRdfTerm();
+ if (existingRdfTerm == null) {
+ random = 0;
+ }
+ return existingRdfTerm;
+ }
+ }
+
+ private static int rollDice(int faces) {
+ return Double.valueOf(Math.random() * faces).intValue();
+ }
+
+ private RdfTerm createRandomRdfTerm() {
+ switch (rollDice(3)) {
+ case 0:
+ return new BlankNode();
+ case 1:
+ return createRandomIri();
+ case 2:
+ return new PlainLiteralImpl(RandomStringUtils.random(rollDice(100) + 1));
+ }
+ throw new RuntimeException("in createRandomRdfTerm()");
+ }
+
+ private RdfTerm getExistingRdfTerm() {
+ Triple triple = getRandomTriple();
+ if (triple == null) {
+ return null;
+ }
+ switch (rollDice(3)) {
+ case 0:
+ return triple.getSubject();
+ case 1:
+ return triple.getPredicate();
+ case 2:
+ return triple.getObject();
+ }
+ return null;
+ }
+
+ private Iri createRandomIri() {
+ return new Iri("http://" + UUID.randomUUID().toString());
+ }
+
+ /**
+ * Returns a random triple contained in the Graph.
+ */
+ public Triple getRandomTriple() {
+ int size = this.size();
+ if (size == 0) {
+ return null;
+ }
+ Iterator<Triple> triples = iterator();
+ while (triples.hasNext()) {
+ Triple triple = triples.next();
+ if (rollDice(this.size()) == 0) {
+ return triple;
+ }
+ }
+ return getRandomTriple();
+ }
+
+ private void setupInitialSize(int initialSize) {
+ for (int i = 0; i < initialSize; i++) {
+ addRandomTriple();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/4bc320a8/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomMGraph.java b/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomMGraph.java
deleted file mode 100644
index 4d805ca..0000000
--- a/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/RandomMGraph.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * 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.clerezza.rdf.core.test;
-
-import java.util.Iterator;
-import java.util.UUID;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.MGraph;
-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.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.commons.lang.RandomStringUtils;
-
-/**
- * A <code>MGraph</code> wrapper that allows growing and shrinking of
- * the wrapped mgraph.
- *
- * @author mir
- */
-public class RandomMGraph extends MGraphWrapper {
-
- private int interconnectivity = 2;
-
- public RandomMGraph(MGraph mGraph, int interconnectivity) {
- super(mGraph);
- this.interconnectivity = interconnectivity;
- }
-
- /**
- * Creates a new random mutual graph.
- *
- * @param initialSize Determines the initial size of the content graph
- * @param interconnectivity Determines the probability of using already existing
- * resource when creating a new triple. The probability of using an existing
- * resource over creating a new resouce is 1-(1/interconnectivity).
- * @param mGraph
- */
- public RandomMGraph(int initialSize, int interconnectivity, MGraph mGraph) {
- super(mGraph);
- if (interconnectivity <= 0) {
- throw new IllegalArgumentException("growth speed and the interconnectivity "
- + "value have to be equals or highter one");
- }
- this.interconnectivity = interconnectivity;
-
- setupInitialSize(initialSize);
- }
-
- /**
- * Add or removes randomly a triple.
- *
- * @return the triple that was added or removed.
- */
- public Triple evolve() {
- Triple triple;
- int random = rollDice(2);
- if (random == 0 && size() != 0) {
- triple = getRandomTriple();
- remove(triple);
- } else {
- triple = createRandomTriple();
- add(triple);
- }
- return triple;
- }
-
- /**
- * Removes a random triple.
- *
- * @return the triple that was removed.
- */
- public Triple removeRandomTriple() {
- Triple randomTriple = getRandomTriple();
- remove(randomTriple);
- return randomTriple;
- }
-
- /**
- * Adds a random triple.
- *
- * @return the triple that was added.
- */
- public Triple addRandomTriple() {
- Triple randomTriple;
- do {
- randomTriple = createRandomTriple();
- } while(contains(randomTriple));
-
- add(randomTriple);
- return randomTriple;
- }
-
- private Triple createRandomTriple() {
- return new TripleImpl(getSubject(), getPredicate(), getObject());
- }
-
- private NonLiteral getSubject() {
- int random = rollDice(interconnectivity);
- if (size() == 0) {
- random = 0;
- }
- switch (random) {
- case 0: // create new NonLiteral
- Resource newResource;
- do {
- newResource = createRandomResource();
- } while (!(newResource instanceof NonLiteral));
- return (NonLiteral) newResource;
- default: // get existing NonLiteral
- Resource existingResource;
- do {
- existingResource = getExistingResource();
- if (existingResource == null) {
- random = 0;
- }
- } while (!(existingResource instanceof NonLiteral));
-
- return (NonLiteral) existingResource;
- }
- }
-
- private UriRef getPredicate() {
- int random = rollDice(interconnectivity);
- if (size() == 0) {
- random = 0;
- }
- switch (random) {
- case 0: // create new UriRef
- return createRandomUriRef();
- default: // get existing UriRef
- Resource existingResource;
- do {
- existingResource = getExistingResource();
- if (existingResource == null) {
- random = 0;
- }
- } while (!(existingResource instanceof UriRef));
- return (UriRef) existingResource;
- }
- }
-
- private Resource getObject() {
- int random = rollDice(interconnectivity);
- if (size() == 0) {
- random = 0;
- }
- switch (random) {
- case 0: // create new resource
- return createRandomResource();
- default: // get existing resource
- Resource existingResource = getExistingResource();
- if (existingResource == null) {
- random = 0;
- }
- return existingResource;
- }
- }
-
- private static int rollDice(int faces) {
- return Double.valueOf(Math.random() * faces).intValue();
- }
-
- private Resource createRandomResource() {
- switch (rollDice(3)) {
- case 0:
- return new BNode();
- case 1:
- return createRandomUriRef();
- case 2:
- return new PlainLiteralImpl(RandomStringUtils.random(rollDice(100) + 1));
- }
- throw new RuntimeException("in createRandomResource()");
- }
-
- private Resource getExistingResource() {
- Triple triple = getRandomTriple();
- if (triple == null) {
- return null;
- }
- switch (rollDice(3)) {
- case 0:
- return triple.getSubject();
- case 1:
- return triple.getPredicate();
- case 2:
- return triple.getObject();
- }
- return null;
- }
-
- private UriRef createRandomUriRef() {
- return new UriRef("http://" + UUID.randomUUID().toString());
- }
-
- /**
- * Returns a random triple contained in the MGraph.
- */
- public Triple getRandomTriple() {
- int size = this.size();
- if (size == 0) {
- return null;
- }
- Iterator<Triple> triples = iterator();
- while (triples.hasNext()) {
- Triple triple = triples.next();
- if (rollDice(this.size()) == 0) {
- return triple;
- }
- }
- return getRandomTriple();
- }
-
- private void setupInitialSize(int initialSize) {
- for (int i = 0; i < initialSize; i++) {
- addRandomTriple();
- }
- }
-}
[2/6] clerezza git commit: CLEREZZA-961: renamed methods to match new
Class names
Posted by re...@apache.org.
CLEREZZA-961: renamed methods to match new Class names
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/47cc3733
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/47cc3733
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/47cc3733
Branch: refs/heads/rdf-commons
Commit: 47cc3733e3653c04a4a74f71be30a3501a29025c
Parents: 340cdca
Author: Reto Gmuer <re...@apache.org>
Authored: Thu Mar 19 21:33:05 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Thu Mar 19 21:33:05 2015 +0000
----------------------------------------------------------------------
rdf.core/pom.xml | 3 +--
.../access/ImmutableGraphServiceFactory.java | 2 +-
.../clerezza/rdf/core/access/TcManager.java | 20 +++++++--------
.../clerezza/rdf/core/access/TcProvider.java | 23 +++++++++--------
.../rdf/core/access/TcProviderMultiplexer.java | 22 ++++++++---------
.../access/security/TcAccessController.java | 2 +-
.../clerezza/rdf/core/access/SecurityTest.java | 26 ++++++++++----------
.../clerezza/rdf/core/access/TcManagerTest.java | 16 ++++++------
.../rdf/core/access/providers/WeightedA.java | 10 ++++----
.../rdf/core/access/providers/WeightedA1.java | 10 ++++----
.../core/access/providers/WeightedAHeavy.java | 10 ++++----
.../core/access/providers/WeightedBlight.java | 10 ++++----
.../core/access/providers/WeightedDummy.java | 12 ++++-----
13 files changed, 82 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.core/pom.xml b/rdf.core/pom.xml
index 134f93f..6fdb138 100644
--- a/rdf.core/pom.xml
+++ b/rdf.core/pom.xml
@@ -57,7 +57,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
- <version>1.2.4</version>
+ <version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
@@ -122,7 +122,6 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
- <version>1.15.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
index 900c8d8..b6ee4a1 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
@@ -47,7 +47,7 @@ public class ImmutableGraphServiceFactory implements ServiceFactory {
@Override
public Object getService(Bundle arg0, ServiceRegistration arg1) {
Graph tc =
- new SecuredGraph(tcManager.getGraph(name), name,
+ new SecuredGraph(tcManager.getImmutableGraph(name), name,
tcAccessController);
return tc.getImmutableGraph();
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
index 6e56479..45ced37 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
@@ -206,9 +206,9 @@ public class TcManager extends TcProviderMultiplexer {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
tcAccessController.checkReadPermission(name);
- return super.getGraph(name);
+ return super.getImmutableGraph(name);
}
@Override
@@ -223,28 +223,28 @@ public class TcManager extends TcProviderMultiplexer {
}
@Override
- public Graph getTriples(Iri name) {
+ public Graph getGraph(Iri name) {
try {
tcAccessController.checkReadWritePermission(name);
} catch (AccessControlException e) {
tcAccessController.checkReadPermission(name);
return new WriteBlockedGraph(
- super.getTriples(name));
+ super.getGraph(name));
}
- return super.getTriples(name);
+ return super.getGraph(name);
}
@Override
- public Graph createMGraph(Iri name)
+ public Graph createGraph(Iri name)
throws UnsupportedOperationException {
tcAccessController.checkReadWritePermission(name);
- return super.createMGraph(name);
+ return super.createGraph(name);
}
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples) {
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples) {
tcAccessController.checkReadWritePermission(name);
- return super.createGraph(name, triples);
+ return super.createImmutableGraph(name, triples);
}
@Override
@@ -395,7 +395,7 @@ public class TcManager extends TcProviderMultiplexer {
}
final QueryEngine queryEngine = this.queryEngine;
if (queryEngine != null) {
- return queryEngine.execute(this, this.getTriples(defaultGraphName), query);
+ return queryEngine.execute(this, this.getGraph(defaultGraphName), query);
} else {
throw new NoQueryEngineException();
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProvider.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProvider.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProvider.java
index 6a97ff7..2201e2a 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProvider.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProvider.java
@@ -22,7 +22,6 @@ import java.util.Set;
import org.apache.commons.rdf.ImmutableGraph;
import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Graph;
import org.apache.commons.rdf.Iri;
/**
@@ -41,10 +40,10 @@ public interface TcProvider {
* @throws NoSuchEntityException if there is no <code>ImmutableGraph</code>
* with the specified name
*/
- ImmutableGraph getGraph(Iri name) throws NoSuchEntityException;
+ ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException;
/**
- * Get an <code>Graph</code> by its name. The instances
+ * Get an <code>Graph</code> taht is not <code>ImmutableGrah</code>. The instances
* returned in different invocations are <code>equals</code>.
*
* @param the name of the <code>Graph</code>
@@ -56,18 +55,18 @@ public interface TcProvider {
/**
* This method is used to get a <code>Graph</code> indifferently
- * whether it's a ImmutableGraph or an Graph. If the <code>name</code> names an
+ * whether it's a ImmutableGraph or not. If the <code>name</code> names an
* <code>Graph</code> the result is the same as when invoking
* <code>getMGraph</code> with that argument, analogously for
* <code>ImmutableGraph</code>S the method returns an instance equals to what
- * <code>getGraph</code> would return.
+ * <code>getImmutableGraph</code> would return.
*
* @param name the name of the <Code>ImmutableGraph</code> or <code>Graph</code>
* @return the <Code>ImmutableGraph</code> or <code>Graph</code>
* @throws NoSuchEntityException if there is no <code>ImmutableGraph</code>
* or <code>Graph</code> with the specified name
*/
- Graph getTriples(Iri name) throws NoSuchEntityException;
+ Graph getGraph(Iri name) throws NoSuchEntityException;
/**
* Lists the name of the <Code>ImmutableGraph</code>s available through this
@@ -81,7 +80,7 @@ public interface TcProvider {
/**
* Lists the name of the <Code>Graph</code>s available through this
- * <code>TcProvider</code>, implementations may take into account the
+ * <code>TcProvider</code> that are not <Code>ImmutableGraph</code>, implementations may take into account the
* security context and omit <Code>Graph</code>s for which access is not
* allowed.
*
@@ -91,8 +90,8 @@ public interface TcProvider {
/**
* Lists the name of the <Code>Graph</code>s available through this
- * <code>TcProvider</code> indifferently whether they are Graphs or an
- * MGraphs, implementations may take into account the security context and
+ * <code>TcProvider</code> indifferently whether they are mutables or
+ * immutables, implementations may take into account the security context and
* omit <Code>Graph</code>s for which access is not allowed.
*
* @return the list of <Code>Graph</code>s
@@ -109,7 +108,7 @@ public interface TcProvider {
* @throws EntityAlreadyExistsException if an Graph with the specified name
* already exists
*/
- Graph createMGraph(Iri name) throws UnsupportedOperationException,
+ Graph createGraph(Iri name) throws UnsupportedOperationException,
EntityAlreadyExistsException;
/**
@@ -123,7 +122,7 @@ public interface TcProvider {
* @throws EntityAlreadyExistsException if a ImmutableGraph with the specified name
* already exists
*/
- ImmutableGraph createGraph(Iri name, Graph triples)
+ ImmutableGraph createImmutableGraph(Iri name, Graph triples)
throws UnsupportedOperationException, EntityAlreadyExistsException;
/**
@@ -148,5 +147,5 @@ public interface TcProvider {
* @return the set names of <code>ImmutableGraph</code>, the set is empty if
* <code>ImmutableGraph</code> is unknown
*/
- Set<Iri> getNames(ImmutableGraph ImmutableGraph);
+ Set<Iri> getNames(ImmutableGraph immutableGraph);
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
index 2d2ca96..a084158 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
@@ -159,7 +159,7 @@ public class TcProviderMultiplexer implements TcProvider {
continue;
}
}
- Graph triples = newProvider.getTriples(name);
+ Graph triples = newProvider.getGraph(name);
if (triples instanceof Graph) {
mGraphCache.put(name, new MGraphHolder(newProvider, ensureLockable((Graph)triples)));
mGraphAppears(name);
@@ -200,7 +200,7 @@ public class TcProviderMultiplexer implements TcProvider {
// And if so register as service.
for (WeightedTcProvider provider : providerList) {
try {
- Graph triples = provider.getTriples(name);
+ Graph triples = provider.getGraph(name);
if (triples instanceof Graph) {
mGraphCache.put(name, new MGraphHolder(provider, ensureLockable((Graph)triples)));
mGraphAppears(name);
@@ -218,10 +218,10 @@ public class TcProviderMultiplexer implements TcProvider {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
for (TcProvider provider : providerList) {
try {
- return provider.getGraph(name);
+ return provider.getImmutableGraph(name);
} catch (NoSuchEntityException e) {
//we do nothing and try our luck with the next provider
} catch (IllegalArgumentException e) {
@@ -276,12 +276,12 @@ public class TcProviderMultiplexer implements TcProvider {
}
@Override
- public Graph getTriples(Iri name)
+ public Graph getGraph(Iri name)
throws NoSuchEntityException {
Graph result;
for (WeightedTcProvider provider : providerList) {
try {
- result = provider.getTriples(name);
+ result = provider.getGraph(name);
if (result instanceof ImmutableGraph) {
return result;
} else {
@@ -298,12 +298,12 @@ public class TcProviderMultiplexer implements TcProvider {
}
@Override
- public Graph createMGraph(Iri name)
+ public Graph createGraph(Iri name)
throws UnsupportedOperationException {
for (WeightedTcProvider provider : providerList) {
try {
- Graph result = provider.createMGraph(name);
+ Graph result = provider.createGraph(name);
// unregisters a possible ImmutableGraph or Graph service under this name
// provided by a WeightedTcProvider with a lower weight.
tcDisappears(name);
@@ -323,10 +323,10 @@ public class TcProviderMultiplexer implements TcProvider {
}
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples) {
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples) {
for (WeightedTcProvider provider : providerList) {
try {
- ImmutableGraph result = provider.createGraph(name, triples);
+ ImmutableGraph result = provider.createImmutableGraph(name, triples);
// unregisters a possible ImmutableGraph or Graph service under this name
// provided by a WeightedTcProvider with a lower weight.
@@ -368,7 +368,7 @@ public class TcProviderMultiplexer implements TcProvider {
}
}
// this throws a NoSuchEntityException if the ImmutableGraph doesn't exist
- getTriples(name);
+ getGraph(name);
// the entity exists but cannot be deleted
throw new UnsupportedOperationException(
"No provider could delete the entity.");
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
index 155cccb..c4d1264 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
@@ -342,7 +342,7 @@ public abstract class TcAccessController {
try {
return tcManager.getMGraph(permissionGraphName);
} catch (NoSuchEntityException e) {
- return tcManager.createMGraph(permissionGraphName);
+ return tcManager.createGraph(permissionGraphName);
}
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
index deb0baf..97a0fd4 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
@@ -57,8 +57,8 @@ public class SecurityTest {
////needed to unbind because this is injected with META-INF/services - file
TcManager.getInstance().unbindWeightedTcProvider(new WeightedA());
TcManager.getInstance().bindWeightedTcProvider(new WeightedDummy());
- TcManager.getInstance().createMGraph(new Iri("http://example.org/ImmutableGraph/alreadyexists"));
- TcManager.getInstance().createMGraph(new Iri("http://example.org/read/ImmutableGraph"));
+ TcManager.getInstance().createGraph(new Iri("http://example.org/ImmutableGraph/alreadyexists"));
+ TcManager.getInstance().createGraph(new Iri("http://example.org/read/ImmutableGraph"));
}
@AfterClass
@@ -112,22 +112,22 @@ public class SecurityTest {
@Test(expected=NoSuchEntityException.class)
public void testAcessGraph() {
- TcManager.getInstance().getGraph(new Iri("http://example.org/permitted"));
+ TcManager.getInstance().getImmutableGraph(new Iri("http://example.org/permitted"));
}
@Test(expected=AccessControlException.class)
public void testNoWildCard() {
- TcManager.getInstance().getGraph(new Iri("http://example.org/permitted/subthing"));
+ TcManager.getInstance().getImmutableGraph(new Iri("http://example.org/permitted/subthing"));
}
@Test(expected=NoSuchEntityException.class)
public void testAllowedArea() {
- TcManager.getInstance().getGraph(new Iri("http://example.org/area/allowed/something"));
+ TcManager.getInstance().getImmutableGraph(new Iri("http://example.org/area/allowed/something"));
}
@Test(expected=AccessControlException.class)
public void testAcessForbiddenGraph() {
- TcManager.getInstance().getGraph(new Iri("http://example.org/forbidden"));
+ TcManager.getInstance().getImmutableGraph(new Iri("http://example.org/forbidden"));
}
@Test(expected=NoSuchEntityException.class)
@@ -136,7 +136,7 @@ public class SecurityTest {
TcManager.getInstance().getTcAccessController().setRequiredReadPermissionStrings(graphUri,
Collections.singletonList("(java.io.FilePermission \"/etc\" \"write\")"));
//new FilePermission("/etc", "write").toString()));
- Graph ag = TcManager.getInstance().getTriples(new Iri("urn:x-localinstance:/ImmutableGraph-access.ImmutableGraph"));
+ Graph ag = TcManager.getInstance().getGraph(new Iri("urn:x-localinstance:/ImmutableGraph-access.ImmutableGraph"));
System.out.print(ag.toString());
TcManager.getInstance().getMGraph(graphUri);
}
@@ -147,9 +147,9 @@ public class SecurityTest {
TcManager.getInstance().getTcAccessController().setRequiredReadPermissionStrings(graphUri,
Collections.singletonList("(java.io.FilePermission \"/etc\" \"write\")"));
//new FilePermission("/etc", "write").toString()));
- Graph ag = TcManager.getInstance().getTriples(new Iri("urn:x-localinstance:/ImmutableGraph-access.ImmutableGraph"));
+ Graph ag = TcManager.getInstance().getGraph(new Iri("urn:x-localinstance:/ImmutableGraph-access.ImmutableGraph"));
System.out.print(ag.toString());
- TcManager.getInstance().createMGraph(graphUri);
+ TcManager.getInstance().createGraph(graphUri);
}
@Test
@@ -158,18 +158,18 @@ public class SecurityTest {
TcManager.getInstance().getTcAccessController().setRequiredReadWritePermissionStrings(graphUri,
Collections.singletonList("(java.io.FilePermission \"/etc\" \"write\")"));
//new FilePermission("/etc", "write").toString()));
- Graph ag = TcManager.getInstance().getTriples(new Iri("urn:x-localinstance:/ImmutableGraph-access.ImmutableGraph"));
+ Graph ag = TcManager.getInstance().getGraph(new Iri("urn:x-localinstance:/ImmutableGraph-access.ImmutableGraph"));
System.out.print(ag.toString());
- TcManager.getInstance().createMGraph(graphUri);
+ TcManager.getInstance().createGraph(graphUri);
}
@Test(expected=EntityAlreadyExistsException.class)
public void testCreateMGraph() {
- TcManager.getInstance().createMGraph(new Iri("http://example.org/ImmutableGraph/alreadyexists"));
+ TcManager.getInstance().createGraph(new Iri("http://example.org/ImmutableGraph/alreadyexists"));
}
@Test(expected=AccessControlException.class)
public void testCreateMGraphWithoutWritePermission() {
- TcManager.getInstance().createMGraph(new Iri("http://example.org/read/ImmutableGraph"));
+ TcManager.getInstance().createGraph(new Iri("http://example.org/read/ImmutableGraph"));
}
@Test(expected=ReadOnlyException.class)
public void testAddTripleToMGraph() {
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
index 59ce257..138fe34 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
@@ -82,11 +82,11 @@ public class TcManagerTest {
@Test
public void getGraphFromA() {
- ImmutableGraph graphA = graphAccess.getGraph(uriRefA);
+ ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefA);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
assertFalse(iterator.hasNext());
- Graph triplesA = graphAccess.getTriples(uriRefA);
+ Graph triplesA = graphAccess.getGraph(uriRefA);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
assertFalse(iterator.hasNext());
@@ -94,11 +94,11 @@ public class TcManagerTest {
@Test
public void getGraphFromB() {
- ImmutableGraph graphA = graphAccess.getGraph(uriRefB);
+ ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefB);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
assertFalse(iterator.hasNext());
- Graph triplesA = graphAccess.getTriples(uriRefB);
+ Graph triplesA = graphAccess.getGraph(uriRefB);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
assertFalse(iterator.hasNext());
@@ -107,12 +107,12 @@ public class TcManagerTest {
@Test
public void getGraphFromAAfterUnbinding() {
graphAccess.unbindWeightedTcProvider(weightedA);
- ImmutableGraph graphA = graphAccess.getGraph(uriRefA);
+ ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefA);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefA1, uriRefA1, uriRefA1),
iterator.next());
assertFalse(iterator.hasNext());
- Graph triplesA = graphAccess.getTriples(uriRefA);
+ Graph triplesA = graphAccess.getGraph(uriRefA);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefA1, uriRefA1, uriRefA1),
iterator.next());
@@ -123,12 +123,12 @@ public class TcManagerTest {
public void getGraphFromAWithHeavy() {
final WeightedAHeavy weightedAHeavy = new WeightedAHeavy();
graphAccess.bindWeightedTcProvider(weightedAHeavy);
- ImmutableGraph graphA = graphAccess.getGraph(uriRefA);
+ ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefA);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefAHeavy, uriRefAHeavy, uriRefAHeavy),
iterator.next());
assertFalse(iterator.hasNext());
- Graph triplesA = graphAccess.getTriples(uriRefA);
+ Graph triplesA = graphAccess.getGraph(uriRefA);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefAHeavy, uriRefAHeavy, uriRefAHeavy),
iterator.next());
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
index f61bd44..364d252 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
@@ -44,7 +44,7 @@ public class WeightedA implements WeightedTcProvider {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleMGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefA,
@@ -61,17 +61,17 @@ public class WeightedA implements WeightedTcProvider {
}
@Override
- public Graph getTriples(Iri name) throws NoSuchEntityException {
- return getGraph(name);
+ public Graph getGraph(Iri name) throws NoSuchEntityException {
+ return getImmutableGraph(name);
}
@Override
- public Graph createMGraph(Iri name) {
+ public Graph createGraph(Iri name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples) {
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
index 4a9bcf2..2fe8336 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
@@ -45,7 +45,7 @@ public class WeightedA1 implements WeightedTcProvider {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleMGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefA1,
@@ -62,17 +62,17 @@ public class WeightedA1 implements WeightedTcProvider {
}
@Override
- public Graph getTriples(Iri name) throws NoSuchEntityException {
- return getGraph(name);
+ public Graph getGraph(Iri name) throws NoSuchEntityException {
+ return getImmutableGraph(name);
}
@Override
- public Graph createMGraph(Iri name) {
+ public Graph createGraph(Iri name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples) {
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
index 82307ad..c0cec77 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
@@ -46,7 +46,7 @@ public class WeightedAHeavy implements WeightedTcProvider {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefAHeavy,
@@ -62,17 +62,17 @@ public class WeightedAHeavy implements WeightedTcProvider {
}
@Override
- public Graph getTriples(Iri name) throws NoSuchEntityException {
- return getGraph(name);
+ public Graph getGraph(Iri name) throws NoSuchEntityException {
+ return getImmutableGraph(name);
}
@Override
- public Graph createMGraph(Iri name) {
+ public Graph createGraph(Iri name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples) {
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
index c5023d8..ef7068f 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
@@ -44,7 +44,7 @@ public class WeightedBlight implements WeightedTcProvider {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefB)) {
Graph mResult = new SimpleMGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefB, TcManagerTest.uriRefB, TcManagerTest.uriRefB));
@@ -64,17 +64,17 @@ public class WeightedBlight implements WeightedTcProvider {
}
@Override
- public Graph getTriples(Iri name) throws NoSuchEntityException {
- return getGraph(name);
+ public Graph getGraph(Iri name) throws NoSuchEntityException {
+ return getImmutableGraph(name);
}
@Override
- public Graph createMGraph(Iri name) {
+ public Graph createGraph(Iri name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples) {
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/47cc3733/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
index 183d1f7..b464033 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
@@ -43,7 +43,7 @@ public class WeightedDummy implements WeightedTcProvider {
private Map<Iri, Graph> tripleMap = new HashMap<Iri, Graph>();
@Override
- public ImmutableGraph createGraph(Iri name, Graph triples)
+ public ImmutableGraph createImmutableGraph(Iri name, Graph triples)
throws EntityAlreadyExistsException {
if ((name == null) || (name.getUnicodeString() == null)
|| (name.getUnicodeString().trim().length() == 0)) {
@@ -53,7 +53,7 @@ public class WeightedDummy implements WeightedTcProvider {
try {
// throws NoSuchEntityException if a Graph with that name
// already exists
- this.getTriples(name);
+ this.getGraph(name);
} catch (NoSuchEntityException e) {
ImmutableGraph result;
if (ImmutableGraph.class.isAssignableFrom(triples.getClass())) {
@@ -69,7 +69,7 @@ public class WeightedDummy implements WeightedTcProvider {
}
@Override
- public Graph createMGraph(Iri name) throws EntityAlreadyExistsException {
+ public Graph createGraph(Iri name) throws EntityAlreadyExistsException {
if ((name == null) || (name.getUnicodeString() == null)
|| (name.getUnicodeString().trim().length() == 0)) {
throw new IllegalArgumentException("Name must not be null");
@@ -78,7 +78,7 @@ public class WeightedDummy implements WeightedTcProvider {
try {
// throws NoSuchEntityException if a Graph with that name
// already exists
- this.getTriples(name);
+ this.getGraph(name);
} catch (NoSuchEntityException e) {
Graph result = new SimpleMGraph();
tripleMap.put(name, result);
@@ -96,7 +96,7 @@ public class WeightedDummy implements WeightedTcProvider {
}
@Override
- public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
+ public ImmutableGraph getImmutableGraph(Iri name) throws NoSuchEntityException {
Graph Graph = tripleMap.get(name);
if (Graph == null) {
throw new NoSuchEntityException(name);
@@ -124,7 +124,7 @@ public class WeightedDummy implements WeightedTcProvider {
}
@Override
- public Graph getTriples(Iri name)
+ public Graph getGraph(Iri name)
throws NoSuchEntityException {
Graph Graph = tripleMap.get(name);
if (Graph == null) {
[6/6] clerezza git commit: CLEREZZA-964: using rdf-commons from
clerezza-rdf-core repository
Posted by re...@apache.org.
CLEREZZA-964: using rdf-commons from clerezza-rdf-core repository
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/de5881d4
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/de5881d4
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/de5881d4
Branch: refs/heads/rdf-commons
Commit: de5881d42112f2c68ff3dc8d9edf120389a7133a
Parents: 4bc320a
Author: Reto Gmuer <re...@apache.org>
Authored: Thu Mar 19 21:34:13 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Thu Mar 19 21:34:13 2015 +0000
----------------------------------------------------------------------
rdf.utils/pom.xml | 18 +-
.../apache/clerezza/rdf/utils/GraphNode.java | 244 +++++++-------
.../apache/clerezza/rdf/utils/GraphUtils.java | 163 ++++++++++
.../org/apache/clerezza/rdf/utils/IriUtil.java | 63 ++++
.../apache/clerezza/rdf/utils/MGraphUtils.java | 164 ----------
.../org/apache/clerezza/rdf/utils/RdfList.java | 88 +++---
.../clerezza/rdf/utils/SeeAlsoExpander.java | 42 +--
.../org/apache/clerezza/rdf/utils/Smusher.java | 24 +-
.../apache/clerezza/rdf/utils/UnionGraph.java | 286 +++++++++++++++++
.../apache/clerezza/rdf/utils/UnionMGraph.java | 314 -------------------
.../clerezza/rdf/utils/UnionWatchableGraph.java | 54 ++++
.../clerezza/rdf/utils/UriMutatingGraph.java | 223 +++++++++++++
.../rdf/utils/UriMutatingTripleCollection.java | 222 -------------
.../apache/clerezza/rdf/utils/UriRefUtil.java | 63 ----
.../graphnodeprovider/GraphNodeProvider.java | 10 +-
.../rdf/utils/smushing/BaseSmusher.java | 61 ++--
.../clerezza/rdf/utils/smushing/IfpSmusher.java | 42 ++-
.../rdf/utils/smushing/SameAsSmusher.java | 33 +-
.../clerezza/rdf/utils/GraphUtilsTest.java | 104 ++++++
.../apache/clerezza/rdf/utils/IfpSmushTest.java | 56 ++--
.../clerezza/rdf/utils/MGraphUtilsTest.java | 104 ------
.../apache/clerezza/rdf/utils/RdfListTest.java | 62 ++--
.../clerezza/rdf/utils/SameAsSmushTest.java | 26 +-
.../clerezza/rdf/utils/TestGraphNode.java | 146 ++++-----
.../clerezza/rdf/utils/UnionGraphTest.java | 78 +++++
.../clerezza/rdf/utils/UnionMGraphTest.java | 78 -----
.../rdf/utils/smushing/SameAsSmushTest.java | 31 +-
27 files changed, 1392 insertions(+), 1407 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.utils/pom.xml b/rdf.utils/pom.xml
index b446eb5..16e120c 100644
--- a/rdf.utils/pom.xml
+++ b/rdf.utils/pom.xml
@@ -24,7 +24,7 @@
<parent>
<artifactId>clerezza</artifactId>
<groupId>org.apache.clerezza</groupId>
- <version>0.5</version>
+ <version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<groupId>org.apache.clerezza</groupId>
@@ -42,17 +42,27 @@
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.core</artifactId>
- <version>0.14</version>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-api</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-impl-utils</artifactId>
+ <version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.ontologies</artifactId>
- <version>0.12</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.core.test</artifactId>
- <version>0.15</version>
+ <version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
index 487d7d2..8a1365f 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphNode.java
@@ -18,35 +18,37 @@
*/
package org.apache.clerezza.rdf.utils;
-import org.apache.clerezza.rdf.core.*;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.*;
+import org.apache.commons.rdf.impl.utils.*;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import java.util.*;
import java.util.concurrent.locks.Lock;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.commons.rdf.*;
/**
* This class represents a node in the context of a graph. It provides
* utility methods to explore and modify its neighbourhood. The method
* modifying the graph will throw an {@link UnsupportedOperationException}
- * it the underlying TripleCollection in immutable (i.e. is a {@link Graph}.
+ * it the underlying Graph in immutable (i.e. is a {@link ImmutableGraph}.
*
* @since 0.2
* @author reto, mir
*/
public class GraphNode {
- private final Resource resource;
- private final TripleCollection graph;
+ private final RdfTerm resource;
+ private final Graph graph;
/**
* Create a GraphNode representing resource within graph.
*
* @param resource the resource this GraphNode represents
- * @param graph the TripleCollection that describes the resource
+ * @param graph the Graph that describes the resource
*/
- public GraphNode(Resource resource, TripleCollection graph) {
+ public GraphNode(RdfTerm resource, Graph graph) {
if (resource == null) {
throw new IllegalArgumentException("resource may not be null");
}
@@ -62,7 +64,7 @@ public class GraphNode {
*
* @return the graph of this GraphNode
*/
- public TripleCollection getGraph() {
+ public Graph getGraph() {
return graph;
}
@@ -71,7 +73,7 @@ public class GraphNode {
*
* @return the node represented by this GraphNode
*/
- public Resource getNode() {
+ public RdfTerm getNode() {
return resource;
}
@@ -90,38 +92,38 @@ public class GraphNode {
* as subject or object and recursively the context of the b-nodes in any
* of these statements.
*
- * The triples in the Graph returned by this method contain the same bnode
+ * The triples in the ImmutableGraph returned by this method contain the same bnode
* instances as in the original graph.
*
* @return the context of the node represented by the instance
*/
- public Graph getNodeContext() {
+ public ImmutableGraph getNodeContext() {
Lock l = readLock();
l.lock();
try {
- final HashSet<Resource> dontExpand = new HashSet<Resource>();
+ final HashSet<RdfTerm> dontExpand = new HashSet<RdfTerm>();
dontExpand.add(resource);
- if (resource instanceof UriRef) {
- return getContextOf((UriRef) resource, dontExpand).getGraph();
+ if (resource instanceof Iri) {
+ return getContextOf((Iri) resource, dontExpand).getImmutableGraph();
}
- return getContextOf(resource, dontExpand).getGraph();
+ return getContextOf(resource, dontExpand).getImmutableGraph();
} finally {
l.unlock();
}
}
- private MGraph getContextOf(UriRef node, final Set<Resource> dontExpand) {
+ private Graph getContextOf(Iri node, final Set<RdfTerm> dontExpand) {
final String uriPrefix = node.getUnicodeString()+'#';
return getContextOf(node, dontExpand, new Acceptor() {
@Override
- public boolean expand(Resource resource) {
- if (resource instanceof BNode) {
+ public boolean expand(RdfTerm resource) {
+ if (resource instanceof BlankNode) {
return true;
}
- if (resource instanceof UriRef) {
- return ((UriRef)resource).getUnicodeString().startsWith(uriPrefix);
+ if (resource instanceof Iri) {
+ return ((Iri)resource).getUnicodeString().startsWith(uriPrefix);
}
return false;
}
@@ -129,19 +131,19 @@ public class GraphNode {
}
/**
- * Returns the context of a <code>NonLiteral</code>
+ * Returns the context of a <code>BlankNodeOrIri</code>
*
* @param node
* @param dontExpand a list of bnodes at which to stop expansion, if node
- * is a BNode it should be contained (potentially faster)
+ * is a BlankNode it should be contained (potentially faster)
* @return the context of a node
*/
- private MGraph getContextOf(Resource node, final Set<Resource> dontExpand) {
+ private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand) {
return getContextOf(node, dontExpand, new Acceptor() {
@Override
- public boolean expand(Resource resource) {
- if (resource instanceof BNode) {
+ public boolean expand(RdfTerm resource) {
+ if (resource instanceof BlankNode) {
return true;
}
return false;
@@ -150,16 +152,16 @@ public class GraphNode {
}
private interface Acceptor {
- boolean expand(Resource resource);
+ boolean expand(RdfTerm resource);
}
- private MGraph getContextOf(Resource node, final Set<Resource> dontExpand, Acceptor acceptor) {
- MGraph result = new SimpleMGraph();
- if (node instanceof NonLiteral) {
- Iterator<Triple> forwardProperties = graph.filter((NonLiteral) node, null, null);
+ private Graph getContextOf(RdfTerm node, final Set<RdfTerm> dontExpand, Acceptor acceptor) {
+ Graph result = new SimpleGraph();
+ if (node instanceof BlankNodeOrIri) {
+ Iterator<Triple> forwardProperties = graph.filter((BlankNodeOrIri) node, null, null);
while (forwardProperties.hasNext()) {
Triple triple = forwardProperties.next();
result.add(triple);
- Resource object = triple.getObject();
+ RdfTerm object = triple.getObject();
if (acceptor.expand(object) && !dontExpand.contains(object)) {
dontExpand.add(object);
result.addAll(getContextOf(object, dontExpand, acceptor));
@@ -170,7 +172,7 @@ public class GraphNode {
while (backwardProperties.hasNext()) {
Triple triple = backwardProperties.next();
result.add(triple);
- NonLiteral subject = triple.getSubject();
+ BlankNodeOrIri subject = triple.getSubject();
if (acceptor.expand(subject) && !dontExpand.contains(subject)) {
dontExpand.add(subject);
result.addAll(getContextOf(subject, dontExpand, acceptor));
@@ -179,8 +181,8 @@ public class GraphNode {
return result;
}
- private <T> Iterator<T> getTypeSelectedObjects(UriRef property, final Class<T> type) {
- final Iterator<Resource> objects = getObjects(property);
+ private <T> Iterator<T> getTypeSelectedObjects(Iri property, final Class<T> type) {
+ final Iterator<RdfTerm> objects = getObjects(property);
return new Iterator<T>() {
T next = prepareNext();
@@ -204,7 +206,7 @@ public class GraphNode {
private T prepareNext() {
while (objects.hasNext()) {
- Resource nextObject = objects.next();
+ RdfTerm nextObject = objects.next();
if (type.isAssignableFrom(nextObject.getClass())) {
return (T) nextObject;
}
@@ -214,8 +216,8 @@ public class GraphNode {
};
}
- public Iterator<Literal> getLiterals(UriRef property) {
- final Iterator<Resource> objects = getObjects(property);
+ public Iterator<Literal> getLiterals(Iri property) {
+ final Iterator<RdfTerm> objects = getObjects(property);
return new Iterator<Literal>() {
Literal next = prepareNext();
@@ -239,7 +241,7 @@ public class GraphNode {
private Literal prepareNext() {
while (objects.hasNext()) {
- Resource nextObject = objects.next();
+ RdfTerm nextObject = objects.next();
if (nextObject instanceof Literal) {
return (Literal) nextObject;
}
@@ -257,8 +259,8 @@ public class GraphNode {
* @return the number of triples in the underlying triple-collection
* which meet the specified condition
*/
- public int countObjects(UriRef property) {
- return countTriples(graph.filter((NonLiteral) resource, property, null));
+ public int countObjects(Iri property) {
+ return countTriples(graph.filter((BlankNodeOrIri) resource, property, null));
}
private int countTriples(final Iterator<Triple> triples) {
@@ -277,10 +279,10 @@ public class GraphNode {
* @param property the property
* @return
*/
- public Iterator<Resource> getObjects(UriRef property) {
- if (resource instanceof NonLiteral) {
- final Iterator<Triple> triples = graph.filter((NonLiteral) resource, property, null);
- return new Iterator<Resource>() {
+ public Iterator<RdfTerm> getObjects(Iri property) {
+ if (resource instanceof BlankNodeOrIri) {
+ final Iterator<Triple> triples = graph.filter((BlankNodeOrIri) resource, property, null);
+ return new Iterator<RdfTerm>() {
@Override
public boolean hasNext() {
@@ -288,7 +290,7 @@ public class GraphNode {
}
@Override
- public Resource next() {
+ public RdfTerm next() {
final Triple triple = triples.next();
if (triple != null) {
return triple.getObject();
@@ -303,7 +305,7 @@ public class GraphNode {
}
};
} else {
- return new Iterator<Resource>() {
+ return new Iterator<RdfTerm>() {
@Override
public boolean hasNext() {
@@ -311,7 +313,7 @@ public class GraphNode {
}
@Override
- public Resource next() {
+ public RdfTerm next() {
return null;
}
@@ -333,11 +335,11 @@ public class GraphNode {
* @return true if the node represented by this object is the subject of a
* statement with the given prediate and object, false otherwise
*/
- public boolean hasProperty(UriRef property, Resource object) {
+ public boolean hasProperty(Iri property, RdfTerm object) {
Lock l = readLock();
l.lock();
try {
- Iterator<Resource> objects = getObjects(property);
+ Iterator<RdfTerm> objects = getObjects(property);
if (object == null) {
return objects.hasNext();
}
@@ -360,7 +362,7 @@ public class GraphNode {
* @return the number of triples in the underlying triple-collection
* which meet the specified condition
*/
- public int countSubjects(UriRef property) {
+ public int countSubjects(Iri property) {
Lock l = readLock();
l.lock();
try {
@@ -377,9 +379,9 @@ public class GraphNode {
* @param property the property
* @return
*/
- public Iterator<NonLiteral> getSubjects(UriRef property) {
+ public Iterator<BlankNodeOrIri> getSubjects(Iri property) {
final Iterator<Triple> triples = graph.filter(null, property, resource);
- return new Iterator<NonLiteral>() {
+ return new Iterator<BlankNodeOrIri>() {
@Override
public boolean hasNext() {
@@ -387,7 +389,7 @@ public class GraphNode {
}
@Override
- public NonLiteral next() {
+ public BlankNodeOrIri next() {
return triples.next().getSubject();
}
@@ -398,24 +400,24 @@ public class GraphNode {
};
}
- public Iterator<UriRef> getUriRefObjects(UriRef property) {
- return getTypeSelectedObjects(property, UriRef.class);
+ public Iterator<Iri> getIriObjects(Iri property) {
+ return getTypeSelectedObjects(property, Iri.class);
}
/**
- * Get all available properties as an {@link Iterator}<{@link UriRef}>.
- * You can use <code>getObjects(UriRef property)</code> to get the values of
+ * Get all available properties as an {@link Iterator}<{@link Iri}>.
+ * You can use <code>getObjects(Iri property)</code> to get the values of
* each property
*
* @return an iterator over properties of this node
*/
- public Iterator<UriRef> getProperties() {
- if (resource instanceof NonLiteral) {
- final Iterator<Triple> triples = graph.filter((NonLiteral) resource, null, null);
+ public Iterator<Iri> getProperties() {
+ if (resource instanceof BlankNodeOrIri) {
+ final Iterator<Triple> triples = graph.filter((BlankNodeOrIri) resource, null, null);
return getUniquePredicates(triples);
} else {
- return new Iterator<UriRef>() {
+ return new Iterator<Iri>() {
@Override
public boolean hasNext() {
@@ -423,7 +425,7 @@ public class GraphNode {
}
@Override
- public UriRef next() {
+ public Iri next() {
return null;
}
@@ -436,13 +438,13 @@ public class GraphNode {
}
/**
- * Get all inverse properties as an {@link Iterator}<{@link UriRef}>.
- * You can use <code>getSubject(UriRef property)</code> to get the values of
+ * Get all inverse properties as an {@link Iterator}<{@link Iri}>.
+ * You can use <code>getSubject(Iri property)</code> to get the values of
* each inverse property
*
* @return an iterator over properties pointing to this node
*/
- public Iterator<UriRef> getInverseProperties() {
+ public Iterator<Iri> getInverseProperties() {
final Iterator<Triple> triples = graph.filter(null, null, resource);
return getUniquePredicates(triples);
}
@@ -450,11 +452,11 @@ public class GraphNode {
/**
*
* @param triples
- * @returnan {@link Iterator}<{@link UriRef}> containing the predicates from
+ * @returnan {@link Iterator}<{@link Iri}> containing the predicates from
* an {@link Iterator}<{@link Triple}>
*/
- private Iterator<UriRef> getUniquePredicates(final Iterator<Triple> triples) {
- final Set<UriRef> resultSet = new HashSet<UriRef>();
+ private Iterator<Iri> getUniquePredicates(final Iterator<Triple> triples) {
+ final Set<Iri> resultSet = new HashSet<Iri>();
while (triples.hasNext()) {
resultSet.add(triples.next().getPredicate());
}
@@ -467,9 +469,9 @@ public class GraphNode {
* @param predicate
* @param object
*/
- public void addProperty(UriRef predicate, Resource object) {
- if (resource instanceof NonLiteral) {
- graph.add(new TripleImpl((NonLiteral) resource, predicate, object));
+ public void addProperty(Iri predicate, RdfTerm object) {
+ if (resource instanceof BlankNodeOrIri) {
+ graph.add(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
} else {
throw new RuntimeException("Literals cannot be the subject of a statement");
}
@@ -483,7 +485,7 @@ public class GraphNode {
* @param property the predicate of the triple to be created
* @param value the value of the typed literal object
*/
- public void addPropertyValue(UriRef property, Object value) {
+ public void addPropertyValue(Iri property, Object value) {
addProperty(property,
LiteralFactory.getInstance().createTypedLiteral(value));
}
@@ -495,9 +497,9 @@ public class GraphNode {
* @param predicate
* @param subject
*/
- public void addInverseProperty(UriRef predicate, Resource subject) {
- if (subject instanceof NonLiteral) {
- graph.add(new TripleImpl((NonLiteral) subject, predicate, resource));
+ public void addInverseProperty(Iri predicate, RdfTerm subject) {
+ if (subject instanceof BlankNodeOrIri) {
+ graph.add(new TripleImpl((BlankNodeOrIri) subject, predicate, resource));
} else {
throw new RuntimeException("Literals cannot be the subject of a statement");
}
@@ -506,13 +508,13 @@ public class GraphNode {
/**
* creates and returns an <code>RdfList</code> for the node and
- * TripleCollection represented by this object.
+ * Graph represented by this object.
*
* @return a List to easy access the rdf:List represented by this node
*/
- public List<Resource> asList() {
- if (resource instanceof NonLiteral) {
- return new RdfList((NonLiteral) resource, graph);
+ public List<RdfTerm> asList() {
+ if (resource instanceof BlankNodeOrIri) {
+ return new RdfList((BlankNodeOrIri) resource, graph);
} else {
throw new RuntimeException("Literals cannot be the subject of a List");
}
@@ -524,9 +526,9 @@ public class GraphNode {
*
* @param predicate
*/
- public void deleteProperties(UriRef predicate) {
- if (resource instanceof NonLiteral) {
- Iterator<Triple> tripleIter = graph.filter((NonLiteral) resource, predicate, null);
+ public void deleteProperties(Iri predicate) {
+ if (resource instanceof BlankNodeOrIri) {
+ Iterator<Triple> tripleIter = graph.filter((BlankNodeOrIri) resource, predicate, null);
Collection<Triple> toDelete = new ArrayList<Triple>();
while (tripleIter.hasNext()) {
Triple triple = tripleIter.next();
@@ -544,9 +546,9 @@ public class GraphNode {
* @param predicate
* @param object
*/
- public void deleteProperty(UriRef predicate, Resource object) {
- if (resource instanceof NonLiteral) {
- graph.remove(new TripleImpl((NonLiteral) resource, predicate, object));
+ public void deleteProperty(Iri predicate, RdfTerm object) {
+ if (resource instanceof BlankNodeOrIri) {
+ graph.remove(new TripleImpl((BlankNodeOrIri) resource, predicate, object));
}
}
@@ -556,27 +558,27 @@ public class GraphNode {
}
/**
- * Replaces the graph node resouce with the specified <code>NonLiteral</code>.
+ * Replaces the graph node resouce with the specified <code>BlankNodeOrIri</code>.
* The resource is only replaced where it is either subject or object.
* @param replacement
* @return a GraphNode representing the replecement node
*/
- public GraphNode replaceWith(NonLiteral replacement) {
+ public GraphNode replaceWith(BlankNodeOrIri replacement) {
return replaceWith(replacement, false);
}
/**
- * Replaces the graph node resouce with the specified <code>NonLiteral</code>.
+ * Replaces the graph node resouce with the specified <code>BlankNodeOrIri</code>.
* Over the boolean <code>checkPredicate</code> it can be specified if the
* resource should also be replaced where it is used as predicate.
* @param replacement
* @param checkPredicates
* @return a GraphNode representing the replecement node
*/
- public GraphNode replaceWith(NonLiteral replacement, boolean checkPredicates) {
- MGraph newTriples = new SimpleMGraph();
+ public GraphNode replaceWith(BlankNodeOrIri replacement, boolean checkPredicates) {
+ Graph newTriples = new SimpleGraph();
if (!(resource instanceof Literal)) {
- Iterator<Triple> subjectTriples = graph.filter((NonLiteral) resource, null,
+ Iterator<Triple> subjectTriples = graph.filter((BlankNodeOrIri) resource, null,
null);
while (subjectTriples.hasNext()) {
Triple triple = subjectTriples.next();
@@ -600,14 +602,14 @@ public class GraphNode {
graph.addAll(newTriples);
newTriples.clear();
- if (checkPredicates && replacement instanceof UriRef
- && resource instanceof UriRef) {
+ if (checkPredicates && replacement instanceof Iri
+ && resource instanceof Iri) {
Iterator<Triple> predicateTriples = graph.filter(null,
- (UriRef) resource, null);
+ (Iri) resource, null);
while (predicateTriples.hasNext()) {
Triple triple = predicateTriples.next();
Triple newTriple = new TripleImpl(triple.getSubject(),
- (UriRef) replacement, triple.getObject());
+ (Iri) replacement, triple.getObject());
predicateTriples.remove();
newTriples.add(newTriple);
}
@@ -624,8 +626,8 @@ public class GraphNode {
* @param property
* @return
*/
- public Iterator<GraphNode> getObjectNodes(UriRef property) {
- final Iterator<Resource> objects = this.getObjects(property);
+ public Iterator<GraphNode> getObjectNodes(Iri property) {
+ final Iterator<RdfTerm> objects = this.getObjects(property);
return new Iterator<GraphNode>() {
@Override
@@ -635,7 +637,7 @@ public class GraphNode {
@Override
public GraphNode next() {
- Resource object = objects.next();
+ RdfTerm object = objects.next();
return new GraphNode(object, graph);
}
@@ -655,8 +657,8 @@ public class GraphNode {
* @param property
* @return
*/
- public Iterator<GraphNode> getSubjectNodes(UriRef property) {
- final Iterator<NonLiteral> subjects = this.getSubjects(property);
+ public Iterator<GraphNode> getSubjectNodes(Iri property) {
+ final Iterator<BlankNodeOrIri> subjects = this.getSubjects(property);
return new Iterator<GraphNode>() {
@Override
@@ -666,7 +668,7 @@ public class GraphNode {
@Override
public GraphNode next() {
- Resource object = subjects.next();
+ RdfTerm object = subjects.next();
return new GraphNode(object, graph);
}
@@ -700,13 +702,12 @@ public class GraphNode {
}
/**
- * @return a ReadLock if the underlying Graph is a LockableMGraph it returns its lock, otherwise null
+ * @return a ReadLock if the underlying ImmutableGraph is a LockableGraph it returns its lock, otherwise null
*/
public Lock readLock() {
- if (getGraph() instanceof LockableMGraph) {
- return ((LockableMGraph) getGraph()).getLock().readLock();
- }
- return new FakeLock();
+
+ return getGraph().getLock().readLock();
+
}
/**
@@ -714,33 +715,8 @@ public class GraphNode {
* @return
*/
public Lock writeLock() {
- if (getGraph() instanceof LockableMGraph) {
- return ((LockableMGraph) getGraph()).getLock().writeLock();
- }
- return new FakeLock();
- }
-
- private static class FakeLock implements Lock {
-
- public void lock() {
- }
-
- public void lockInterruptibly() throws java.lang.InterruptedException {
- }
- public boolean tryLock() {
- return false;
- }
+ return (getGraph()).getLock().writeLock();
- public boolean tryLock(long l, java.util.concurrent.TimeUnit timeUnit) throws java.lang.InterruptedException {
- return false;
- }
-
- public void unlock() {
- }
-
- public java.util.concurrent.locks.Condition newCondition() {
- return null;
- }
}
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
new file mode 100644
index 0000000..dc3943b
--- /dev/null
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/GraphUtils.java
@@ -0,0 +1,163 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
+
+/**
+ * Utility methods to manipulate <code>Graph</code>s
+ *
+ * @author reto
+ */
+public class GraphUtils {
+
+ /**
+ * Removes a subGraph from an Graph. The subGraph must match a subgraph of
+ * Graph so that for every node in <code>subGraph</code>
+ * each triple it appears in is also present in <code>mGraph</code>. Two
+ * bnodes are considered equals if their contexts (as returned by
+ * <code>GraphNode.getNodeContext</code> are equals.
+ *
+ * @param mGraph
+ * @param subGraph
+ * @throws org.apache.clerezza.rdf.utils.GraphUtils.NoSuchSubGraphException
+ */
+ public static void removeSubGraph(Graph mGraph, Graph subGraph)
+ throws NoSuchSubGraphException {
+ //point to triples of mGraph that are to be removed (if something is removed)
+ final Set<Triple> removingTriples = new HashSet<Triple>();
+ //we first check only the grounded triples and put the non-grounded in here:
+ final Graph unGroundedTriples = new SimpleGraph();
+ for (Triple triple : subGraph) {
+ if (isGrounded(triple)) {
+ if (!mGraph.contains(triple)) {
+ throw new NoSuchSubGraphException();
+ }
+ removingTriples.add(triple);
+ } else {
+ unGroundedTriples.add(triple);
+ }
+ }
+
+ //we first remove the context of bnodes we find in object position
+ OBJ_BNODE_LOOP: while (true) {
+ final Triple triple = getTripleWithBlankNodeObject(unGroundedTriples);
+ if (triple == null) {
+ break;
+ }
+ final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
+ BlankNodeOrIri subject = triple.getSubject();
+ ImmutableGraph context = objectGN.getNodeContext();
+ Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
+ while (potentialIter.hasNext()) {
+ try {
+ final Triple potentialTriple = potentialIter.next();
+ BlankNode potentialMatch = (BlankNode)potentialTriple.getObject();
+ final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
+ if (potentialContext.equals(context)) {
+ removingTriples.addAll(potentialContext);
+ unGroundedTriples.removeAll(context);
+ continue OBJ_BNODE_LOOP;
+ }
+ } catch (ClassCastException e) {
+ continue;
+ }
+ }
+ throw new NoSuchSubGraphException();
+ }
+ SUBJ_BNODE_LOOP: while (true) {
+ final Triple triple = getTripleWithBlankNodeSubject(unGroundedTriples);
+ if (triple == null) {
+ break;
+ }
+ final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
+ RdfTerm object = triple.getObject();
+ if (object instanceof BlankNode) {
+ object = null;
+ }
+ ImmutableGraph context = subjectGN.getNodeContext();
+ Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object);
+ while (potentialIter.hasNext()) {
+ try {
+ final Triple potentialTriple = potentialIter.next();
+ BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject();
+ final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
+ if (potentialContext.equals(context)) {
+ removingTriples.addAll(potentialContext);
+ unGroundedTriples.removeAll(context);
+ continue SUBJ_BNODE_LOOP;
+ }
+ } catch (ClassCastException e) {
+ continue;
+ }
+ }
+ throw new NoSuchSubGraphException();
+ }
+ mGraph.removeAll(removingTriples);
+ }
+
+ private static boolean isGrounded(Triple triple) {
+ if (triple.getSubject() instanceof BlankNode) {
+ return false;
+ }
+ if (triple.getObject() instanceof BlankNode) {
+ return false;
+ }
+ return true;
+ }
+
+ /** retrun triples with a bnode only at object position
+ *
+ * @param triples
+ * @return
+ */
+ private static Triple getTripleWithBlankNodeObject(Graph triples) {
+ for (Triple triple : triples) {
+ if (triple.getSubject() instanceof BlankNode) {
+ continue;
+ }
+ if (triple.getObject() instanceof BlankNode) {
+ return triple;
+ }
+ }
+ return null;
+ }
+ private static Triple getTripleWithBlankNodeSubject(Graph triples) {
+ for (Triple triple : triples) {
+ if (triple.getSubject() instanceof BlankNode) {
+ return triple;
+ }
+ }
+ return null;
+ }
+
+ public static class NoSuchSubGraphException extends Exception {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
new file mode 100644
index 0000000..323c9f2
--- /dev/null
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/IriUtil.java
@@ -0,0 +1,63 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+
+/**
+ * A utility class for Iri and String manipulations.
+ *
+ * @author tio
+ */
+public class IriUtil {
+
+ /**
+ * Strips #x00 - #x1F and #x7F-#x9F from a Unicode string
+ * @see <a href="http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference">
+ * http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference</a> and
+ * replaces all US-ASCII space character with a "+".
+ *
+ * @param inputChars
+ * @return the stripped string
+ *
+ */
+ public static String stripNonIriChars(CharSequence inputChars) {
+
+ if (inputChars == null) {
+ return "";
+ }
+
+ StringBuffer buffer = new StringBuffer();
+
+ for (int i = 0; i < inputChars.length(); i++) {
+ char c = inputChars.charAt(i);
+
+ if (!isIllegal(c)) {
+ buffer.append(c);
+ }
+ }
+ return buffer.toString().replaceAll("\\s+", "+");
+ }
+
+ private static boolean isIllegal(char ch) {
+ if ((ch >= 0x7F) && (ch <= 0x9F)) {
+ return true;
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
deleted file mode 100644
index ab003b9..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/MGraphUtils.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.clerezza.rdf.utils;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-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.TripleCollection;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-
-/**
- * Utility methods to manipulate <code>MGraph</code>s
- *
- * @author reto
- */
-public class MGraphUtils {
-
- /**
- * Removes a subGraph from an MGraph. The subGraph must match a subgraph of
- * MGraph so that for every node in <code>subGraph</code>
- * each triple it appears in is also present in <code>mGraph</code>. Two
- * bnodes are considered equals if their contexts (as returned by
- * <code>GraphNode.getNodeContext</code> are equals.
- *
- * @param mGraph
- * @param subGraph
- * @throws org.apache.clerezza.rdf.utils.MGraphUtils.NoSuchSubGraphException
- */
- public static void removeSubGraph(MGraph mGraph, TripleCollection subGraph)
- throws NoSuchSubGraphException {
- //point to triples of mGraph that are to be removed (if something is removed)
- final Set<Triple> removingTriples = new HashSet<Triple>();
- //we first check only the grounded triples and put the non-grounded in here:
- final TripleCollection unGroundedTriples = new SimpleMGraph();
- for (Triple triple : subGraph) {
- if (isGrounded(triple)) {
- if (!mGraph.contains(triple)) {
- throw new NoSuchSubGraphException();
- }
- removingTriples.add(triple);
- } else {
- unGroundedTriples.add(triple);
- }
- }
-
- //we first remove the context of bnodes we find in object position
- OBJ_BNODE_LOOP: while (true) {
- final Triple triple = getTripleWithBNodeObject(unGroundedTriples);
- if (triple == null) {
- break;
- }
- final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
- NonLiteral subject = triple.getSubject();
- Graph context = objectGN.getNodeContext();
- Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
- while (potentialIter.hasNext()) {
- try {
- final Triple potentialTriple = potentialIter.next();
- BNode potentialMatch = (BNode)potentialTriple.getObject();
- final Graph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
- if (potentialContext.equals(context)) {
- removingTriples.addAll(potentialContext);
- unGroundedTriples.removeAll(context);
- continue OBJ_BNODE_LOOP;
- }
- } catch (ClassCastException e) {
- continue;
- }
- }
- throw new NoSuchSubGraphException();
- }
- SUBJ_BNODE_LOOP: while (true) {
- final Triple triple = getTripleWithBNodeSubject(unGroundedTriples);
- if (triple == null) {
- break;
- }
- final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
- Resource object = triple.getObject();
- if (object instanceof BNode) {
- object = null;
- }
- Graph context = subjectGN.getNodeContext();
- Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object);
- while (potentialIter.hasNext()) {
- try {
- final Triple potentialTriple = potentialIter.next();
- BNode potentialMatch = (BNode)potentialTriple.getSubject();
- final Graph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
- if (potentialContext.equals(context)) {
- removingTriples.addAll(potentialContext);
- unGroundedTriples.removeAll(context);
- continue SUBJ_BNODE_LOOP;
- }
- } catch (ClassCastException e) {
- continue;
- }
- }
- throw new NoSuchSubGraphException();
- }
- mGraph.removeAll(removingTriples);
- }
-
- private static boolean isGrounded(Triple triple) {
- if (triple.getSubject() instanceof BNode) {
- return false;
- }
- if (triple.getObject() instanceof BNode) {
- return false;
- }
- return true;
- }
-
- /** retrun triples with a bnode only at object position
- *
- * @param triples
- * @return
- */
- private static Triple getTripleWithBNodeObject(TripleCollection triples) {
- for (Triple triple : triples) {
- if (triple.getSubject() instanceof BNode) {
- continue;
- }
- if (triple.getObject() instanceof BNode) {
- return triple;
- }
- }
- return null;
- }
- private static Triple getTripleWithBNodeSubject(TripleCollection triples) {
- for (Triple triple : triples) {
- if (triple.getSubject() instanceof BNode) {
- return triple;
- }
- }
- return null;
- }
-
- public static class NoSuchSubGraphException extends Exception {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
index edaa46d..db994e9 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/RdfList.java
@@ -27,59 +27,59 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.BlankNode;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.commons.rdf.Graph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An implementation of an <code>java.util.List</code> backed by an RDF
* collection (rdf:List). The list allows modification that are reflected
- * to the underlying <code>TripleCollection</code>. It reads the data from the
- * <code>TripleCollection</code> when it is first needed, so changes to the
- * TripleCollection affecting the rdf:List may or may not have an effect on the
+ * to the underlying <code>Graph</code>. It reads the data from the
+ * <code>Graph</code> when it is first needed, so changes to the
+ * Graph affecting the rdf:List may or may not have an effect on the
* values returned by instances of this class. For that reason only one
* instance of this class should be used for accessing an rdf:List of sublists
* thereof when the lists are being modified, having multiple lists exclusively
- * for read operations (such as for immutable <code>TripleCollection</code>s) is
+ * for read operations (such as for immutable <code>Graph</code>s) is
* not problematic.
*
* @author rbn, mir
*/
-public class RdfList extends AbstractList<Resource> {
+public class RdfList extends AbstractList<RdfTerm> {
private static final Logger logger = LoggerFactory.getLogger(RdfList.class);
- private final static UriRef RDF_NIL =
- new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
+ private final static Iri RDF_NIL =
+ new Iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
/**
* a list of the linked rdf:List elements in order
*/
- private List<NonLiteral> listList = new ArrayList<NonLiteral>();
- private List<Resource> valueList = new ArrayList<Resource>();
- private NonLiteral firstList;
- private TripleCollection tc;
+ private List<BlankNodeOrIri> listList = new ArrayList<BlankNodeOrIri>();
+ private List<RdfTerm> valueList = new ArrayList<RdfTerm>();
+ private BlankNodeOrIri firstList;
+ private Graph tc;
private boolean totallyExpanded = false;
/**
* Get a list for the specified resource.
*
* If the list is modified using the created instance
- * <code>listResource</code> will always be the first list.
+ * <code>listRdfTerm</code> will always be the first list.
*
- * @param listResource
+ * @param listRdfTerm
* @param tc
*/
- public RdfList(NonLiteral listResource, TripleCollection tc) {
- firstList = listResource;
+ public RdfList(BlankNodeOrIri listRdfTerm, Graph tc) {
+ firstList = listRdfTerm;
this.tc = tc;
}
@@ -90,28 +90,28 @@ public class RdfList extends AbstractList<Resource> {
* @param listNode
*/
public RdfList(GraphNode listNode) {
- this((NonLiteral)listNode.getNode(), listNode.getGraph());
+ this((BlankNodeOrIri)listNode.getNode(), listNode.getGraph());
}
/**
* Creates an empty RdfList by writing a triple
- * "{@code listResource} owl:sameAs rdf.nil ." to {@code tc}.
+ * "{@code listRdfTerm} owl:sameAs rdf.nil ." to {@code tc}.
*
- * @param listResource
+ * @param listRdfTerm
* @param tc
* @return an empty rdf:List.
* @throws IllegalArgumentException
- * if the provided {@code listResource} is a non-empty rdf:List.
+ * if the provided {@code listRdfTerm} is a non-empty rdf:List.
*/
- public static RdfList createEmptyList(NonLiteral listResource, TripleCollection tc)
+ public static RdfList createEmptyList(BlankNodeOrIri listRdfTerm, Graph tc)
throws IllegalArgumentException {
- if (!tc.filter(listResource, RDF.first, null).hasNext()) {
- RdfList list = new RdfList(listResource, tc);
- list.tc.add(new TripleImpl(listResource, OWL.sameAs, RDF_NIL));
+ if (!tc.filter(listRdfTerm, RDF.first, null).hasNext()) {
+ RdfList list = new RdfList(listRdfTerm, tc);
+ list.tc.add(new TripleImpl(listRdfTerm, OWL.sameAs, RDF_NIL));
return list;
} else {
- throw new IllegalArgumentException(listResource + "is a non-empty rdf:List.");
+ throw new IllegalArgumentException(listRdfTerm + "is a non-empty rdf:List.");
}
}
@@ -119,7 +119,7 @@ public class RdfList extends AbstractList<Resource> {
if (totallyExpanded) {
return;
}
- NonLiteral currentList;
+ BlankNodeOrIri currentList;
if (listList.size() > 0) {
currentList = listList.get(listList.size()-1);
} else {
@@ -150,7 +150,7 @@ public class RdfList extends AbstractList<Resource> {
@Override
- public Resource get(int index) {
+ public RdfTerm get(int index) {
expandTill(index + 1);
return valueList.get(index);
}
@@ -162,7 +162,7 @@ public class RdfList extends AbstractList<Resource> {
}
@Override
- public void add(int index, Resource element) {
+ public void add(int index, RdfTerm element) {
expandTill(index);
if (index == 0) {
//special casing to make sure the first list remains the same resource
@@ -187,9 +187,9 @@ public class RdfList extends AbstractList<Resource> {
* @param index is > 0
* @param element
*/
- private void addInRdfList(int index, Resource element) {
+ private void addInRdfList(int index, RdfTerm element) {
expandTill(index+1);
- NonLiteral newList = new BNode() {
+ BlankNodeOrIri newList = new BlankNode() {
};
tc.add(new TripleImpl(newList, RDF.first, element));
if (index < listList.size()) {
@@ -205,7 +205,7 @@ public class RdfList extends AbstractList<Resource> {
}
@Override
- public Resource remove(int index) {
+ public RdfTerm remove(int index) {
//keeping the first list resource
tc.remove(new TripleImpl(listList.get(index), RDF.first, valueList.get(index)));
if (index == (listList.size() - 1)) {
@@ -233,28 +233,28 @@ public class RdfList extends AbstractList<Resource> {
return valueList.remove(index);
}
- private NonLiteral getRest(NonLiteral list) {
- return (NonLiteral) tc.filter(list, RDF.rest, null).next().getObject();
+ private BlankNodeOrIri getRest(BlankNodeOrIri list) {
+ return (BlankNodeOrIri) tc.filter(list, RDF.rest, null).next().getObject();
}
- private Resource getFirstEntry(final NonLiteral listResource) {
+ private RdfTerm getFirstEntry(final BlankNodeOrIri listRdfTerm) {
try {
- return tc.filter(listResource, RDF.first, null).next().getObject();
+ return tc.filter(listRdfTerm, RDF.first, null).next().getObject();
} catch (final NullPointerException e) {
RuntimeException runtimeEx = AccessController.doPrivileged(new PrivilegedAction<RuntimeException>() {
@Override
public RuntimeException run(){
try {
final FileOutputStream fileOutputStream = new FileOutputStream("/tmp/broken-list.nt");
- final GraphNode graphNode = new GraphNode(listResource, tc);
+ final GraphNode graphNode = new GraphNode(listRdfTerm, tc);
Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE);
fileOutputStream.flush();
logger.warn("GraphNode: " + graphNode);
- final Iterator<UriRef> properties = graphNode.getProperties();
+ final Iterator<Iri> properties = graphNode.getProperties();
while (properties.hasNext()) {
logger.warn("available: " + properties.next());
}
- return new RuntimeException("broken list " + listResource, e);
+ return new RuntimeException("broken list " + listRdfTerm, e);
} catch (Exception ex) {
return new RuntimeException(ex);
}
@@ -265,7 +265,7 @@ public class RdfList extends AbstractList<Resource> {
}
}
- public NonLiteral getListResource() {
+ public BlankNodeOrIri getListRdfTerm() {
return firstList;
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
index ecf3ba5..fef7e4b 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/SeeAlsoExpander.java
@@ -23,9 +23,9 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.locks.Lock;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.clerezza.rdf.ontologies.RDFS;
@@ -37,7 +37,7 @@ import org.apache.clerezza.rdf.ontologies.RDFS;
*/
public class SeeAlsoExpander {
/**
- * using TcManger instead of TcProvider as this ensures LockableMGraphs
+ * using TcManger instead of TcProvider as this ensures LockableGraphs
*/
private final TcManager tcManager;
public SeeAlsoExpander(TcManager tcManager) {
@@ -56,32 +56,32 @@ public class SeeAlsoExpander {
* @return a new GraphNode over the union of the original and all expansion graphs
*/
public GraphNode expand(GraphNode node, int recursion) {
- Set<UriRef> alreadyVisited = new HashSet();
- Set<TripleCollection> resultTripleCollections = new HashSet<TripleCollection>();
+ Set<Iri> alreadyVisited = new HashSet();
+ Set<Graph> resultTripleCollections = new HashSet<Graph>();
resultTripleCollections.add(node.getGraph());
- for (UriRef uriRef : expand(node, alreadyVisited, recursion)) {
+ for (Iri uriRef : expand(node, alreadyVisited, recursion)) {
try {
- resultTripleCollections.add(tcManager.getTriples(uriRef));
+ resultTripleCollections.add(tcManager.getGraph(uriRef));
} catch (NoSuchEntityException e) {
//ignore
}
}
return new GraphNode(node.getNode(),
- new UnionMGraph(resultTripleCollections.toArray(
- new TripleCollection[resultTripleCollections.size()])));
+ new UnionGraph(resultTripleCollections.toArray(
+ new Graph[resultTripleCollections.size()])));
}
- private Set<UriRef> getSeeAlsoObjectUris(GraphNode node) {
- Set<UriRef> result = new HashSet<UriRef>();
+ private Set<Iri> getSeeAlsoObjectUris(GraphNode node) {
+ Set<Iri> result = new HashSet<Iri>();
Lock l = node.readLock();
l.lock();
try {
- Iterator<Resource> objects = node.getObjects(RDFS.seeAlso);
+ Iterator<RdfTerm> objects = node.getObjects(RDFS.seeAlso);
while (objects.hasNext()) {
- Resource next = objects.next();
- if (next instanceof UriRef) {
- result.add((UriRef)next);
+ RdfTerm next = objects.next();
+ if (next instanceof Iri) {
+ result.add((Iri)next);
}
}
} finally {
@@ -90,18 +90,18 @@ public class SeeAlsoExpander {
return result;
}
- private Set<UriRef> expand(GraphNode node, Set<UriRef> alreadyVisited, int recursion) {
- Set<UriRef> rdfSeeAlsoTargets = getSeeAlsoObjectUris(node);
- Set<UriRef> result = new HashSet<UriRef>();
+ private Set<Iri> expand(GraphNode node, Set<Iri> alreadyVisited, int recursion) {
+ Set<Iri> rdfSeeAlsoTargets = getSeeAlsoObjectUris(node);
+ Set<Iri> result = new HashSet<Iri>();
result.addAll(rdfSeeAlsoTargets);
recursion++;
if (recursion > 0) {
rdfSeeAlsoTargets.removeAll(alreadyVisited);
alreadyVisited.addAll(rdfSeeAlsoTargets);
- for (UriRef target : rdfSeeAlsoTargets) {
+ for (Iri target : rdfSeeAlsoTargets) {
try {
result.addAll(expand(new GraphNode(node.getNode(),
- tcManager.getTriples(target)), alreadyVisited, recursion));
+ tcManager.getGraph(target)), alreadyVisited, recursion));
} catch (NoSuchEntityException e) {
//ignore
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
index 269ea92..8d0ea45 100644
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
@@ -18,10 +18,7 @@
*/
package org.apache.clerezza.rdf.utils;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+import org.apache.commons.rdf.Graph;
import org.apache.clerezza.rdf.utils.smushing.IfpSmusher;
import org.apache.clerezza.rdf.utils.smushing.SameAsSmusher;
import org.slf4j.Logger;
@@ -46,8 +43,8 @@ public class Smusher {
* @param mGraph
* @param tBox
*/
- public static void smush(MGraph mGraph, TripleCollection tBox) {
- smush(lockable(mGraph), tBox);
+ public static void smush(Graph mGraph, Graph tBox) {
+ new IfpSmusher().smush(mGraph, tBox);
}
/**
@@ -56,20 +53,9 @@ public class Smusher {
* @param mGraph
* @param owlSameStatements
*/
- public static void sameAsSmush(MGraph mGraph, TripleCollection owlSameStatements) {
- sameAsSmush(lockable(mGraph), owlSameStatements);
- }
-
- public static void smush(LockableMGraph mGraph, TripleCollection tBox) {
- new IfpSmusher().smush(mGraph, tBox);
- }
-
- public static void sameAsSmush(LockableMGraph mGraph, TripleCollection owlSameStatements) {
+ public static void sameAsSmush(Graph mGraph, Graph owlSameStatements) {
new SameAsSmusher().smush(mGraph, owlSameStatements, true);
}
- private static LockableMGraph lockable(MGraph mGraph) {
- return mGraph instanceof LockableMGraph ?
- (LockableMGraph) mGraph : new LockableMGraphWrapper(mGraph);
- }
+
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
new file mode 100644
index 0000000..a928f79
--- /dev/null
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionGraph.java
@@ -0,0 +1,286 @@
+/*
+ * 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.clerezza.rdf.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.commons.rdf.BlankNodeOrIri;
+import org.apache.commons.rdf.RdfTerm;
+import org.apache.commons.rdf.Triple;
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.Iri;
+import org.apache.commons.rdf.impl.utils.AbstractGraph;
+
+/**
+ *
+ * This class represents the union of multiple triple collections. A UnionGraph
+ * appears like a merge of the different graphs (see.
+ * http://www.w3.org/TR/rdf-mt/#graphdefs).
+ *
+ * @author hasan
+ */
+public class UnionGraph extends AbstractGraph {
+
+ protected Graph[] baseTripleCollections;
+ private Lock readLock;
+ private Lock writeLock;
+
+ /**
+ * Constructs a UnionGraph over the specified baseTripleCollections. Write
+ * and delete operations are forwarded to the first baseTripleCollections.
+ *
+ * @param baseTripleCollections the baseTripleCollections
+ */
+ public UnionGraph(Graph... baseTripleCollections) {
+ this.baseTripleCollections = baseTripleCollections;
+ readLock = getPartialReadLock(0);
+ writeLock = createWriteLock();
+ }
+
+ @Override
+ public int performSize() {
+ int size = 0;
+ for (Graph graph : baseTripleCollections) {
+ size += graph.size();
+ }
+ return size;
+ }
+
+ @Override
+ public Iterator<Triple> performFilter(final BlankNodeOrIri subject,
+ final Iri predicate, final RdfTerm object) {
+ if (baseTripleCollections.length == 0) {
+ return new HashSet<Triple>(0).iterator();
+ }
+ return new Iterator<Triple>() {
+
+ int currentBaseTC = 0;
+ Iterator<Triple> currentBaseIter = baseTripleCollections[0].filter(
+ subject, predicate, object);
+ private Triple lastReturned;
+
+ @Override
+ public boolean hasNext() {
+ if (currentBaseIter.hasNext()) {
+ return true;
+ }
+ if (currentBaseTC == baseTripleCollections.length - 1) {
+ return false;
+ }
+ currentBaseTC++;
+ currentBaseIter = baseTripleCollections[currentBaseTC].filter(
+ subject, predicate, object);
+ return hasNext();
+ }
+
+ @Override
+ public Triple next() {
+ lastReturned = hasNext() ? currentBaseIter.next() : null;
+ return lastReturned;
+ }
+
+ @Override
+ public void remove() {
+ if (lastReturned == null) {
+ throw new IllegalStateException();
+ }
+ if (currentBaseTC == 0) {
+ currentBaseIter.remove();
+ }
+ lastReturned = null;
+ }
+ };
+ }
+
+ @Override
+ public boolean add(Triple e) {
+ if (baseTripleCollections.length == 0) {
+ throw new RuntimeException("no base graph for adding triples");
+ }
+ return baseTripleCollections[0].add(e);
+ }
+
+ @Override
+ public boolean remove(Object e) {
+ if (baseTripleCollections.length == 0) {
+ throw new RuntimeException("no base graph for removing triples");
+ }
+ return baseTripleCollections[0].remove(e);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj.getClass().equals(getClass()))) {
+ return false;
+ }
+ UnionGraph other = (UnionGraph) obj;
+ Set<Graph> otherGraphs
+ = new HashSet(Arrays.asList(other.baseTripleCollections));
+ Set<Graph> thisGraphs
+ = new HashSet(Arrays.asList(baseTripleCollections));
+ return thisGraphs.equals(otherGraphs)
+ && baseTripleCollections[0].equals(other.baseTripleCollections[0]);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ for (Graph graph : baseTripleCollections) {
+ hash += graph.hashCode();
+ }
+ hash *= baseTripleCollections[0].hashCode();
+ return hash;
+ }
+
+ @Override
+ public ReadWriteLock getLock() {
+ return readWriteLock;
+ }
+ private ReadWriteLock readWriteLock = new ReadWriteLock() {
+
+ @Override
+ public Lock readLock() {
+ return readLock;
+ }
+
+ @Override
+ public Lock writeLock() {
+ return writeLock;
+ }
+ };
+
+ private Lock getPartialReadLock(int startPos) {
+ ArrayList<Lock> resultList = new ArrayList<Lock>();
+ for (int i = startPos; i < baseTripleCollections.length; i++) {
+ Graph graph = baseTripleCollections[i];
+
+ final Lock lock = graph.getLock().readLock();
+ resultList.add(lock);
+ }
+ return new UnionLock(resultList.toArray(new Lock[resultList.size()]));
+ }
+
+ private Lock createWriteLock() {
+ Lock partialReadLock = getPartialReadLock(1);
+
+ Lock baseWriteLock
+ = (baseTripleCollections[0]).getLock().writeLock();
+ return new UnionLock(baseWriteLock, partialReadLock);
+
+ }
+
+ ;
+
+
+ private static class UnionLock implements Lock {
+
+ Lock[] locks;
+
+ public UnionLock(Lock... locks) {
+ this.locks = locks;
+ }
+
+ @Override
+ public void lock() {
+ boolean isLocked = false;
+ while (!isLocked) {
+ try {
+ isLocked = tryLock(10000, TimeUnit.NANOSECONDS);
+ } catch (InterruptedException ex) {
+
+ }
+ }
+ }
+
+ @Override
+ public void lockInterruptibly() throws InterruptedException {
+ Set<Lock> aquiredLocks = new HashSet<Lock>();
+ try {
+ for (Lock lock : locks) {
+ lock.lockInterruptibly();
+ aquiredLocks.add(lock);
+ }
+ } catch (InterruptedException e) {
+ for (Lock lock : aquiredLocks) {
+ lock.unlock();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public boolean tryLock() {
+ Set<Lock> aquiredLocks = new HashSet<Lock>();
+ for (Lock lock : locks) {
+ if (!lock.tryLock()) {
+ for (Lock aquiredLock : aquiredLocks) {
+ aquiredLock.unlock();
+ }
+ return false;
+ }
+ aquiredLocks.add(lock);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
+ Set<Lock> aquiredLocks = new HashSet<Lock>();
+ long timeInNanos = unit.convert(time, TimeUnit.NANOSECONDS);
+ long startTime = System.nanoTime();
+ try {
+ for (Lock lock : locks) {
+ if (!lock.tryLock((timeInNanos + startTime) - System.nanoTime(),
+ TimeUnit.NANOSECONDS)) {
+ for (Lock aquiredLock : aquiredLocks) {
+ aquiredLock.unlock();
+ }
+ return false;
+ }
+ aquiredLocks.add(lock);
+ }
+ } catch (InterruptedException e) {
+ for (Lock lock : aquiredLocks) {
+ lock.unlock();
+ }
+ throw e;
+ }
+ return true;
+ }
+
+ @Override
+ public void unlock() {
+ for (Lock lock : locks) {
+ lock.unlock();
+ }
+ }
+
+ @Override
+ public Condition newCondition() {
+ throw new UnsupportedOperationException("Conditions not supported.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java
deleted file mode 100644
index dbcdf23..0000000
--- a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionMGraph.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * 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.clerezza.rdf.utils;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-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.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.event.FilterTriple;
-import org.apache.clerezza.rdf.core.event.GraphListener;
-import org.apache.clerezza.rdf.core.impl.AbstractMGraph;
-
-/**
- *
- * This class represents the union of multiple triple collections. A
- * UnionGraph appears like a merge of the different graphs (see.
- * http://www.w3.org/TR/rdf-mt/#graphdefs).
- *
- * @author hasan
- */
-public class UnionMGraph extends AbstractMGraph implements LockableMGraph {
-
- private TripleCollection[] baseTripleCollections;
- private Lock readLock;
- private Lock writeLock;
-
- /**
- * Constructs a UnionMGraph over the specified baseTripleCollections. Write
- * and delete operations are forwarded to the first baseTripleCollections.
- *
- * @param baseTripleCollections the baseTripleCollections
- */
- public UnionMGraph(TripleCollection... baseTripleCollections) {
- this.baseTripleCollections = baseTripleCollections;
- readLock = getPartialReadLock(0);
- writeLock = createWriteLock();
- }
-
- @Override
- public int size() {
- int size = 0;
- for (TripleCollection tripleCollection : baseTripleCollections) {
- size += tripleCollection.size();
- }
- return size;
- }
-
- @Override
- public Iterator<Triple> performFilter(final NonLiteral subject,
- final UriRef predicate, final Resource object) {
- if (baseTripleCollections.length == 0) {
- return new HashSet<Triple>(0).iterator();
- }
- return new Iterator<Triple>() {
-
- int currentBaseTC = 0;
- Iterator<Triple> currentBaseIter = baseTripleCollections[0].filter(
- subject, predicate, object);
- private Triple lastReturned;
-
- @Override
- public boolean hasNext() {
- if (currentBaseIter.hasNext()) {
- return true;
- }
- if (currentBaseTC == baseTripleCollections.length - 1) {
- return false;
- }
- currentBaseTC++;
- currentBaseIter = baseTripleCollections[currentBaseTC].filter(
- subject, predicate, object);
- return hasNext();
- }
-
- @Override
- public Triple next() {
- lastReturned = hasNext() ? currentBaseIter.next() : null;
- return lastReturned;
- }
-
- @Override
- public void remove() {
- if (lastReturned == null) {
- throw new IllegalStateException();
- }
- if (currentBaseTC == 0) {
- currentBaseIter.remove();
- }
- lastReturned = null;
- }
- };
- }
-
- @Override
- public boolean add(Triple e) {
- if (baseTripleCollections.length == 0) {
- throw new RuntimeException("no base graph for adding triples");
- }
- return baseTripleCollections[0].add(e);
- }
-
- @Override
- public boolean remove(Object e) {
- if (baseTripleCollections.length == 0) {
- throw new RuntimeException("no base graph for removing triples");
- }
- return baseTripleCollections[0].remove(e);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj.getClass().equals(getClass()))) {
- return false;
- }
- UnionMGraph other = (UnionMGraph) obj;
- Set<TripleCollection> otherGraphs =
- new HashSet(Arrays.asList(other.baseTripleCollections));
- Set<TripleCollection> thisGraphs =
- new HashSet(Arrays.asList(baseTripleCollections));
- return thisGraphs.equals(otherGraphs)
- && baseTripleCollections[0].equals(other.baseTripleCollections[0]);
- }
-
- @Override
- public int hashCode() {
- int hash = 0;
- for (TripleCollection graph : baseTripleCollections) {
- hash += graph.hashCode();
- }
- hash *= baseTripleCollections[0].hashCode();
- return hash;
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- for (TripleCollection tripleCollection : baseTripleCollections) {
- tripleCollection.addGraphListener(listener, filter);
- }
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
- for (TripleCollection tripleCollection : baseTripleCollections) {
- tripleCollection.addGraphListener(listener, filter, delay);
- }
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- for (TripleCollection tripleCollection : baseTripleCollections) {
- tripleCollection.removeGraphListener(listener);
- }
- }
-
- @Override
- public ReadWriteLock getLock() {
- return readWriteLock;
- }
- private ReadWriteLock readWriteLock = new ReadWriteLock() {
-
- @Override
- public Lock readLock() {
- return readLock;
- }
-
- @Override
- public Lock writeLock() {
- return writeLock;
- }
- };
-
-
- private Lock getPartialReadLock(int startPos) {
- ArrayList<Lock> resultList = new ArrayList<Lock>();
- for (int i = startPos; i < baseTripleCollections.length; i++) {
- TripleCollection tripleCollection = baseTripleCollections[i];
- if (tripleCollection instanceof LockableMGraph) {
- final Lock lock = ((LockableMGraph) tripleCollection).getLock().readLock();
- resultList.add(lock);
- }
- }
- return new UnionLock(resultList.toArray(new Lock[resultList.size()]));
- }
-
-
- private Lock createWriteLock() {
- Lock partialReadLock = getPartialReadLock(1);
- if (baseTripleCollections[0] instanceof LockableMGraph) {
- Lock baseWriteLock =
- ((LockableMGraph)baseTripleCollections[0]).getLock().writeLock();
- return new UnionLock(baseWriteLock, partialReadLock);
-
- } else {
- return partialReadLock;
- }
- };
-
-
- private static class UnionLock implements Lock {
-
- Lock[] locks;
- public UnionLock(Lock... locks) {
- this.locks = locks;
- }
-
-
- @Override
- public void lock() {
- boolean isLocked = false;
- while(!isLocked) {
- try {
- isLocked = tryLock(10000, TimeUnit.NANOSECONDS);
- } catch (InterruptedException ex) {
-
- }
- }
- }
-
- @Override
- public void lockInterruptibly() throws InterruptedException {
- Set<Lock> aquiredLocks = new HashSet<Lock>();
- try {
- for(Lock lock : locks) {
- lock.lockInterruptibly();
- aquiredLocks.add(lock);
- }
- } catch (InterruptedException e) {
- for (Lock lock : aquiredLocks) {
- lock.unlock();
- }
- throw e;
- }
- }
-
- @Override
- public boolean tryLock() {
- Set<Lock> aquiredLocks = new HashSet<Lock>();
- for(Lock lock : locks) {
- if (!lock.tryLock()) {
- for (Lock aquiredLock : aquiredLocks) {
- aquiredLock.unlock();
- }
- return false;
- }
- aquiredLocks.add(lock);
- }
- return true;
- }
-
- @Override
- public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
- Set<Lock> aquiredLocks = new HashSet<Lock>();
- long timeInNanos = unit.convert(time, TimeUnit.NANOSECONDS);
- long startTime = System.nanoTime();
- try {
- for(Lock lock : locks) {
- if (!lock.tryLock((timeInNanos+startTime)-System.nanoTime(),
- TimeUnit.NANOSECONDS)) {
- for (Lock aquiredLock : aquiredLocks) {
- aquiredLock.unlock();
- }
- return false;
- }
- aquiredLocks.add(lock);
- }
- } catch (InterruptedException e) {
- for (Lock lock : aquiredLocks) {
- lock.unlock();
- }
- throw e;
- }
- return true;
- }
-
- @Override
- public void unlock() {
- for(Lock lock : locks) {
- lock.unlock();
- }
- }
-
- @Override
- public Condition newCondition() {
- throw new UnsupportedOperationException("Conditions not supported.");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/de5881d4/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
----------------------------------------------------------------------
diff --git a/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
new file mode 100644
index 0000000..3892811
--- /dev/null
+++ b/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/UnionWatchableGraph.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed 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.clerezza.rdf.utils;
+
+import org.apache.commons.rdf.Graph;
+import org.apache.commons.rdf.WatchableGraph;
+import org.apache.commons.rdf.event.FilterTriple;
+import org.apache.commons.rdf.event.GraphListener;
+
+/**
+ *
+ * @author developer
+ */
+public class UnionWatchableGraph extends UnionGraph implements WatchableGraph {
+
+ public UnionWatchableGraph(WatchableGraph... baseTripleCollections) {
+ super(baseTripleCollections);
+ }
+ @Override
+ public void addGraphListener(GraphListener listener, FilterTriple filter) {
+ for (Graph graph : baseTripleCollections) {
+ ((WatchableGraph)graph).addGraphListener(listener, filter);
+ }
+ }
+
+ @Override
+ public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
+ for (Graph graph : baseTripleCollections) {
+ ((WatchableGraph)graph).addGraphListener(listener, filter, delay);
+ }
+ }
+
+ @Override
+ public void removeGraphListener(GraphListener listener) {
+ for (Graph graph : baseTripleCollections) {
+ ((WatchableGraph)graph).removeGraphListener(listener);
+ }
+ }
+
+
+}