Changeset 349 for trunk/src/TM-SPARQL
- Timestamp:
- 11/23/10 16:45:57 (14 years ago)
- Location:
- trunk/src/TM-SPARQL
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/TM-SPARQL/sparql.lisp ¶
r347 r349 17 17 (defvar *empty-label* "_empty_label_symbol") 18 18 19 (defclass Variable-Container () 20 ((variables :initarg :variables 21 :accessor variables ;this value is only for internal purposes 22 ;purposes and mustn't be reset 23 :type List 24 :initform nil 25 :documentation "A list of the form ((:variable var-name 26 :value value-object)), that contains tuples 27 for each variable and its result.")) 28 (:documentation "This class is used to store all variable in a WHERE{} 29 statement")) 19 20 ;(defclass SPARQL-Triple () 21 ; (()) 22 ; ) 30 23 31 24 32 (defclass SPARQL-Query ( Variable-Container)25 (defclass SPARQL-Query () 33 26 ((original-query :initarg :query 34 27 :accessor original-query ;this value is only for internal … … 40 33 :message "From TM-Query(): original-query must be set")) 41 34 :documentation "Containst the original received querry as string") 35 (variables :initarg :variables 36 :accessor variables ;this value is only for internal purposes 37 ;purposes and mustn't be reset 38 :type List 39 :initform nil 40 :documentation "A list of the form ((:variable var-name 41 :value value-object)), that contains tuples 42 for each selected variable and its result.") 42 43 (prefixes :initarg :prefixes 43 44 :accessor prefixes ;this value is only for internal purposes … … 98 99 overwritten. An entry is of the form 99 100 (:variable string :value any-type).") 100 (:method ((construct Variable-Container) (variable-name String) variable-value)101 (:method ((construct SPARQL-Query) (variable-name String) variable-value) 101 102 (let ((existing-tuple 102 103 (find-if #'(lambda(x) -
TabularUnified trunk/src/TM-SPARQL/sparql_parser.lisp ¶
r348 r349 105 105 (error (make-sparql-parser-condition trimmed-str 106 106 (original-query construct) "{"))) 107 (let ((query-tail (parse-group construct (subseq trimmed-str 1) nil nil)))107 (let ((query-tail (parse-group construct (subseq trimmed-str 1)))) 108 108 ;TODO: process query-tail 109 109 query-tail)))) 110 110 111 111 112 (defgeneric parse-group (construct query-string values filters)112 (defgeneric parse-group (construct query-string &key last-subject values filters) 113 113 (:documentation "The entry-point for the parsing of a {} statement.") 114 114 (:method ((construct SPARQL-Query) (query-string String) 115 (values List) (filters List)) 115 &key (last-subject nil) (values nil) (filters nil)) 116 (declare (List last-subject values filters)) 116 117 (let ((trimmed-str (cut-comment query-string))) 117 118 (cond ((string-starts-with trimmed-str "BASE") … … 123 124 "FILTER, BASE, or triple. Grouping is currently no implemented."))) 124 125 ((string-starts-with trimmed-str "FILTER") 125 nil) ;TODO: call parse-group with added filter126 nil) ;TODO: parse-filter and store it 126 127 ((string-starts-with trimmed-str "OPTIONAL") 127 128 (error (make-sparql-parser-condition … … 136 137 (subseq trimmed-str 1)) 137 138 (t 138 (let ((result (parse-triple construct trimmed-str values))) 139 (parse-group construct (getf result :next-query) 140 (getf result :values) filters))))))) 141 139 ;(let ((result 140 (parse-triple construct trimmed-str :values values 141 :filters filters :last-subject last-subject)))))) 142 143 144 (defun parse-filter (query-string query-object) 145 "A helper functions that returns a filter and the next-query string 146 in the form (:next-query string :filter object)." 147 ;; !, +, -, *, /, (, ), &&, ||, =, !=, <, >, >=, <=, REGEX(string, pattern) 148 (declare (String query-string) 149 (SPARQL-Query query-object)) 150 ;;TODO: implement 151 (or query-string query-object)) 142 152 143 153 … … 418 428 419 429 420 (defgeneric parse-triple (construct query-string values &key last-subject) 430 (defgeneric parse-triple (construct query-string 431 &key last-subject values filters) 421 432 (:documentation "Parses a triple within a trippel group and returns a 422 433 a list of the form (:next-query :values (:subject … … 424 435 (:type <'VAR|'IRI> :value string) 425 436 :object (:type <'VAR|'IRI|'LITERAL> :value string))).") 426 (:method ((construct SPARQL-Query) (query-string String) (values List)427 &key (last-subject nil) )428 (declare (List last-subject ))437 (:method ((construct SPARQL-Query) (query-string String) 438 &key (last-subject nil) (values nil) (filters nil)) 439 (declare (List last-subject filters values)) 429 440 (let* ((trimmed-str (cut-comment query-string)) 430 441 (subject-result (if last-subject ;;is used after a ";" … … 445 456 (let ((tr-str (cut-comment (getf object-result :next-query)))) 446 457 (cond ((string-starts-with tr-str ";") 447 (parse-triple construct (subseq tr-str 1) all-values 448 :last-subject (list :value 449 (getf subject-result :value)))) 458 (parse-group 459 construct (subseq tr-str 1) 460 :last-subject (list :value (getf subject-result :value)) 461 :values all-values 462 :filters filters)) 450 463 ((string-starts-with tr-str ".") 451 (parse-triple construct (subseq tr-str 1) all-values)) 452 ((string-starts-with tr-str "}") ;no other triples follows 453 (list :next-query tr-str 454 :values all-values))))))) 464 (parse-group construct (subseq tr-str 1) :values all-values 465 :filters filters)) 466 ((string-starts-with tr-str "}") 467 (parse-group construct tr-str :values all-values 468 :filters filters))))))) 455 469 456 470
Note: See TracChangeset
for help on using the changeset viewer.