--- a/aRDF/src/main/scala/GraphIsomorphism.scala Sun Jan 22 17:16:56 2012 -0500
+++ b/aRDF/src/main/scala/GraphIsomorphism.scala Sun Jan 22 18:52:57 2012 -0500
@@ -1,19 +1,7 @@
package org.w3.rdf
-
-
-abstract class GraphIsomorphism[M <: Model](m: M) {
+abstract class GraphIsomorphism[M <: Model] {
def isIsomorphicWith(g1: M#Graph, g2: M#Graph): Boolean
}
-
-import org.w3.rdf.jena._
-
-object GraphIsomorphismForJenaModel extends GraphIsomorphism[JenaModel](JenaModel) {
-
- def isIsomorphicWith(g1: JenaModel#Graph, g2: JenaModel#Graph): Boolean =
- g1.jenaGraph isIsomorphicWith g2.jenaGraph
-
-
-}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/src/main/scala/GraphIsomorphismForJenaModel.scala Sun Jan 22 18:52:57 2012 -0500
@@ -0,0 +1,12 @@
+package org.w3.rdf
+
+import org.w3.rdf.Modules.JenaModel
+import org.w3.rdf.jena._
+
+trait GraphIsomorphismForJenaModel extends GraphIsomorphism[JenaModel] {
+
+ def isIsomorphicWith(g1: JenaModel#Graph, g2: JenaModel#Graph): Boolean =
+ g1.jenaGraph isIsomorphicWith g2.jenaGraph
+
+
+}
\ No newline at end of file
--- a/aRDF/src/main/scala/JenaModel.scala Sun Jan 22 17:16:56 2012 -0500
+++ b/aRDF/src/main/scala/JenaModel.scala Sun Jan 22 18:52:57 2012 -0500
@@ -12,7 +12,7 @@
case class IRI(iri:String) { override def toString = '"' + iri + '"' }
object IRI extends Isomorphic1[String, IRI]
- class Graph(val jenaGraph:JenaGraph) extends GraphLike {
+ class Graph(val jenaGraph: JenaGraph) extends GraphLike {
def iterator:Iterator[Triple] = new Iterator[Triple] {
val iterator = jenaGraph.find(JenaNode.ANY, JenaNode.ANY, JenaNode.ANY)
def hasNext = iterator.hasNext
@@ -37,6 +37,7 @@
}
object Graph extends GraphObject {
+ def fromJena(jenaGraph: JenaGraph): Graph = new Graph(jenaGraph)
def empty:Graph = new Graph(Factory.createDefaultGraph)
def apply(elems:Triple*):Graph = apply(elems.toIterable)
def apply(it:Iterable[Triple]):Graph = {
@@ -122,5 +123,3 @@
object LangTag extends Isomorphic1[String, LangTag]
}
-
-object JenaModel extends JenaModel
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/src/main/scala/Modules.scala Sun Jan 22 18:52:57 2012 -0500
@@ -0,0 +1,23 @@
+package org.w3.rdf.Modules
+
+import org.w3.rdf.jena._
+import org.w3.rdf._
+
+object ScalaModel extends ScalaModel
+
+object JenaModel extends JenaModel
+
+object ScalaToJena extends Transformer[ScalaModel, JenaModel](ScalaModel, JenaModel)
+
+object JenaToScala extends Transformer[JenaModel, ScalaModel](JenaModel, ScalaModel)
+
+object GraphIsomorphismForJenaModel extends GraphIsomorphismForJenaModel
+
+
+
+
+object PimpMyRDF {
+
+ // TODO
+
+}
\ No newline at end of file
--- a/aRDF/src/main/scala/Transformer.scala Sun Jan 22 17:16:56 2012 -0500
+++ b/aRDF/src/main/scala/Transformer.scala Sun Jan 22 18:52:57 2012 -0500
@@ -7,7 +7,7 @@
class Transformer[ModelA <: Model, ModelB <: Model](val a: ModelA, val b: ModelB) {
- def transform(graph: ModelA#Graph): b.Graph =
+ def transform(graph: ModelA#Graph): ModelB#Graph =
b.Graph(graph map (transformTriple _))
def transformTriple(t: ModelA#Triple): b.Triple = {
@@ -15,7 +15,7 @@
b.Triple(transformSubject(s), transformPredicate(p), transformObject(o))
}
- def transformIRI(iri: ModelA#IRI): b.IRI = {
+ def transformIRI(iri: a.IRI): b.IRI = {
val a.IRI(i) = iri
b.IRI(i)
}
@@ -60,8 +60,3 @@
}
-import org.w3.rdf.jena._
-
-object ScalaToJena extends Transformer[ScalaModel, JenaModel](ScalaModel, JenaModel)
-
-object JenaToScala extends Transformer[JenaModel, ScalaModel](JenaModel, ScalaModel)
--- a/aRDF/src/test/scala/ModelSpec.scala Sun Jan 22 17:16:56 2012 -0500
+++ b/aRDF/src/test/scala/ModelSpec.scala Sun Jan 22 18:52:57 2012 -0500
@@ -7,26 +7,27 @@
import com.hp.hpl.jena.rdf.model._
import com.hp.hpl.jena.graph._
import org.w3.rdf.jena._
+import org.w3.rdf.Modules._
class ModelSpec {
@Test()
def mytest(): Unit = {
-
val model = ModelFactory.createDefaultModel()
model.getReader("TURTLE").read(model, new FileReader("src/test/resources/card.ttl"), "http://www.w3.org/People/Berners-Lee/card")
- val jenaGraph = new JenaModel.Graph(model.getGraph)
+ val jenaGraph: JenaModel#Graph = JenaModel.Graph.fromJena(model.getGraph)
// println(jenaGraph)
val scalaGraph: ScalaModel#Graph = JenaToScala.transform(jenaGraph)
- val jenaGraphAgain = ScalaToJena.transform(scalaGraph)
+ val jenaGraphAgain: JenaModel#Graph = ScalaToJena.transform(scalaGraph)
// println(jenaGraphAgain)
- assertTrue(jenaGraph.jenaGraph isIsomorphicWith jenaGraphAgain.jenaGraph)
+ // assertTrue(jenaGraph.jenaGraph isIsomorphicWith jenaGraphAgain.jenaGraph)
+ assertTrue(GraphIsomorphismForJenaModel.isIsomorphicWith(jenaGraph, jenaGraphAgain))
}