You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by bb...@apache.org on 2011/06/22 15:00:31 UTC
svn commit: r1138445 - in
/incubator/clerezza/trunk/parent/rdf.scala.utils/src:
main/scala/org/apache/clerezza/rdf/scala/utils/
test/scala/org/apache/clerezza/rdf/scala/utils/
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