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)
 
        }
 


Reply via email to