Permalink
Browse files

added basic profile vocab, some more documentation and enhanced basic…

… serialisation of resource
  • Loading branch information...
1 parent 5177b1d commit 12301e88156683ad42a74e34b3a3d38c9284491b @mhausenblas committed Apr 9, 2012
Showing with 106 additions and 16 deletions.
  1. +22 −0 README.md
  2. +56 −0 bp-vocab.ttl
  3. +28 −16 info.paygoo.core.scala
View
@@ -2,8 +2,30 @@
An object-orient implementation of '[Linked Data Basic Profile](http://www.w3.org/Submission/2012/SUBM-ldbp-20120326/ "Linked Data Basic Profile 1.0")'-compliant containers/resources.
+## Usage
+
+After you got the source somewhere local (via git clone or download facility) you want to compile it:
+
+ scalac -cp lib/scardf-0.6-SNAPSHOT.jar:lib/joda-time-1.6.jar info.paygoo.core.scala
+
+Then you can run the built-in test:
+
+ scala -cp lib/scardf-0.6-SNAPSHOT.jar:lib/joda-time-1.6.jar info.paygoo.core.PayGooResource
+
+...which should yield something like the following:
+
+ <div>About <a href='http://data.example.com/test#it'>pg0</a>, last updated 2012-04-09</div>
+ {"base" : "http:\/\/data.example.com\/test#", "label" : "pg0", "date" : 2012-04-09}
+ base=http://data.example.com/test#, label=pg0, date=2012-04-09
+ <http://data.example.com/test#it> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Thing> .
+ <http://data.example.com/test#it> <http://purl.org/dc/terms/title> "pg0" .
+ <http://data.example.com/test#it> <http://purl.org/dc/terms/date> "2012-04-09"^^<http://www.w3.org/2001/XMLSchema#date> .
+
+ [PayGooResource: base=http://data.example.com/test# | label=pg0 | date=2012-04-09]
+
## Dependencies
+* Scala 2.9.1
* [scardf](http://code.google.com/p/scardf/ "Scala RDF API - Google Project Hosting")
* [spray](spray.cc "A suite of lightweight Scala libraries for building and consuming RESTful web services on top of Akka")
View
@@ -0,0 +1,56 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix dcterms: <http://purl.org/dc/terms/> .
+
+<http://open-services.net/ns/basicProfile#> a owl:Ontology ;
+ dcterms:title "The Linked Data Basic Profile (LDBP) Vocabulary" ;
+ dcterms:description "All vocabulary URIs defined in the Linked Data Basic Profile (LDBP) namespace." ;
+ rdfs:label "Linked Data Basic Profile (LDBP)" ;
+ rdfs:seeAlso <http://www.w3.org/2011/09/LinkedData/> , <http://www.ibm.com/developerworks/rational/library/basic-profile-linked-data/> , <http://open-services.net/ns/basicProfile/ldbp.rdf> .
+
+<http://open-services.net/ns/basicProfile#Container> a rdfs:Class ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "Container" ;
+ rdfs:comment """A Basic Profile Resource (BPR) that also conforms to additional patterns
+ and conventions in this document for managing membership.""" .
+
+<http://open-services.net/ns/basicProfile#Page> a rdfs:Class ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "Page" ;
+ rdfs:comment "A resource that represents a limited set of members of a Basic Profile Container." .
+
+<http://open-services.net/ns/basicProfile#membershipPredicate> a rdf:Property ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "membershipPredicate" ;
+ rdfs:comment "Indicates which predicate of the container should be used to determine the membership." ;
+ rdfs:domain <http://open-services.net/ns/basicProfile#Container> ;
+ rdfs:range rdf:Property .
+
+<http://open-services.net/ns/basicProfile#membershipSubject> a rdf:Property ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "membershipSubject" ;
+ rdfs:comment "Indicates which resource is the subject for the members of the container." ;
+ rdfs:domain <http://open-services.net/ns/basicProfile#Container> ;
+ rdfs:range rdf:Property .
+
+<http://open-services.net/ns/basicProfile#pageOf> a rdf:Property ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "pageOf" ;
+ rdfs:comment "Associated a page with its container." ;
+ rdfs:domain <http://open-services.net/ns/basicProfile#Page> ;
+ rdfs:range <http://open-services.net/ns/basicProfile#Container> .
+
+<http://open-services.net/ns/basicProfile#nextPage> a rdf:Property ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "nextPage" ;
+ rdfs:comment "From a known page, how to indicate the next or last page as rdf:nil." ;
+ rdfs:domain <http://open-services.net/ns/basicProfile#Page> ;
+ rdfs:range rdfs:Resource .
+
+<http://open-services.net/ns/basicProfile#containerSortPredicates> a rdf:Property ;
+ rdfs:isDefinedBy <http://open-services.net/ns/basicProfile#> ;
+ rdfs:label "containerSortPredicates" ;
+ rdfs:comment "List of predicates that indicate the ascending order of the members in a page." ;
+ rdfs:domain <http://open-services.net/ns/basicProfile#Page> ;
+ rdfs:range rdf:List .
View
@@ -1,27 +1,32 @@
import scala.actors.Actor
import scala.actors.Actor._
import scala.util.parsing.json._
+import org.scardf._
+import org.joda.time.LocalDate
package info.paygoo.core {
/**
- * Objects that represent a PayGoo's serialisation (or wire format).
- * A PayGoo MUST support all four media types.
+ * Represent a PayGoo's serialisation (aka wire format).
+ * A PayGoo MUST support all of the following four media types.
*
* @param mediatype as of http://www.iana.org/assignments/media-types/
*/
- case class WireFormat ( val mediatype: String )
- object HTML extends WireFormat ( mediatype = "text/html" )
- object JSON extends WireFormat ( mediatype = "application/json" )
- object Text extends WireFormat ( mediatype = "text/plain" )
- object Turtle extends WireFormat ( mediatype = "text/turtle" )
+ case class WireFormat ( val mediatype: String, val target: String )
+ object HTML extends WireFormat ( mediatype = "text/html", target = "human" )
+ object JSON extends WireFormat ( mediatype = "application/json", target = "machine" )
+ object Text extends WireFormat ( mediatype = "text/plain", target = "human" )
+ object NTriple extends WireFormat ( mediatype = "text/plain", target = "machine" )
/**
* The core PayGoo class, just has a label.
*
* @param label a human-readable label for the PayGoo
*/
- abstract class PayGoo ( var label: String ) {
+ abstract class PayGoo (val base: String, var label: String ) {
+ val s = Vocabulary( "http://schema.org/" )
+ val dc = Vocabulary( "http://purl.org/dc/terms/" )
+ val bp = Vocabulary( "http://open-services.net/ns/basicProfile#" )
def ser( format: WireFormat = JSON ) : String
}
@@ -31,29 +36,36 @@ package info.paygoo.core {
* @param rlabel a human-readable label for the PayGoo resource
* @return dunno
*/
- case class PayGooResource ( rlabel: String ) extends PayGoo ( rlabel ) {
- private var r = Map ( "label" -> rlabel )
+ case class PayGooResource (rbase: String, rlabel: String ) extends PayGoo ( rbase, rlabel ) {
+ private var r = Map ( "base" -> rbase, "label" -> rlabel, "date" -> new LocalDate())
+ private val rself = r("base") + "it"
override def ser ( format: WireFormat = JSON ) : String = format match {
- case HTML => "<div>" + rlabel + "</div>"
+ case HTML => "<div>About <a href='" + rself + "'>" + r("label") + "</a>, last updated " + r("date") + "</div>"
case JSON => JSONObject(r).toString
- case Text => r("label")
- case Turtle => ":a rdfs:label '" + r("label") + "' ."
+ case Text => "base=" + r("base") + ", label=" + r("label") + ", date=" + r("date")
+ case NTriple => val g = Graph.build( UriRef( rself ) - (
+ RDF.Type -> s.uriref("Thing"),
+ dc.uriref("title") -> r("label"),
+ dc.uriref("date") -> r("date")
+ )
+ )
+ g.rend
}
- override def toString = "[PayGooResource: label=" + r("label") + "]"
+ override def toString = "[PayGooResource: base=" + r("base") + " | label=" + r("label") + " | date=" + r("date") + "]"
}
/**
* Testing the resource ...
*/
object PayGooResource extends App {
- val r = new PayGooResource("pg0")
+ val r = new PayGooResource("http://data.example.com/test#", "pg0")
println(r.ser(format=HTML))
println(r.ser(format=JSON))
println(r.ser(format=Text))
- println(r.ser(format=Turtle))
+ println(r.ser(format=NTriple))
println(r)
}
}

0 comments on commit 12301e8

Please sign in to comment.