Changeset 370


Ignore:
Timestamp:
12/18/10 03:30:41 (14 years ago)
Author:
lgiessmann
Message:

TM-SPARQL: added the handling of the binary + and - operators

File:
1 edited

Legend:

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

    r369 r370  
    120120   It must not be in a literal string or directly after a (."
    121121  (declare (String filter-string))
    122   (let ((first-pos (search-first-ignore-literals (list "*" "/") filter-string)))
     122  (let ((first-pos
     123         (search-first-ignore-literals *supported-primary-arithmetic-operators*
     124                                       filter-string)))
    123125    (when first-pos
    124126      (let ((left-part (trim-whitespace-right (subseq filter-string 0 first-pos))))
     
    163165          (let ((inner-value
    164166                 (search-first-ignore-literals
    165                   (append *supported-join-operators*
    166                           *supported-secundary-arithmetic-operators*
     167                  (append *supported-secundary-arithmetic-operators*
    167168                          *supported-compare-operators*)
    168169                  left-string :from-end t)))
     
    190191  (declare (String right-string))
    191192  (let* ((first-pos (search-first-ignore-literals
    192                      (append *supported-join-operators*
    193                              (*supported-arithmetic-operators*)
     193                     (append (*supported-arithmetic-operators*)
    194194                             *supported-compare-operators*)
    195195                     right-string))
     
    218218                   string to the the corresponding lisp functions.")
    219219  (:method ((construct SPARQL-Query) (filter-string String))
    220     ;TODO: implement
    221     filter-string))
     220    (let ((op-pos (find-+--operators filter-string)))
     221      (if (or (not op-pos) (= *tmp* 5))
     222            filter-string
     223          (let* ((op-str (subseq filter-string op-pos (1+ op-pos)))
     224                 (left-str (subseq filter-string 0 op-pos))
     225                 (right-str (subseq filter-string (1+ op-pos)))
     226                 (left-scope (find-+--left-scope left-str))
     227                 (right-scope (find-+--right-scope right-str))
     228                 (modified-str
     229                  (concatenate
     230                   'string (subseq left-str 0 (- (length left-str)
     231                                                 (length left-scope)))
     232                   "(" op-str " " left-scope " " right-scope ")"
     233                   (subseq right-str (length right-scope)))))
     234            ;(format t "fs:_~a_~%os:_~a_~%ls:_~a_~%lc:_~a_~%rs:_~a_~%rc:_~a_~%ms:_~a_~%~%"
     235            ;filter-string op-str left-str left-scope right-str right-scope
     236            ;modified-str)
     237            (set-+-and---operators construct modified-str))))))
     238
     239
     240(defun find-+--left-scope (left-string)
     241  "Returns the string that is the left part of the binary scope."
     242  (declare (String left-string))
     243  ;TODO: adapt
     244  (let* ((first-bracket
     245          (let ((inner-value (search-first-unclosed-paranthesis left-string)))
     246            (when inner-value
     247              (+ inner-value (1+ (length (name-after-paranthesis
     248                                          (subseq left-string inner-value))))))))
     249         (other-anchor
     250          (let ((inner-value
     251                 (search-first-ignore-literals
     252                  (append *supported-secundary-arithmetic-operators*
     253                          *supported-compare-operators*)
     254                  left-string :from-end t)))
     255            (when inner-value
     256              (1+ inner-value))))
     257         (paranthesis-pair-idx
     258          (let* ((cleaned-str (trim-whitespace-right left-string))
     259                 (bracket-scope (reverse-bracket-scope cleaned-str)))
     260            (when bracket-scope
     261              (- (- (length left-string)
     262                    (- (length left-string) (length cleaned-str)))
     263                 (length bracket-scope)))))
     264         (start-idx (cond (paranthesis-pair-idx
     265                           paranthesis-pair-idx)
     266                          ((and first-bracket other-anchor)
     267                           (max first-bracket other-anchor))
     268                          ((or first-bracket other-anchor)
     269                           (or first-bracket other-anchor))
     270                          (t 0))))
     271    (subseq left-string start-idx)))
     272
     273
     274(defun find-+--right-scope (right-string)
     275  "Returns the string that is the right part of the binary scope."
     276  (declare (String right-string))
     277  ;TODO: adapt
     278  (let* ((first-pos (search-first-ignore-literals
     279                     (append (*supported-arithmetic-operators*)
     280                             *supported-compare-operators*)
     281                     right-string))
     282         (first-bracket
     283          (let ((inner-value (search-first-unopened-paranthesis right-string)))
     284            (when inner-value (1+ inner-value))))
     285         (paranthesis-pair-idx
     286          (let* ((cleaned-str (trim-whitespace-left right-string))
     287                 (bracket-scope (bracket-scope cleaned-str)))
     288            (when bracket-scope
     289              (+ (- (length right-string) (length cleaned-str))
     290                 (length bracket-scope)))))
     291         (end-idx (cond (paranthesis-pair-idx
     292                         paranthesis-pair-idx)
     293                        ((and first-pos first-bracket)
     294                         (min first-pos first-bracket))
     295                        (first-pos first-pos)
     296                        (first-bracket first-bracket)
     297                        (t (if (= (length right-string) 0)
     298                               (1- (length right-string)))))))
     299    (subseq right-string 0 end-idx)))
     300
     301
     302(defun find-+--operators (filter-string)
     303  "Returns the idx of the first found + or - operator.
     304   It must not be in a literal string or directly after a (."
     305  (declare (String filter-string))
     306  (let ((first-pos
     307         (search-first-ignore-literals *supported-secundary-arithmetic-operators*
     308                                       filter-string)))
     309    (when first-pos
     310      (let ((left-part (trim-whitespace-right (subseq filter-string 0 first-pos))))
     311        (if (and (not (string-ends-with left-part "(one"))
     312                 (not (string-ends-with left-part "(")))
     313            first-pos
     314            (let ((next-pos
     315                   (find-+--operators (subseq filter-string (1+ first-pos)))))
     316              (when next-pos
     317                (+ 1 first-pos next-pos))))))))
    222318
    223319
Note: See TracChangeset for help on using the changeset viewer.