~ fixed Model to reflect changes from RDF 1.1 (see how Literal values are handled)
--- a/aRDF/src/main/scala/JenaModel.scala Sun Jan 08 16:40:05 2012 -0500
+++ b/aRDF/src/main/scala/JenaModel.scala Sun Jan 08 17:56:57 2012 -0500
@@ -110,28 +110,25 @@
if (node.isLiteral) Some(node.asInstanceOf[Node_Literal]) else None
}
+ lazy val mapper = TypeMapper.getInstance
type Literal = Node_Literal
- type PlainLiteral = Node_Literal
- object PlainLiteral extends Isomorphic2[String, Option[LangTag], PlainLiteral] {
- def apply(lit:String, langtagOption:Option[LangTag]) =
- langtagOption match {
- case Some(LangTag(langtag)) => JenaNode.createLiteral(lit, langtag, false).asInstanceOf[Node_Literal]
- case None => JenaNode.createLiteral(lit).asInstanceOf[Node_Literal]
- }
- def unapply(literal:PlainLiteral):Option[(String, Option[LangTag])] =
- tryopt { ( literal.getLiteralValue.toString, Option(LangTag(literal.getLiteralLanguage)) ) }
+ object Literal extends Isomorphic3[String, Option[LangTag], Option[IRI], Literal] {
+ def apply(lit: String, langtagOption: Option[LangTag], datatypeOption: Option[IRI]): Literal = {
+ JenaNode.createLiteral(
+ lit,
+ langtagOption.map{_.s}.getOrElse(null),
+ datatypeOption.map{i => mapper.getTypeByName(i.iri)}.getOrElse(null)
+ ).asInstanceOf[Literal]
+ }
+ def unapply(literal: Literal): Option[(String, Option[LangTag], Option[IRI])] = {
+ tryopt {(
+ literal.getLiteralValue.toString,
+ { val l = literal.getLiteralLanguage; if (l != "") Some(LangTag(l)) else None },
+ Option(literal.getLiteralDatatype).map{typ => IRI(typ.getURI)}
+ )}
+ }
}
- type TypedLiteral = Node_Literal
- lazy val mapper = TypeMapper.getInstance
- object TypedLiteral extends Isomorphic2[String, IRI, TypedLiteral] {
- def apply(lit:String, iri:IRI):TypedLiteral = {
- val IRI(typ) = iri
- JenaNode.createLiteral(lit, null, mapper.getTypeByName(typ)).asInstanceOf[Node_Literal]
- }
- def unapply(literal:TypedLiteral):Option[(String, IRI)] =
- tryopt((literal.getLiteralValue.toString, IRI(literal.getLiteralDatatype.getURI)))
- }
-
+
case class LangTag(s:String)
object LangTag extends Isomorphic1[String, LangTag]
--- a/aRDF/src/main/scala/Model.scala Sun Jan 08 16:40:05 2012 -0500
+++ b/aRDF/src/main/scala/Model.scala Sun Jan 08 17:56:57 2012 -0500
@@ -22,8 +22,6 @@
type ObjectNode <: Object
type ObjectLiteral <: Object
type Literal
- type PlainLiteral <: Literal
- type TypedLiteral <: Literal
type LangTag
val IRI : Isomorphic1[String, IRI]
@@ -49,9 +47,7 @@
val ObjectNode : Isomorphic1[Node, ObjectNode]
val ObjectLiteral : Isomorphic1[Literal, ObjectLiteral]
- val PlainLiteral : Isomorphic2[String, Option[LangTag], PlainLiteral]
- val TypedLiteral : Isomorphic2[String, IRI, TypedLiteral]
-
+ val Literal : Isomorphic3[String, Option[LangTag], Option[IRI], Literal]
val LangTag : Isomorphic1[String, LangTag]
// val StringDatatype = IRI("http://www.w3.org/2001/XMLSchema#string")
--- a/aRDF/src/main/scala/ScalaModel.scala Sun Jan 08 16:40:05 2012 -0500
+++ b/aRDF/src/main/scala/ScalaModel.scala Sun Jan 08 17:56:57 2012 -0500
@@ -43,16 +43,9 @@
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 Literal(lexicalForm: String, langtag: Option[LangTag], datatype: Option[IRI])
+ object Literal extends Isomorphic3[String, Option[LangTag], Option[IRI], Literal]
+
case class LangTag(s:String)
object LangTag extends Isomorphic1[String, LangTag]
--- a/aRDF/src/main/scala/Test.scala Sun Jan 08 16:40:05 2012 -0500
+++ b/aRDF/src/main/scala/Test.scala Sun Jan 08 17:56:57 2012 -0500
@@ -8,15 +8,21 @@
import m._
- val g: Graph = Graph(
- Triple(
- SubjectNode(NodeIRI(IRI("http://www.w3.org/"))),
- PredicateIRI(IRI("http://www.w3.org/predicate")),
- ObjectLiteral(PlainLiteral("toto", None))
- )
+ val t = Triple(
+ SubjectNode(NodeIRI(IRI("http://www.w3.org/"))),
+ PredicateIRI(IRI("http://www.w3.org/predicate")),
+ ObjectLiteral(Literal("toto", None, None))
)
+ val g: Graph = Graph(t)
+ t match {
+ case Triple(SubjectNode(NodeIRI(IRI(s))), PredicateIRI(IRI(p)), ObjectLiteral(Literal(o, _, _))) => println(s.toString + p.toString + o.toString)
+
+
+ }
+
+ Literal("toto", None, None) match { case Literal(t, None, None) => () }
println(g)