Author: lgiessmann Date: Mon Nov 22 15:54:02 2010 New Revision: 348
Log: TM-SPARQL: added some unit-tests for parsing of more triples in a statment => fixed a bug when collecting the values of those triples
Modified: trunk/src/TM-SPARQL/sparql_parser.lisp trunk/src/unit_tests/sparql_test.lisp
Modified: trunk/src/TM-SPARQL/sparql_parser.lisp ============================================================================== --- trunk/src/TM-SPARQL/sparql_parser.lisp (original) +++ trunk/src/TM-SPARQL/sparql_parser.lisp Mon Nov 22 15:54:02 2010 @@ -419,9 +419,10 @@
(defgeneric parse-triple (construct query-string values &key last-subject) (:documentation "Parses a triple within a trippel group and returns a - a list of the form (:next-query :subject (:type <'VAR|'IRI> - :value string) :predicate (:type <'VAR|'IRI> :value string) - :object (:type <'VAR|'IRI|'LITERAL> :value string)).") + a list of the form (:next-query :values (:subject + (:type <'VAR|'IRI> :value string) :predicate + (:type <'VAR|'IRI> :value string) + :object (:type <'VAR|'IRI|'LITERAL> :value string))).") (:method ((construct SPARQL-Query) (query-string String) (values List) &key (last-subject nil)) (declare (List last-subject)) @@ -437,9 +438,10 @@ (object-result (parse-triple-elem (getf predicate-result :next-query) construct :literal-allowed t)) (all-values (append values - (list :subject (getf subject-result :value) - :predicate (getf predicate-result :value) - :object (getf object-result :value))))) + (list + (list :subject (getf subject-result :value) + :predicate (getf predicate-result :value) + :object (getf object-result :value)))))) (let ((tr-str (cut-comment (getf object-result :next-query)))) (cond ((string-starts-with tr-str ";") (parse-triple construct (subseq tr-str 1) all-values
Modified: trunk/src/unit_tests/sparql_test.lisp ============================================================================== --- trunk/src/unit_tests/sparql_test.lisp (original) +++ trunk/src/unit_tests/sparql_test.lisp Mon Nov 22 15:54:02 2010 @@ -276,5 +276,150 @@ (signals sparql-parser-error (tm-sparql::parse-triple-elem query-8 dummy-object))))
+ +(test test-parse-group-1 + "Test various functionality of several functions responsible for parsing + the SELECT-WHERE-statement." + (let ((query-1 "?subject ?predicate $object }") + (query-2 "<subject> pref:predicate 1234.5e12}") + (query-3 "pref:subject ?predicate 'literal'@en}") + (dummy-object (make-instance 'SPARQL-Query :query "" + :base "http://base.value/"))) + (is-true dummy-object) + (tm-sparql::add-prefix dummy-object "pref" "http://prefix.value/") + (let ((result (tm-sparql::parse-triple dummy-object query-1 nil))) + (is (string= (getf result :next-query) "}")) + (is (= (length (getf result :values)) 1)) + (is (eql (getf (getf (first (getf result :values)) :subject) :type) + 'TM-SPARQL::VAR)) + (is (string= (getf (getf (first (getf result :values)) :subject) :value) + "subject")) + (is (eql (getf (getf (first (getf result :values)) :predicate) :type) + 'TM-SPARQL::VAR)) + (is (string= (getf (getf (first (getf result :values)) :predicate) :value) + "predicate")) + (is (eql (getf (getf (first (getf result :values)) :object) :type) + 'TM-SPARQL::VAR)) + (is (string= (getf (getf (first (getf result :values)) :object) :value) + "object"))) + (let ((result (tm-sparql::parse-triple dummy-object query-2 nil))) + (is (string= (getf result :next-query) "}")) + (is (eql (getf (getf (first (getf result :values)) :subject) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :subject) :value) + "http://base.value/subject")) + (is (eql (getf (getf (first (getf result :values)) :predicate) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :predicate) :value) + "http://prefix.value/predicate")) + (is (eql (getf (getf (first (getf result :values)) :object) :type) + 'TM-SPARQL::LITERAL)) + (is (= (getf (getf (first (getf result :values)) :object) :value) + 1234.5e12)) + (is (string= (getf (getf (first (getf result :values)) :object) + :literal-type) + *xml-double*))) + (let ((result (tm-sparql::parse-triple dummy-object query-3 nil))) + (is (string= (getf result :next-query) "}")) + (is (eql (getf (getf (first (getf result :values)) :subject) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :subject) :value) + "http://prefix.value/subject")) + (is (eql (getf (getf (first (getf result :values)) :predicate) :type) + 'TM-SPARQL::VAR)) + (is (string= (getf (getf (first (getf result :values)) :predicate) :value) + "predicate")) + (is (eql (getf (getf (first (getf result :values)) :object) :type) + 'TM-SPARQL::LITERAL)) + (is (string= (getf (getf (first (getf result :values)) :object) :value) + "literal")) + (is (string= (getf (getf (first (getf result :values)) :object) + :literal-lang) + "en"))))) + + +(test test-parse-group-2 + "Test various functionality of several functions responsible for parsing + the SELECT-WHERE-statement." + (let ((query-4 (concatenate 'string "<subject> <predicate> '''true'''^^" + *xml-boolean* "; pref:predicate-2 "12"^^" + *xml-integer* "}")) + (query-5 (concatenate 'string "<subject> <predicate> '''false'''^^" + *xml-boolean* "; pref:predicate-2 "abc"^^" + *xml-string* "}")) + (dummy-object (make-instance 'SPARQL-Query :query "" + :base "http://base.value/"))) + (is-true dummy-object) + (tm-sparql::add-prefix dummy-object "pref" "http://prefix.value/") + (let ((result (tm-sparql::parse-triple dummy-object query-4 nil))) + (is (string= (getf result :next-query) "}")) + (is (= (length (getf result :values)) 2)) + (is (eql (getf (getf (first (getf result :values)) :subject) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :subject) :value) + "http://base.value/subject")) + (is (eql (getf (getf (first (getf result :values)) :predicate) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :predicate) :value) + "http://base.value/predicate")) + (is (eql (getf (getf (first (getf result :values)) :object) :type) + 'TM-SPARQL::LITERAL)) + (is (eql (getf (getf (first (getf result :values)) :object) :value) t)) + (is (string= (getf (getf (first (getf result :values)) :object) + :literal-type) + *xml-boolean*)) + (is (string= (getf result :next-query) "}")) + (is (= (length (getf result :values)) 2)) + (is (eql (getf (getf (second (getf result :values)) :subject) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (second (getf result :values)) :subject) :value) + "http://base.value/subject")) + (is (eql (getf (getf (second (getf result :values)) :predicate) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (second (getf result :values)) :predicate) :value) + "http://prefix.value/predicate-2")) + (is (eql (getf (getf (second (getf result :values)) :object) :type) + 'TM-SPARQL::LITERAL)) + (is (= (getf (getf (second (getf result :values)) :object) :value) 12)) + (is (string= (getf (getf (second (getf result :values)) :object) + :literal-type) + *xml-integer*))) + (let ((result (tm-sparql::parse-triple dummy-object query-5 nil))) + (is (string= (getf result :next-query) "}")) + (is (= (length (getf result :values)) 2)) + (is (eql (getf (getf (first (getf result :values)) :subject) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :subject) :value) + "http://base.value/subject")) + (is (eql (getf (getf (first (getf result :values)) :predicate) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (first (getf result :values)) :predicate) :value) + "http://base.value/predicate")) + (is (eql (getf (getf (first (getf result :values)) :object) :type) + 'TM-SPARQL::LITERAL)) + (is (eql (getf (getf (first (getf result :values)) :object) :value) nil)) + (is (string= (getf (getf (first (getf result :values)) :object) + :literal-type) + *xml-boolean*)) + (is (string= (getf result :next-query) "}")) + (is (= (length (getf result :values)) 2)) + (is (eql (getf (getf (second (getf result :values)) :subject) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (second (getf result :values)) :subject) :value) + "http://base.value/subject")) + (is (eql (getf (getf (second (getf result :values)) :predicate) :type) + 'TM-SPARQL::IRI)) + (is (string= (getf (getf (second (getf result :values)) :predicate) :value) + "http://prefix.value/predicate-2")) + (is (eql (getf (getf (second (getf result :values)) :object) :type) + 'TM-SPARQL::LITERAL)) + (is (string= (getf (getf (second (getf result :values)) :object) :value) + "abc")) + (is (string= (getf (getf (second (getf result :values)) :object) + :literal-type) + *xml-string*))))) + + + (defun run-sparql-tests () (it.bese.fiveam:run! 'sparql-test:sparql-tests))