--- a/rdfxml/src/main/scala/RDFXML.scala Fri Jan 07 19:20:00 2011 -0500
+++ b/rdfxml/src/main/scala/RDFXML.scala Sun Jan 09 17:23:40 2011 -0500
@@ -1,6 +1,6 @@
package org.w3.sw.rdfxml
-import org.w3.sw.rdf._
+import org.w3.sw._
import com.hp.hpl.jena.rdf.arp._
import org.xml.sax._
@@ -10,35 +10,6 @@
import java.util.{StringTokenizer, Enumeration, Hashtable}
import java.net.URI
-object RDFXML {
-
- /**
- * http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/AResource.html
- * note: see setUserData and getUserData for when BNode will be abstract
- */
- def toNode(a:AResource):Node =
- if (a.isAnonymous)
- NodeBNode(BNode(a.getAnonymousID))
- else
- NodeIRI(IRI(a.getURI))
-
- def toPredicate(a:AResource):Predicate = PredicateIRI(IRI(a.getURI))
-
- def toLiteral(l:ALiteral):Literal = {
- val datatype:String = l.getDatatypeURI
- if (datatype == null) {
- val lang = l.getLang match {
- case "" => None
- case l => Some(LangTag(l))
- }
- PlainLiteral(l.toString, lang)
- } else {
- TypedLiteral(l.toString, IRI(datatype))
- }
- }
-
-}
-
sealed trait ParseErrorType
object RDFParseError extends ParseErrorType { override def toString:String = "RDF" }
object XMLParseError extends ParseErrorType { override def toString:String = "XML" }
@@ -67,9 +38,70 @@
}
}
-class RDFXML() {
+trait RDFXML[IRI,
+ Graph <: Traversable[Triple],
+ Triple,
+ BNode,
+ Node,
+ NodeIRI <: Node,
+ NodeBNode <: Node,
+ Subject,
+ SubjectNode <: Subject,
+ Predicate,
+ PredicateIRI <: Predicate,
+ Object,
+ ObjectNode <: Object,
+ ObjectLiteral <: Object,
+ Literal,
+ PlainLiteral <: Literal,
+ TypedLiteral <: Literal,
+ LangTag] {
- import RDFXML._
+ val RDFModule:RDFModule[IRI,
+ Graph,
+ Triple,
+ BNode,
+ Node,
+ NodeIRI,
+ NodeBNode,
+ Subject,
+ SubjectNode,
+ Predicate,
+ PredicateIRI,
+ Object,
+ ObjectNode,
+ ObjectLiteral,
+ Literal,
+ PlainLiteral,
+ TypedLiteral,
+ LangTag]
+
+ import RDFModule._
+
+ /**
+ * http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/AResource.html
+ * note: see setUserData and getUserData for when BNode will be abstract
+ */
+ def toNode(a:AResource):Node =
+ if (a.isAnonymous)
+ NodeBNode(BNode(a.getAnonymousID))
+ else
+ NodeIRI(IRI(a.getURI))
+
+ def toPredicate(a:AResource):Predicate = PredicateIRI(IRI(a.getURI))
+
+ def toLiteral(l:ALiteral):Literal = {
+ val datatype:String = l.getDatatypeURI
+ if (datatype == null) {
+ val lang = l.getLang match {
+ case "" => None
+ case l => Some(LangTag(l))
+ }
+ PlainLiteral(l.toString, lang)
+ } else {
+ TypedLiteral(l.toString, IRI(datatype))
+ }
+ }
def toGraph(file:File):(Graph, List[ParseError]) = toGraph(new FileInputStream(file))
@@ -113,7 +145,7 @@
arp.load(in)
// returns an immutable set and the potential errors
- (triples.toSet, parseErrors)
+ (Graph(triples), parseErrors)
}
}
--- a/rdfxml/src/test/scala/RDFXMLTest.scala Fri Jan 07 19:20:00 2011 -0500
+++ b/rdfxml/src/test/scala/RDFXMLTest.scala Sun Jan 09 17:23:40 2011 -0500
@@ -1,12 +1,68 @@
package org.w3.sw.rdfxml
-import org.w3.sw.rdf._
+import org.w3.sw._
import org.scalatest.FunSuite
-class RDFXMLTest extends FunSuite {
+class RDFXMLTestWithRDF extends RDFXMLTest(RDFConcreteModuleWithImplicits)
- val parser = new RDFXML
+abstract class RDFXMLTest[IRI,
+ Graph <: Traversable[Triple],
+ Triple,
+ BNode,
+ Node,
+ NodeIRI <: Node,
+ NodeBNode <: Node,
+ Subject,
+ SubjectNode <: Subject,
+ Predicate,
+ PredicateIRI <: Predicate,
+ Object,
+ ObjectNode <: Object,
+ ObjectLiteral <: Object,
+ Literal,
+ PlainLiteral <: Literal,
+ TypedLiteral <: Literal,
+ LangTag](val RDFModule:RDFModuleWithImplicits[IRI,
+ Graph,
+ Triple,
+ BNode,
+ Node,
+ NodeIRI,
+ NodeBNode,
+ Subject,
+ SubjectNode,
+ Predicate,
+ PredicateIRI,
+ Object,
+ ObjectNode,
+ ObjectLiteral,
+ Literal,
+ PlainLiteral,
+ TypedLiteral,
+ LangTag])
+extends FunSuite { self =>
+
+ import RDFModule._
+
+ val parser = new RDFXML[IRI,
+ Graph,
+ Triple,
+ BNode,
+ Node,
+ NodeIRI,
+ NodeBNode,
+ Subject,
+ SubjectNode,
+ Predicate,
+ PredicateIRI,
+ Object,
+ ObjectNode,
+ ObjectLiteral,
+ Literal,
+ PlainLiteral,
+ TypedLiteral,
+ LangTag] { val RDFModule = self.RDFModule }
test("default on http://www.rdfabout.com/demo/validator/") {
--- a/sparql/src/main/scala/SPARQL.scala Fri Jan 07 19:20:00 2011 -0500
+++ b/sparql/src/main/scala/SPARQL.scala Sun Jan 09 17:23:40 2011 -0500
@@ -1,9 +1,27 @@
package org.w3.sw.sparql
-import org.w3.sw.rdf
import scala.util.parsing.combinator._
import java.net.URI
+object rdf {
+
+ 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 }
+ }
+ case class TypedLiteral(override val lexicalForm:String, datatype:IRI) extends Literal(lexicalForm) {
+ override def toString = "\"" + lexicalForm + "\"^^" + datatype
+ }
+ case class LangTag(s:String)
+
+ case class IRI(iri:String) { override def toString = '"' + iri + '"' }
+ lazy val StringDatatype = IRI("http://www.w3.org/2001/XMLSchema#string")
+ lazy val IntegerDatatype = IRI("http://www.w3.org/2001/XMLSchema#integer")
+ lazy val DateDatatype = IRI("http://www.w3.org/2001/XMLSchema#date")
+ lazy val DateTimeDatatype = IRI("http://www.w3.org/2001/XMLSchema#dateTime")
+
+}
+
object MyParsers extends RegexParsers {
val uri = """[a-zA-Z0-9:/#_\.\-\+]+""".r
--- a/sparql/src/test/scala/SparqlTest.scala Fri Jan 07 19:20:00 2011 -0500
+++ b/sparql/src/test/scala/SparqlTest.scala Sun Jan 09 17:23:40 2011 -0500
@@ -1,6 +1,5 @@
package org.w3.sw.sparql
-import org.w3.sw.rdf
import org.scalatest.FunSuite
class SparqlTest extends FunSuite {
--- a/sparql2sql/src/main/scala/SparqlToSql.scala Fri Jan 07 19:20:00 2011 -0500
+++ b/sparql2sql/src/main/scala/SparqlToSql.scala Sun Jan 09 17:23:40 2011 -0500
@@ -16,8 +16,8 @@
import org.w3.sw.rdb
import org.w3.sw.sql
import org.w3.sw.sql.PrettySql.toPrettySql
-import org.w3.sw.rdf
import org.w3.sw.sparql
+import org.w3.sw.sparql.rdf
import org.w3.sw.util
case class StemURI(s:String)