Author: reto
Date: Fri Jul  1 05:58:50 2011
New Revision: 1141820

URL: http://svn.apache.org/viewvc?rev=1141820&view=rev
Log:
CLEREZZA-510: cleaning up code, and renamed EzGraph to EzMGraph

Added:
    
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala
      - copied, changed from r1141744, 
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
Removed:
    
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/AltStyles.scala
    
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
Modified:
    
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
    
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala

Copied: 
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala
 (from r1141744, 
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/EzMGraph.scala?p2=incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala&p1=incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala&r1=1141744&r2=1141820&rev=1141820&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/EzMGraph.scala
 Fri Jul  1 05:58:50 2011
@@ -19,33 +19,20 @@
 
 package org.apache.clerezza.rdf.scala.utils
 
-import java.math.BigInteger
-import java.lang.Boolean
-import java.net.{URL, URI}
-import org.apache.clerezza.rdf.ontologies.{XSD, RDF}
-import java.util.Date
-import collection.mutable.{ListBuffer, HashMap}
-import org.apache.clerezza.rdf.utils.{GraphNode, UnionMGraph}
 import org.apache.clerezza.rdf.core._
 import org.apache.clerezza.rdf.core.impl._
-
-object EzGraph {
-       //not sure this is needed, as a EzGraph is typically subclassed by an 
anonymous class
-       def apply(graph: MGraph) = new EzGraph(graph)
-       def apply() = new EzGraph()
-
-}
+import scala.collection.mutable.HashMap
 
 
 /**
- * EzGraph enhances graph writing. Used together with EzGraphNode, it can make 
writing rdf graphs in code a lot more
+ * EzMGraph enhances graph writing, 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
+ * @param graph: a Triple collection
+ * @author hjs, reto
  * @created: 20/04/2011
  */
-class EzGraph(val baseTc: MGraph) extends AbstractMGraph with 
TcDependentConversions {
+class EzMGraph(val baseTc: MGraph) extends AbstractMGraph with 
TcDependentConversions {
 
 
        def this() = this (new SimpleMGraph())
@@ -70,9 +57,9 @@ class EzGraph(val baseTc: MGraph) extend
        def bnode: BNode = {
                new BNode
        }
-//
-       val namedBnodes = new HashMap[String,BNode]
-//
+
+       private val namedBnodes = new HashMap[String,BNode]
+
        /**
         * create a new named bnode based EzGraphNode with the preferred 
writing style
         */
@@ -87,178 +74,6 @@ class EzGraph(val baseTc: MGraph) extend
                }
        }
 
-//     /**
-//      * create a new url based EzGraphNode with the preferred writing style
-//      */
-//     def u[T<: EzGraphNode](url: String)(implicit writingStyle: 
EzStyle[T]=EzStyleChoice.arrow): T = {
-//             node(new UriRef(url))(writingStyle)
-//     }
-//
-//     /**
-//      * create a new Resource based EzGraphNode with the preferred writing 
style.
-//      * 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,baseTc)
-//     }
-
-//     /**
-//      * Add a a relation
-//      * @param subj: subject of relation
-//      * @param relation: relation
-//      * @param: obj: the object of the statement
-//      * @return this, to making method chaining easier
-//      */
-//     def add(subj: NonLiteral, relation: UriRef, obj: Resource ) = {
-//             baseTc.add(new TripleImpl(subj,relation,obj))
-//             baseTc
-//     }
-//
-//     /**
-//      * Add a type relation for the subject
-//      * @param subj: the subject of the relation
-//      * @param clazz: the rdfs:Class the subject is an instance of
-//      * @return this, to making method chaining easier
-//      */
-//     def addType(subj: NonLiteral, clazz: UriRef) = {
-//             baseTc.add(new TripleImpl(subj,RDF.`type`,clazz))
-//             baseTc
-//     }
-
-
 }
 
-/**
- * Ascii Arrow notation for EzGraphNode. This is easy to write using an ascii 
keyboard but because
- * of operator precedence rules, some operators will have higher and some 
lower precedence to these
- * meaning that one has to keep in mind these rules:
- *
- * <blockquote>
-      The precedence of an infix operator is determined by the operator’s 
first character.
-      Characters are listed below in increasing order of precedence, with 
characters on
-      the same line having the same precedence.
-              (all letters)
-               |
-               ^
-              &
-              < >
-              = !
-              :
-             + -
-             * / %
-           (all other special characters)
-
-    That is, operators starting with a letter have lowest precedence, followed 
by operators
-    starting with ‘|’, etc.
-    There’s one exception to this rule, which concerns assignment 
operators(§6.12.4).
-    The precedence of an assigment operator is the same as the one of simple 
assignment
-    (=). That is, it is lower than the precedence of any other operator.
-    The associativity of an operator is determined by the operator’s last 
character. Operators
-    ending in a colon ‘:’ are right-associative. All other operators are 
leftassociative.
- </blockquote>
- */
-//class EzGraphNodeA(ref: NonLiteral, graph: TripleCollection) extends 
EzGraphNode(ref, graph) {
-//
-//     type T_Pred = PredicateA
-//     type T_InvP = InversePredicateA
-//     type T_EzGN = EzGraphNodeA
-//
-//     override protected def  make(ref: NonLiteral, graph: TripleCollection) 
= new EzGraphNodeA(ref,graph)
-//     override protected def  predicate(rel: UriRef) = new PredicateA(rel)
-//     override protected def  inverse(rel: UriRef) = new 
InversePredicateA(rel)
-//
-//     /**
-//      * relate the subject via the given relation to....
-//      */
-//     def --(rel: UriRef) = predicate(rel)
-//
-//     /**
-//      * relate the subject via the given (expressed as string) relation 
to....
-//      */
-//     def --(rel: String) = predicate(new UriRef(rel))
-//
-//     /**
-//      * relate the subject via the inverse of the given relation to....
-//      * note: we can't have <-- as that messes up the balance of precedence
-//      */
-//     def -<-(rel: UriRef) = inverse(rel)
-//
-//     class PredicateA(rel: UriRef) extends Predicate(rel) {
-//             /**
-//              * ...to the following non resource
-//              */
-//             def -->(obj: Resource) = add(obj)
-//
-//
-//             /**
-//              * Adds a relation to a real linked list.
-//              * If you want one relation to each entry use -->> or ⟶*
-//              */
-//             //def -->(list: List[Resource]) = addList(list)
-//
-//             /**
-//              * ...to the EzGraphNode, which is useful for opening a 
parenthesis.
-//              */
-//             def -->(sub: EzGraphNode) = addEG(sub)
-//
-//             /**
-//              * Add one relation for each member of the iterable collection
-//              */
-//             def -->>[T <: Resource](uris: Iterable[T]) = addMany(uris)
-//
-//
-//     }
-//
-//     class InversePredicateA(ref: UriRef) extends InversePredicate(ref) {
-//             /**
-//              * ...to the following non literal
-//              */
-//             def --(subj: NonLiteral) = add(subj)
-//             /**
-//              * ...to the following resource (given as a string)
-//              */
-//             def --(subj: String) = add(new UriRef(subj))
-//
-//             /**
-//              * ...to the following EzGraphNode
-//              * (useful for opening a new parenthesis and specifying other 
things in more detail
-//              */
-//             def --(subj: EzGraphNode) = addGN(subj)
-//             // since we can only have inverses from non literals (howto 
deal with bndoes?)
-//     }
-
-//}
-
-
-/**
- * EzGraphNode. Create instances from an EzGraph object. Differnt notations 
implementations can be used.
- */
-//abstract class EzGraphNode(val ref: NonLiteral, val graph: TripleCollection) 
extends RichGraphNode(ref, graph) {
-
-//     lazy val easyGraph = graph match {
-//             case eg: EzGraph => eg
-//             case other: TripleCollection => new EzGraph(graph)
-//     }
-
-       //removed this as:
-       // + is typically a symmatric operation, which it isn't here
-       // we should use a unin-mgraph rather than copying around triples
-       /*def +(sub: EzGraphNode) = {
-               if (graph ne sub.graph) graph.addAll(sub.graph)
-               this
-       }*/
-
-
-       
-
-//}
-
-//object EzGraphNode {
-//     /**
-//      * create a new EzGraphNode in the preferred writing style
-//      */
-//     def apply[T<:EzGraphNode](ref: NonLiteral, graph: 
TripleCollection)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow ): T = {
-//             writingStyle.preferred(ref,graph)
-//     }
-//}
 

Modified: 
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.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/RichGraphNode.scala?rev=1141820&r1=1141819&r2=1141820&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
 Fri Jul  1 05:58:50 2011
@@ -24,7 +24,6 @@ import java.util.Iterator
 import _root_.scala.collection.JavaConversions._
 import _root_.scala.reflect.Manifest
 import org.apache.clerezza.rdf.core.impl.SimpleMGraph
-import org.apache.clerezza.rdf.core.impl.TripleImpl
 import org.apache.clerezza.rdf.core.{TripleCollection, UriRef, Resource, 
Literal, TypedLiteral, LiteralFactory, NonLiteral, BNode}
 import org.apache.clerezza.rdf.utils.UnionMGraph
 
@@ -183,30 +182,26 @@ class RichGraphNode(resource: Resource, 
        //TODO add support for adding many for symmetry reasons
        class InversePredicate(rel: UriRef) {
 
-               protected def add(subj: GraphNode): RichGraphNode = {
-                       //RichGraphNode.this + subj
-                       add(subj.getNode.asInstanceOf[NonLiteral])
-               }
-
-               protected def add(subj: NonLiteral): RichGraphNode = {
-                       RichGraphNode.this.addInverseProperty(rel, subj)
-                       RichGraphNode.this
-               }
-
                /**
                 * ...to the following non literal
                 */
-               def --(subj: NonLiteral) = add(subj)
+               def --(subj: NonLiteral): RichGraphNode = {
+                       RichGraphNode.this.addInverseProperty(rel, subj)
+                       RichGraphNode.this
+               }
+               
                /**
                 * ...to the following resource (given as a string)
                 */
-               def --(subj: String) = add(new UriRef(subj))
+               def --(subj: String): RichGraphNode = --(new UriRef(subj))
 
                /**
                 * ...to the following EzGraphNode
                 * (useful for opening a new parenthesis and specifying other 
things in more detail
                 */
-               def --(subj: GraphNode) = add(subj)
+               def --(subj: GraphNode): RichGraphNode = {
+                       --(subj.getNode.asInstanceOf[NonLiteral])
+               }
                // since we can only have inverses from non literals (howto 
deal with bndoes?)
        }
 
@@ -215,81 +210,31 @@ class RichGraphNode(resource: Resource, 
         */
        class Predicate(rel: UriRef) {
 
-               protected def add(obj: Resource): RichGraphNode = {
-                       RichGraphNode.this.addProperty(rel, obj)
-                       RichGraphNode.this
-               }
-
                /**
-                * Add one relation for each member of the iterable collection
+                * ...to the following non resource
                 */
-               protected def addMany[T<:Resource](uris: Iterable[T]): 
RichGraphNode = {
-                       for (u <- uris) add(u)
+               def -->(obj: Resource): RichGraphNode = {
+                       RichGraphNode.this.addProperty(rel, obj)
                        RichGraphNode.this
                }
 
-               protected def addEG(sub: GraphNode): RichGraphNode = {
-                       //RichGraphNode.this + sub
-                       add(sub.getNode)
-               }
-
-               /**
-                * ...to the following non resource
-                */
-               def -->(obj: Resource) = add(obj)
-
-
-               /**
-                * Adds a relation to a real linked list.
-                * If you want one relation to each entry use -->> or ⟶*
-                */
-               //def -->(list: List[Resource]) = addList(list)
 
                /**
                 * ...to the EzGraphNode, which is useful for opening a 
parenthesis.
                 */
-               def -->(sub: GraphNode) = addEG(sub)
-
+               def -->(sub: GraphNode): RichGraphNode = {
+                       //RichGraphNode.this + sub
+                       -->(sub.getNode)
+               }
                /**
                 * Add one relation for each member of the iterable collection
                 */
-               def -->>[T <: Resource](uris: Iterable[T]) = addMany(uris)
-
-
-               /*private def toTriples[T <: Resource](head: NonLiteral,list : 
List[T]): List[Triple] = {
-                       val answer = new ListBuffer[Triple]
-                       var varList = list
-                       var headRef = head
-                       while (varList != Nil) {
-                               varList = varList match {
-                                       case head :: next :: rest => {
-                                               val nextRef = new BNode
-                                               answer.append(new 
TripleImpl(headRef, RDF.first, head))
-                                               answer.append(new 
TripleImpl(headRef, RDF.rest, nextRef))
-                                               headRef = nextRef
-                                               next :: rest
-                                       }
-                                       case head :: Nil => {
-                                               answer.append(new 
TripleImpl(headRef, RDF.first, head))
-                                               answer.append(new 
TripleImpl(headRef, RDF.rest, RDF.nil))
-                                               Nil
-                                       }
-                                       case Nil => Nil
-                               }
-                       }
-                       answer.toList
+               def -->>[T <: Resource](uris: Iterable[T]): RichGraphNode = {
+                       for (u <- uris) -->(u)
+                       RichGraphNode.this
                }
 
 
-               protected def addList[T <: Resource](list: List[T]) = {
-                       val headNode = new BNode
-                       addTriple(headNode)
-                       val tripleLst = toTriples(headNode,list);
-                       graph.add(new TripleImpl(headNode,RDF.`type`,RDF.List))
-                       
graph.addAll(collection.JavaConversions.asJavaCollection(tripleLst))
-                       EzGraphNod
-               }*/
-
        }
 }
 

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=1141820&r1=1141819&r2=1141820&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
 Fri Jul  1 05:58:50 2011
@@ -89,7 +89,7 @@ class EzGraphTest {
                        s.add(new TripleImpl(henryUri.uri, FOAF.knows, 
retoUri.uri))
                        s.getGraph
                }
-               val ez = new EzGraph() {
+               val ez = new EzMGraph() {
                        henryUri.uri -- FOAF.knows --> retoUri.uri
                }
                Assert.assertEquals("The two graphs should be equals", 
expected, ez.getGraph)
@@ -272,7 +272,7 @@ class EzGraphTest {
 //
        @Test
        def usingAsciiArrows {
-               val ez = new EzGraph() {
+               val ez = new EzMGraph() {
                        b_("reto").a(FOAF.Person) --
                        FOAF.name --> "Reto Bachman-Gmür".lang('rm) --
                        FOAF.title --> "Mr" --
@@ -297,7 +297,7 @@ class EzGraphTest {
                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)
                //We can add triples by creating a new anonymous instance
-               new EzGraph(ez) {(
+               new EzMGraph(ez) {(
                        "http://bblfish.net/#hjs".uri -- FOAF.name --> "William"
                        -- FOAF.name --> "Bill"
                )}


Reply via email to