Changeset 418
- Timestamp:
- 04/06/11 11:01:57 (14 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/TM-SPARQL/sparql.lisp ¶
r417 r418 298 298 299 299 300 301 (defgeneric cast-variable-values(construct variable-value-list) 302 (:documentation "Casts all values contained in the variable value list 303 to the corresponding type that is also stored in the 304 variable-value list.") 305 (:method ((construct SPARQL-Query) (variable-value-list List)) 306 (map 'list 307 #'(lambda(item) 308 (map 'list 309 #'(lambda(inner-item) 310 (list :variable-name (getf inner-item :variable-name) 311 :variable-value 312 (if (and (getf inner-item :variable-value) 313 (getf inner-item :literal-datatype)) 314 (cast-literal (getf inner-item :variable-value) 315 (getf inner-item :literal-datatype) 316 :back-as-string-when-unsupported t) 317 (getf inner-item :variable-value)))) 318 item)) 319 variable-value-list))) 320 321 300 322 (defgeneric make-variable-values(construct variable-name existing-results) 301 323 (:documentation "Returns a list of values that are bound to the passed … … 311 333 (string= (value (subject triple)) variable-name)) 312 334 return (progn (setf found-p t) 313 ( subject-result triple))335 (list :result (subject-result triple))) 314 336 when (and (variable-p (predicate triple)) 315 337 (string= (value (predicate triple)) variable-name)) 316 338 return (progn (setf found-p t) 317 ( predicate-result triple))339 (list :result (predicate-result triple))) 318 340 when (and (variable-p (object triple)) 319 341 (string= (value (object triple)) 320 342 variable-name)) 321 343 return (progn (setf found-p t) 322 (object-result triple)))) 344 (list :result (object-result triple) 345 :literal-datatype (object-datatype triple))))) 323 346 (new-results nil)) 324 347 (if (not found-p) 325 348 existing-results 326 349 (if existing-results 327 (do list (result resultsnew-results)350 (dotimes (idx (length (getf results :result)) new-results) 328 351 (dolist (old-result existing-results) 329 (push (append old-result (list (list :variable-name variable-name 330 :variable-value result))) 352 (push (append old-result 353 (list 354 (list :variable-name variable-name 355 :literal-datatype 356 (when (getf results :literal-datatype) 357 (elt (getf results :literal-datatype) idx)) 358 :variable-value 359 (elt (getf results :result) idx)))) 331 360 new-results))) 332 (map 'list #'(lambda(result) 333 (list (list :variable-name variable-name 334 :variable-value result))) 335 results)))))) 361 (loop for idx to (1- (length (getf results :result))) 362 collect (list 363 (list :variable-name variable-name 364 :literal-datatype 365 (when (getf results :literal-datatype) 366 (elt (getf results :literal-datatype) idx)) 367 :variable-value 368 (elt (getf results :result) idx))))))))) 336 369 337 370 … … 390 423 (setf filter-variable-values 391 424 (make-variable-values construct var-name filter-variable-values))) 425 (setf filter-variable-values 426 (cast-variable-values construct filter-variable-values)) 392 427 (dolist (filter (filters construct)) 393 428 (dolist (var-elem filter-variable-values) 429 430 ;(format t "~a~%==>~a~%~%" (to-lisp-code var-elem filter) 431 ;(eval (read-from-string (to-lisp-code var-elem filter)))) ;TODO: remove 432 394 433 (when (eval (read-from-string (to-lisp-code var-elem filter))) 395 434 (map 'list #'(lambda(list-elem) 396 435 (push list-elem true-values)) 397 436 var-elem)))) 437 ;(format t "tv: -->~a<--~%" true-values) ;TODO: remove 398 438 (let ((values-to-remove 399 439 (return-false-values filter-variable-values 400 440 (remove-duplicates true-values 401 441 :test #'variable-list=)))) 442 ;(format t "vr: -->~a<--~%" values-to-remove) ;TODO: remove 402 443 (dolist (to-del values-to-remove) 403 444 (delete-rows-by-value construct (getf to-del :variable-name) … … 416 457 (cond ((eql what :subject) (subject-result construct)) 417 458 ((eql what :predicate) (predicate-result construct)) 418 ((eql what :object) (object-result construct)))) 419 (is-variable 459 ((eql what :object) 460 (if (object-datatype construct) 461 (loop for idx to (1- (length (object-result construct))) 462 when (elt (object-datatype construct) idx) 463 collect (cast-literal 464 (elt (object-result construct) idx) 465 (elt (object-datatype construct) idx) 466 :back-as-string-when-unsupported t) 467 else 468 collect (elt (object-result construct) idx)) 469 (object-result construct))))) 470 (variable-p 420 471 (cond ((eql what :subject) 421 472 (and (variable-p (subject construct)) … … 427 478 (and (variable-p (object construct)) 428 479 (value (object construct))))))) 429 (when is-variable480 (when variable-p 430 481 (remove-null 431 482 (dotimes (idx (length local-results)) -
TabularUnified trunk/src/unit_tests/sparql_test.lisp ¶
r417 r418 2366 2366 <http://some.where/tmsparql/author/goethe> ?pred1 ?obj1. 2367 2367 FILTER ?obj1 = 'von Goethe' || ?obj1 = 82 2368 FILTER ?obj1 = 'von Goethe' || ?obj1 = 822369 FILTER (?obj1 = 'von Goethe' || 82 = ?obj1)2370 FILTER (?obj1 = 'von Goethe') || (82 = ?obj1)2371 FILTER ((?obj1 = 'von Goethe') || (82 = ?obj1))"2372 2368 #FILTER ?obj1 = 'von Goethe' || ?obj1 = '82'^^" *xml-integer* " 2369 #FILTER (?obj1 = 'von Goethe' || 82 = ?obj1) 2370 #FILTER (?obj1 = 'von Goethe') || (82 = ?obj1) 2371 #FILTER ((?obj1 = 'von Goethe') || (82 = ?obj1))" 2372 " 2373 2373 }")) 2374 2374 (r-1 (tm-sparql:result (make-instance 'TM-SPARQL:SPARQL-Query :query q-1)))) 2375 2375 2376 2376 2377 (map 'list #'(lambda(triple)2378 2379 2380 2381 2382 2383 2377 ;(map 'list #'(lambda(triple) 2378 ;(format t "~a - ~a - ~a[~a]~%" 2379 ;(tm-sparql::subject-result triple) 2380 ;(tm-sparql::predicate-result triple) 2381 ;(tm-sparql::object-result triple) 2382 ;(tm-sparql::object-datatype triple))) 2383 ;(tm-sparql::select-group (make-instance 'TM-SPARQL:SPARQL-Query :query q-1))) 2384 2384 2385 2385
Note: See TracChangeset
for help on using the changeset viewer.