You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2011/06/30 17:07:18 UTC
svn commit: r1141564 - in /incubator/clerezza/issues: CLEREZZA-510-bblfish/
CLEREZZA-510-bblfish/rdf.scala.utils/
CLEREZZA-510-bblfish/rdf.scala.utils/src/
CLEREZZA-510-bblfish/rdf.scala.utils/src/main/
CLEREZZA-510-bblfish/rdf.scala.utils/src/main/sca...
Author: reto
Date: Thu Jun 30 15:07:17 2011
New Revision: 1141564
URL: http://svn.apache.org/viewvc?rev=1141564&view=rev
Log:
CLEREZZA-510: created 2 issue branche to facitate talking in code without affecting trunk
Added:
incubator/clerezza/issues/CLEREZZA-510-bblfish/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/ (with props)
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/pom.xml
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/CollectedIter.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/NameSpace.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
incubator/clerezza/issues/CLEREZZA-510-reto/
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/
- copied from r1141554, incubator/clerezza/trunk/parent/rdf.scala.utils/
Removed:
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
Modified:
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
Propchange: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 30 15:07:17 2011
@@ -0,0 +1,2 @@
+target
+.project
Propchange: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Jun 30 15:07:17 2011
@@ -0,0 +1 @@
+/incubator/clerezza/issues/CLEREZZA-29/org.apache.clerezza.rdf.scala.utils:891751-892221
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/pom.xml?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/pom.xml (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/pom.xml Thu Jun 30 15:07:17 2011
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>parent</artifactId>
+ <groupId>org.apache.clerezza</groupId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.scala.utils</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Clerezza - SCB Scala Utilities</name>
+ <description>OSGi bundle providing utilities for accessing SCB
+ TripleCollections with Scala. Adding import
+ "org.apache.clerezza.rdf.scala.utils.Preamble._" will allow to use
+ "node/-FOAF.knows/FOAF.name!" with a GraphNode node as shortcut for
+ node.getSubject(FOAF.knows).getObject(FOAF.name).getNode(). To access
+ multiple property values the position can be indicated using the %-operator,
+ e.g. "node/-FOAF.knows%2/FOAF.name%0!", see the ScalaDocs for RichGraphNode
+ for all operations
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.utils</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>utf-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.15.2</version>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ <args>
+ <arg>-target:jvm-1.5</arg>
+ <arg>-deprecation</arg>
+ </args>
+ <charset>UTF-8</charset>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>${project.groupId}.${project.artifactId}.*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+ <version>2.14.1</version>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/CollectedIter.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/CollectedIter.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/CollectedIter.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/CollectedIter.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,133 @@
+/*
+ * 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 java.util.ConcurrentModificationException
+import java.util.Iterator
+import _root_.scala.collection
+import collection.mutable._
+import collection.immutable
+import _root_.scala.collection.JavaConversions._
+import java.util.concurrent.locks.Lock
+
+/**
+ *
+ * A Collection that groups the elements of an iterator, giving a view over it as over a
+ * sequence.
+ *
+ * The collection takes a function returning an iterator, in order to allow for cases where the
+ * iterator needs to be called from the beginning again. i.e. when a ConcurrentModificationException
+ * occurs and the iteration is repeated in a section used using the provided readLock.
+ */
+class CollectedIter[T](iterCreator: () => Iterator[T], readLock: Lock) extends immutable.Seq[T] {
+
+ def this(jList : java.util.List[T], readLock: Lock) = this(() => jList.iterator(), readLock)
+ def this() = this( ()=> java.util.Collections.emptyList[T].iterator(),null)
+
+ var iter = iterCreator()
+ var firstIter = true
+
+ private val collectedElems = new ArrayBuffer[T]()
+
+ /**
+ * This method allows the position to be expressed between parenthesis
+ */
+ def apply(pos : Int) = {
+ ensureReadTill(pos)
+ collectedElems(pos)
+ }
+
+
+ /**
+ * returns a new fully expanded and sorted CollectediterCreator
+ */
+ def sort(lt : (T,T) => Boolean) = {
+ val sortedElems = iterator.toList.sortWith(lt)
+ //TODO this re-expands everything, return sorted-list directly
+ new CollectedIter[T](sortedElems, readLock)
+
+ }
+
+ /**
+ * Operator style syntax to access a position.
+ */
+ def %(pos: Int) = apply(pos)
+
+ private def ensureReadTill(pos: Int) {
+ try {
+
+ while (iter.hasNext && (collectedElems.length-1 <= pos)) {
+ val next = iter.next()
+ if (firstIter || !collectedElems.contains(next)) {
+ collectedElems += next
+ }
+ }
+ } catch {
+ case e: ConcurrentModificationException => {
+ readLock.lock()
+ try {
+ iter = iterCreator()
+ firstIter = false
+ //going beyond pos, do reduce chance we have to aquire another lock
+ val biggerPos = if (pos < (Integer.MAX_VALUE - 100)) {
+ pos + 100
+ } else {
+ Integer.MAX_VALUE
+ }
+ while (iter.hasNext && (collectedElems.length-1 <= biggerPos)) {
+ val next = iter.next()
+ if (!collectedElems.contains(next)) {
+ collectedElems += next
+ }
+ }
+ } finally {
+ readLock.unlock()
+ }
+ }
+ case e => throw e
+ }
+ }
+
+ override def length : Int = {
+ length(Integer.MAX_VALUE)
+ }
+
+ /**
+ * The value returned is same or less than the length of the collection,
+ * the underlying Iterator isn't expanded till more than <code>max</code>. If
+ * the result is smaller than max it is the length of the collection.
+ */
+ def length(max: Int) : Int = {
+ ensureReadTill(max)
+ collectedElems.length
+ }
+
+ override def toString() = {
+ if (length(1) > 0) {
+ apply(0).toString
+ } else {
+ "empty"
+ }
+ }
+
+ override def iterator = {
+ ensureReadTill(Integer.MAX_VALUE)
+ collectedElems.iterator
+ }
+}
\ No newline at end of file
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/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-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,630 @@
+/*
+ * 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 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 {
+
+ def apply(graph: TripleCollection) = new EzGraph(graph)
+ def apply() = new EzGraph()
+
+ private val litFactory = LiteralFactory.getInstance
+
+ implicit def string2lit(str: String) = new EzLiteral(str)
+
+ implicit def lit2String(lit: Literal) = lit.getLexicalForm
+
+ implicit def date2lit(date: Date) = litFactory.createTypedLiteral(date)
+
+ implicit def int2lit(int: Int) = litFactory.createTypedLiteral(int)
+
+ implicit def bigint2lit(bint: BigInt) = litFactory.createTypedLiteral(bint.underlying())
+
+ implicit def bigint2lit(bigInt: BigInteger) = litFactory.createTypedLiteral(bigInt)
+
+ implicit def bool2lit(boolean: Boolean) = litFactory.createTypedLiteral(boolean)
+
+ implicit def scalaBool2lit(boolean: scala.Boolean) = litFactory.createTypedLiteral(boolean)
+
+ implicit def long2lit(long: Long) = litFactory.createTypedLiteral(long)
+
+ implicit def double2lit(double: Double) = litFactory.createTypedLiteral(double)
+
+ implicit def uriRef2Prefix(uriRef: UriRef) = new NameSpace(uriRef.getUnicodeString)
+
+ implicit def URItoUriRef(uri: URI) = new UriRef(uri.toString)
+
+ implicit def URLtoUriRef(url: URL) = new UriRef(url.toExternalForm)
+
+ //inspired from http://programming-scala.labs.oreilly.com/ch11.html
+
+}
+
+/**
+ * An easy Literal implementations, contains functions for mapping literals to other literals, ie from String literals to
+ * typed literals.
+ */
+class EzLiteral(lexicalForm: String) extends TypedLiteral {
+
+ def unapply(lexical: String) = lexical
+
+ /**
+ * @return a plain literal with language specified by lang
+ */
+ def lang(lang: Lang) = new PlainLiteralImpl(lexicalForm, lang)
+ def lang(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new Language(lang.name)) //todo lookup in LangId instead
+
+ /**
+ * Map to a Typed Literal of given type
+ */
+ def ^^(typ: UriRef) = new TypedLiteralImpl(lexicalForm, typ)
+
+ /**
+ * Map to a URI of given lexical form
+ */
+ def uri = new UriRef(lexicalForm)
+
+ /**
+ * get the pure string
+ */
+ override def getLexicalForm = lexicalForm
+
+ override def equals(other: Any) = {
+ other match {
+ case olit: TypedLiteral => (olit eq this) || (olit.getLexicalForm == lexicalForm && olit.getDataType == this.getDataType)
+ case _ => false
+ }
+ }
+
+ override def hashCode() = XSD.string.hashCode() + lexicalForm.hashCode()
+
+ def getDataType = XSD.string
+
+ /**
+ * String literals are just strings
+ * See RDF Semantics rules xsd 1a and xsd 1b in http://www.w3.org/TR/rdf-mt/
+ */
+ override def toString() = lexicalForm
+}
+
+/**
+ * A way to select one's preferred writing style
+ */
+abstract class EzStyle[T<:EzGraphNode]() {
+ def preferred(ref: NonLiteral, tc: TripleCollection):T
+}
+
+/**
+ * import your preferred writing styles into your code
+ */
+object EzStyleChoice {
+ implicit val unicode = new EzStyle[EzGraphNodeU](){
+ override def preferred(ref: NonLiteral, tc: TripleCollection): EzGraphNodeU = new EzGraphNodeU(ref,tc)
+ }
+ implicit val ascii = new EzStyle[EzGraphNodeA](){
+ override def preferred(ref: NonLiteral, tc: TripleCollection): EzGraphNodeA = new EzGraphNodeA(ref,tc)
+ }
+ implicit val english = new EzStyle[EzGraphNodeEn](){
+ override def preferred(ref: NonLiteral, tc: TripleCollection): EzGraphNodeEn = new EzGraphNodeEn(ref,tc)
+ }
+
+
+}
+/**
+ * EzGraph enhances graph writing. Used together with EzGraphNode, 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
+ * @created: 20/04/2011
+ */
+//todo: should this take a TripleCollection or a Set[Triple]
+class EzGraph(val graph: TripleCollection) {
+
+ def this() = this (new SimpleMGraph())
+
+ /**
+ * Add all triples into the other graph to this one
+ */
+ def +=(other: Graph) = {
+ if (graph ne other) graph.addAll(other)
+ }
+
+ /**
+ * create a new bnode based EzGraphNode with the preferred writing style
+ */
+ def bnode[T<: EzGraphNode](implicit writingStyle: EzStyle[T]=EzStyleChoice.unicode ): T = {
+ node(new BNode)(writingStyle)
+ }
+
+ val namedBnodes = new HashMap[String,BNode]
+
+ /**
+ * create a new named bnode based EzGraphNode with the preferred writing style
+ */
+ def b_[T<: EzGraphNode](name: String)(implicit writingStyle: EzStyle[T]=EzStyleChoice.unicode): T = {
+ namedBnodes.get(name) match {
+ case Some(bnode) => writingStyle.preferred(bnode,graph)
+ case None => {
+ val bn = new BNode
+ namedBnodes.put(name, bn);
+ writingStyle.preferred(bn,graph)
+ }
+ }
+ }
+
+ /**
+ * create a new url based EzGraphNode with the preferred writing style
+ */
+ def u[T<: EzGraphNode](url: String)(implicit writingStyle: EzStyle[T]=EzStyleChoice.unicode): 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.unicode ): T = {
+ writingStyle.preferred(subj,graph)
+ }
+
+ /**
+ * 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 ) = {
+ graph.add(new TripleImpl(subj,relation,obj))
+ graph
+ }
+
+ /**
+ * 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) = {
+ graph.add(new TripleImpl(subj,RDF.`type`,clazz))
+ graph
+ }
+
+
+}
+
+/**
+ * Unicode arrow notation for EzGraphNode. Very clean, short and efficient, but unicode values may not
+ * be available everywhere yet.
+ *
+ * Because of operator binding rules all the mathematical operators bind the strongest. This means that
+ * anything outside of these operators should be put into brackets or use dot notation if you wish them to
+ * bind more tightly.
+ *
+ *
+ * @prefix graph: should this be an MGraph, since the EzGraphNode is really designed for editing
+ *
+ */
+class EzGraphNodeU(ref: NonLiteral, graph: TripleCollection) extends EzGraphNode(ref, graph) {
+ //
+ // symbolic notation
+ //
+ // (shorter and more predictable precedence rules, but unicode issues)
+
+ type T_Pred = PredicateU
+ type T_InvP = InversePredicateU
+ type T_EzGN = EzGraphNodeU
+
+ override def make(ref: NonLiteral, graph: TripleCollection) = new EzGraphNodeU(ref,graph)
+ override def predicate(rel: UriRef) = new PredicateU(rel)
+ override def inverse(rel: UriRef) = new InversePredicateU(rel)
+
+ /**
+ * relate the subject via the given relation to....
+ */
+ def â(rel: UriRef) = predicate(rel)
+
+ /**
+ * relate the subject via the given relation to....
+ */
+ def â(rel: String) = predicate(new UriRef(rel))
+
+ /**
+ * relate the subject via the inverse of the given relation to....
+ */
+ def âµ(rel: UriRef) = inverse(rel)
+
+ /**
+ * the subject is a member of the given class
+ */
+ def â(rdfclass: UriRef) = a(rdfclass)
+
+
+ class InversePredicateU(rel: UriRef) extends InversePredicate(rel) {
+ /**
+ * ...to the following non literal
+ */
+ def â(subj: NonLiteral) = add(subj)
+
+ /**
+ * ...to the following resource (given as a string)
+ */
+ def â(uri: String) = add(new UriRef(uri))
+
+ /**
+ * ...to the following EzGraphNode
+ * (useful for opening a new parenthesis and specifying other things in more detail
+ */
+ def â(sub: EzGraphNodeU) = addGN(sub)
+ }
+
+ class PredicateU(rel: UriRef) extends Predicate(rel) {
+
+ /**
+ * ...to the following literal string
+ */
+ def â¶(obj: String) = add(new EzLiteral(obj))
+
+ /**
+ * ...to the following resource
+ */
+ def â¶(obj: Resource) = add(obj)
+
+ /**
+ * ...to the following list as an RDF List
+ */
+ def â¶(list: List[Resource]) = addList(list)
+
+ /**
+ * Add one relation for each member of the iterable collection
+ */
+ def â¶*[T <: Resource](objs: Iterable[T]) = addMany(objs)
+
+ /**
+ * ...to the EzGraphNode, which is useful for opening a parenthesis.
+ */
+ def â¶(sub: EzGraphNode) = addEG(sub)
+
+ }
+
+
+}
+
+/**
+ * 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)
+
+ /**
+ * ...to the following string literal
+ */
+ def -->(lit: String) = add(new EzLiteral(lit))
+
+ /**
+ * 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?)
+ }
+
+}
+
+/**
+ * English language looking Notation for EzGraphNode. This feels gives somewhat awkward
+ * english, but the operator binding priorities for ascii named operators is the weakest, which
+ * means that one needs very few parenthesis when writing out the code as all other operators bind
+ * more tightly.
+ */
+class EzGraphNodeEn(ref: NonLiteral, graph: TripleCollection) extends EzGraphNode(ref, graph) {
+
+ type T_Pred = PredicateEn
+ type T_InvP = InversePredicateEn
+ type T_EzGN = EzGraphNodeEn
+
+ override protected def make(ref: NonLiteral, graph: TripleCollection) = new EzGraphNodeEn(ref,graph)
+ override protected def predicate(rel: UriRef) = new PredicateEn(rel)
+ override protected def inverse(rel: UriRef) = new InversePredicateEn(rel)
+
+ /**
+ * the subject has the given relation to....
+ */
+ def has(rel: UriRef) = predicate(rel)
+
+ /**
+ * the subject has the given relation (specified as string) to....
+ */
+ def has(rel: String) = predicate(new UriRef(rel))
+
+ /**
+ * the subject is the inverse relation of ...
+ */
+ def is(rel: UriRef) = inverse(rel)
+
+ class InversePredicateEn(rel: UriRef) extends InversePredicate(rel) {
+
+
+ /**
+ * ...the following non literal
+ */
+ def of(subj: NonLiteral) = add(subj)
+
+ /**
+ * ...the following resource (as String)
+ */
+ def of(subj: String) = add(new UriRef(subj))
+
+ /**
+ * ...the following EzGraphNode - useful for opening a new bracket
+ */
+ def of(subj: EzGraphNode) = addGN(subj)
+ }
+
+ class PredicateEn(rel: UriRef) extends Predicate(rel) {
+
+
+ /**
+ * ...to the following literal string
+ */
+ def to(lit: String) = add(new EzLiteral(lit))
+
+ /**
+ * ...to the following resource
+ */
+ def to(obj: Resource) = add(obj)
+
+ /**
+ * ...to the following RDF list
+ */
+ def to(list: List[Resource]) = addList(list)
+
+ /**
+ * ... each of the members of the iterable collection
+ */
+ def toEach[T <: Resource](objs: Iterable[T]) = addMany(objs)
+
+ /**
+ * ...to the EzGraphNode, which is useful for opening a parenthesis.
+ */
+ def to(sub: EzGraphNode) = addEG(sub)
+
+ }
+
+}
+
+object EzGraphNode {
+ /**
+ * create a new EzGraphNode in the preferred writing style
+ */
+ def apply[T<:EzGraphNode](ref: NonLiteral, graph: TripleCollection)(implicit writingStyle: EzStyle[T]=EzStyleChoice.unicode ): T = {
+ writingStyle.preferred(ref,graph)
+ }
+}
+
+/**
+ * EzGraphNode. Create instances from an EzGraph object. Differnt notations implementations can be used.
+ */
+abstract class EzGraphNode(val ref: NonLiteral, val graph: TripleCollection) extends GraphNode(ref, graph) {
+
+// lazy val easyGraph = graph match {
+// case eg: EzGraph => eg
+// case other: TripleCollection => new EzGraph(graph)
+// }
+
+ def +(sub: EzGraphNode) = {
+ if (graph ne sub.graph) graph.addAll(sub.graph)
+ this
+ }
+
+ type T_Pred <: Predicate
+ type T_InvP <: InversePredicate
+ type T_EzGN <: EzGraphNode
+
+ protected def predicate(rel: UriRef): T_Pred
+ protected def inverse(rel: UriRef): T_InvP
+ protected def make(ref: NonLiteral, graph: TripleCollection): T_EzGN
+
+ /** is an instance of the given class */
+ def a(rdfclass: UriRef): T_EzGN = {
+ graph.add(new TripleImpl(ref, RDF.`type`, rdfclass))
+ return this.asInstanceOf[T_EzGN]
+ }
+
+ /*
+ * create an EzGraphNode from this one where the backing graph is protected from writes by a new
+ * SimpleGraph.
+ */
+ def protect(): T_EzGN = make(ref, new UnionMGraph(new SimpleMGraph(), graph))
+
+ def this(s: NonLiteral) = this (s, new SimpleMGraph())
+
+ def this() = this (new BNode)
+
+ /** class for Inverse relations with the current EzGraphNode.ref as object */
+ abstract class InversePredicate(rel: UriRef) {
+
+ protected def addGN(subj: EzGraphNode) = {
+ EzGraphNode.this + subj
+ add(subj.ref)
+ }
+
+ protected def add(subj: NonLiteral) = {
+ graph.add(new TripleImpl(subj, rel, ref))
+ EzGraphNode.this.asInstanceOf[T_EzGN]
+ }
+ }
+
+ /**
+ * class for relations with the current EzGraphNode.ref as subject
+ */
+ abstract class Predicate(rel: UriRef) {
+
+ protected def add(obj: Resource): T_EzGN = {
+ addTriple(obj)
+ EzGraphNode.this.asInstanceOf[T_EzGN]
+ }
+
+ protected def addTriple(obj: Resource) {
+ graph.add(new TripleImpl(ref, rel, obj))
+ }
+
+ protected def addMany[T<:Resource](uris: Iterable[T]): T_EzGN = {
+ for (u <- uris) addTriple(u)
+ EzGraphNode.this.asInstanceOf[T_EzGN]
+ }
+
+ protected def addEG(sub: EzGraphNode): T_EzGN = {
+ EzGraphNode.this + sub
+ add(sub.ref)
+ }
+
+ 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
+ }
+
+
+ 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))
+ EzGraphNode.this.asInstanceOf[T_EzGN]
+ }
+
+ }
+
+}
+
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,82 @@
+/*
+ * 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 Lang(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)
+
+}
+
+
+
+
+
+/**
+ * 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
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/NameSpace.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/NameSpace.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/NameSpace.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/NameSpace.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.UriRef
+
+/**
+ * A IRI-namespace prefix
+ */
+class NameSpace(prefix: String) {
+
+ /**
+ * returns a UriRef applying this namespace prefix to the given symbol
+ */
+ def +(s: Symbol) = new UriRef(prefix + s.name)
+
+ /**
+ * returns a UriRef applying this prefix to the given string
+ */
+ def +(s: String) = new UriRef(prefix + s)
+}
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,167 @@
+/*
+ * 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.impl.PlainLiteralImpl
+import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl
+import org.apache.clerezza.rdf.ontologies.XSD
+import org.apache.clerezza.rdf.utils.GraphNode
+import java.math.BigInteger
+import java.net.URI
+import java.net.URL
+import java.util.Date
+import org.apache.clerezza.rdf.core._
+
+/**
+* This object provides the implicit conversions. Typically this is used by
+* adding
+* {{{
+* 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 {
+
+}
+
+/**
+* This class provides the implicit conversions of its companion Object and
+* additional conversions that require an evaluation graph, i.e. the conversion
+* from a resource to a RichGraphNode.
+*
+* Typically this is used by
+* adding
+* {{{
+* val preamble = new org.apache.clerezza.rdf.scala.utils.Preamble(myMGraph)
+* import preamble._
+* }}}
+* before the
+* code section using the conversions
+*
+* @author hjs, reto
+*/
+class Preamble(baseTc: TripleCollection) extends TcIndependentConversions {
+ implicit def toRichGraphNode(resource: Resource) = {
+ new RichGraphNode(new GraphNode(resource, baseTc))
+ }
+}
+
+protected trait TcIndependentConversions {
+ implicit def toRichGraphNode(node: GraphNode) = {
+ new RichGraphNode(node)
+ }
+
+ implicit def toFirstElement(c: CollectedIter[RichGraphNode]) = {
+ if (c.length(1) > 0) {
+ c(0)
+ } else {
+ TcIndependentConversions.emptyLiteral
+ }
+ }
+
+ 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
+
+ implicit def litBuilder2lit(litBuilder: TcIndependentConversions.LiteralBuilder) = litFactory.createTypedLiteral(litBuilder.lexicalForm)
+
+ implicit def date2lit(date: Date) = litFactory.createTypedLiteral(date)
+
+ implicit def int2lit(int: Int) = litFactory.createTypedLiteral(int)
+
+ implicit def bigint2lit(bint: BigInt) = litFactory.createTypedLiteral(bint.underlying())
+
+ implicit def bigint2lit(bigInt: BigInteger) = litFactory.createTypedLiteral(bigInt)
+
+ implicit def bool2lit(boolean: Boolean) = litFactory.createTypedLiteral(boolean)
+
+ implicit def scalaBool2lit(boolean: scala.Boolean) = litFactory.createTypedLiteral(boolean)
+
+ implicit def long2lit(long: Long) = litFactory.createTypedLiteral(long)
+
+ implicit def double2lit(double: Double) = litFactory.createTypedLiteral(double)
+
+ implicit def uriRef2Prefix(uriRef: UriRef) = new NameSpace(uriRef.getUnicodeString)
+
+ implicit def URItoUriRef(uri: URI) = new UriRef(uri.toString)
+
+ implicit def URLtoUriRef(url: URL) = new UriRef(url.toExternalForm)
+
+}
+protected object TcIndependentConversions {
+ val emptyGraph = new impl.SimpleGraph(new impl.SimpleMGraph)
+ val emptyLiteral = new RichGraphNode(new GraphNode(new impl.PlainLiteralImpl(""), emptyGraph))
+
+ /**
+ * A Literal Builder enriches a String with methods to create a literal
+ */
+ class LiteralBuilder(val lexicalForm: String) {
+
+ /**
+ * 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))
+
+ /**
+ * 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) {
+
+ /**
+ * returns a UriRef with the wrapped string as unicode representation
+ */
+ def uri = new UriRef(string)
+
+ }
+}
\ No newline at end of file
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/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-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,139 @@
+/*
+ * 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.utils.GraphNode
+import java.util.Iterator
+import _root_.scala.collection.JavaConversions._
+import _root_.scala.reflect.Manifest
+import org.apache.clerezza.rdf.core.{TripleCollection, UriRef, Resource, Literal, TypedLiteral, LiteralFactory}
+
+
+/**
+ * A RichGraphNode decorates A GraphNode with additional method to be part on a DSL-style scala library.
+ *
+ * The default constructor is same a the GraphNode constructor, i.e. it takes the node and its context
+ * Triple-collection
+ *
+ * @param resource the node represented by this RichGraphNode
+ * @param graph the TripleCollection that describes the resource
+ */
+class RichGraphNode(resource: Resource, graph: TripleCollection ) extends GraphNode(resource, graph) {
+
+ /**
+ * Construct a RichGraphNode given an existing [[GraphNde]]
+ *
+ * @param node The GraphNode to be wrapped
+ */
+ def this(node: GraphNode) = this(node.getNode, node.getGraph)
+
+ /**
+ * Operator syntax shortcut to get all objects as <code>RichGraphNode</code>
+ *
+ * @return all objects of the specified property of the node wrapped by this object
+ */
+ def /(property: UriRef): CollectedIter[RichGraphNode] = {
+ new CollectedIter[RichGraphNode](() => new GraphNodeIter(getObjects(property)), readLock)
+ }
+
+ /**
+ * Operator syntax shortcut to get all subjects as <code>RichGraphNode</code>ref
+ *
+ * @param property the property for which the subjects pointing to this node by that property are requested
+ * @return the matching resources
+ */
+ def /-(property: UriRef): CollectedIter[RichGraphNode] = {
+ new CollectedIter[RichGraphNode](() => new GraphNodeIter(getSubjects(property)), readLock)
+ }
+
+ /**
+ * Get the elements of the rdf:List represented by this node
+ * @return a List with the elements of the rdf:List represented by this node
+ */
+ def !! = (for (listElem <- asList) yield {
+ new RichGraphNode(new GraphNode(listElem, getGraph))
+ }).toList
+
+ /**
+ * get a specified of the rdf:List represented by this node
+ *
+ * @return the specified index value
+ */
+ def %!!(index: Int) = new RichGraphNode(new GraphNode(asList.get(index),
+ getGraph))
+
+ /**
+ * produces a default String representation for the node, this is the lexical form of literals,
+ * the unicode-string for UriRef and for BNodes the value returned by toString
+ *
+ * @return the default string representation of the node
+ */
+ def * : String = {
+ getNode() match {
+ case lit: Literal => lit.getLexicalForm
+ case uri: UriRef => uri.getUnicodeString
+ case wrappedNode => wrappedNode.toString
+ }
+ }
+
+ private def asClass[T](clazz : Class[T]) : T= {
+ val typedLiteral = getNode().asInstanceOf[TypedLiteral]
+ clazz match {
+ case c if(c == classOf[Boolean]) => LiteralFactory.getInstance().createObject(
+ classOf[java.lang.Boolean], typedLiteral).booleanValue.asInstanceOf[T]
+ case _ => LiteralFactory.getInstance().createObject(clazz, typedLiteral)
+ }
+ }
+
+ /**
+ * Creates an instance of specified Class-Type representing the value of the literal wrapped by this
+ * <code>GraphNode</code>
+ *
+ * @return the literal represented by this node as instance of the specified type
+ */
+ def as[T](implicit m: Manifest[T]): T = {
+ asClass(m.erasure.asInstanceOf[Class[T]])
+ }
+
+ /**
+ * Operator syntax shortcut to get the <code>Resource</code> wrapped by this
+ * <code>GraphNode</code>
+ *
+ * @return the node represented by this GraphNode as Resource, same as <code>getNode</code>
+ */
+ def ! = {
+ getNode()
+ }
+
+ private class GraphNodeIter[T <: Resource](base: Iterator[T]) extends Iterator[RichGraphNode] {
+ override def hasNext() = {
+ base.hasNext();
+ }
+
+ override def next() : RichGraphNode = {
+ new RichGraphNode(new GraphNode(base.next(), getGraph));
+ }
+
+ override def remove() {
+ base.remove()
+ }
+ }
+}
+
+
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/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-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,332 @@
+/*
+ * 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.ontologies._
+import org.junit._
+import org.apache.clerezza.rdf.core._
+import impl._
+
+class EzGraphTest {
+
+ 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")
+
+ val henryUri: String = "http://bblfish.net/#hjs"
+ val retoUri: String = "http://farewellutopia.com/reto/#me"
+ val danbriUri: String = "http://danbri.org/foaf.rdf#danbri"
+
+
+ private val tinyGraph: Graph = {
+ val gr = new SimpleMGraph
+ val reto= new BNode()
+ val danny = new BNode()
+ val henry = new UriRef(henryUri)
+
+ 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"))))
+ //it is difficult to remember that one needs to put a string literal if one does not want to specify a language
+ gr.add(new TripleImpl(reto,FOAF.title, new TypedLiteralImpl("Mr",XSD.string)))
+ 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 TypedLiteralImpl("Henry Story",XSD.string))) //It is tricky to remember that one needs this for pure strings
+ gr.add(new TripleImpl(henry,FOAF.currentProject,new UriRef("http://webid.info/")))
+ 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 simpleGraphEquality {
+ val gr = new SimpleMGraph
+
+ val reto= new BNode()
+ gr.add(new TripleImpl(reto,RDF.`type`, FOAF.Person))
+
+ val ez = EzGraph()
+ ez.bnode â FOAF.Person
+
+ Assert.assertEquals("the two graphs should be of same size",gr.size(),ez.graph.size())
+ Assert.assertEquals("the two graphs should be equals",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+
+ }
+
+ @Test
+ def testList {
+ val gr = new SimpleMGraph
+ val reto= new UriRef(retoUri)
+ val todoRef = new UriRef("http://clerezza.org/ex/ont/todo")
+ val holiday = "http://dbpedia.org/resource/Holiday"
+ val list = new BNode
+ val list2 = new BNode
+ val list3 = new BNode
+
+ gr.add(new TripleImpl(reto, todoRef, list ))
+ gr.add(new TripleImpl(list,RDF.`type`, RDF.List))
+ gr.add(new TripleImpl(list,RDF.first, new PlainLiteralImpl("SPARQL update support",new Language("en"))))
+ gr.add(new TripleImpl(list,RDF.rest,list2))
+ gr.add(new TripleImpl(list2,RDF.first, new PlainLiteralImpl("XSPARQL support",new Language("en"))))
+ gr.add(new TripleImpl(list2,RDF.rest,list3))
+ gr.add(new TripleImpl(list3,RDF.first, new UriRef(holiday)))
+ gr.add(new TripleImpl(list3,RDF.rest,RDF.nil))
+ gr.add(new TripleImpl(reto,RDF.`type`, FOAF.Person))
+
+ val ez = EzGraph()
+
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ import org.apache.clerezza.rdf.scala.utils.Lang._
+ ( ez.u(retoUri) â FOAF.Person
+ â todoRef â¶ List[Resource]("SPARQL update support".lang(en),"XSPARQL support".lang(en),holiday.uri))
+
+ Assert.assertEquals("the two graphs should be of same size",gr.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+
+ }
+
+ @Test
+ def oneToMany {
+ val gr = new SimpleMGraph
+ val reto= new UriRef(retoUri)
+ gr.add(new TripleImpl(reto,FOAF.knows,new UriRef(henryUri)))
+ gr.add(new TripleImpl(reto,FOAF.knows,new UriRef(danbriUri)))
+
+ val ez = EzGraph()
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ (ez.u(retoUri)(EzStyleChoice.ascii) -- FOAF.knows -->> List(henryUri.uri,danbriUri.uri))
+
+ Assert.assertEquals("the two graphs should be of same size",gr.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+
+ val ez2 = EzGraph()
+ (ez2.u(retoUri)(EzStyleChoice.unicode) â FOAF.knows â¶* Set(danbriUri.uri,henryUri.uri))
+
+ Assert.assertEquals("the two graphs should be of same size",gr.size(),ez2.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph,new SimpleGraph(ez2.graph)) //mutable graphs cannot be compared for equality
+
+ }
+
+ @Test
+ def langEquals {
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ import org.apache.clerezza.rdf.scala.utils.Lang._
+
+ val lit = new PlainLiteralImpl("SPARQL update support",new Language("en"))
+ val lit2 = "SPARQL update support".lang(en)
+
+ Assert.assertEquals("the two literals should be equsl",lit.hashCode(),lit2.hashCode())
+ Assert.assertEquals("the two literals should be equsl",lit,lit2)
+
+ val lit3 = new PlainLiteralImpl("Reto Bachman-Gmür",new Language("rm"))
+ val lit4 = "Reto Bachman-Gmür".lang(rm)
+
+ Assert.assertEquals("the two lang literals should have same hash",lit3.hashCode(),lit4.hashCode())
+ Assert.assertEquals("the two lang literals should be equal",lit3,lit4)
+
+
+ }
+
+ @Test
+ def uriEquals {
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ val uc = new UriRef("http://clerezza.org/")
+ val ec = "http://clerezza.org/".uri
+
+ Assert.assertEquals("the two uris should have an equal hash",uc.hashCode(),ec.hashCode())
+ Assert.assertEquals("the two uris should be equal",uc,ec)
+
+
+ }
+
+ @Test
+ def literalTester1 {
+ val n3 = """
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
+ <http://bblfish.net/#hjs> a foaf:Person .
+ """
+ val n3Lit : Literal = new TypedLiteralImpl(n3,new UriRef("http://example.com/turtle"))
+ val gr = new SimpleMGraph
+ gr.add(new TripleImpl(new BNode,OWL.sameAs,n3Lit))
+
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ import org.apache.clerezza.rdf.scala.utils.Lang._
+ val ez = EzGraph()
+
+ val res : EzGraphNode = (ez.bnode â OWL.sameAs â¶ (n3^^"http://example.com/turtle".uri))
+
+ Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+
+ }
+
+ @Test
+ def literalTester2 {
+ val exp = LiteralFactory.getInstance().createTypedLiteral(65537)
+ val mod= new TypedLiteralImpl(bblfishModulus,hex)
+
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ val modZ: TypedLiteral = bblfishModulus^^hex
+ val expZ: TypedLiteral = 65537
+
+ Assert.assertEquals("the two literals should have an equal hash",exp.hashCode(),expZ.hashCode())
+ Assert.assertEquals("the two literals should be equal",exp,expZ)
+
+ Assert.assertEquals("the two literals should have an equal hash",mod.hashCode(),modZ.hashCode())
+ Assert.assertEquals("the two literals should be equal",mod,modZ)
+
+ }
+
+
+ @Test
+ def usingSymbolicArrows {
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ import org.apache.clerezza.rdf.scala.utils.Lang._
+ val ez = EzGraph()
+ import EzStyleChoice.unicode //in IntelliJ this is needed for the moment to remove the red lines
+ // example using arrows
+ (
+ ez.b_("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 â¶* Set(ez.b_("reto").ref,ez.b_("danny").ref)
+ )
+ â FOAF.knows â¶ (
+ ez.b_("danny") â FOAF.Person
+ â FOAF.name â¶ "Danny Ayers".lang(en)
+ â FOAF.knows â¶ "http://bblfish.net/#hjs".uri //knows
+ â FOAF.knows â¶ ez.b_("reto")
+ )
+ )
+ Assert.assertEquals("the two graphs should be of same size",tinyGraph.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",tinyGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+ ez.b_("danny") â FOAF.name â¶ "George"
+ Assert.assertNotSame("Added one more triple, so graphs should no longer be equal", tinyGraph,ez.graph)
+ }
+
+ @Test
+ def usingAsciiArrows {
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ import org.apache.clerezza.rdf.scala.utils.Lang._
+ import EzStyleChoice.ascii
+ val ez = EzGraph()
+ // example using arrows
+ (
+ ez.b_("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 -->> List(ez.b_("reto").ref,ez.b_("danny").ref)
+ )
+ -- FOAF.knows --> (ez.b_("danny").a(FOAF.Person)
+ -- FOAF.name --> "Danny Ayers".lang(en)
+ -- FOAF.knows --> "http://bblfish.net/#hjs".uri //knows
+ -- FOAF.knows --> ez.b_("reto")
+ )
+ )
+ Assert.assertEquals("the two graphs should be of same size",tinyGraph.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",tinyGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+ ez.b_("danny") -- FOAF.name --> "George"
+ Assert.assertNotSame("Added one more triple, so graphs should no longer be equal",tinyGraph,ez.graph)
+
+ }
+
+
+ @Test
+ def usingWordOperators {
+ import org.apache.clerezza.rdf.scala.utils.EzGraph._
+ import org.apache.clerezza.rdf.scala.utils.Lang._
+ import EzStyleChoice.english
+
+ val ez = EzGraph()
+ // example using arrows
+ (
+ ez.b_("reto").asInstanceOf[EzGraphNodeEn] a FOAF.Person
+ has FOAF.name to "Reto Bachman-Gmür".lang(rm)
+ has FOAF.title to "Mr"
+ has FOAF.currentProject to "http://clerezza.org/".uri
+ has FOAF.knows to (
+ ez.u("http://bblfish.net/#hjs") a FOAF.Person
+ has FOAF.name to "Henry Story"
+ has FOAF.currentProject to "http://webid.info/".uri
+ is identity of (
+ ez.bnode a RSAPublicKey //. notation because of precedence of operators
+ has modulus to 65537
+ has public_exponent to bblfishModulus^^hex // brackets needed due to precedence
+ )
+ has FOAF.knows toEach List(ez.b_("reto").ref,ez.b_("danny").ref)
+ )
+ has FOAF.knows to ( ez.b_("danny") a FOAF.Person
+ has FOAF.name to "Danny Ayers".lang(en)
+ has FOAF.knows to "http://bblfish.net/#hjs".uri //knows
+ has FOAF.knows to ez.b_("reto")
+ )
+ )
+ Assert.assertEquals("the two graphs should be of same size",tinyGraph.size(),ez.graph.size())
+ Assert.assertEquals("Both graphs should contain exactly the same triples",tinyGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
+ ez.b_("danny") has FOAF.name to "George"
+ Assert.assertNotSame("Added one more triple, so graphs should no longer be equal",tinyGraph,new SimpleGraph(ez.graph))
+
+ }
+
+}
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,163 @@
+/*
+ * 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.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._
+
+class RichGraphNodeTest {
+
+ private val johnUri = new UriRef("http://example.org/john")
+ private val susanneUri = new UriRef("http://example.org/susanne")
+ private val listUri = new UriRef("http://example.org/list")
+ private val greetingsUri = new UriRef("http://example.org/greetings")
+ private val billBNode = new BNode()
+ private var node : RichGraphNode = null;
+ private var mGraph = new SimpleMGraph()
+
+ @Before
+ def prepare() = {
+ mGraph.add(new TripleImpl(johnUri, FOAF.name, new PlainLiteralImpl("John")));
+ mGraph.add(new TripleImpl(johnUri, FOAF.nick, new PlainLiteralImpl("johny")));
+ mGraph.add(new TripleImpl(johnUri, FOAF.name, new PlainLiteralImpl("Johnathan Guller")));
+ mGraph.add(new TripleImpl(johnUri, FOAF.knows, billBNode))
+ mGraph.add(new TripleImpl(billBNode, FOAF.nick, new PlainLiteralImpl("Bill")));
+ mGraph.add(new TripleImpl(billBNode, FOAF.name, new PlainLiteralImpl("William")));
+ mGraph.add(new TripleImpl(billBNode, RDF.`type`, FOAF.Person));
+ mGraph.add(new TripleImpl(susanneUri, FOAF.knows, johnUri));
+ mGraph.add(new TripleImpl(susanneUri, FOAF.name, new PlainLiteralImpl("Susanne")));
+ val rdfList = new RdfList(listUri, mGraph);
+ rdfList.add(johnUri)
+ rdfList.add(new PlainLiteralImpl("foo"))
+ rdfList.add(new PlainLiteralImpl("bar"))
+ mGraph.add(new TripleImpl(johnUri, SKOS.related, listUri))
+ val litEn = new PlainLiteralImpl("hello",
+ new Language("en"))
+ val litFr = new PlainLiteralImpl("satul",
+ new Language("fr"))
+ mGraph.add(new TripleImpl(greetingsUri, RDF.value, litEn))
+ mGraph.add(new TripleImpl(greetingsUri, RDF.value, litFr))
+ node = new GraphNode(johnUri, mGraph)
+ }
+
+ @Test
+ def testBaseGraph {
+ val preamble = new Preamble(mGraph)
+ import preamble._
+ def asGn(gn: GraphNode) = gn
+ val johnUriNode = asGn(johnUri)
+ Assert.assertEquals(johnUriNode, node)
+ }
+
+ @Test
+ def testSlash = {
+ val rNode = new RichGraphNode(node)
+ Assert.assertEquals(new PlainLiteralImpl("johny"), (rNode/FOAF.nick)(0).getNode)
+ Assert.assertEquals(2, (rNode/FOAF.name).length(20))
+ val stringNames = (for(name <- (rNode/FOAF.name).iterator) yield {
+ name.toString
+ }).toList
+ Assert.assertTrue(stringNames.contains("\"Johnathan Guller\""))
+ Assert.assertTrue(stringNames.contains("\"John\""))
+ }
+
+ @Test
+ def testIterate = {
+ val simple: MGraph = new SimpleMGraph();
+ val node = new GraphNode(new BNode(), simple);
+ node.addProperty(DCTERMS.provenance, new UriRef("http://example.org/foo"));
+ node.addProperty(DCTERMS.language, new UriRef("http://www.bluewin.ch/"));
+ simple.add(new TripleImpl(new UriRef("http://www.bluewin.ch/"),RDF.`type`, RDFS.Container));
+ node.addProperty(RDF.`type`, PLATFORM.HeadedPage);
+ node.addProperty(RDF.`type`, RDFS.Class);
+ val test: CollectedIter[RichGraphNode] = node/DCTERMS.language/RDF.`type`;
+ Assert.assertEquals(1, test.length)
+ var counter = 0;
+ for(k <- test) { counter = counter + 1 }
+ Assert.assertEquals(1, counter)
+ }
+
+ @Test
+ def testInverse = {
+ val rNode = new RichGraphNode(node)
+ Assert.assertEquals(1, (rNode/-FOAF.knows).length)
+ }
+
+ @Test
+ def testMissingProperty = {
+ val rNode = new RichGraphNode(node)
+ Assert.assertEquals(0, (rNode/FOAF.thumbnail).length)
+ Assert.assertEquals("", rNode/FOAF.thumbnail*)
+
+ }
+
+ @Test
+ def testInverseImplicit = {
+ Assert.assertEquals(1, (node/-FOAF.knows).length)
+ }
+
+ @Test
+ def testPath = {
+ Assert.assertEquals(1, (node/-FOAF.knows).length)
+ Assert.assertEquals(new PlainLiteralImpl("Susanne"), node/-FOAF.knows%0/FOAF.name%0!)
+ Assert.assertEquals(new PlainLiteralImpl("Susanne"), ((node/-FOAF.knows)(0)/FOAF.name)(0)!)
+ Assert.assertEquals(new PlainLiteralImpl("Susanne"), node/-FOAF.knows/FOAF.name!)
+ Assert.assertEquals(new PlainLiteralImpl("Bill"), node/FOAF.knows/FOAF.nick!)
+ Assert.assertEquals("Bill", (node/FOAF.knows/FOAF.nick)(0)*)
+ Assert.assertEquals("Bill", node/FOAF.knows/FOAF.nick*)
+ }
+
+ @Test
+ def testLists = {
+ Assert.assertEquals(new PlainLiteralImpl("foo"),(node/SKOS.related).asList().get(1))
+ Assert.assertEquals(new PlainLiteralImpl("foo"), (node/SKOS.related%0!!)(1)!)
+ Assert.assertEquals(new PlainLiteralImpl("foo"),
+ (for (value <- node/SKOS.related%0!!) yield value!).toList(1))
+ Assert.assertEquals(new PlainLiteralImpl("bar"),
+ (for (value <- node/SKOS.related%0!!) yield value!).toList(2))
+ Assert.assertEquals(new PlainLiteralImpl("foo"), node/SKOS.related%0%!!1!)
+ }
+
+ @Test
+ def sortProperties = {
+ Assert.assertEquals(new PlainLiteralImpl("bar"), (node/SKOS.related%0!!).sortWith((a,b) => ((a*) < (b*)))(0)!)
+ Assert.assertEquals(johnUri, (node/SKOS.related%0!!).sortWith((a,b) => ((a*) > (b*)))(0)!)
+ }
+
+ @Test
+ def literalAsObject = {
+ val dateLiteral = new TypedLiteralImpl("2009-01-01T01:33:58Z",
+ new UriRef("http://www.w3.org/2001/XMLSchema#dateTime"))
+ val node = new GraphNode(dateLiteral, new SimpleMGraph())
+ Assert.assertNotNull(node.as[java.util.Date])
+ }
+
+ @Test
+ def literalLanguage = {
+ node = new GraphNode(greetingsUri, mGraph)
+ val lang = new Language("en")
+ val enValue = (node/RDF.value).find(l=>(l!).asInstanceOf[PlainLiteral].getLanguage == lang).get
+ Assert.assertEquals("hello", enValue*)
+ }
+
+}
Added: incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala?rev=1141564&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-bblfish/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala Thu Jun 30 15:07:17 2011
@@ -0,0 +1,74 @@
+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
+ * 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.
+ */
+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 {
+
+ private val literalFactory = LiteralFactory.getInstance()
+
+ import Preamble._
+
+ @Test
+ 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 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)
+ }*/
+
+ @Test
+ def useStringWithLanguageTag {
+ 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
+ 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)
+ }
+
+}
Modified: 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/EzGraph.scala?rev=1141564&r1=1141554&r2=1141564&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/EzGraph.scala Thu Jun 30 15:07:17 2011
@@ -77,8 +77,9 @@ class EzLiteral(lexicalForm: String) ext
/**
* @return a plain literal with language specified by lang
*/
- def lang(lang: Lang) = new PlainLiteralImpl(lexicalForm, lang)
- def lang(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new Language(lang.name)) //todo lookup in LangId instead
+ def lang(lang: String) = new PlainLiteralImpl(lexicalForm, new Language(lang))
+ def lang(lang: Language) = new PlainLiteralImpl(lexicalForm, lang)
+ def lang(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new Language(lang.name))
/**
* Map to a Typed Literal of given type
Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.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/Preamble.scala?rev=1141564&r1=1141554&r2=1141564&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala Thu Jun 30 15:07:17 2011
@@ -124,14 +124,23 @@ protected object TcIndependentConversion
*/
class LiteralBuilder(val lexicalForm: String) {
- /**
+ /**
* 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)
+ def lang(lang: Language) = new PlainLiteralImpl(lexicalForm, lang)
+
+ /**
+ * Produces a PlainLiteral with the wrapped String as lexical form
+ * and a given language
+ *
+ * @param lang a sthe language tag of the literal to be created as String
+ * @return a plain literal with the specified language
+ */
+ def lang(lang: String) = new PlainLiteralImpl(lexicalForm, new Language(lang))
/**
* Produces a PlainLiteral with the wrapped String as lexical form
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=1141564&r1=1141554&r2=1141564&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 Thu Jun 30 15:07:17 2011
@@ -119,10 +119,9 @@ class EzGraphTest {
val ez = EzGraph()
import org.apache.clerezza.rdf.scala.utils.EzGraph._
- import org.apache.clerezza.rdf.scala.utils.Lang._
import org.apache.clerezza.rdf.scala.utils.EzStyleChoice.unicode
( ez.u(retoUri) â FOAF.Person
- â todoRef â¶ List[Resource]("SPARQL update support".lang(en),"XSPARQL support".lang(en),holiday.uri))
+ â todoRef â¶ List[Resource]("SPARQL update support".lang('en),"XSPARQL support".lang('en),holiday.uri))
Assert.assertEquals("the two graphs should be of same size",gr.size(),ez.graph.size())
Assert.assertEquals("Both graphs should contain exactly the same triples",gr.getGraph,new SimpleGraph(ez.graph)) //mutable graphs cannot be compared for equality
@@ -155,16 +154,15 @@ class EzGraphTest {
@Test
def langEquals {
import org.apache.clerezza.rdf.scala.utils.EzGraph._
- import org.apache.clerezza.rdf.scala.utils.Lang._
val lit = new PlainLiteralImpl("SPARQL update support",new Language("en"))
- val lit2 = "SPARQL update support".lang(en)
+ val lit2 = "SPARQL update support".lang('en)
Assert.assertEquals("the two literals should be equsl",lit.hashCode(),lit2.hashCode())
Assert.assertEquals("the two literals should be equsl",lit,lit2)
val lit3 = new PlainLiteralImpl("Reto Bachman-Gmür",new Language("rm"))
- val lit4 = "Reto Bachman-Gmür".lang(rm)
+ val lit4 = "Reto Bachman-Gmür".lang('rm)
Assert.assertEquals("the two lang literals should have same hash",lit3.hashCode(),lit4.hashCode())
Assert.assertEquals("the two lang literals should be equal",lit3,lit4)
@@ -225,13 +223,12 @@ class EzGraphTest {
@Test
def usingSymbolicArrows {
import org.apache.clerezza.rdf.scala.utils.EzGraph._
- import org.apache.clerezza.rdf.scala.utils.Lang._
val ez = EzGraph()
import EzStyleChoice.unicode //in IntelliJ this is needed for the moment to remove the red lines
// example using arrows
(
ez.b_("reto") â FOAF.Person
- â FOAF.name â¶ "Reto Bachman-Gmür".lang(rm)
+ â FOAF.name â¶ "Reto Bachman-Gmür".lang('rm)
â FOAF.title â¶ "Mr"
â FOAF.currentProject â¶ "http://clerezza.org/".uri
â FOAF.knows â¶ (
@@ -247,7 +244,7 @@ class EzGraphTest {
)
â FOAF.knows â¶ (
ez.b_("danny") â FOAF.Person
- â FOAF.name â¶ "Danny Ayers".lang(en)
+ â FOAF.name â¶ "Danny Ayers".lang('en)
â FOAF.knows â¶ "http://bblfish.net/#hjs".uri //knows
â FOAF.knows â¶ ez.b_("reto")
)
@@ -261,13 +258,12 @@ class EzGraphTest {
@Test
def usingAsciiArrows {
import org.apache.clerezza.rdf.scala.utils.EzGraph._
- import org.apache.clerezza.rdf.scala.utils.Lang._
import EzStyleChoice.arrow
val ez = EzGraph()
// example using arrows
(
ez.b_("reto").a(FOAF.Person)
- -- FOAF.name --> "Reto Bachman-Gmür".lang(rm)
+ -- FOAF.name --> "Reto Bachman-Gmür".lang('rm)
-- FOAF.title --> "Mr"
-- FOAF.currentProject --> "http://clerezza.org/".uri
-- FOAF.knows --> (
@@ -282,7 +278,7 @@ class EzGraphTest {
-- FOAF.knows -->> List(ez.b_("reto").ref,ez.b_("danny").ref)
)
-- FOAF.knows --> (ez.b_("danny").a(FOAF.Person)
- -- FOAF.name --> "Danny Ayers".lang(en)
+ -- FOAF.name --> "Danny Ayers".lang('en)
-- FOAF.knows --> "http://bblfish.net/#hjs".uri //knows
-- FOAF.knows --> ez.b_("reto")
)
@@ -298,14 +294,13 @@ class EzGraphTest {
@Test
def usingWordOperators {
import org.apache.clerezza.rdf.scala.utils.EzGraph._
- import org.apache.clerezza.rdf.scala.utils.Lang._
import EzStyleChoice.english
val ez = EzGraph()
// example using arrows
(
ez.b_("reto").asInstanceOf[EzGraphNodeEn] a FOAF.Person
- has FOAF.name to "Reto Bachman-Gmür".lang(rm)
+ has FOAF.name to "Reto Bachman-Gmür".lang('rm)
has FOAF.title to "Mr"
has FOAF.currentProject to "http://clerezza.org/".uri
has FOAF.knows to (
@@ -320,7 +315,7 @@ class EzGraphTest {
has FOAF.knows toEach List(ez.b_("reto").ref,ez.b_("danny").ref)
)
has FOAF.knows to ( ez.b_("danny") a FOAF.Person
- has FOAF.name to "Danny Ayers".lang(en)
+ has FOAF.name to "Danny Ayers".lang('en)
has FOAF.knows to "http://bblfish.net/#hjs".uri //knows
has FOAF.knows to ez.b_("reto")
)
Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.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/TypeConversionTest.scala?rev=1141564&r1=1141554&r2=1141564&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala Thu Jun 30 15:07:17 2011
@@ -43,9 +43,8 @@ class TypeConversionTest {
@Test
def useStringWithLanguageTag {
- 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 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)