Permalink
Browse files

Basic support for RESTful triples spaces

  • Loading branch information...
antoniogarrote committed Jun 10, 2010
1 parent fef9587 commit 713ba6b0b58c06af379f44158729e857cfc74641

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -93,7 +93,7 @@
true atom)))
-(defn- parse-literal-lexical
+(defn parse-literal-lexical
([lit]
(let [parts-a (.split lit "\\^\\^")
val-a (aget parts-a 0)
@@ -1,8 +1,8 @@
-;; @author Antonio Garote
+;; @author Antonio Garrote
;; @email antoniogarrote@gmail.com
;; @date 26.05.2010
-(ns plaza.rdf.models
+(ns plaza.rdf.schemas
(:use (plaza.rdf core sparql predicates)
(plaza.rdf.implementations common)
(plaza utils)))
@@ -14,12 +14,15 @@
;; Protocols
(defprotocol OntologyModel
"Functions that can be applied to a RDF ontology schema"
- (type-uri [model] "Returns the URI of this model")
- (to-pattern [model props] [model subject props] "Builds a pattern suitable to look for instances of this type. A list of properties can be passed optionally")
- (to-map [model triples] "Transforms a RDF triple set into a map of properties using the provided keys")
- (property-uri [model alias] "Returns the URI for the alias of a property")
- (property-alias [model uri] "Returns the alias for a property URI")
- (parse-prop-value [model alias val] "Parses the provided string value into the right java value for the property defined by alias"))
+ (type-uri [this] "Returns the URI of this model")
+ (to-pattern [this props] [this subject props] "Builds a pattern suitable to look for instances of this type. A list of properties can be passed optionally")
+ (to-map [this triples] "Transforms a RDF triple set into a map of properties using the provided keys")
+ (property-uri [this alias] "Returns the URI for the alias of a property")
+ (property-alias [this uri] "Returns the alias for a property URI")
+ (parse-prop-value [this alias val] "Parses the provided string value into the right java value for the property defined by alias")
+ (prop-value-to-triple-value [this alias val] "Transforms the provided value into the a valid Plaza triple literal, datatype literal or resource")
+ (to-rdf-triples [this] "Transforms this schema into a set of triples")
+ (aliases [this] "Returns all tha aliases for the properties of the model"))
(defn- build-pattern-for-model
([type-uri subj props properties]
@@ -38,36 +41,48 @@
(make-pattern (concat mandatory-pattern optional-pattern)))))
;; Types
-(deftype RDFSModel [type-uri properties ranges] OntologyModel
- (type-uri [this] type-uri)
- (toString [this] (str type-uri " " properties))
+(deftype RDFSModel [this-uri properties ranges] OntologyModel
+ (type-uri [this] this-uri)
+ (toString [this] (str this-uri " " properties))
(to-pattern [this subject props] (let [subj (if (instance? plaza.rdf.core.RDFResource subject) subject (if (coll? subject) (apply rdf-resource subject) (rdf-resource subject) ))]
- (build-pattern-for-model type-uri subj props properties)))
- (to-pattern [this props] (build-pattern-for-model type-uri ?s props properties))
+ (build-pattern-for-model this-uri subj props properties)))
+ (to-pattern [this props] (build-pattern-for-model this-uri ?s props properties))
(to-map [this triples-or-vector] (let [triples (if (:triples (meta triples-or-vector)) triples-or-vector (make-triples triples-or-vector))]
(reduce (fn [ac it] (let [prop (str (resource-id (it properties)))
val (find-property prop triples)]
(if (nil? val) ac (assoc ac it (nth val 2)))))
{}
(keys properties))))
- (property-uri [model alias] (alias properties))
- (property-alias [model uri] (first (filter #(= (str (get properties %1)) (str uri)) (keys properties))))
- (parse-prop-value [model alias val] (let [{kind :kind range :range} (get ranges alias)]
- (if (= kind :resource) val
- (.parse (find-jena-datatype range) val)))))
+ (property-uri [this alias] (alias properties))
+ (property-alias [this uri] (first (filter #(= (str (get properties %1)) (str uri)) (keys properties))))
+ (parse-prop-value [this alias val] (let [{kind :kind range :range} (get ranges alias)]
+ (if (= kind :resource) (rdf-resource val)
+ (.parse (find-jena-datatype (str range)) val))))
+ (prop-value-to-triple-value [this alias val] (let [{kind :kind range :range} (get ranges alias)]
+ (if (= kind :resource) (rdf-resource val)
+ (let [jena-type (find-jena-datatype (str range))]
+ (parse-literal-lexical (str "\"" val "\"^^<" (.getURI jena-type) ">"))))))
+ (to-rdf-triples [this] (let [subject (rdf-resource (type-uri this))]
+ (reduce (fn [ts k] (let [prop (get properties k)
+ range (:range (get ranges k))
+ tsp (conj ts [prop (rdf-resource rdfs:range) range])]
+ (conj tsp [prop (rdf-resource rdfs:domain) subject])))
+ [[subject (rdf-resource rdf:type) (rdf-resource rdfs:Class)]]
+ (keys properties))))
+ (aliases [this] (keys properties)))
;; Type constructor
-(defn make-rdfs-model
+(defn make-rdfs-schema
([type-uri-pre & properties]
(let [type-uri (if (coll? type-uri-pre) (apply rdf-resource type-uri-pre) (rdf-resource type-uri-pre))
props-map-pre (apply hash-map properties)
maps (reduce (fn [[ac-props ac-ranges] it]
(let [{uri :uri range :range} (it props-map-pre)
prop-val (if (coll? uri) (apply rdf-resource uri) (rdf-resource uri))
range-val (if (supported-datatype? range)
- {:kind :datatype :range (datatype-uri range)}
+ {:kind :datatype :range (rdf-resource (datatype-uri range))}
{:kind :resource :range (if (coll? range) (apply rdf-resource range) range)})]
[(assoc ac-props it prop-val)
(assoc ac-ranges it range-val)])) [{} {}] (keys props-map-pre))]
- (plaza.rdf.models.RDFSModel. type-uri (first maps) (second maps)))))
+ (plaza.rdf.schemas.RDFSModel. type-uri (first maps) (second maps)))))
@@ -0,0 +1,59 @@
+;; @author Antonio Garrote
+;; @email antoniogarrote@gmail.com
+;; @date 09.06.2010
+
+(ns plaza.rdf.vocabularies.dublin-core
+ (:use
+ [plaza.rdf.core]
+ [plaza.rdf.schemas]))
+
+;; Dublic Core Metadata Initiative terms
+;; @see http://dublincore.org/schemas/rdfs/
+
+(defonce dc11 "http://purl.org/dc/elements/1.1/")
+
+(defonce dc11:title "http://purl.org/dc/elements/1.1/title")
+(defonce dc11:creator "http://purl.org/dc/elements/1.1/creator")
+(defonce dc11:subject "http://purl.org/dc/elements/1.1/subject")
+(defonce dc11:description "http://purl.org/dc/elements/1.1/description")
+(defonce dc11:publisher "http://purl.org/dc/elements/1.1/publisher")
+(defonce dc11:contributor "http://purl.org/dc/elements/1.1/contributor")
+(defonce dc11:date "http://purl.org/dc/elements/1.1/date")
+(defonce dc11:type "http://purl.org/dc/elements/1.1/type")
+(defonce dc11:format "http://purl.org/dc/elements/1.1/format")
+(defonce dc11:identifier "http://purl.org/dc/elements/1.1/identifier")
+(defonce dc11:source "http://purl.org/dc/elements/1.1/source")
+(defonce dc11:language "http://purl.org/dc/elements/1.1/language")
+(defonce dc11:relation "http://purl.org/dc/elements/1.1/relation")
+(defonce dc11:coverage "http://purl.org/dc/elements/1.1/coverage")
+(defonce dc11:rights "http://purl.org/dc/elements/1.1/rights")
+
+
+(defonce dct "http://purl.org/dc/terms/")
+
+(defonce dct:title "http://purl.org/dc/terms/title")
+(defonce dct:creator "http://purl.org/dc/terms/creator")
+(defonce dct:subject "http://purl.org/dc/terms/subject")
+(defonce dct:description "http://purl.org/dc/terms/description")
+(defonce dct:publisher "http://purl.org/dc/terms/publisher")
+(defonce dct:contributor "http://purl.org/dc/terms/contributor")
+(defonce dct:date "http://purl.org/dc/terms/date")
+(defonce dct:type "http://purl.org/dc/terms/type")
+(defonce dct:format "http://purl.org/dc/terms/format")
+(defonce dct:identifier "http://purl.org/dc/terms/identifier")
+(defonce dct:source "http://purl.org/dc/terms/source")
+(defonce dct:language "http://purl.org/dc/terms/language")
+(defonce dct:relation "http://purl.org/dc/terms/relation")
+(defonce dct:coverage "http://purl.org/dc/terms/coverage")
+(defonce dct:rights "http://purl.org/dc/terms/rights")
+(defonce dct:audience "http://purl.org/dc/terms/audience")
+(defonce dct:alternative "http://purl.org/dc/terms/alternative")
+(defonce dct:tableOfContents "http://purl.org/dc/terms/tableOfContents")
+(defonce dct:abstract "http://purl.org/dc/terms/abstract")
+(defonce dct:created "http://purl.org/dc/terms/created")
+(defonce dct:valid "http://purl.org/dc/terms/valid")
+(defonce dct:available "http://purl.org/dc/terms/available")
+;; add more...
+
+(register-rdf-ns :dc11 dc11)
+(register-rdf-ns :dct dct)
@@ -0,0 +1,116 @@
+;; @author Antonio Garrote
+;; @email antoniogarrote@gmail.com
+;; @date 09.06.2010
+
+(ns plaza.rdf.vocabularies.foaf
+ (:use
+ [plaza.rdf.core]
+ [plaza.rdf.schemas]))
+
+;; FOAF vocabulary
+;; @see http://xmlns.com/foaf/spec/
+
+(defonce foaf "http://xmlns.com/foaf/0.1/")
+
+(defonce foaf:Agent "http://xmlns.com/foaf/0.1/Agent")
+(defonce foaf:Person "http://xmlns.com/foaf/0.1/Person")
+(defonce foaf:name "http://xmlns.com/foaf/0.1/name")
+(defonce foaf:gender "http://xmlns.com/foaf/0.1/gender")
+(defonce foaf:holdsAccount "http://xmlns.com/foaf/0.1/holdsAccount")
+(defonce foaf:birthday "http://xmlns.com/foaf/0.1/birthday")
+(defonce foaf:openid "http://xmlns.com/foaf/0.1/openid")
+(defonce foaf:status "http://xmlns.com/foaf/0.1/status")
+(defonce foaf:nick "http://xmlns.com/foaf/0.1/nick")
+(defonce foaf:title "http://xmlns.com/foaf/0.1/title")
+(defonce foaf:homepage "http://xmlns.com/foaf/0.1/homepage")
+(defonce foaf:mbox "http://xmlns.com/foaf/0.1/mbox")
+(defonce foaf:mbox_sha1sum "http://xmlns.com/foaf/0.1/mbox_sha1sum")
+(defonce foaf:img "http://xmlns.com/foaf/0.1/img")
+(defonce foaf:depiction "http://xmlns.com/foaf/0.1/depiction")
+(defonce foaf:surname "http://xmlns.com/foaf/0.1/surname")
+(defonce foaf:familyName "http://xmlns.com/foaf/0.1/familyName")
+(defonce foaf:givenName "http://xmlns.com/foaf/0.1/givenName")
+(defonce foaf:firstName "http://xmlns.com/foaf/0.1/firstName")
+(defonce foaf:lastName "http://xmlns.com/foaf/0.1/lastName")
+(defonce foaf:weblog "http://xmlns.com/foaf/0.1/weblog")
+(defonce foaf:knows "http://xmlns.com/foaf/0.1/knows")
+(defonce foaf:interest "http://xmlns.com/foaf/0.1/interest")
+(defonce foaf:currentProject "http://xmlns.com/foaf/0.1/currentProject")
+(defonce foaf:pastProject "http://xmlns.com/foaf/0.1/pastProject")
+(defonce foaf:plan "http://xmlns.com/foaf/0.1/plan")
+(defonce foaf:based_near "http://xmlns.com/foaf/0.1/based_near")
+(defonce foaf:age "http://xmlns.com/foaf/0.1/age")
+(defonce foaf:workplaceHomepage "http://xmlns.com/foaf/0.1/workplaceHomepage")
+(defonce foaf:workInfoHomepage "http://xmlns.com/foaf/0.1/workInfoHomepage")
+(defonce foaf:schoolHomepage "http://xmlns.com/foaf/0.1/schoolHomepage")
+(defonce foaf:topic_interest "http://xmlns.com/foaf/0.1/topic_interest")
+(defonce foaf:publications "http://xmlns.com/foaf/0.1/publications")
+(defonce foaf:geekcode "http://xmlns.com/foaf/0.1/geekcode")
+(defonce foaf:myersBriggs "http://xmlns.com/foaf/0.1/myersBriggs")
+(defonce foaf:dnaChecksum "http://xmlns.com/foaf/0.1/dnaChecksum")
+(defonce foaf:OnlineAccount "http://xmlns.com/foaf/0.1/OnlineAccount")
+(defonce foaf:OnlineChatAccount "http://xmlns.com/foaf/0.1/OnlineChatAccount")
+(defonce foaf:OnlineEcommerceAccount "http://xmlns.com/foaf/0.1/OnlineEcommerceAccount")
+(defonce foaf:OnlineGamingAccount "http://xmlns.com/foaf/0.1/OnlineGamingAccount")
+(defonce foaf:account "http://xmlns.com/foaf/0.1/account")
+(defonce foaf:accountServiceHomepage "http://xmlns.com/foaf/0.1/accountServiceHomepage")
+(defonce foaf:accountName "http://xmlns.com/foaf/0.1/accountName")
+(defonce foaf:icqChatID "http://xmlns.com/foaf/0.1/icqChatID")
+(defonce foaf:msnChatID "http://xmlns.com/foaf/0.1/msnChatID")
+(defonce foaf:aimChatID "http://xmlns.com/foaf/0.1/aimChatID")
+(defonce foaf:jabberID "http://xmlns.com/foaf/0.1/jabberID")
+(defonce foaf:yahooChatID "http://xmlns.com/foaf/0.1/yahooChatID")
+(defonce foaf:skypeID "http://xmlns.com/foaf/0.1/skypeID")
+(defonce foaf:Project "http://xmlns.com/foaf/0.1/Project")
+(defonce foaf:Organization "http://xmlns.com/foaf/0.1/Organization")
+(defonce foaf:Group "http://xmlns.com/foaf/0.1/Group")
+(defonce foaf:member "http://xmlns.com/foaf/0.1/member")
+(defonce foaf:membershipClass "http://xmlns.com/foaf/0.1/membershipClass")
+(defonce foaf:Document "http://xmlns.com/foaf/0.1/Document")
+(defonce foaf:Image "http://xmlns.com/foaf/0.1/Image")
+(defonce foaf:PersonalProfileDocument "http://xmlns.com/foaf/0.1/PersonalProfileDocument")
+(defonce foaf:topic "http://xmlns.com/foaf/0.1/topic")
+(defonce foaf:primaryTopicOf "http://xmlns.com/foaf/0.1/primaryTopicOf")
+(defonce foaf:primaryTopic "http://xmlns.com/foaf/0.1/primaryTopic")
+(defonce foaf:tipjar "http://xmlns.com/foaf/0.1/tipjar")
+(defonce foaf:sha1 "http://xmlns.com/foaf/0.1/sha1")
+(defonce foaf:made "http://xmlns.com/foaf/0.1/made")
+(defonce foaf:thumbnail "http://xmlns.com/foaf/0.1/thumbnail")
+(defonce foaf:logo "http://xmlns.com/foaf/0.1/logo")
+
+(register-rdf-ns :foaf foaf)
+
+
+(defonce foaf:Agent-schema
+ (make-rdfs-schema foaf:Agent
+ :weblog {:uri foaf:weblog :range foaf:Document }
+ :gender {:uri foaf:gender :range :string }
+ :holdsAccount {:uri foaf:holdsAccount :range foaf:OnlineAccount }
+ :birthday {:uri foaf:birthday :range :date }
+ :age {:uri foaf:age :range :integer }
+ :made {:uri foaf:made :range "http://www.w3.org/2002/07/owl#Thing"}
+ :skypeID {:uri foaf:skypeID :range :string}
+ :msnChatID {:uri foaf:msnChatID :range :string}
+ :icqChatID {:uri foaf:icqChatID :range :string}
+ :mbox {:uri foaf:mbox :range "http://www.w3.org/2002/07/owl#Thing"}
+ :status {:uri foaf:status :range :string}
+ :mbox_sha1sum {:uri foaf:mbox_sha1sum :range :string}
+ :account {:uri foaf:account :range foaf:OnlineAccount}
+ :yahooChatID {:uri foaf:yahooChatID :range :string}
+ :aimChatID {:uri foaf:aimChatID :range :string}
+ :jabberID {:uri foaf:jabberID :range :string}
+ :openid {:uri foaf:openid :range :string }
+ :tipjar {:uri foaf:tipjar :range :string}))
+
+
+(defonce foaf:OnlineAccount-schema
+ (make-rdfs-schema foaf:OnlineAccount
+ :accountName {:uri foaf:accountName :range :string }
+ :accountServiceHomepage {:uri foaf:accountServiceHomepage :range foaf:Document }))
+
+
+(defonce foaf:Document-schema
+ (make-rdfs-schema foaf:Document
+ :sha1 {:uri foaf:sha1 :range "http://www.w3.org/2002/07/owl#Thing"}
+ :topic {:uri foaf:topic :range "http://www.w3.org/2002/07/owl#Thing"}
+ :primaryTopic {:uri foaf:primaryTopic :range "http://www.w3.org/2002/07/owl#Thing"}))
Oops, something went wrong.

0 comments on commit 713ba6b

Please sign in to comment.