--- a/project/build/RDB2RDF.scala Wed Dec 29 19:02:27 2010 -0500
+++ b/project/build/RDB2RDF.scala Wed Dec 29 19:03:39 2010 -0500
@@ -15,7 +15,7 @@
lazy val algebraicpattern = project("algebraicpattern", "algebraicpattern", new AlgebraicPattern(_))
lazy val rdb = project("rdb", "rdb", new RDB(_))
lazy val sql = project("sql", "sql", new SQL(_), rdb)
- lazy val rdf = project("rdf", "rdf", new RDF(_))
+ lazy val rdf = project("rdf", "rdf", new RDF(_), algebraicpattern)
lazy val rdfdsl = project("rdfdsl", "rdfdsl", new RDFDSL(_), rdf)
lazy val turtle = project("turtle", "turtle", new Turtle(_), rdf)
lazy val rdfxml = project("rdfxml", "rdfxml", new RDFXML(_), rdf)
--- a/rdf/src/main/scala/RDF.scala Wed Dec 29 19:02:27 2010 -0500
+++ b/rdf/src/main/scala/RDF.scala Wed Dec 29 19:03:39 2010 -0500
@@ -1,8 +1,144 @@
package org.w3.sw
+trait RDFModel {
+
+ import org.w3.algebraic._
+
+ type IRI
+ val IRI : Algebraic1[String, IRI]
+
+ // it should actually be an Ordered Set
+ type Graph <: Traversable[Triple]
+ val Graph : {
+ def empty:Graph
+ def apply(elems:Triple*):Graph
+ def apply(it:Iterable[Triple]):Graph
+ }
+
+ type Triple
+ val Triple : Algebraic3[Subject, Predicate, Object, Triple]
+
+ type BNode
+ val BNode : Algebraic1[String, BNode]
+
+ // sealed type Node: NodeIRI NodeBNode
+ type Node
+ type NodeIRI <: Node
+ type NodeBNode <: Node
+ val NodeIRI : Algebraic1[IRI, NodeIRI]
+ val NodeBNode : Algebraic1[BNode, NodeBNode]
+
+ type Subject
+ type SubjectNode <: Subject
+ val SubjectNode : Algebraic1[Node, SubjectNode]
+
+ type Predicate
+ type PredicateIRI <: Predicate
+ val PredicateIRI : Algebraic1[IRI, PredicateIRI]
+
+ type Object
+ type ObjectNode <: Object
+ type ObjectLiteral <: Object
+ val ObjectNode : Algebraic1[Node, ObjectNode]
+ val ObjectLiteral : Algebraic1[Literal, ObjectLiteral]
+
+ // val lexicalForm:String
+ type Literal
+ type PlainLiteral <: Literal
+ type TypedLiteral <: Literal
+ val PlainLiteral : Algebraic2[String, Option[LangTag], PlainLiteral]
+ val TypedLiteral : Algebraic2[String, IRI, TypedLiteral]
+
+ type LangTag
+ val LangTag : Algebraic1[String, LangTag]
+
+ val StringDatatype = IRI("http://www.w3.org/2001/XMLSchema#string")
+ val IntegerDatatype = IRI("http://www.w3.org/2001/XMLSchema#integer")
+ val DateDatatype = IRI("http://www.w3.org/2001/XMLSchema#date")
+ val DateTimeDatatype = IRI("http://www.w3.org/2001/XMLSchema#dateTime")
+
+}
+
+trait RDFImplicits extends RDFModel {
+
+ implicit def iri2nodeiri(i:IRI):Node = NodeIRI(i)
+ implicit def bnode2nodebnode(b:BNode):Node = NodeBNode(b)
+ implicit def node2subjectnode(n:Node):Subject = SubjectNode(n)
+ implicit def iri2subjectnode(i:IRI):Subject = SubjectNode(i)
+ implicit def bnode2subjectnode(b:BNode):Subject = SubjectNode(b)
+ implicit def iri2predicateiri(i:IRI):Predicate = PredicateIRI(i)
+ implicit def node2objectnode(n:Node):Object = ObjectNode(n)
+ implicit def iri2objectnode(i:IRI):Object = ObjectNode(i)
+ implicit def bnode2objectnode(b:BNode):Object = ObjectNode(b)
+ implicit def typed2object(i:TypedLiteral):Object = ObjectLiteral(i)
+ implicit def plain2object(b:PlainLiteral):Object = ObjectLiteral(b)
+}
+
+trait RDF extends RDFModel {
+
+ import org.w3.algebraic._
+
+ case class IRI(iri:String) { override def toString = '"' + iri + '"' }
+ object IRI extends Algebraic1[String, IRI]
+
+ type Graph = Set[Triple]
+ val Graph = new Object {
+ def empty:Graph = Set[Triple]()
+ def apply(elems:Triple*):Graph = Set[Triple](elems:_*)
+ def apply(it:Iterable[Triple]):Graph = it.toSet
+ }
+
+ case class Triple (s:Subject, p:Predicate, o:Object)
+ object Triple extends Algebraic3[Subject, Predicate, Object, Triple]
+
+ case class BNode(label:String)
+ object BNode extends Algebraic1[String, BNode]
+
+ sealed trait Node
+ case class NodeIRI(i:IRI) extends Node
+ object NodeIRI extends Algebraic1[IRI, NodeIRI]
+ case class NodeBNode(b:BNode) extends Node
+ object NodeBNode extends Algebraic1[BNode, NodeBNode]
+
+ sealed trait Subject
+ case class SubjectNode(n:Node) extends Subject
+ object SubjectNode extends Algebraic1[Node, SubjectNode]
+
+ sealed trait Predicate
+ case class PredicateIRI(i:IRI) extends Predicate
+ object PredicateIRI extends Algebraic1[IRI, PredicateIRI]
+
+ sealed trait Object
+ case class ObjectNode(n:Node) extends Object
+ object ObjectNode extends Algebraic1[Node, ObjectNode]
+ case class ObjectLiteral (n:Literal) extends Object
+ object ObjectLiteral extends Algebraic1[Literal, ObjectLiteral]
+
+ sealed abstract class Literal(val lexicalForm:String)
+ case class PlainLiteral(override val lexicalForm:String, langtag:Option[LangTag]) extends Literal(lexicalForm) {
+ override def toString = "\"" + lexicalForm + "\"" + { if (langtag.isDefined) langtag.get }
+ }
+ object PlainLiteral extends Algebraic2[String, Option[LangTag], PlainLiteral]
+ case class TypedLiteral(override val lexicalForm:String, datatype:IRI) extends Literal(lexicalForm) {
+ override def toString = "\"" + lexicalForm + "\"^^" + datatype
+ }
+ object TypedLiteral extends Algebraic2[String, IRI, TypedLiteral]
+
+ case class LangTag(s:String)
+ object LangTag extends Algebraic1[String, LangTag]
+
+}
+
+
+
object rdf {
-type Graph = Set[Triple]
+ case class Graph(triples:Set[Triple])
+ object Graph {
+ 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)