--- a/jena/src/main/scala/JenaModel.scala Mon Feb 14 14:38:46 2011 -0500
+++ b/jena/src/main/scala/JenaModel.scala Mon Feb 14 18:34:47 2011 -0500
@@ -23,13 +23,18 @@
case class IRI(iri:String) { override def toString = '"' + iri + '"' }
object IRI extends Isomorphic1[String, IRI]
- class Graph(val jenaGraph:JenaGraph) extends Iterable[Triple] {
+ 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
def next = iterator.next
}
+ def ++(other:Graph):Graph = new Graph(new com.hp.hpl.jena.graph.compose.Union(jenaGraph, other.jenaGraph))
+ // {
+ // for(triple <- other) jenaGraph add triple
+ // this
+ // }
override def equals(o:Any):Boolean = ( o.isInstanceOf[Graph] && jenaGraph.isIsomorphicWith(o.asInstanceOf[Graph].jenaGraph) )
}
--- a/rdf/src/main/scala/RDF.scala Mon Feb 14 14:38:46 2011 -0500
+++ b/rdf/src/main/scala/RDF.scala Mon Feb 14 18:34:47 2011 -0500
@@ -5,7 +5,10 @@
trait Model {
type IRI
- type Graph <: Iterable[Triple]
+ trait GraphLike extends Iterable[Triple] { self =>
+ def ++(other:Graph):Graph
+ }
+ type Graph <: GraphLike
type Triple
type BNode
type Node
@@ -80,11 +83,14 @@
case class IRI(iri:String) { override def toString = '"' + iri + '"' }
object IRI extends Isomorphic1[String, IRI]
- type Graph = Set[Triple]
+ case class Graph(triples:Set[Triple]) extends GraphLike {
+ def iterator = triples.iterator
+ def ++(other:Graph):Graph = Graph(triples ++ other.triples)
+ }
object Graph extends GraphObject {
- def empty:Graph = Set[Triple]()
- def apply(elems:Triple*):Graph = Set[Triple](elems:_*)
- def apply(it:Iterable[Triple]):Graph = it.toSet
+ def empty:Graph = Graph(Set[Triple]())
+ def apply(elems:Triple*):Graph = Graph(Set[Triple](elems:_*))
+ def apply(it:Iterable[Triple]):Graph = Graph(it.toSet)
}
case class Triple (s:Subject, p:Predicate, o:Object)