Changeset 349 for trunk/src/TM-SPARQL


Ignore:
Timestamp:
11/23/10 16:45:57 (14 years ago)
Author:
lgiessmann
Message:

TM-SPARQL: fixed a recursion bug when parsing SELECT-WHERE-statements

Location:
trunk/src/TM-SPARQL
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/TM-SPARQL/sparql.lisp

    r347 r349  
    1717(defvar *empty-label* "_empty_label_symbol")
    1818
    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;  )
    3023
    3124
    32 (defclass SPARQL-Query (Variable-Container)
     25(defclass SPARQL-Query ()
    3326  ((original-query :initarg :query
    3427                   :accessor original-query  ;this value is only for internal
     
    4033                               :message "From TM-Query(): original-query must be set"))
    4134                   :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.")
    4243   (prefixes :initarg :prefixes
    4344             :accessor prefixes ;this value is only for internal purposes
     
    9899                   overwritten. An entry is of the form
    99100                   (: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)
    101102    (let ((existing-tuple
    102103           (find-if #'(lambda(x)
  • TabularUnified trunk/src/TM-SPARQL/sparql_parser.lisp

    r348 r349  
    105105        (error (make-sparql-parser-condition trimmed-str
    106106                                             (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))))
    108108        ;TODO: process query-tail
    109109        query-tail))))
    110110
    111111
    112 (defgeneric parse-group (construct query-string values filters)
     112(defgeneric parse-group (construct query-string &key last-subject values filters)
    113113  (:documentation "The entry-point for the parsing of a {} statement.")
    114114  (: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))
    116117    (let ((trimmed-str (cut-comment query-string)))
    117118      (cond ((string-starts-with trimmed-str "BASE")
     
    123124                     "FILTER, BASE, or triple. Grouping is currently no implemented.")))
    124125            ((string-starts-with trimmed-str "FILTER")
    125              nil) ;TODO: call parse-group with added filter
     126             nil) ;TODO: parse-filter and store it
    126127            ((string-starts-with trimmed-str "OPTIONAL")
    127128             (error (make-sparql-parser-condition
     
    136137             (subseq trimmed-str 1))
    137138            (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))
    142152
    143153
     
    418428
    419429
    420 (defgeneric parse-triple (construct query-string values &key last-subject)
     430(defgeneric parse-triple (construct query-string
     431                                    &key last-subject values filters)
    421432  (:documentation "Parses a triple within a trippel group and returns a
    422433                   a list of the form (:next-query :values (:subject
     
    424435                   (:type <'VAR|'IRI> :value string)
    425436                   :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))
    429440    (let* ((trimmed-str (cut-comment query-string))
    430441           (subject-result (if last-subject ;;is used after a ";"
     
    445456      (let ((tr-str (cut-comment (getf object-result :next-query))))
    446457        (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))
    450463              ((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)))))))
    455469
    456470
Note: See TracChangeset for help on using the changeset viewer.