Author: bblfish
Date: Wed Jun 22 13:00:31 2011
New Revision: 1138445

URL: http://svn.apache.org/viewvc?rev=1138445&view=rev
Log:
CLEREZZA-510: filled in intial test suite, simplified EasyGraph and co, and 
added initial Lang (EzLang?) class.

Added:
    
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
Modified:
    
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
    
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala
    
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala

Modified: 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala?rev=1138445&r1=1138444&r2=1138445&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
 Wed Jun 22 13:00:31 2011
@@ -23,24 +23,26 @@ import org.apache.clerezza.rdf.core._
 import impl._
 import org.apache.clerezza.rdf.ontologies.RDF
 import java.math.BigInteger
-import java.util.Date
 import java.lang.Boolean
 import java.net.{URL, URI}
 import org.apache.clerezza.rdf.core._
 import reflect.Apply
 import org.apache.clerezza.rdf.utils.{UnionMGraph, GraphNode}
+import java.util.Date
+import scala.collection.mutable.HashMap
+import scala.Option
 
 object EasyGraph {
 
        private val litFactory = LiteralFactory.getInstance
 
-       implicit def string2litBuilder(str: String) = new LiteralBuilder(str)
+       implicit def string2litBuilder(str: String) = new EzLiteral(str)
 
-       implicit def string2lit(str: String) = 
litFactory.createTypedLiteral(str)
+//     implicit def string2lit(str: String) = 
litFactory.createTypedLiteral(str)
 
        implicit def lit2String(lit: Literal) = lit.getLexicalForm
 
-       implicit def litBuilder2lit(litBuilder: LiteralBuilder) = 
litFactory.createTypedLiteral(litBuilder.lexicalForm)
+       implicit def litBuilder2lit(litBuilder: EzLiteral) = 
litFactory.createTypedLiteral(litBuilder.lexicalForm)
 
        implicit def date2lit(date: Date) = litFactory.createTypedLiteral(date)
 
@@ -65,72 +67,29 @@ object EasyGraph {
        implicit def URLtoUriRef(url: URL) = new UriRef(url.toExternalForm)
 
 
-       //      val g = new EasyGraph(new SimpleMGraph)
-       //      val sub = g.bnode
-
-       // example using old graph notation
-       // of course the add method could be overloaded to take triples, but it 
is still very repetitive
-
-       //      val gr = new SimpleMGraph
-       //      val subj= new BNode()
-       //      gr.add(new TripleImpl(subj,RDF.`type`, FOAF.Person))
-       //      gr.add(new TripleImpl(subj,FOAF.knows, new 
UriRef("http://bblfish.net/#hjs";)))
-       //      gr.add(new TripleImpl(subj,FOAF.name, new 
PlainLiteralImpl("Henry Story","en")))
-       //      val other = new BNode()
-       //      gr.add(new TripleImpl(subj,FOAF.knows, other))
-       //      gr.add(new TripleImpl(subj,FOAF.name,new 
PlainLiteralImpl("Danny Ayers")))
-       //
-       //      //Example using english easy to type non unicode chars and 
simple object typing
-       //      ( g.u("http://bblfish.net/#hjs";) a FOAF.Person
-       //               has FOAF.knows toUris 
Seq("http://www.w3.org/People/Connolly/#me";, "http://farewellutopia.com/#me";)
-       //               has FOAF.name to {"Henry "+ " Story"}
-       //               hasQ (true, FOAF.depiction){ p =>  p.to(new 
UriRef("hello")) }
-       //              )
-       //
-       //
-       //         // example using arrows
-       //              (
-       //                      sub ∈ FOAF.Person
-       //                              ⟝ FOAF.knows ⟶  
"http://bblfish.net/#hjs".uri
-       //                         ⟝ FOAF.name ⟶ "Henry Story"(en)
-       //                              ⟝ FOAF.title ⟶ "Software"+" 
Architect"
-       //                         ⟝ FOAF.knows ⟶ ( g.bnode ⟝ FOAF.name 
⟶ "Danny Ayers" )
-       //              )
-       //
-       //      // example using just brackets ( the apply() method )
-       //      ( 
g.bnode(FOAF.knows)("http://bblfish.net/#hjs".uri,"http://farewellutopia.com/#me".uri)
-       //                    (FOAF.knows)(g.bnode(FOAF.name)("Danny 
Ayers"('en)))
-       //      )
-
-       // should work like http://programming-scala.labs.oreilly.com/ch11.html
+       //inspired from http://programming-scala.labs.oreilly.com/ch11.html
 
 }
 
 /**
- * A builder for creating RDF resources from a String. provides method to 
created literals as well as a UriRef.
- *
- * When a language is added a PlainLiteral is returned, otherwise the 
conversion to literal results in a Literal with
- * datatype xsd:String.
+ * An Easy Literal, contains functions for mapping literals to other literals, 
ie from String literals to
+ * typed literals.
  */
-case class LiteralBuilder(lexicalForm: String) {
+case class EzLiteral(lexicalForm: String) extends Literal {
 
-       /**
-        * @return a plain literal with language specified by lang
-        */
-       def apply(lang: String) = new PlainLiteralImpl(lexicalForm, new 
Language(lang))
 
        /**
         * @return a plain literal with language specified by lang
         */
-       def apply(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new 
Language(lang.name))
-
        //TODO get a better name for this
-       def `@`(lang: String) = apply(lang)
+       def lang(lang: LangId) = new PlainLiteralImpl(lexicalForm, lang)
+       def lang(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new 
Language(lang.name)) //todo lookup in LangId instead
 
        def ^^(typ: UriRef) = new TypedLiteralImpl(lexicalForm, typ)
 
        def uri = new UriRef(lexicalForm)
 
+       def getLexicalForm = lexicalForm
 }
 
 
@@ -145,6 +104,7 @@ case class LiteralBuilder(lexicalForm: S
 @deprecated("Don't use yet other than for trying out this class as it may be 
merged with another class or changed dramatically." +
        " Send feedback to CLEREZZA-510. ")
 class EasyGraph(val graph: TripleCollection) extends SimpleMGraph(graph) {
+       val namedBnodes = new HashMap[String,EasyGraphNode]
 
        /*
        * because we can't jump straight to super constructor in Scala we need 
to
@@ -160,6 +120,13 @@ class EasyGraph(val graph: TripleCollect
                new EasyGraphNode(new BNode(), graph)
        }
 
+       def bnode(name: String): EasyGraphNode = {
+               namedBnodes.get(name) match {
+                       case Some(ezGraphNode) => ezGraphNode
+                       case None => { val ezgn = bnode; namedBnodes.put(name, 
ezgn); ezgn }
+               }
+       }
+
        def u(url: String) = new EasyGraphNode(new UriRef(url), this)
 
        def apply(subj: NonLiteral) = new EasyGraphNode(subj, this)
@@ -219,13 +186,14 @@ class EasyGraphNode(val ref: NonLiteral,
 
        def this() = this (new BNode)
 
-       def apply(rel: UriRef): Predicate = has(rel)
+       def --(rel: UriRef): Predicate = new Predicate(rel)
 
-       def apply(rel: String): Predicate = has(rel)
+       def --(rel: String): Predicate = new Predicate(new UriRef(rel))
 
-       def has(rel: UriRef): Predicate = new Predicate(rel)
-
-       def has(rel: String): Predicate = new Predicate(new UriRef(rel))
+       /**
+        * we Can't have <-- as that messes up the balance of precedence
+        */
+       def -<-(rel: UriRef) = new InversePredicate(rel)
 
        // does not worked as hoped, and does not look that good either
        //      def hasQ(yes: Boolean, rel: UriRef )(func: Predicate => 
EasyGraphNode): EasyGraphNode =
@@ -233,12 +201,12 @@ class EasyGraphNode(val ref: NonLiteral,
        //              else this
 
 
-       def ⟝(rel: UriRef): Predicate = has(rel)
+       def ⟝(rel: UriRef): Predicate = --(rel)
 
-       def ⟝(rel: String): Predicate = has(rel)
+       def ⟝(rel: String): Predicate = --(rel)
 
        /* For inverse relationships */
-       def ⟵(rel: UriRef) = new InversePredicate(rel)
+       def ⟵(rel: UriRef) = -<-(rel)
 
        // does not work as hoped
        //      def ⟝?(yes: Boolean, uri: UriRef)(func: Predicate => 
EasyGraphNode): EasyGraphNode = hasQ(yes,uri)(func)
@@ -250,6 +218,7 @@ class EasyGraphNode(val ref: NonLiteral,
 
        def a(rdfclass: UriRef) = ∈(rdfclass)
 
+
        def ∈(rdfclass: UriRef): EasyGraphNode = {
                graph.add(new TripleImpl(ref, RDF.`type`, rdfclass))
                return EasyGraphNode.this
@@ -260,6 +229,14 @@ class EasyGraphNode(val ref: NonLiteral,
 
                def ⟞(subj: String) = add(new UriRef(subj))
 
+               def ⟞(sub: EasyGraphNode):  EasyGraphNode = {
+                       EasyGraphNode.this + sub
+                       add(sub.ref)
+               }
+
+               def --(subj: NonLiteral) = ⟞(subj)
+               def --(subj: String) = ⟞(subj)
+               def --(subj: EasyGraphNode) = ⟞(subj)
                // since we can only have inverses from non literals (howto 
deal with bndoes?)
 
                protected def add(subj: NonLiteral) = {
@@ -273,56 +250,46 @@ class EasyGraphNode(val ref: NonLiteral,
                //
                // methods that do the work
                //
-               def to(obj: Resource): EasyGraphNode = add(obj)
+               def -->(obj: Resource): EasyGraphNode = add(obj)
 
                /* add a relation to each object in the argument list */
-               def to(objs: Resource*): EasyGraphNode = {
+               def -->(objs: Resource*): EasyGraphNode = {
                        for (o <- objs) add(o)
                        EasyGraphNode.this
                }
 
-               def to[T <: Resource](objs: Iterable[T]): EasyGraphNode = {
+               def -->[T <: Resource](objs: Iterable[T]): EasyGraphNode = {
                        for (o <- objs) add(o)
                        EasyGraphNode.this
                }
 
-               def to(uri: String): EasyGraphNode = add(new 
PlainLiteralImpl(uri))
+               def -->(lit: String): EasyGraphNode = add(new 
PlainLiteralImpl(lit))
 
-               def to(sub: EasyGraphNode): EasyGraphNode = {
+               def -->(sub: EasyGraphNode): EasyGraphNode = {
                        EasyGraphNode.this + sub
                        add(sub.ref)
                }
 
-               def toUri(uri: String) = add(new UriRef(uri))
+               def -->>(uri: String) = add(new UriRef(uri))
 
-               def toUris(uris: Seq[String]) = {
+               def -->>(uris: Seq[String]) = {
                        for (u <- uris) add(new UriRef(u))
                        EasyGraphNode.this
                }
 
-               //
-               //apply method allows turns brackets () into an equivalent of 
<rel>
-               //
-               def apply(obj: Resource) = to(obj)
-
-               def apply(objs: Resource*) = to(objs: _*)
-
-               def apply(uri: String) = to(uri)
-
-               def apply(sub: EasyGraphNode) = to(sub)
 
                //
                // arrow notation
                //
                // todo: a relation to a list
 
-               def ⟶(obj: String) = to(obj)
+               def ⟶(obj: String) = -->(obj)
 
-               def ⟶(obj: Resource) = to(obj)
+               def ⟶(obj: Resource) = -->(obj)
 
-               def ⟶*[T <: Resource](objs: Iterable[T]) = to(objs)
+               def ⟶*[T <: Resource](objs: Iterable[T]) = -->(objs)
 
-               def ⟶(sub: EasyGraphNode) = to(sub)
+               def ⟶(sub: EasyGraphNode) = -->(sub)
 
                protected def add(obj: Resource) = {
                        graph.add(new TripleImpl(ref, rel, obj))

Added: 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala?rev=1138445&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
 Wed Jun 22 13:00:31 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.scala.utils
+
+import org.apache.clerezza.rdf.core.Language
+
+/**
+ * Language tags in html and rdf are explained in more detail
+ * http://www.w3.org/International/questions/qa-choosing-language-tags
+ *
+ * @author hjs
+ * @created: 21/06/2011
+ */
+
+
+/**
+ * A Language Identifier can be a language and a number of Language variations
+ * Would be nice if this could just implement the java
+ */
+class LangId(val id: String) extends Language(id: String) {
+}
+
+/**
+ * Language and regions can be composed
+ *    http://www.i18nguy.com/unicode/language-identifiers.html
+ *
+ */
+class LangRegion(lang: Lang, region: Region) extends 
LangId(lang.toString+"_"+region.toString)
+object LangRegion {
+       import Lang._
+       def apply(lang: Lang, region: Region) = new LangRegion(lang,region)
+       val en_uk = LangRegion(en,uk)
+       val en_dm = LangRegion(en,dm)
+       val fr_ch = LangRegion(fr,ch)
+       val de_ch = LangRegion(de,ch)
+       val it_ch = LangRegion(it,ch)
+}
+
+/**
+ * the simple two character language names
+ */
+object Lang {
+       def apply(id: String) = new Lang(id)
+
+       val en = Lang("en")
+       val de = Lang("de")
+       val fr = Lang("fr")
+       val it = Lang("it")
+       val rm = Lang("rm") //raeto-romance (swiss language)
+
+}
+class Lang(code: String) extends LangId(code)
+
+
+
+
+
+/**
+ * region
+ */
+class Region
+
+case object uk extends Region
+case object us extends Region
+case object dm extends Region //dominican
+case object ch extends Region //switzerland
\ No newline at end of file

Modified: 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala?rev=1138445&r1=1138444&r2=1138445&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala
 Wed Jun 22 13:00:31 2011
@@ -7,7 +7,7 @@
  * "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
+ *    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
@@ -19,62 +19,140 @@
 package org.apache.clerezza.rdf.scala.utils
 
 import org.apache.clerezza.rdf.utils._
-import org.apache.clerezza.rdf.core._
-import org.apache.clerezza.rdf.core.impl._
 import org.apache.clerezza.rdf.ontologies._
-import org.junit._
 import Preamble._
+import org.apache.clerezza.rdf.core._
+import impl.{TypedLiteralImpl, TripleImpl, SimpleMGraph, PlainLiteralImpl}
+import org.junit._
 
 class EasyGraphTest {
 
+       val bblfishModulus = """
+       9D ☮ 79 ☮ BF ☮ E2 ☮ F4 ☮ 98 ☮ BC ☮ 79 ☮ 6D ☮ AB ☮ 
73 ☮ E2 ☮ 8B ☮ 39 ☮ 4D ☮ B5 26 ✜ 68 ✜ 49 ✜ EE ✜ 71 ✜ 87 ✜
+       06 ✜ 32 ✜ C9 ✜ 9F ✜ 3F ✜ 94 ✜ E5 ✜ CB ✜ 4D ✜ B5 12 
☮ 35 ☮ 13 ☮ 69 ☮ 60 ☮ 81 ☮ 58 ☮ 79 ☮ 66 ☮ F3 ☮ 79 ☮ 20 ☮
+       91 ☮ 6A ☮ 3F ☮ 42 5A ✜ F6 ✜ 54 ✜ 42 ✜ 88 ✜ B2 ✜ E9 
✜ 19 ✜ 4A ✜ 79 ✜ 87 ✜ 2E ✜ 62 ✜ 44 ✜ 2D ✜ 7C 06 ☽ 78 ☽ F8
+       ☽ FD ☽ 52 ☽ 92 ☽ 6D ☽ CD ☽ D6 ☽ F3 ☽ 28 ☽ 6B ☽ 1F 
☽ DB ☽ CB ☽ D3 F2 ☮ 08 ☮ 34 ☮ 72 ☮ A2 ☮ 12 ☮ 75 ☮ AE ☮ D1
+       ☮ 09 ☮ 17 ☮ D0 ☮ 88 ☮ 4C ☮ 04 ☮ 8E 04 ☾ E5 ☾ BF ☾ 
D1 ☾ 41 ☾ 64 ☾ D1 ☾ F7 ☾ 89 ☾ 6D ☾ 8B ☾ B2 ☾ F2 ☾ 46 ☾ C0
+       ☾ 56 87 ☮ 8D ☮ B8 ☮ 7C ☮ C6 ☮ FE ☮ E9 ☮ 61 ☮ 88 ☮ 
08 ☮ 61 ☮ DD ☮ E3 ☮ B8 ☮ B5 ☮ 47 ♥
+       """
+
+       /** import some references in order to reduce dependencies */
+
+       final val hex: UriRef = new UriRef("http://www.w3.org/ns/auth/cert#hex";)
+       final val identity: UriRef = new 
UriRef("http://www.w3.org/ns/auth/cert#identity";)
+       final val RSAPublicKey: UriRef = new 
UriRef("http://www.w3.org/ns/auth/rsa#RSAPublicKey";)
+       final val modulus: UriRef = new 
UriRef("http://www.w3.org/ns/auth/rsa#modulus";)
+       final val public_exponent: UriRef = new 
UriRef("http://www.w3.org/ns/auth/rsa#public_exponent";)
+
 
-       private val tinyGraph: Graph = {
+               private val tinyGraph: Graph = {
                val gr = new SimpleMGraph
-               val subj= new BNode()
-               gr.add(new TripleImpl(subj,RDF.`type`, FOAF.Person))
-               gr.add(new TripleImpl(subj,FOAF.knows, new 
UriRef("http://bblfish.net/#hjs";)))
-               gr.add(new TripleImpl(subj,FOAF.name, new 
PlainLiteralImpl("Henry Story", new Language("en"))))
-               val other = new BNode()
-               gr.add(new TripleImpl(subj,FOAF.knows, other))
-               gr.add(new TripleImpl(subj,FOAF.name,new 
PlainLiteralImpl("Danny Ayers")))
+               val reto= new BNode()
+               val danny = new BNode()
+               val henry = new UriRef("http://bblfish.net/#hjs";)
+
+               gr.add(new TripleImpl(reto,RDF.`type`, FOAF.Person))
+               gr.add(new TripleImpl(reto,FOAF.name, new 
PlainLiteralImpl("Reto Bachman-Gmür", new Language("rm"))))
+               gr.add(new TripleImpl(reto,FOAF.title, new 
PlainLiteralImpl("Mr")))
+               gr.add(new TripleImpl(reto,FOAF.currentProject, new 
UriRef("http://clerezza.org/";)))
+               gr.add(new TripleImpl(reto,FOAF.knows, henry))
+               gr.add(new TripleImpl(reto,FOAF.knows, danny))
+
+               gr.add(new TripleImpl(danny,FOAF.name,new 
PlainLiteralImpl("Danny Ayers", new Language("en"))))
+               gr.add(new TripleImpl(danny,RDF.`type`, FOAF.Person))
+               gr.add(new TripleImpl(danny,FOAF.knows, henry))
+               gr.add(new TripleImpl(danny,FOAF.knows, reto))
+
+               gr.add(new TripleImpl(henry,FOAF.name,new 
PlainLiteralImpl("Henry Story")))
+               gr.add(new TripleImpl(henry,RDF.`type`, FOAF.Person))
+               gr.add(new TripleImpl(henry,FOAF.knows, danny))
+               gr.add(new TripleImpl(henry,FOAF.knows, reto))
+
+               val pk = new BNode()
+               gr.add(new TripleImpl(pk,RDF.`type`,RSAPublicKey))
+               gr.add(new TripleImpl(pk,identity,henry))
+               gr.add(new 
TripleImpl(pk,modulus,LiteralFactory.getInstance().createTypedLiteral(65537)))
+               gr.add(new TripleImpl(pk,public_exponent,new 
TypedLiteralImpl(bblfishModulus,hex)))
                gr.getGraph
        }
 
        @Test
        def plainChracter {
-               /*val simpleMGraph = new SimpleMGraph
+/*
                val g = new EasyGraph(simpleMGraph)
                val sub = g.bnode
                ( g.u("http://bblfish.net/#hjs";) a FOAF.Person
                 has FOAF.name to {"Henry Story"}
                )
                
-               Assert.assertEquals(tinyGraph, simpleMGraph.getGraph)*/
+               Assert.assertEquals(tinyGraph, simpleMGraph.getGraph)
+*/
        }
 
        @Test
-       def usingArrows {
-
-               /*
+       def usingSymbolicArrows {
+               import org.apache.clerezza.rdf.scala.utils.EasyGraph._
+               import org.apache.clerezza.rdf.scala.utils.Lang._
+                val ez = new EasyGraph()
                 // example using arrows
                 (
-                sub ∈ FOAF.Person
-                ⟝ FOAF.knows ⟶  "http://bblfish.net/#hjs".uri
-                ⟝ FOAF.name ⟶ "Henry Story"(en)
-                ⟝ FOAF.title ⟶ "Software"+" Architect"
-                ⟝ FOAF.knows ⟶ ( g.bnode ⟝ FOAF.name ⟶ "Danny Ayers" )
+                  ez.bnode("reto") ∈ FOAF.Person
+                        ⟝ FOAF.name ⟶ "Reto Bachman-Gmür".lang(rm)
+                        ⟝ FOAF.title ⟶ "Mr"
+                        ⟝ FOAF.currentProject ⟶ "http://clerezza.org/".uri
+                        ⟝ FOAF.knows ⟶ (ez.u("http://bblfish.net/#hjs";) 
∈ FOAF.Person
+                                 ⟝ FOAF.name ⟶ "Henry Story"
+                                 ⟝ FOAF.currentProject ⟶ 
"http://webid.info/".uri
+                                 ⟵ identity ⟞ ( ez.bnode ∈ RSAPublicKey
+                                        ⟝ modulus ⟶ 65537
+                                        ⟝ public_exponent ⟶ 
(bblfishModulus^^hex) // brackets needed due to precedence
+                                 )
+                                 ⟝ FOAF.knows ⟶ ez.bnode("reto")
+                                           ⟝ FOAF.knows ⟶ ez.bnode("danny")
+                        )
+                        ⟝ FOAF.knows ⟶ (ez.bnode("danny") ∈ FOAF.Person
+                                 ⟝ FOAF.name ⟶ "Danny Ayers"
+                            ⟝ FOAF.knows ⟶ "http://bblfish.net/#hjs".uri 
//knows
+                                           ⟝ FOAF.knows ⟶ ez.bnode("reto")
+                        )
                 )
-                */
+
+               Assert.assertEquals("Both graphs should contain exactly the 
same triples",ez, tinyGraph)
+               ez.bnode("danny") ⟝  FOAF.name ⟶  "George"
+               Assert.assertNotSame("Added one more triple, so graphs should 
no longer be equal",ez, tinyGraph)
        }
 
        @Test
-       def usingBrackets {
-               /*
-                // example using just brackets ( the apply() method )
-                ( 
g.bnode(FOAF.knows)("http://bblfish.net/#hjs".uri,"http://farewellutopia.com/#me".uri)
-                (FOAF.knows)(g.bnode(FOAF.name)("Danny Ayers"('en)))
+       def usingAsciiArrows {
+               import org.apache.clerezza.rdf.scala.utils.EasyGraph._
+               import org.apache.clerezza.rdf.scala.utils.Lang._
+                val ez = new EasyGraph()
+                // example using arrows
+                (
+                  ez.bnode("reto").a(FOAF.Person)
+                        -- FOAF.name --> "Reto Bachman-Gmür".lang(rm)
+                        -- FOAF.title --> "Mr"
+                        -- FOAF.currentProject --> "http://clerezza.org/".uri
+                        -- FOAF.knows --> ( 
ez.u("http://bblfish.net/#hjs";).a(FOAF.Person)
+                                 -- FOAF.name --> "Henry Story"
+                                 -- FOAF.currentProject --> 
"http://webid.info/".uri
+                                 -<- identity -- (  ez.bnode.a(RSAPublicKey) 
//. notation because of precedence of operators
+                                              -- modulus --> 65537
+                                              -- public_exponent --> 
(bblfishModulus^^hex) // brackets needed due to precedence
+                                              )
+                                 -- FOAF.knows --> ez.bnode("reto")
+                                           -- FOAF.knows --> ez.bnode("danny")
+                        )
+                        -- FOAF.knows --> (ez.bnode("danny").a(FOAF.Person)
+                                 -- FOAF.name --> "Danny Ayers"
+                            -- FOAF.knows --> "http://bblfish.net/#hjs".uri 
//knows
+                                           -- FOAF.knows --> ez.bnode("reto")
+                        )
                 )
-                */
+               Assert.assertEquals("Both graphs should contain exactly the 
same triples",ez, tinyGraph)
+               ez.bnode("danny") -- FOAF.name --> "George"
+               Assert.assertNotSame("Added one more triple, so graphs should 
no longer be equal",ez, tinyGraph)
+
        }
 
 

Modified: 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala?rev=1138445&r1=1138444&r2=1138445&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
 Wed Jun 22 13:00:31 2011
@@ -21,6 +21,7 @@ package org.apache.clerezza.rdf.scala.ut
 import org.junit._
 import org.apache.clerezza.rdf.core._
 import impl.{TripleImpl, PlainLiteralImpl, TypedLiteralImpl}
+import com.sun.xml.internal.ws.developer.MemberSubmissionAddressing.Validation
 
 class TypeConversionTest {
 
@@ -40,17 +41,24 @@ class TypeConversionTest {
                Assert.assertEquals(new PlainLiteralImpl("a value", new 
Language("en")), t.getObject)
        }*/
 
+       @Test
        def useStringWithLanguageTag {
-               val t = new TripleImpl(new 
UriRef(("http://example.org/subject";)), new 
UriRef(("http://example.org/predicate";)), "a value"`@`"en")
-               Assert.assertEquals(new PlainLiteralImpl("a value", new 
Language("en")), t.getObject)
+               import org.apache.clerezza.rdf.scala.utils.Lang._
+          val lit = new PlainLiteralImpl("a value", new Language("en"))
+               val t = new TripleImpl(new 
UriRef(("http://example.org/subject";)), new 
UriRef(("http://example.org/predicate";)), "a value" lang en)
+               val t2 = new TripleImpl(new 
UriRef(("http://example.org/subject";)), new 
UriRef(("http://example.org/predicate";)), "a value" lang 'en)
+               Assert.assertEquals(lit, t.getObject)
+               Assert.assertEquals(lit, t2.getObject)
        }
 
+       @Test
        def useStringWithType {
                val typeUri = new UriRef("http://example.org/dt";)
                val t = new TripleImpl(new 
UriRef(("http://example.org/subject";)), new 
UriRef(("http://example.org/predicate";)), "a value"^^typeUri)
                Assert.assertEquals(new TypedLiteralImpl("a value", typeUri), 
t.getObject)
        }
 
+       @Test
        def literaToString {
                val lit = literalFactory.createTypedLiteral("a value")
                val s: String = lit


Reply via email to