Author: reto
Date: Wed Jun 22 21:24:23 2011
New Revision: 1138639
URL: http://svn.apache.org/viewvc?rev=1138639&view=rev
Log:
CLEREZZA-577: Being more explicit about UriRef and Literal Builder seprating
concerns to various classes. Added Henry as author as most of the new code is
his (originally in CLEREZZA-510)
Modified:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
Modified:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala?rev=1138639&r1=1138638&r2=1138639&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
(original)
+++
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
Wed Jun 22 21:24:23 2011
@@ -35,6 +35,8 @@ import org.apache.clerezza.rdf.core._
* import org.apache.clerezza.rdf.scala.utils.Preamble._
* }}} near the top of the
* file using SCB Utilities for Scala
+*
+* @author hjs, reto
*/
object Preamble extends TcIndependentConversions {
@@ -53,6 +55,8 @@ object Preamble extends TcIndependentCon
* }}}
* before the
* code section using the conversions
+*
+* @author hjs, reto
*/
class Preamble(baseTc: TripleCollection) extends TcIndependentConversions {
implicit def toRichGraphNode(resource: Resource) = {
@@ -75,8 +79,13 @@ protected trait TcIndependentConversions
private val litFactory = LiteralFactory.getInstance
+ /*a strig is dynamically converted to 3 types of objects, a Literal, a
+ LiteralBuilder or a UriRefBuilder*/
+
implicit def string2litBuilder(str: String) = new
TcIndependentConversions.LiteralBuilder(str)
+ implicit def string2uriRefBuilder(str: String) = new
TcIndependentConversions.UriRefBuilder(str)
+
implicit def string2lit(str: String) =
litFactory.createTypedLiteral(str)
implicit def lit2String(lit: Literal) = lit.getLexicalForm
@@ -111,20 +120,48 @@ protected object TcIndependentConversion
val emptyLiteral = new RichGraphNode(new GraphNode(new
impl.PlainLiteralImpl(""), emptyGraph))
/**
- * An Easy Literal, contains functions for mapping literals to other
literals, ie from String literals to
- * typed literals.
+ * A Literal Builder enriches a String with methods to create a literal
*/
class LiteralBuilder(val lexicalForm: String) {
/**
- * @return a plain literal with language specified by lang
+ * Produces a PlainLiteral with the wrapped String as lexical
form
+ * and a given language
+ *
+ * @param lang the language tag of the literal to be created
+ * @return a plain literal with the specified language
*/
def lang(lang: Lang) = new PlainLiteralImpl(lexicalForm, lang)
+
+ /**
+ * Produces a PlainLiteral with the wrapped String as lexical
form
+ * and a given language
+ *
+ * @param lang a symbol of which the name is the language tag
of the literal to be created
+ * @return a plain literal with the specified language
+ */
def lang(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new
Language(lang.name))
- def ^^(typ: UriRef) = new TypedLiteralImpl(lexicalForm, typ)
+ /**
+ * Produces a TypedLiteral with the wrapped String as lexical
form
+ * and a data type
+ *
+ * @param dataType the data type
+ * @return the TypedLiteral of the specified type
+ */
+ def ^^(dataType: UriRef) = new TypedLiteralImpl(lexicalForm,
dataType)
+
+ }
+
+ /**
+ * A UriRef Builder enriches a String with methods to create a UriRef
+ */
+ class UriRefBuilder(string: String) {
- def uri = new UriRef(lexicalForm)
+ /**
+ * returns a UriRef with the wrapped string as unicode
representation
+ */
+ def uri = new UriRef(string)
}
}
\ No newline at end of file