[http://trac.common-lisp.net/isidorus/wiki/ 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 [http://www.networkedplanet.com/ontopic/2009/11/making_topic_maps_sparql.html 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
SELECT $object ?predicate WHERE{
?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" ""
;; "_:n946" "_:n953" ""
;; "" "_:o991"
;; "" "_:o1004" "_:o1009"))
;; (:VARIABLE "predicate" :RESULT
;; (""
;; ""
;; "" ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; ""
;; "")))
}}}
The query object can als be serialised directly as JSON
{{{
(let* ((query-1
"BASE
SELECT $object ?predicate WHERE{
?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\",\"\",\"_:n946\",\"_:n953\",\"\",
;; \"\",\"_:o991\",\"\",\"_:o1004\",\"_:o1009\"],\"predicate\":[\"\",
;; \"\",\"\",\"\",\"\",
;; \"\",\"\",\"\",
;; \"\",\"\",
;; \"\",\"\",
;; \"\",\"\",
;; \"\",\"\"]}"
}}}
== Web Interface ==
The TM-SPARQL interface can be also used via a RESTful handler, see [http://trac.common-lisp.net/isidorus/wiki/AjaxInterface wiki]