changeset 9:98e06551a3c7

~ migrated to more conventional RDF model
author Eric Prud'hommeaux <eric@w3.org>
date Thu, 03 Jun 2010 19:31:14 -0400
parents cd394d9cfc8b
children 76e6d541cd7d
files src/main/scala/Main.scala src/test/scala/Test.scala
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Tue Jun 01 11:39:49 2010 -0400
+++ b/src/main/scala/Main.scala	Thu Jun 03 19:31:14 2010 -0400
@@ -5,15 +5,32 @@
 // RDF node types
 object RDF {
   type RDFGraph = Set[Triple]
-  case class Triple (s:IRI, p:IRI, o:RDFObject)
-  sealed abstract class RDFObject
-  case class IRIObject (i:IRI) extends RDFObject
-  case class LiteralObject (l:Literal) extends RDFObject
+  case class Triple (s:Subject, p:IRI, o:Object)
+
+  sealed abstract class Subject
+  case class SubjectIRI(i:IRI) extends Subject
+  case class SubjectBNode(b:BNode) extends Subject
+
+  sealed abstract class Predicate
+  case class PredicateIRI(i:IRI) extends Predicate
+
+  sealed abstract class Object
+  case class ObjectIRI(i:IRI) extends Object
+  case class ObjectBNode(b:BNode) extends Object
+  case class ObjectLiteral (l:Literal) extends Object
+
   case class IRI(iri:String)
+  case class BNode(label:String)
   case class Literal(value:String, datatype:IRI)
 
-  implicit def lit2object(l:Literal):RDFObject = LiteralObject(l)
-  implicit def iri2object(i:IRI):RDFObject = IRIObject(i)
+  implicit def iri2subjectiri(i:IRI):Subject = SubjectIRI(i)
+  implicit def bnode2subjectbnode(b:BNode):Subject = SubjectBNode(b)
+
+  implicit def iri2predicateiri(i:IRI):Predicate = PredicateIRI(i)
+
+  implicit def iri2objectiri(i:IRI):Object = ObjectIRI(i)
+  implicit def bnode2objectbnode(b:BNode):Object = ObjectBNode(b)
+  implicit def literal2objectliteral(l:Literal):Object = ObjectLiteral(l)
 }
 
 // Relational structure
@@ -78,8 +95,8 @@
       case l:LexicalValue => {
 	val p = predicatemap (u, r, a)
 	val o = linktype(h, a) match {
-  	  case Fk(r2, a2) => IRIObject(nodemap(u, r2, a2, l))
-	  case _ => LiteralObject(literalmap(l, sqlDatatype(h, a)))
+  	  case Fk(r2, a2) => ObjectIRI(nodemap(u, r2, a2, l))
+	  case _ => ObjectLiteral(literalmap(l, sqlDatatype(h, a)))
 	}
 	Some(Triple(s, p, o))
       }
--- a/src/test/scala/Test.scala	Tue Jun 01 11:39:49 2010 -0400
+++ b/src/test/scala/Test.scala	Thu Jun 03 19:31:14 2010 -0400
@@ -32,7 +32,7 @@
       Set(
 	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#ID"),Literal("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
 	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#fname"),Literal("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#addr"),IRIObject(IRI("http://foo.example/DB/Addresses/ID.18#_"))),
+	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#addr"),IRI("http://foo.example/DB/Addresses/ID.18#_")),
 	Triple(IRI("http://foo.example/DB/People/ID.8#_"),IRI("http://foo.example/DB/People#ID"),Literal("8",IRI("http://www.w3.org/2001/XMLSchema#int"))),
 	Triple(IRI("http://foo.example/DB/People/ID.8#_"),IRI("http://foo.example/DB/People#fname"),Literal("Sue",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
 
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.