--- a/src/main/scala/Main.scala Tue Jun 08 16:58:32 2010 -0400
+++ b/src/main/scala/Main.scala Sun Sep 26 07:12:51 2010 -0400
@@ -2,37 +2,6 @@
import scala.collection.Set
-// RDF node types
-object RDF {
- type RDFGraph = Set[Triple]
- 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 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
object SQL {
@@ -42,11 +11,12 @@
def keySet () = types.keySet
}
- type Body = Set[Tuple]
type PrimaryKey = List[AttrName]
type ForeignKeys = Map[AttrName, Target]
case class Target(rel:RelName, attr:AttrName)
+ type Body = Set[Tuple]
+
abstract class CellValue
case class LexicalValue (s:String) extends CellValue
case class ☹ () extends CellValue
@@ -70,6 +40,37 @@
}
+// RDF node types
+object RDF {
+ type RDFGraph = Set[Triple]
+ case class Triple (s:Subject, p:IRI, o:Object)
+
+ sealed abstract class Subject
+ case class SubjectIRI(i:IRI) extends Subject
+ implicit def iri2subjectiri(i:IRI):Subject = SubjectIRI(i)
+ case class SubjectBNode(b:BNode) extends Subject
+ implicit def bnode2subjectbnode(b:BNode):Subject = SubjectBNode(b)
+
+ sealed abstract class Predicate
+ case class PredicateIRI(i:IRI) extends Predicate
+ implicit def iri2predicateiri(i:IRI):Predicate = PredicateIRI(i)
+
+ sealed abstract class Object
+ case class ObjectIRI(i:IRI) extends Object
+ implicit def iri2objectiri(i:IRI):Object = ObjectIRI(i)
+ case class ObjectBNode(b:BNode) extends Object
+ implicit def bnode2objectbnode(b:BNode):Object = ObjectBNode(b)
+ case class ObjectTypedLiteral (l:TypedLiteral) extends Object
+ implicit def literal2objectliteral(l:TypedLiteral):Object = ObjectTypedLiteral(l)
+
+ case class IRI(iri:String)
+ case class BNode(label:String)
+ case class TypedLiteral(value:String, datatype:IRI)
+
+
+
+}
+
object Transformer {
import RDF._
@@ -107,7 +108,7 @@
def scalartriples (u:StemIRI, rn:RelName, s:IRI, a:AttrName, h:Header, t:Tuple) : Triple = {
val p = predicatemap (u, rn, a)
val l = t(a).asInstanceOf[LexicalValue]
- val o = ObjectLiteral(literalmap(l, sqlDatatype(h, a)))
+ val o = ObjectTypedLiteral(literalmap(l, sqlDatatype(h, a)))
Triple(s, p, o)
}
def referencetriples (u:StemIRI, rn:RelName, s:IRI, a:AttrName, h:Header, t:Tuple) : Triple = {
@@ -129,7 +130,7 @@
def cellmap (u:StemIRI, rn:RelName, h:Header, a:AttrName, s:IRI, t:Tuple) : Option[Triple] = {
def hasForeignKeys(a:AttrName):Boolean = h.fks.get(a).isDefined
lexvalue(h, t, a) match {
- case _ if h.pk contains a => None
+ // case _ if h.pk contains a => None
case ☹() => None
case l:LexicalValue if hasForeignKeys(a) => {
val target = h.fks(a)
@@ -139,7 +140,7 @@
}
case l:LexicalValue => {
val p = predicatemap (u, rn, a)
- val o = ObjectLiteral(literalmap(l, sqlDatatype(h, a)))
+ val o = ObjectTypedLiteral(literalmap(l, sqlDatatype(h, a)))
Some(Triple(s, p, o))
}
}
@@ -157,8 +158,8 @@
case SQLInt() => IRI("http://www.w3.org/2001/XMLSchema#int")
}
- def literalmap (l:LexicalValue, d:SQLDatatype) : Literal =
- Literal(l.s, XSD(d))
+ def literalmap (l:LexicalValue, d:SQLDatatype) : TypedLiteral =
+ TypedLiteral(l.s, XSD(d))
}
--- a/src/test/scala/Test.scala Tue Jun 08 16:58:32 2010 -0400
+++ b/src/test/scala/Test.scala Sun Sep 26 07:12:51 2010 -0400
@@ -38,15 +38,15 @@
val expected:RDFGraph =
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#ID"),TypedLiteral("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"),TypedLiteral("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"),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"))),
+ Triple(IRI("http://foo.example/DB/People/ID.8#_"),IRI("http://foo.example/DB/People#ID"),TypedLiteral("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"),TypedLiteral("Sue",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-/* Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#ID"),Literal("18",IRI("http://www.w3.org/2001/XMLSchema#int"))), */
- Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#city"),Literal("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
- Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#state"),Literal("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
+ Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+ Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+ Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
)
assert (expected === g)
}
@@ -71,10 +71,10 @@
val expected:RDFGraph =
Set(
-/* Triple(IRI("http://foo.example/DB/Employees/ID.1#_"),IRI("http://foo.example/DB/Employees#ID"),Literal("1",IRI("http://www.w3.org/2001/XMLSchema#int"))), */
- Triple(IRI("http://foo.example/DB/Employees/ID.1#_"),IRI("http://foo.example/DB/Employees#fname"),Literal("Alice",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-/* Triple(IRI("http://foo.example/DB/Employees/ID.2#_"),IRI("http://foo.example/DB/Employees#ID"),Literal("2",IRI("http://www.w3.org/2001/XMLSchema#int"))), */
- Triple(IRI("http://foo.example/DB/Employees/ID.2#_"),IRI("http://foo.example/DB/Employees#fname"),Literal("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+ Triple(IRI("http://foo.example/DB/Employees/ID.1#_"),IRI("http://foo.example/DB/Employees#ID"),TypedLiteral("1",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+ Triple(IRI("http://foo.example/DB/Employees/ID.1#_"),IRI("http://foo.example/DB/Employees#fname"),TypedLiteral("Alice",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+ Triple(IRI("http://foo.example/DB/Employees/ID.2#_"),IRI("http://foo.example/DB/Employees#ID"),TypedLiteral("2",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+ Triple(IRI("http://foo.example/DB/Employees/ID.2#_"),IRI("http://foo.example/DB/Employees#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
Triple(IRI("http://foo.example/DB/Employees/ID.2#_"),IRI("http://foo.example/DB/Employees#boss"),IRI("http://foo.example/DB/Employees/ID.1#_"))
)
assert (expected === g)