+ files from FeDeRate
authorAlexandre Bertails <bertails@gmail.com>
Sun, 08 Jan 2012 15:36:45 -0500
changeset 2 24c7e2084525
parent 1 182175c0d212
child 3 0b441c4a28ac
+ files from FeDeRate
aRDF/src/main/scala/Isomorphic.scala
aRDF/src/main/scala/Model.scala
aRDF/src/main/scala/ScalaModel.scala
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/src/main/scala/Isomorphic.scala	Sun Jan 08 15:36:45 2012 -0500
@@ -0,0 +1,31 @@
+package org.w3.isomorphic
+
+trait PatternMatching0[R] {
+  def unapply(r: R): Boolean
+}
+
+trait Isomorphic0[R] extends Function0[R] with PatternMatching0[R]
+
+trait PatternMatching1[T, R] {
+  def unapply(r: R): Option[T]
+}
+
+trait Isomorphic1[T, R] extends Function1[T, R] with PatternMatching1[T, R]
+
+trait PatternMatching2[T1, T2, R] {
+  def unapply(r: R): Option[(T1, T2)]
+}
+
+/**
+ * basically, you have to implement both following functions
+ *   def apply(t1:T1, t2:T2):R
+ *   def unapply(r:R):Option[(T1, T2)]
+ */
+trait Isomorphic2[T1, T2, R] extends Function2[T1, T2, R] with PatternMatching2[T1, T2, R]
+
+trait PatternMatching3[T1, T2, T3, R] {
+  def unapply(r: R): Option[(T1, T2, T3)]
+}
+
+trait Isomorphic3[T1, T2, T3, R] extends Function3[T1, T2, T3, R] with PatternMatching3[T1, T2, T3, R]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/src/main/scala/Model.scala	Sun Jan 08 15:36:45 2012 -0500
@@ -0,0 +1,67 @@
+package org.w3.rdf
+
+import org.w3.isomorphic._
+
+trait Model {
+
+  type IRI
+  trait GraphLike extends Iterable[Triple] { self =>
+    def ++(other:Graph):Graph
+  }
+  type Graph <: GraphLike
+  type Triple
+  type BNode
+  type Node
+  type NodeIRI <: Node
+  type NodeBNode <: Node
+  type Subject
+  type SubjectNode <: Subject
+  type Predicate
+  type PredicateIRI <: Predicate
+  type Object
+  type ObjectNode <: Object
+  type ObjectLiteral <: Object
+  type Literal
+  type PlainLiteral <: Literal
+  type TypedLiteral <: Literal
+  type LangTag
+
+  val IRI : Isomorphic1[String, IRI]
+
+  trait GraphObject {
+    def empty:Graph
+    def apply(elems:Triple*):Graph
+    def apply(it:Iterable[Triple]):Graph
+  }
+  val Graph : GraphObject
+
+  val Triple : Isomorphic3[Subject, Predicate, Object, Triple]
+
+  val BNode : Isomorphic1[String, BNode]
+
+  val NodeIRI   : Isomorphic1[IRI, NodeIRI]
+  val NodeBNode : Isomorphic1[BNode, NodeBNode]
+
+  val SubjectNode : Isomorphic1[Node, SubjectNode]
+
+  val PredicateIRI : Isomorphic1[IRI, PredicateIRI]
+
+  val ObjectNode    : Isomorphic1[Node, ObjectNode]
+  val ObjectLiteral : Isomorphic1[Literal, ObjectLiteral]
+
+  val PlainLiteral : Isomorphic2[String, Option[LangTag], PlainLiteral]
+  val TypedLiteral : Isomorphic2[String, IRI, TypedLiteral]
+
+  val LangTag : Isomorphic1[String, LangTag]
+
+  // val StringDatatype = IRI("http://www.w3.org/2001/XMLSchema#string")
+  // val IntegerDatatype = IRI("http://www.w3.org/2001/XMLSchema#integer")
+  // val FloatDatatype = IRI("http://www.w3.org/2001/XMLSchema#float")
+  // val DateDatatype = IRI("http://www.w3.org/2001/XMLSchema#date")
+  // val DateTimeDatatype = IRI("http://www.w3.org/2001/XMLSchema#dateTime")
+
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/src/main/scala/ScalaModel.scala	Sun Jan 08 15:36:45 2012 -0500
@@ -0,0 +1,61 @@
+package org.w3.rdf
+
+import org.w3.isomorphic._
+
+trait ScalaModel extends Model {
+
+  case class IRI(iri:String) { override def toString = '"' + iri + '"' }
+  object IRI extends Isomorphic1[String, IRI]
+
+  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 = 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)
+  object Triple extends Isomorphic3[Subject, Predicate, Object, Triple]
+
+  case class BNode(label:String)
+  object BNode extends Isomorphic1[String, BNode]
+
+  sealed trait Node
+  case class NodeIRI(i:IRI) extends Node
+  object NodeIRI extends Isomorphic1[IRI, NodeIRI]
+  case class NodeBNode(b:BNode) extends Node
+  object NodeBNode extends Isomorphic1[BNode, NodeBNode]
+
+  sealed trait Subject
+  case class SubjectNode(n:Node) extends Subject
+  object SubjectNode extends Isomorphic1[Node, SubjectNode]
+
+  sealed trait Predicate
+  case class PredicateIRI(i:IRI) extends Predicate
+  object PredicateIRI extends Isomorphic1[IRI, PredicateIRI]
+
+  sealed trait Object
+  case class ObjectNode(n:Node) extends Object
+  object ObjectNode extends Isomorphic1[Node, ObjectNode]
+  case class ObjectLiteral (n:Literal) extends Object
+  object ObjectLiteral extends Isomorphic1[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 Isomorphic2[String, Option[LangTag], PlainLiteral]
+  case class TypedLiteral(override val lexicalForm:String, datatype:IRI) extends Literal(lexicalForm) {
+    override def toString = "\"" + lexicalForm + "\"^^" + datatype
+  }
+  object TypedLiteral extends Isomorphic2[String, IRI, TypedLiteral]
+
+  case class LangTag(s:String)
+  object LangTag extends Isomorphic1[String, LangTag]
+
+}
+
+object ScalaModel extends ScalaModel