Author: bblfish
Date: Thu Jun 30 12:20:17 2011
New Revision: 1141503
URL: http://svn.apache.org/viewvc?rev=1141503&view=rev
Log:
CLEREZZA-510: EzGraph now no longer extends SimpleMGraph but wraps a
TripleCollection, which makes more sense
Modified:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
Modified:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala?rev=1141503&r1=1141502&r2=1141503&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
Thu Jun 30 12:20:17 2011
@@ -693,7 +693,7 @@ class Assertor {
for (test <- assertions) {
test.toRdf()
}
- g
+ g.graph
}
class Assertion(testName: UriRef,
Modified:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala?rev=1141503&r1=1141502&r2=1141503&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
(original)
+++
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
Thu Jun 30 12:20:17 2011
@@ -23,7 +23,7 @@ import java.math.BigInteger
import java.lang.Boolean
import java.net.{URL, URI}
import org.apache.clerezza.rdf.ontologies.{XSD, RDF}
-import java.util.{HashSet, Date}
+import java.util.Date
import collection.mutable.{ListBuffer, HashMap}
import org.apache.clerezza.rdf.utils.{GraphNode, UnionMGraph}
import org.apache.clerezza.rdf.core._
@@ -31,7 +31,7 @@ import org.apache.clerezza.rdf.core.impl
object EzGraph {
- def apply(graph: HashSet[Triple]) = new EzGraph(graph)
+ def apply(graph: TripleCollection) = new EzGraph(graph)
def apply() = new EzGraph()
private val litFactory = LiteralFactory.getInstance
@@ -62,8 +62,6 @@ object EzGraph {
implicit def URLtoUriRef(url: URL) = new UriRef(url.toExternalForm)
- import EzStyleChoice.unicode
-
//inspired from http://programming-scala.labs.oreilly.com/ch11.html
}
@@ -120,28 +118,17 @@ object EzStyleChoice {
}
/**
- * This is really a TripleCollection , should it just extend a TC? Or a MGraph?
+ * EzGraph enhances graph writing. Used together with EzGraphNode, it can make
writing rdf graphs in code a lot more
+ * readable, as it avoids a lot of repetition.
*
* @param graph: a Triple collection - or should it be an MGraph since it is
really meant to be modifiable
* @author hjs
* @created: 20/04/2011
*/
+//todo: should this take a TripleCollection or a Set[Triple]
+class EzGraph(val graph: TripleCollection) {
-class EzGraph(val graph: HashSet[Triple]) extends SimpleMGraph(graph) {
-
- /*
- * because we can't jump straight to super constructor in Scala we need
to
- * create the collection here
- **/
- def this() = this (new HashSet[Triple])
-
-
- /**
- * Constructor for collection
- * Because superclasses map copy information to a new HashSet, we do
this now, so that this class can keep
- * track of the container. If super class changes this may become
unnecessary
- */
- def this(tripleColl: java.util.Collection[Triple]) = this(new
HashSet[Triple](tripleColl))
+ def this() = this (new SimpleMGraph())
def +=(other: Graph) = {
if (graph ne other) graph.addAll(other)
@@ -154,11 +141,11 @@ class EzGraph(val graph: HashSet[Triple]
val namedBnodes = new HashMap[String,BNode]
def b_[T<: EzGraphNode](name: String)(implicit writingStyle:
EzStyle[T]=EzStyleChoice.unicode): T = {
namedBnodes.get(name) match {
- case Some(bnode) => writingStyle.preferred(bnode,this)
+ case Some(bnode) => writingStyle.preferred(bnode,graph)
case None => {
val bn = new BNode
namedBnodes.put(name, bn);
- writingStyle.preferred(bn,this)
+ writingStyle.preferred(bn,graph)
}
}
}
@@ -168,7 +155,7 @@ class EzGraph(val graph: HashSet[Triple]
}
def node[T<: EzGraphNode](subj: NonLiteral)(implicit writingStyle:
EzStyle[T]=EzStyleChoice.unicode ): T = {
- writingStyle.preferred(subj,this)
+ writingStyle.preferred(subj,graph)
}
/**
Modified:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala?rev=1141503&r1=1141502&r2=1141503&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
(original)
+++
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
Thu Jun 30 12:20:17 2011
@@ -47,7 +47,6 @@ class EzGraphTest {
val danbriUri: String = "http://danbri.org/foaf.rdf#danbri"
-
private val tinyGraph: Graph = {
val gr = new SimpleMGraph
val reto= new BNode()
@@ -91,8 +90,8 @@ class EzGraphTest {
val ez = EzGraph()
ez.bnode â FOAF.Person
- Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez.size())
- Assert.assertTrue("the two graphs should be
equals",gr.getGraph.equals(ez.getGraph)) //mutable graphs cannot be compared
for equality
+ Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez.graph.size())
+ Assert.assertEquals("the two graphs should be
equals",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
}
@@ -123,8 +122,8 @@ class EzGraphTest {
( ez.u(retoUri) â FOAF.Person
â todoRef â¶ List[Resource]("SPARQL update
support".lang(en),"XSPARQL support".lang(en),holiday.uri))
- Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez.size())
- Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,ez.getGraph)
+ Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
}
@@ -139,14 +138,14 @@ class EzGraphTest {
import org.apache.clerezza.rdf.scala.utils.EzGraph._
(ez.u(retoUri)(EzStyleChoice.ascii) -- FOAF.knows -->>
List(henryUri.uri,danbriUri.uri))
- Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez.size())
- Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,ez.getGraph)
+ Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
val ez2 = EzGraph()
(ez2.u(retoUri)(EzStyleChoice.unicode) â FOAF.knows â¶*
Set(danbriUri.uri,henryUri.uri))
- Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez2.size())
- Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,ez2.getGraph)
+ Assert.assertEquals("the two graphs should be of same
size",gr.size(),ez2.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,new SimpleGraph(ez2.graph)) //mutable graphs cannot
be compared for equality
}
@@ -198,7 +197,7 @@ class EzGraphTest {
val res : EzGraphNode = (ez.bnode â OWL.sameAs â¶
(n3^^"http://example.com/turtle".uri))
- Assert.assertEquals("the two graphs must be
equal",gr.getGraph,ez.getGraph)
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
}
@@ -250,10 +249,10 @@ class EzGraphTest {
â FOAF.knows â¶ ez.b_("reto")
)
)
- Assert.assertEquals("the two graphs should be of same
size",tinyGraph.size(),ez.size())
- Assert.assertEquals("Both graphs should contain exactly the
same triples",tinyGraph,ez.getGraph)
+ Assert.assertEquals("the two graphs should be of same
size",tinyGraph.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",tinyGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
ez.b_("danny") â FOAF.name â¶ "George"
- Assert.assertNotSame("Added one more triple, so graphs should
no longer be equal", tinyGraph,ez.getGraph)
+ Assert.assertNotSame("Added one more triple, so graphs should
no longer be equal", tinyGraph,ez.graph)
}
@Test
@@ -285,10 +284,10 @@ class EzGraphTest {
-- FOAF.knows --> ez.b_("reto")
)
)
- Assert.assertEquals("the two graphs should be of same
size",tinyGraph.size(),ez.size())
- Assert.assertEquals("Both graphs should contain exactly the
same triples",tinyGraph,ez.getGraph)
+ Assert.assertEquals("the two graphs should be of same
size",tinyGraph.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",tinyGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
ez.b_("danny") -- FOAF.name --> "George"
- Assert.assertNotSame("Added one more triple, so graphs should
no longer be equal",tinyGraph,ez.getGraph)
+ Assert.assertNotSame("Added one more triple, so graphs should
no longer be equal",tinyGraph,ez.graph)
}
@@ -323,10 +322,10 @@ class EzGraphTest {
has FOAF.knows to ez.b_("reto")
)
)
- Assert.assertEquals("the two graphs should be of same
size",tinyGraph.size(),ez.size())
- Assert.assertEquals("Both graphs should contain exactly the
same triples",tinyGraph,ez.getGraph)
+ Assert.assertEquals("the two graphs should be of same
size",tinyGraph.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the
same triples",tinyGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be
compared for equality
ez.b_("danny") has FOAF.name to "George"
- Assert.assertNotSame("Added one more triple, so graphs should
no longer be equal",tinyGraph,ez.getGraph)
+ Assert.assertNotSame("Added one more triple, so graphs should
no longer be equal",tinyGraph,new SimpleGraph(ez.graph))
}