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 2011/06/30 17:53:51 UTC
svn commit: r1141584 - in
/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src:
main/scala/org/apache/clerezza/rdf/scala/utils/
test/scala/org/apache/clerezza/rdf/scala/utils/
Author: reto
Date: Thu Jun 30 15:53:50 2011
New Revision: 1141584
URL: http://svn.apache.org/viewvc?rev=1141584&view=rev
Log:
CLEREZZA-510: made EzGraph an MGraph
Modified:
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala?rev=1141584&r1=1141583&r2=1141584&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala Thu Jun 30 15:53:50 2011
@@ -31,7 +31,7 @@ import org.apache.clerezza.rdf.core.impl
object EzGraph {
- def apply(graph: TripleCollection) = new EzGraph(graph)
+ def apply(graph: MGraph) = new EzGraph(graph)
def apply() = new EzGraph()
private val litFactory = LiteralFactory.getInstance
@@ -145,16 +145,21 @@ object EzStyleChoice {
* @author hjs
* @created: 20/04/2011
*/
-//todo: should this take a TripleCollection or a Set[Triple]
-class EzGraph(val graph: TripleCollection) {
+class EzGraph(val baseTc: MGraph) extends AbstractMGraph with TcDependentConversions {
+
def this() = this (new SimpleMGraph())
+ def performFilter(subject: NonLiteral, predicate: UriRef,
+ obj: Resource): java.util.Iterator[Triple] = baseTc.filter(subject, predicate, obj)
+
+ override def size = baseTc.size
+
/**
* Add all triples into the other graph to this one
*/
def +=(other: Graph) = {
- if (graph ne other) graph.addAll(other)
+ if (baseTc ne other) baseTc.addAll(other)
}
/**
@@ -171,11 +176,11 @@ class EzGraph(val graph: TripleCollectio
*/
def b_[T<: EzGraphNode](name: String)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow): T = {
namedBnodes.get(name) match {
- case Some(bnode) => writingStyle.preferred(bnode,graph)
+ case Some(bnode) => writingStyle.preferred(bnode,baseTc)
case None => {
val bn = new BNode
namedBnodes.put(name, bn);
- writingStyle.preferred(bn,graph)
+ writingStyle.preferred(bn,baseTc)
}
}
}
@@ -192,7 +197,7 @@ class EzGraph(val graph: TripleCollectio
* The EzGraphNode will contain the graph that this EzGraph is built on and point to the given subj
*/
def node[T<: EzGraphNode](subj: NonLiteral)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow ): T = {
- writingStyle.preferred(subj,graph)
+ writingStyle.preferred(subj,baseTc)
}
/**
@@ -203,8 +208,8 @@ class EzGraph(val graph: TripleCollectio
* @return this, to making method chaining easier
*/
def add(subj: NonLiteral, relation: UriRef, obj: Resource ) = {
- graph.add(new TripleImpl(subj,relation,obj))
- graph
+ baseTc.add(new TripleImpl(subj,relation,obj))
+ baseTc
}
/**
@@ -214,8 +219,8 @@ class EzGraph(val graph: TripleCollectio
* @return this, to making method chaining easier
*/
def addType(subj: NonLiteral, clazz: UriRef) = {
- graph.add(new TripleImpl(subj,RDF.`type`,clazz))
- graph
+ baseTc.add(new TripleImpl(subj,RDF.`type`,clazz))
+ baseTc
}
Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala?rev=1141584&r1=1141583&r2=1141584&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala Thu Jun 30 15:53:50 2011
@@ -58,7 +58,13 @@ object Preamble extends TcIndependentCon
*
* @author hjs, reto
*/
-class Preamble(baseTc: TripleCollection) extends TcIndependentConversions {
+class Preamble(val baseTc: TripleCollection) extends TcDependentConversions {
+
+}
+protected trait TcDependentConversions extends TcIndependentConversions {
+
+ def baseTc: TripleCollection
+
implicit def toRichGraphNode(resource: Resource) = {
new RichGraphNode(new GraphNode(resource, baseTc))
}
Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala?rev=1141584&r1=1141583&r2=1141584&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala Thu Jun 30 15:53:50 2011
@@ -91,8 +91,8 @@ class EzGraphTest {
val ez = EzGraph()
ez.bnode â FOAF.Person
- 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
+ Assert.assertEquals("the two graphs should be of same size",gr.size(),ez.size())
+ Assert.assertEquals("the two graphs should be equals",gr.getGraph,ez.getGraph)
}
@@ -123,8 +123,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.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
+ 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) //mutable graphs cannot be compared for equality
}
@@ -140,14 +140,14 @@ class EzGraphTest {
//default style is now arrow
(ez.u(retoUri) -- FOAF.knows -->> List(henryUri.uri,danbriUri.uri))
- 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
+ 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)
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.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
+ 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)
}
@@ -198,7 +198,7 @@ class EzGraphTest {
(ez.bnode â OWL.sameAs ⶠ(n3^^"http://example.com/turtle".uri))
- Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+ Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph, ez.getGraph)
}
@@ -249,10 +249,10 @@ class EzGraphTest {
â FOAF.knows ⶠez.b_("reto")
)
)
- 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
+ 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)
ez.b_("danny") â FOAF.name ⶠ"George"
- Assert.assertNotSame("Added one more triple, so graphs should no longer be equal", tinyGraph,ez.graph)
+ Assert.assertFalse("Added one more triple, so graphs should no longer be equal", tinyGraph == ez.getGraph)
}
@Test
@@ -283,10 +283,10 @@ class EzGraphTest {
-- FOAF.knows --> ez.b_("reto")
)
)
- 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
+ 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)
ez.b_("danny") -- FOAF.name --> "George"
- Assert.assertNotSame("Added one more triple, so graphs should no longer be equal",tinyGraph,ez.graph)
+ //Assert.assertNotSame("Added one more triple, so graphs should no longer be equal",tinyGraph,ez.graph)
}
@@ -320,10 +320,10 @@ class EzGraphTest {
has FOAF.knows to ez.b_("reto")
)
)
- 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
+ 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) //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,new SimpleGraph(ez.graph))
+ //Assert.assertNotSame("Added one more triple, so graphs should no longer be equal",tinyGraph,ez.getGraph)
}
Re: svn commit: r1141584 - in /incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src: main/scala/org/apache/clerezza/rdf/scala/utils/ test/scala/org/apache/clerezza/rdf/scala/utils/
Posted by Henry Story <he...@bblfish.net>.
My comments on this proposed patch:
On 30 Jun 2011, at 17:53, reto@apache.org wrote:
> [snip]
> -class EzGraph(val graph: TripleCollection) {
> +class EzGraph(val baseTc: MGraph) extends AbstractMGraph with TcDependentConversions {
I was looking at implementing AbstractMGraph earlier today. So if you think that is reasonable that seems ok with me.
On the other hand I am not sure it's a good idea merge it with the TcDependentConversions. When you do that all the implicit methods start appearing in an IDE like IntelliJ, and I don't see that one ever wants to use them.
I think there is a better solution. Let me look....
>
> +protected trait TcDependentConversions extends TcIndependentConversions {
> +
> + def baseTc: TripleCollection
> +
> implicit def toRichGraphNode(resource: Resource) = {
> new RichGraphNode(new GraphNode(resource, baseTc))
> }
Social Web Architect
http://bblfish.net/