Changeset 381 for trunk/src/TM-SPARQL
- Timestamp:
- 12/20/10 20:47:48 (14 years ago)
- Location:
- trunk/src/TM-SPARQL
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/TM-SPARQL/filter_wrappers.lisp ¶
r379 r381 14 14 15 15 16 (defun filter-functions::normalize-value (value) 17 "Returns the normalized value, i.e. if a literal 18 is passed as '12'^^xsd:integer 12 is returned." 19 (cond ((not (stringp value)) 20 value) 21 ((or (base-tools:string-starts-with value "'") 22 (base-tools:string-starts-with value "\"")) 23 (let* ((literal-result (tm-sparql::get-literal value)) 24 (literal-value 25 (cond ((or (base-tools:string-starts-with 26 (getf literal-result :literal) "\"\"\"") 27 (base-tools:string-starts-with 28 (getf literal-result :literal) "'''")) 29 (subseq (getf literal-result :literal) 3 30 (- (length (getf literal-result :literal)) 3))) 31 (t 32 (subseq (getf literal-result :literal) 1 33 (- (length (getf literal-result :literal)) 1))))) 34 (given-datatype 35 (when (base-tools:string-starts-with 36 (getf literal-result :next-string) "^^") 37 (subseq (getf literal-result :next-string) 2)))) 38 (tm-sparql::cast-literal literal-value given-datatype))) 39 (t 40 value))) 41 42 16 43 (defun filter-functions::not(x) 17 (not x))44 (not (filter-functions::normalize-value x))) 18 45 19 46 20 47 (defun filter-functions::one+(x) 21 (1+ x))48 (1+ (filter-functions::normalize-value x))) 22 49 23 50 24 51 (defun filter-functions::one-(x) 25 (1- x))52 (1- (filter-functions::normalize-value x))) 26 53 27 54 28 55 (defun filter-functions::+(x y) 29 (+ x y)) 56 (+ (filter-functions::normalize-value x) 57 (filter-functions::normalize-value y))) 30 58 31 59 32 60 (defun filter-functions::-(x y) 33 (- x y)) 61 (- (filter-functions::normalize-value x) 62 (filter-functions::normalize-value y))) 34 63 35 64 36 65 (defun filter-functions::*(x y) 37 (* x y)) 66 (* (filter-functions::normalize-value x) 67 (filter-functions::normalize-value y))) 38 68 39 69 40 70 (defun filter-functions::/(x y) 41 (/ x y)) 71 (/ (filter-functions::normalize-value x) 72 (filter-functions::normalize-value y))) 42 73 43 74 44 75 (defun filter-functions::or(x y) 45 (or x y)) 76 (or (filter-functions::normalize-value x) 77 (filter-functions::normalize-value y))) 46 78 47 79 48 80 (defun filter-functions::and(x y) 49 (and x y)) 81 (and (filter-functions::normalize-value x) 82 (filter-functions::normalize-value y))) 50 83 51 84 52 85 (defun filter-functions::=(x y) 53 (cond ((and (stringp x) (stringp y)) 54 (string= x y)) 55 ((and (numberp x)( numberp y)) 56 (= x y)) 57 (t 58 (eql x y)))) 86 (let ((local-x (filter-functions::normalize-value x)) 87 (local-y (filter-functions::normalize-value y))) 88 (cond ((and (stringp local-x) (stringp local-y)) 89 (string= local-x local-y)) 90 ((and (numberp local-x)( numberp local-y)) 91 (= local-x local-y)) 92 (t 93 (eql local-x local-y))))) 59 94 60 95 … … 65 100 66 101 (defun filter-functions::<(x y) 67 (cond ((and (numberp x) (numberp y)) 68 (< x y)) 69 ((and (stringp x) (stringp y)) 70 (string< x y)) 71 ((and (typep x 'Boolean) (typep y 'Boolean)) 72 (and (not x) y)) 73 (t 74 nil))) 102 (let ((local-x (filter-functions::normalize-value x)) 103 (local-y (filter-functions::normalize-value y))) 104 (cond ((and (numberp local-x) (numberp local-y)) 105 (< local-x local-y)) 106 ((and (stringp local-x) (stringp local-y)) 107 (string< local-x local-y)) 108 ((and (typep local-x 'Boolean) (typep local-y 'Boolean)) 109 (and (not local-x) local-y)) 110 (t 111 nil)))) 75 112 76 113 … … 93 130 94 131 (defun filter-functions::regex(str pattern &optional flags) 95 ( declare (Ignorable flags))96 (let* ((case-insensitive (when (find #\iflags) t))97 (multi-line (when (find #\m flags) t))98 (single-line (when (find #\s flags) t))132 (let* ((local-flags (filter-functions::normalize-value flags)) 133 (case-insensitive (when (find #\i local-flags) t)) 134 (multi-line (when (find #\m local-flags) t)) 135 (single-line (when (find #\s local-flags) t)) 99 136 (local-pattern 100 (if (find #\x flags)137 (if (find #\x local-flags) 101 138 (base-tools:string-replace 102 139 (base-tools:string-replace 103 140 (base-tools:string-replace 104 (base-tools:string-replace pattern (string #\newline) "") 141 (base-tools:string-replace 142 (filter-functions::normalize-value pattern) 143 (string #\newline) "") 105 144 (string #\tab) "") (string #\cr) "") " " "") 106 pattern))145 (filter-functions::normalize-value pattern))) 107 146 (scanner 108 147 (ppcre:create-scanner local-pattern -
TabularUnified trunk/src/TM-SPARQL/sparql.lisp ¶
r379 r381 1011 1011 1012 1012 1013 (defun cast-literal (literal-value literal-type) 1014 "A helper function that casts the passed string value of the literal 1015 corresponding to the passed literal-type." 1016 (declare (String literal-value literal-type)) 1017 (cond ((string= literal-type *xml-string*) 1018 literal-value) 1019 ((string= literal-type *xml-boolean*) 1020 (when (and (string/= literal-value "false") 1021 (string/= literal-value "true")) 1022 (error (make-condition 1023 'sparql-parser-error 1024 :message (format nil "Could not cast from ~a to ~a" 1025 literal-value literal-type)))) 1026 (if (string= literal-value "false") 1027 nil 1028 t)) 1029 ((string= literal-type *xml-integer*) 1030 (handler-case (parse-integer literal-value) 1031 (condition () 1032 (error (make-condition 1033 'sparql-parser-error 1034 :message (format nil "Could not cast from ~a to ~a" 1035 literal-value literal-type)))))) 1036 ((or (string= literal-type *xml-decimal*) ;;both types are 1037 (string= literal-type *xml-double*)) ;;handled the same way 1038 (let ((value (read-from-string literal-value))) 1039 (unless (numberp value) 1040 (error (make-condition 1041 'sparql-parser-error 1042 :message (format nil "Could not cast from ~a to ~a" 1043 literal-value literal-type)))) 1044 value)) 1045 (t ; return the value as a string 1046 literal-value))) 1047 1048 1013 1049 (defmethod initialize-instance :after ((construct SPARQL-Query) &rest args) 1014 1050 (declare (ignorable args)) -
TabularUnified trunk/src/TM-SPARQL/sparql_filter.lisp ¶
r380 r381 122 122 construct filter-string-functions original-filter-string)) 123 123 (parse-group construct next-query)))) 124 ;;TODO: implement125 ;; *add ^^datatype to the object-literal-results126 ;; *implement to-literal => CharacteristicC => \"...\"^^datatype => use for tm-sparql127 ;; *implement str correctly128 124 129 125 -
TabularUnified trunk/src/TM-SPARQL/sparql_parser.lisp ¶
r379 r381 218 218 219 219 220 (defun cast-literal (literal-value literal-type)221 "A helper function that casts the passed string value of the literal222 corresponding to the passed literal-type."223 (declare (String literal-value literal-type))224 (cond ((string= literal-type *xml-string*)225 literal-value)226 ((string= literal-type *xml-boolean*)227 (when (and (string/= literal-value "false")228 (string/= literal-value "true"))229 (error (make-condition230 'sparql-parser-error231 :message (format nil "Could not cast from ~a to ~a"232 literal-value literal-type))))233 (if (string= literal-value "false")234 nil235 t))236 ((string= literal-type *xml-integer*)237 (handler-case (parse-integer literal-value)238 (condition ()239 (error (make-condition240 'sparql-parser-error241 :message (format nil "Could not cast from ~a to ~a"242 literal-value literal-type))))))243 ((or (string= literal-type *xml-decimal*) ;;both types are244 (string= literal-type *xml-double*)) ;;handled the same way245 (let ((value (read-from-string literal-value)))246 (unless (numberp value)247 (error (make-condition248 'sparql-parser-error249 :message (format nil "Could not cast from ~a to ~a"250 literal-value literal-type))))251 value))252 (t ; return the value as a string253 literal-value)))254 255 256 220 (defgeneric separate-literal-lang-or-type (construct query-string) 257 221 (:documentation "A helper function that returns (:next-query string
Note: See TracChangeset
for help on using the changeset viewer.