Changeset 423 for trunk/src/TM-SPARQL
- Timestamp:
- 04/07/11 09:22:22 (14 years ago)
- Location:
- trunk/src/TM-SPARQL
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/TM-SPARQL/filter_wrappers.lisp ¶
r419 r423 153 153 154 154 155 (defun filter-functions::write-to-symbol (name-string) 156 (common-lisp:intern (common-lisp:string-upcase name-string))) 157 158 155 159 (defun filter-functions::bound(x) 156 (boundp x))160 (boundp (filter-functions::write-to-symbol x))) 157 161 158 162 -
TabularUnified trunk/src/TM-SPARQL/sparql.lisp ¶
r422 r423 395 395 "Returns a list that contains all values from all-values that 396 396 are not contained in true-values." 397 (let ((local-all-values 398 (remove-duplicates (reduce #'(lambda(x y) (append x y)) all-values) 399 :test #'variable-list=)) 400 (results nil)) 401 (dolist (value local-all-values) 402 (when (not (find value true-values :test #'variable-list=)) 403 (push value results))) 404 results)) 397 (cond ((not all-values) 398 nil) 399 ((not true-values) 400 (let ((local-all-values 401 (remove-duplicates (reduce #'(lambda(x y) (append x y)) all-values) 402 :test #'variable-list=))) 403 local-all-values)) 404 (t 405 (let ((local-all-values 406 (remove-duplicates (reduce #'(lambda(x y) (append x y)) all-values) 407 :test #'variable-list=)) 408 (results nil)) 409 (dolist (value local-all-values) 410 (when (not (find value true-values :test #'variable-list=)) 411 (push value results))) 412 results)))) 405 413 406 414 … … 414 422 (defgeneric process-filters (construct) 415 423 (:documentation "Processes all filters by calling invoke-filter.") 416 (:method ((construct SPARQL-Query)) 424 (:method ((construct SPARQL-Query)) 417 425 (dolist (filter (filters construct)) 418 (let* ((filter-variable-names 419 (get-variables-from-filter-string filter)) 420 (filter-variable-values nil)) 426 (let ((filter-variable-names (get-variables-from-filter-string filter)) 427 (filter-variable-values nil)) 421 428 (dolist (var-name filter-variable-names) 422 429 (setf filter-variable-values 423 430 (make-variable-values construct var-name filter-variable-values))) 431 (setf filter-variable-values 432 (remove-duplicates-from-variable-list construct filter-variable-values)) 424 433 (setf filter-variable-values 425 434 (cast-variable-values construct filter-variable-values)) … … 436 445 (dolist (to-del values-to-remove) 437 446 (delete-rows-by-value construct (getf to-del :variable-name) 438 (getf to-del :variable-value))))))) 439 construct)) 447 (getf to-del :variable-value))))))))) 448 449 450 (defgeneric remove-duplicates-from-variable-list (construct variable-list) 451 (:documentation "Removes all duplicates from the passed variable list") 452 (:method ((construct SPARQL-QUERY) (variable-list LIST)) 453 (remove-duplicates 454 variable-list 455 :test #'(lambda(x y) 456 (when (= (length x) (length y)) 457 (let ((result nil)) 458 (dotimes (idx (length x) result) 459 (let ((cx (elt x idx)) 460 (cy (elt y idx))) 461 (when (or (string/= (getf cx :variable-name) 462 (getf cy :variable-name)) 463 (and (getf cx :literal-datatype) 464 (getf cy :literal-datatype) 465 (string/= (getf cx :literal-datatype) 466 (getf cy :literal-datatype))) 467 (and (getf cx :literal-datatype) 468 (not (getf cy :literal-datatype))) 469 (and (not (getf cx :literal-datatype)) 470 (getf cy :literal-datatype)) 471 (and (getf cx :variable-value) 472 (getf cy :variable-value) 473 (string/= (getf cx :variable-value) 474 (getf cy :variable-value))) 475 (and (getf cx :variable-value) 476 (not (getf cy :variable-value))) 477 (and (not (getf cx :variable-value)) 478 (getf cy :variable-value))) 479 (setf idx (length x)))) 480 (when (= idx (max 0 (1- (length x)))) 481 (setf result t))))))))) 440 482 441 483 -
TabularUnified trunk/src/TM-SPARQL/sparql_filter.lisp ¶
r421 r423 231 231 (cleaned-arg-list (clean-function-arguments arg-list)) 232 232 (modified-str 233 (concat 234 left-str "(" fun-name " " cleaned-arg-list ")" 235 (subseq right-str (+ (- (length right-str) 236 (length cleaned-right-str)) 237 (length arg-list)))))) 233 (let ((modified-arg-list 234 (if (string= fun-name "BOUND") 235 (let* ((var-start 236 (search-first (list "?" "$") cleaned-arg-list)) 237 (var-end 238 (when var-start 239 (search-first 240 (list ")") 241 (subseq cleaned-arg-list var-start))))) 242 (when (and var-start var-end) 243 (concat (subseq cleaned-arg-list 0 var-start) 244 "\"" (subseq cleaned-arg-list var-start 245 (+ var-start var-end)) 246 "\"" (subseq cleaned-arg-list 247 (+ var-start var-end))))) 248 cleaned-arg-list))) 249 (concat 250 left-str "(" fun-name " " modified-arg-list ")" 251 (subseq right-str (+ (- (length right-str) 252 (length cleaned-right-str)) 253 (length arg-list))))))) 238 254 (set-functions construct modified-str)))))) 239 255 … … 1001 1017 (dotimes (idx (length filter-string)) 1002 1018 (let ((current-string (subseq filter-string idx))) 1003 (when (and (or (string-starts-with current-string "?") 1004 (string-starts-with current-string "$")) 1005 (not (in-literal-string-p filter-string idx))) 1006 (let ((end-pos 1007 (let ((inner-value 1008 (search-first 1009 (append (list " " "?" "$" "." ",") 1010 (*supported-operators*) 1011 *supported-brackets* 1012 (map 'list #'string (white-space))) 1013 (subseq current-string 1)))) 1014 (if inner-value 1015 (1+ inner-value) 1016 (length current-string))))) 1017 (push (subseq current-string 1 end-pos) variables) 1018 (incf idx end-pos))))) 1019 (cond ((and (or (string-starts-with current-string "?") 1020 (string-starts-with current-string "$")) 1021 (not (in-literal-string-p filter-string idx))) 1022 (let ((end-pos 1023 (let ((inner-value 1024 (search-first 1025 (append (list " " "?" "$" "." ",") 1026 (*supported-operators*) 1027 *supported-brackets* 1028 (map 'list #'string (white-space))) 1029 (subseq current-string 1)))) 1030 (if inner-value 1031 (1+ inner-value) 1032 (length current-string))))) 1033 (push (subseq current-string 1 end-pos) variables) 1034 (incf idx end-pos))) 1035 ;BOUND needs a separate hanlding since all variables 1036 ; were written into strings so they have to be 1037 ; searched different 1038 ((and (string-starts-with current-string "BOUND ") 1039 (not (in-literal-string-p filter-string idx))) 1040 (let* ((next-str (subseq current-string (length "BOUND "))) 1041 (literal (when (string-starts-with next-str "\"") 1042 (let ((val (get-literal next-str))) 1043 (when val 1044 (getf val :literal)))))) 1045 (when (and literal (> (length literal) 3)) ;"?.." | "$.." 1046 (push (subseq (string-trim (list #\") literal) 1) variables)) 1047 (incf idx (+ (length "BOUND ") (length literal)))))))) 1019 1048 (remove-duplicates variables :test #'string=)))
Note: See TracChangeset
for help on using the changeset viewer.