wiki:TmSparql

Wiki

TM-SPARQL

TM-SPARQL serves an API that allows to query information about the stored topic map data. The data is treated as RDF, the entire notion of the TM-SPARQL api is available at networkedplanet.

Supported functions

  • PREFIX
  • BASE
  • SELECT - WHERE (only one group, i.e. OPTIONAL, ALTERNATIVE is not supported)
  • FILTER (BOUND, STR, isLITERAL, REGEX, DATATYPE, , | |, &&, (, ), *, /, +, -, !, !=, <=, >=, =, <, >)

Supported datatypes

  • xml:string (lisp string)
  • xml:integer (lisp integer)
  • xml:boolean (lisp boolean)
  • xml:double (lisp double float)
  • xml:decimal (lisp single float)
  • unsupported data types are handled as strings

Howto

Getting the result of a query can be achieved with an object of the type tm-sparql:SPARQL-Query:

(let* ((query-1
         "BASE <http://some.where/psis/poem/>
          SELECT $object ?predicate WHERE{
           <http://some.where/tmsparql/author/goethe> ?predicate ?object}")
      (r-1 (tm-sparql:result (make-instance 'TM-SPARQL:SPARQL-Query :query query-1))))
  r-1)

;; r is a list of plists, every plist stands for a variable that is selected
;;	   
;; ((:VARIABLE "object" :RESULT
;;   ("\"\"\"28.08.1749\"\"\"^^http://www.w3.org/2001/XMLSchema#date"
;;    "\"\"\"22.03.1832\"\"\"^^http://www.w3.org/2001/XMLSchema#date" 82 T NIL
;;    "von Goethe" "Johann Wolfgang" "<http://some.where/tmsparql/author>"
;;    "_:n946" "_:n953" "<http://some.where/ii/goethe-untyped-name>"
;;    "<http://some.where/ii/goethe-occ>" "_:o991"
;;    "<http://some.where/ii/goethe-years-occ>" "_:o1004" "_:o1009"))
;;  (:VARIABLE "predicate" :RESULT
;;   ("<http://some.where/tmsparql/date-of-birth>"
;;    "<http://some.where/tmsparql/date-of-death>"
;;    "<http://some.where/tmsparql/years>" "<http://some.where/tmsparql/isDead>"
;;    "<http://some.where/tmsparql/isAlive>"
;;    "<http://some.where/tmsparql/last-name>"
;;    "<http://some.where/tmsparql/first-name>"
;;    "<http://psi.topicmaps.org/iso13250/model/type>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>"
;;    "<http://www.networkedplanet.com/tmsparql/topicProperty>")))

The query object can als be serialised directly as JSON

(let* ((query-1
         "BASE <http://some.where/psis/poem/>
          SELECT $object ?predicate WHERE{
           <http://some.where/tmsparql/author/goethe> ?predicate ?object}")
       (qo-1 (make-instance 'TM-SPARQL:SPARQL-Query :query query-1)))
  (json-exporter:to-json-string qo-1))

;; the result is the following JSON-string
;;
;; "{\"object\":[\"\\\"\\\"\\\"28.08.1749\\\"\\\"\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#date\",\"\\\"\\\"\\\"22.03.1832\\\"\\\"\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#date\",
;;   82,true,null,\"von Goethe\",\"Johann Wolfgang\",\"<http:\\/\\/some.where\\/tmsparql\\/author>\",\"_:n946\",\"_:n953\",\"<http:\\/\\/some.where\\/ii\\/goethe-untyped-name>\",
;;   \"<http:\\/\\/some.where\\/ii\\/goethe-occ>\",\"_:o991\",\"<http:\\/\\/some.where\\/ii\\/goethe-years-occ>\",\"_:o1004\",\"_:o1009\"],\"predicate\":[\"<http:\\/\\/some.where\\/tmsparql\\/date-of-birth>\",
;;   \"<http:\\/\\/some.where\\/tmsparql\\/date-of-death>\",\"<http:\\/\\/some.where\\/tmsparql\\/years>\",\"<http:\\/\\/some.where\\/tmsparql\\/isDead>\",\"<http:\\/\\/some.where\\/tmsparql\\/isAlive>\",
;;   \"<http:\\/\\/some.where\\/tmsparql\\/last-name>\",\"<http:\\/\\/some.where\\/tmsparql\\/first-name>\",\"<http:\\/\\/psi.topicmaps.org\\/iso13250\\/model\\/type>\",
;;   \"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",\"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",
;;   \"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",\"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",
;;   \"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",\"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",
;;   \"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\",\"<http:\\/\\/www.networkedplanet.com\\/tmsparql\\/topicProperty>\"]}"

Web Interface

The TM-SPARQL interface can be also used via a RESTful handler, see wiki

Last modified 8 years ago Last modified on 04/18/11 15:30:55