clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1137682 - in /incubator/clerezza/trunk/parent/rdf.scala.utils/src: main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
Date Mon, 20 Jun 2011 16:19:58 GMT
Author: reto
Date: Mon Jun 20 16:19:58 2011
New Revision: 1137682

URL: http://svn.apache.org/viewvc?rev=1137682&view=rev
Log:
CLEREZZA-510: added a test-class to test implicit conversions

Added:
    incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
      - copied, changed from r1135953, incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala
Modified:
    incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.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=1137682&r1=1137681&r2=1137682&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
Mon Jun 20 16:19:58 2011
@@ -34,7 +34,13 @@ object EasyGraph {
 
 	private val litFactory = LiteralFactory.getInstance
 
-	implicit def string2lit(str: String) = new PlainLiteralScala(str)
+	implicit def string2litBuilder(str: String) = new LiteralBuilder(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 date2lit(date: Date) = litFactory.createTypedLiteral(date)
 
@@ -101,24 +107,29 @@ object EasyGraph {
 }
 
 /**
- * An implementation of PlainLiteral for Scala that allows some automatic conversions to
happen
- * when combined with the implicit defs in the EasyGraph object
+ * 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.
  */
-class PlainLiteralScala(string: String) extends PlainLiteralImpl(string) {
+case class LiteralBuilder(lexicalForm: String) {
 
 	/**
 	 * @return a plain literal with language specified by lang
 	 */
-	def apply(lang: String) = new PlainLiteralImpl(string, new Language(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(string, new Language(lang.name))
+	def apply(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new Language(lang.name))
+
+	//TODO get a better name for this
+	def `@`(lang: String) = apply(lang)
 
-	def ^^(typ: UriRef) = new TypedLiteralImpl(string, typ)
+	def ^^(typ: UriRef) = new TypedLiteralImpl(lexicalForm, typ)
 
-	def uri = new UriRef(string)
+	def uri = new UriRef(lexicalForm)
 
 }
 

Copied: incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
(from r1135953, 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/TypeConversionTest.scala?p2=incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala&p1=incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EasyGraphTest.scala&r1=1135953&r2=1137682&rev=1137682&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/TypeConversionTest.scala
Mon Jun 20 16:19:58 2011
@@ -1,3 +1,5 @@
+package org.apache.clerezza.rdf.scala.utils
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,66 +18,49 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-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.{TripleImpl, PlainLiteralImpl, TypedLiteralImpl}
 
-class EasyGraphTest {
+class TypeConversionTest {
 
+	private val literalFactory = LiteralFactory.getInstance()
 
-	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")))
-		gr.getGraph
-	}
+	import EasyGraph._
 
 	@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)*/
+	def useStringAsObject {
+		val t = new TripleImpl(new UriRef(("http://example.org/subject")), new UriRef(("http://example.org/predicate")),
"a value")
+		Assert.assertEquals(literalFactory.createTypedLiteral("a value"), t.getObject)
 	}
 
-	@Test
-	def usingArrows {
+	/*@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)
+	}*/
+
+	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)
+	}
 
-		/*
-		 // 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" )
-		 )
-		 */
+	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 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 literaToString {
+		val lit = literalFactory.createTypedLiteral("a value")
+		val s: String = lit
+		Assert.assertEquals("a value", s)
 	}
 
+	@Test
+	def dotUri {
+		val t = new TripleImpl(new UriRef(("http://example.org/subject")), new UriRef(("http://example.org/predicate")),
"http://example.org".uri)
+		Assert.assertEquals(new UriRef("http://example.org"), t.getObject)
+	}
 
 }



Mime
View raw message