From: <cw...@us...> - 2007-06-21 15:52:57
|
Revision: 463 http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=463&view=rev Author: cweiske Date: 2007-06-21 08:52:53 -0700 (Thu, 21 Jun 2007) Log Message: ----------- Some Sparql parser tests for nested queries and the querysimplifier Modified Paths: -------------- trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php Added Paths: ----------- trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php trunk/rdfapi-php/test/unit/sparqlParserTests.php Removed Paths: ------------- trunk/rdfapi-php/test/unit/Sparql/filterCases.php Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php =================================================================== --- trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php 2007-06-21 14:48:58 UTC (rev 462) +++ trunk/rdfapi-php/test/unit/Sparql/SparqlParserTests_test.php 2007-06-21 15:52:53 UTC (rev 463) @@ -1,7 +1,10 @@ <?php require_once dirname(__FILE__) . '/../../config.php'; +require_once dirname(__FILE__) . '/casesParserFilter.php'; +require_once dirname(__FILE__) . '/casesParserNested.php'; +require_once dirname(__FILE__) . '/SparqlTestHelper.php'; require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlParser.php'; -require_once dirname(__FILE__) . '/filterCases.php'; +require_once RDFAPI_INCLUDE_DIR . 'sparql/SparqlEngineDb/QuerySimplifier.php'; /** @@ -9,6 +12,57 @@ */ class testSparqlParserTests extends UnitTestCase { + /** + * Tests if Query::getLanguageTag() works correctly + */ + function testQueryGetLanguageTag() + { + $this->assertEqual('en', Query::getLanguageTag('?x@en')); + $this->assertEqual('en', Query::getLanguageTag('?x@en^^xsd:integer')); + $this->assertEqual('en', Query::getLanguageTag('?x^^xsd:integer@en')); + $this->assertEqual('en_US', Query::getLanguageTag('?x@en_US')); + }//function testQueryGetLanguageTag() + + + + /** + * Tests if Query::getDatatype() works correctly + */ + function testQueryGetDatatype() + { + $q = new Query(); + $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); + $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); + $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#'); + + $this->assertNull($q->getDatatype('?name')); + $this->assertNull($q->getDatatype('?name@en')); + $this->assertEqual( + 'http://www.w3.org/2001/XMLSchema#integer', + $q->getDatatype('?name^^xsd:integer') + ); + $this->assertEqual( + 'http://www.w3.org/2001/XMLSchema#integer', + $q->getDatatype('?name^^<http://www.w3.org/2001/XMLSchema#integer>') + ); + }//function testQueryGetDatatype() + + + + function testQueryGetFullUri() + { + $q = new Query(); + $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); + $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); + $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#'); + + $this->assertEqual('http://www.w3.org/2001/XMLSchema#integer', $q->getFullUri('xsd:integer')); + $this->assertFalse($q->getFullUri('yyy:integer')); + $this->assertFalse($q->getFullUri('integer')); + }//function testQueryGetFullUri() + + + function testEdgeCases() { $query = <<<EOT @@ -33,7 +87,7 @@ EOT; $p = new SparqlParser(); $q = $p->parse($query); - } + }//function testEdgeCases() @@ -47,7 +101,7 @@ $q = $p->parse($query); $res = $q->getResultPart(); - $constraint = $res[0]->getConstraint(); + $constraint = $res[0]->getConstraints(); $tree = $constraint[0]->getTree(); self::removeLevel($tree); @@ -55,92 +109,29 @@ if ($result != $tree) { var_dump($tree); echo '----------------------' . "\n" . $query . "\n"; - echo "\n!!!!!!!! " . self::renderTree($tree) . "\n\n"; + echo "\n!!!!!!!! " . SparqlTestHelper::renderTree($tree) . "\n\n"; } } - } + }//function testParseFilter() - /** - * Tests if Query::getLanguageTag() works correctly - */ - function testQueryGetLanguageTag() - { - $this->assertEqual('en', Query::getLanguageTag('?x@en')); - $this->assertEqual('en', Query::getLanguageTag('?x@en^^xsd:integer')); - $this->assertEqual('en', Query::getLanguageTag('?x^^xsd:integer@en')); - $this->assertEqual('en_US', Query::getLanguageTag('?x@en_US')); - } - /** - * Tests if Query::getDatatype() works correctly - */ - function testQueryGetDatatype() + function testParseNested() { - $q = new Query(); - $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); - $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); - $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#'); + echo "<b>Nested queries tests</b><br/>\n"; + foreach ($GLOBALS['testSparqlParserTestsNested'] as $arNestedTest) { + list($query, $strExpected) = $arNestedTest; - $this->assertNull($q->getDatatype('?name')); - $this->assertNull($q->getDatatype('?name@en')); - $this->assertEqual( - 'http://www.w3.org/2001/XMLSchema#integer', - $q->getDatatype('?name^^xsd:integer') - ); - $this->assertEqual( - 'http://www.w3.org/2001/XMLSchema#integer', - $q->getDatatype('?name^^<http://www.w3.org/2001/XMLSchema#integer>') - ); - } + $p = new SparqlParser(); + $q = $p->parse($query); + $qs = new SparqlEngineDb_QuerySimplifier(); + $qs->simplify($q); - function testQueryGetFullUri() - { - $q = new Query(); - $q->addPrefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); - $q->addPrefix('rdf' , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); - $q->addPrefix('xsd' , 'http://www.w3.org/2001/XMLSchema#'); - - $this->assertEqual('http://www.w3.org/2001/XMLSchema#integer', $q->getFullUri('xsd:integer')); - $this->assertFalse($q->getFullUri('yyy:integer')); - $this->assertFalse($q->getFullUri('integer')); - } - - - - /** - * Helper method that creates a sparql filter string from the - * given filter tree. - */ - static function renderTree($tree) - { - if (!is_array($tree) || !isset($tree['type'])) { - return 'Parser is broken'; + $strRendResult = SparqlTestHelper::renderResult($q); + $this->assertEqual($strExpected, $strRendResult); } - $negation = isset($tree['negated']) ? '!' : ''; - switch ($tree['type']) { - case 'equation': - return $negation . '(' . self::renderTree($tree['operand1']) - . ' ' . $tree['operator'] . ' ' - . self::renderTree($tree['operand2']) . ')'; - case 'value': - return $negation . $tree['value']; - case 'function': - return $negation . $tree['name'] . '(' - . implode( - ', ', - array_map( - array('self', 'renderTree'), - $tree['parameter'] - ) - ) . ')'; - default: - var_dump($tree); - throw new Exception('Unsupported tree type: ' . $tree['type']); - break; - } - }//static function renderTree($tree) + }//function testParseNested() @@ -157,6 +148,7 @@ self::removeLevel($tree['operand1']); self::removeLevel($tree['operand2']); } - } -} + }//static function removeLevel(&$tree) + +}//class testSparqlParserTests extends UnitTestCase ?> \ No newline at end of file Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php =================================================================== --- trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php 2007-06-21 14:48:58 UTC (rev 462) +++ trunk/rdfapi-php/test/unit/Sparql/SparqlTestHelper.php 2007-06-21 15:52:53 UTC (rev 463) @@ -67,5 +67,66 @@ return true; }//public static resultCheckSort($table, $result) + + + /** + * Helper method that creates a sparql filter string from the + * given filter tree. + */ + static function renderTree($tree) + { + if (!is_array($tree) || !isset($tree['type'])) { + return 'Parser is broken'; + } + $negation = isset($tree['negated']) ? '!' : ''; + switch ($tree['type']) { + case 'equation': + return $negation . '(' . self::renderTree($tree['operand1']) + . ' ' . $tree['operator'] . ' ' + . self::renderTree($tree['operand2']) . ')'; + case 'value': + return $negation . $tree['value']; + case 'function': + return $negation . $tree['name'] . '(' + . implode( + ', ', + array_map( + array('self', 'renderTree'), + $tree['parameter'] + ) + ) . ')'; + default: + var_dump($tree); + throw new Exception('Unsupported tree type: ' . $tree['type']); + break; + } + }//static function renderTree($tree) + + + + /** + * renders the result part of a query object as a string + */ + static function renderResult(Query $query) + { + $s = ''; + foreach ($query->getResultPart() as $gp) { + //dumpGp: + $s .= 'GP #' . $gp->getId(); + if ($gp->getOptional() !== null) $s .= ' optionalTo(' . $gp->getOptional() . ')'; + if ($gp->getUnion() !== null) $s .= ' unionWith(' . $gp->getUnion() . ')'; + if ($gp->getSubpatternOf() !== null) $s .= ' subpatternOf(' . $gp->getSubpatternOf() . ')'; + if (count($gp->getConstraints()) > 0)$s .= ' filter(' . count($gp->getConstraints()) . ')'; + $s .= "\n"; + if ($gp->getTriplePatterns()) { + foreach ($gp->getTriplePatterns() as $tp) { + $s .= ' ' . $tp->getSubject() . ', ' . $tp->getPredicate() + . ', ' . $tp->getObject() . "\n"; + } + } + } + return $s; + }//static function renderResult($query) + }//class SparqlTestHelper ?> \ No newline at end of file Modified: trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php =================================================================== --- trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php 2007-06-21 14:48:58 UTC (rev 462) +++ trunk/rdfapi-php/test/unit/Sparql/SparqlTests_test.php 2007-06-21 15:52:53 UTC (rev 463) @@ -210,7 +210,6 @@ function testFilterTestcases() { foreach($_SESSION['sparql_filter_tests'] as $name) { -echo $name['query'] . "\n"; $_SESSION['test']= $name['query']." test"; $parser = new SparqlParser(); $graphset = ModelFactory::getDatasetMem('Dataset1'); @@ -222,7 +221,11 @@ $q = $parser->parse($qs); $engine = SparqlEngine::factory(); $t = $engine->queryModel($graphset, $q, false); - $this->assertTrue(SparqlTestHelper::resultCheck($t,$result)); + $bOk = SparqlTestHelper::resultCheck($t,$result); + $this->assertTrue($bOk); + if (!$bOk) { + echo $name['query'] . "\n"; + } } } @@ -231,7 +234,6 @@ function testArqTestcases() { foreach($_SESSION['sparql_arq_tests'] as $name) { -echo $name['query'] . "\n"; $_SESSION['test']= $name['query']." test"; $parser = new SparqlParser(); $graphset = ModelFactory::getDatasetMem('Dataset1'); @@ -243,10 +245,15 @@ $q = $parser->parse($qs); $engine = SparqlEngine::factory(); $t = $engine->queryModel($graphset, $q,false); - if($t instanceof MemModel) - $this->assertTrue($t->equals($result)); - else - $this->assertTrue(SparqlTestHelper::resultCheck($t,$result)); + if ($t instanceof MemModel) { + $bOk = $t->equals($result); + } else { + $bOk = SparqlTestHelper::resultCheck($t,$result); + } + $this->assertTrue($bOk); + if (!$bOk) { + echo $name['query'] . "\n"; + } } } } Copied: trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php (from rev 447, trunk/rdfapi-php/test/unit/Sparql/filterCases.php) =================================================================== --- trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php (rev 0) +++ trunk/rdfapi-php/test/unit/Sparql/casesParserFilter.php 2007-06-21 15:52:53 UTC (rev 463) @@ -0,0 +1,406 @@ +<?php +/** +* Filter parser tests +*/ +$GLOBALS['testSparqlParserTestsFilter'] = array( + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +SELECT ?s, ?o +{ ?s foaf:name ?o . FILTER (?s = ?o)} +EOT +, + array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array('type' => 'value', 'value' => '?s', 'quoted' => false), + 'operand2' => array('type' => 'value', 'value' => '?o', 'quoted' => false) + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?s, ?o +{ ?s foaf:name ?o . FILTER (! bound(?s))} +EOT +, + array( + 'negated' => true, + 'type' => 'function', + 'name' => 'bound', + 'parameter' => array( + array('type' => 'value', 'value' => '?s', 'quoted' => false) + ), + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?s, ?o +{ ?s foaf:name ?o . FILTER(?date < xsd:dateTime("2005-01-01T00:00:00Z"))} +EOT +, + array( + 'type' => 'equation', + 'operator' => '<', + 'operand1' => array('type' => 'value', 'value' => '?date', 'quoted' => false), + 'operand2' => array( + 'type' => 'function', + 'name' => 'xsd:dateTime', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => '2005-01-01T00:00:00Z', + 'quoted' => true + ) + ) + ) + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?mbox1 +{ ?name1 foaf:mbox ?mbox1 . FILTER ( (?mbox1 = ?mbox2) && (?name1 != ?name2) )} +EOT +, + array( + 'type' => 'equation', + 'operator' => '&&', + 'operand1' => array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false), + 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false) + ), + 'operand2' => array( + 'type' => 'equation', + 'operator' => '!=', + 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false), + 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false) + ) + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?mbox1 +{ ?name1 foaf:mbox ?mbox1 . FILTER ( ?mbox1 = ?mbox2 && ?name1 != ?name2 )} +EOT +, + array( + 'type' => 'equation', + 'operator' => '&&', + 'operand1' => array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false), + 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false) + ), + 'operand2' => array( + 'type' => 'equation', + 'operator' => '!=', + 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false), + 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false) + ) + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?mbox1 +{ ?name1 foaf:mbox ?mbox1 . FILTER regex(str(?mbox), "@work.example")} +EOT +, + array( + 'type' => 'function', + 'name' => 'regex', + 'parameter' => array( + array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array('type' => 'value', 'value' => '?mbox', 'quoted' => false) + ) + ), + array( + 'type' => 'value', + 'value' => '@work.example', + 'quoted' => true + ) + ), + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?mbox1 +{ ?name1 foaf:mbox ?mbox1 . FILTER str(str(str(str(?mbox))))} +EOT +, + array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => '?mbox', + 'quoted' => false + ) + ) + ) + ) + ) + ) + ) + ) + ) + ), + + array( +<<<EOT +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +PREFIX : <http://example.org/things#> +SELECT ?x +WHERE + { ?x :p ?v . + FILTER (?v = 1.0) + } +EOT +, + array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array('type' => 'value', 'value' => '?v', 'quoted' => false), + 'operand2' => array('type' => 'value', 'value' => '1.0', 'quoted' => false), + ) + ), + + array( +<<<EOT +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +PREFIX : <http://example.org/ns#> +SELECT ?a +WHERE + { ?a :p ?v . + FILTER (?v) . + } +EOT +, + array( + 'type' => 'value', + 'value' => '?v', + 'quoted' => false + ) + ), + + array( +<<<EOT +PREFIX a: <http://www.w3.org/2000/10/annotation-ns#> +PREFIX dc: <http://purl.org/dc/elements/1.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + +SELECT ?annot +WHERE { ?annot a:annotates <http://www.w3.org/TR/rdf-sparql-query/> . + ?annot dc:created ?date . + FILTER ( xsd:dateTime(?date) < xsd:dateTime("2005-01-01T00:00:00Z") ) + } +EOT +, + array( + 'type' => 'equation', + 'operator' => '<', + 'operand1' => array( + 'type' => 'function', + 'name' => 'xsd:dateTime', + 'parameter' => array( + array('type' => 'value', 'value' => '?date', 'quoted' => false), + ) + ), + 'operand2' => array( + 'type' => 'function', + 'name' => 'xsd:dateTime', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => '2005-01-01T00:00:00Z', + 'quoted' => true + ) + ) + ) + ) + ), + + array( +<<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + +SELECT ?p, ?o + { ?s ?p ?o . FILTER (!!!isLiteral(?o)). } +EOT +, + array( + 'negated' => true, + 'type' => 'function', + 'name' => 'isLiteral', + 'parameter' => array( + array('type' => 'value', 'value' => '?o', 'quoted' => false) + ), + ) + ), + + array( +<<<EOT +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +PREFIX : <http://example.org/ns#> +SELECT ?a +WHERE { ?a :p ?v . FILTER ( ! ?v ) . } +EOT +, + array( + 'negated' => true, + 'type' => 'value', + 'value' => '?v', + 'quoted' => false + ) + ), +/**/ + array( +<<<EOT +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +PREFIX : <http://example.org/ns#> +SELECT ?a +WHERE { ?a :p ?v . FILTER ("true"^^xsd:boolean && ?v) .} +EOT +, + array( + 'type' => 'equation', + 'operator' => '&&', + 'operand1' => array( + 'type' => 'value', + 'value' => 'true', + 'quoted' => true, + 'datatype' => 'http://www.w3.org/2001/XMLSchema#boolean' + ), + 'operand2' => array('type' => 'value', 'value' => '?v', 'quoted' => false), + ) + ), + array( +<<<EOT +SELECT * +WHERE + { ?x ?y ?z . + FILTER ( str(?z) = str("value"@en) ) . + } +EOT +, + array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => '?z', + 'quoted' => false + ) + ) + ), + 'operand2' => array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => 'value', + 'quoted' => true, + 'language' => 'en' + ) + ) + ) + ) + ), + array( +<<<EOT +SELECT * WHERE + { ?x ?y ?z . + FILTER ( str(?x) = str(<http://rdf.hp.com/r-1>) ) . + } +EOT +, + array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => '?x', + 'quoted' => false + ) + ) + ), + 'operand2' => array( + 'type' => 'function', + 'name' => 'str', + 'parameter' => array( + array( + 'type' => 'value', + 'value' => '<http://rdf.hp.com/r-1>', + 'quoted' => false + ) + ) + ) + ) + ), + array( +<<<EOT +SELECT DISTINCT ?Res +WHERE { +?Res rdf:type ?_v1 FILTER (?Res = <ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>) +} +ORDER BY ?Res +EOT +, + array( + 'type' => 'equation', + 'operator' => '=', + 'operand1' => array('type' => 'value', 'value' => '?Res', 'quoted' => false), + 'operand2' => array( + 'type' => 'value', + 'value' => '<ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>', + 'quoted'=> false + ) + ) + ), +); +?> \ No newline at end of file Added: trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php =================================================================== --- trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php (rev 0) +++ trunk/rdfapi-php/test/unit/Sparql/casesParserNested.php 2007-06-21 15:52:53 UTC (rev 463) @@ -0,0 +1,146 @@ +<?php +/** +* Nested queries parser test +* While the result format might seem a bit strange, it helps +* us to debug the results easily and spot what doesn't work at which place. +* +* @author Christian Weiske <cw...@cw...> +*/ +$GLOBALS['testSparqlParserTestsNested'] = array( + array(<<<EOT +SELECT ?name ?mbox +WHERE +{ + ?a ?b ?c + { + { + ?g ?h ?i . + { + {?person <some://typ/e> 'asd'} + UNION + {?person3 <some://typ/es2> 'three'} + } + } + UNION + {?person2 <some://typ/es> '2'} + } + ?d ?e ?f +} +EOT + , <<<EOT +GP #0 + ?a, ?b, ?c + ?d, ?e, ?f + ?person2, Resource("some://typ/es"), Literal("2") +GP #2 unionWith(0) + ?a, ?b, ?c + ?d, ?e, ?f + ?g, ?h, ?i + ?person, Resource("some://typ/e"), Literal("asd") +GP #6 unionWith(0) + ?a, ?b, ?c + ?d, ?e, ?f + ?g, ?h, ?i + ?person3, Resource("some://typ/es2"), Literal("three") + +EOT + ), + + /////next\\\\\ + array( <<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> +PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-nss#> +SELECT DISTINCT ?Res ?Attr ?Val +WHERE +{ + { + ?Res rdf:type ?_v1 . + { + ?Res foaf:name ?_v2 FILTER regex(?_v2,"^Alexander Loeser$", "i") + } + UNION + { + ?Res rdfs:label ?_v3 FILTER regex(?_v3,"^Alexander Loeser$", "i") + } + } + ?Res ?Attr ?Val +} +ORDER BY ?Res +EOT + , <<<EOT +GP #0 filter(1) + ?Res, ?Attr, ?Val + ?Res, Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), ?_v1 + ?Res, Resource("http://www.w3.org/1999/02/22-rdf-syntax-nss#label"), ?_v3 +GP #1 unionWith(0) filter(1) + ?Res, ?Attr, ?Val + ?Res, Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), ?_v1 + ?Res, Resource("http://xmlns.com/foaf/0.1/name"), ?_v2 + +EOT + ), + + /////next\\\\\ + array( <<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?name ?mbox +WHERE + { + { ?person rdf:type foaf:Person } . + OPTIONAL { ?person foaf:name ?name } . + OPTIONAL {?person foaf:mbox ?mbox} . + } + UNION + { + { ?person2 rdf:kind foaf:Person } . + OPTIONAL {?person2 <asdf> ?mbox. ?person2 rdf:laughs ?atyou } . + } +EOT + , <<<EOT +GP #1 + ?person, Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), Resource("http://xmlns.com/foaf/0.1/Person") +GP #2 optionalTo(1) + ?person, Resource("http://xmlns.com/foaf/0.1/name"), ?name +GP #3 optionalTo(1) + ?person, Resource("http://xmlns.com/foaf/0.1/mbox"), ?mbox + +EOT + ), + + /////next\\\\\ + array( <<<EOT +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +SELECT DISTINCT ?value +WHERE { + {?s ?p ?value . FILTER (isIRI(?value)). OPTIONAL { ?s ?p ?value} } +UNION {?s ?value ?o . FILTER (isIRI(?value)) } +UNION {?value ?p ?o . FILTER (isIRI(?value)) } + } +EOT + , <<<EOT +GP #1 filter(1) + ?s, ?p, ?value +GP #2 optionalTo(1) + ?s, ?p, ?value +GP #3 unionWith(1) filter(1) + ?s, ?value, ?o +GP #4 unionWith(3) filter(1) + ?value, ?p, ?o + +EOT + ), + +/* + + /////next\\\\\ + array( <<<EOT +EOT + , <<<EOT +EOT + ), +*/ +); +?> \ No newline at end of file Deleted: trunk/rdfapi-php/test/unit/Sparql/filterCases.php =================================================================== --- trunk/rdfapi-php/test/unit/Sparql/filterCases.php 2007-06-21 14:48:58 UTC (rev 462) +++ trunk/rdfapi-php/test/unit/Sparql/filterCases.php 2007-06-21 15:52:53 UTC (rev 463) @@ -1,406 +0,0 @@ -<?php -/** -* Filter parser tests -*/ -$GLOBALS['testSparqlParserTestsFilter'] = array( - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -SELECT ?s, ?o -{ ?s foaf:name ?o . FILTER (?s = ?o)} -EOT -, - array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array('type' => 'value', 'value' => '?s', 'quoted' => false), - 'operand2' => array('type' => 'value', 'value' => '?o', 'quoted' => false) - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -SELECT ?s, ?o -{ ?s foaf:name ?o . FILTER (! bound(?s))} -EOT -, - array( - 'negated' => true, - 'type' => 'function', - 'name' => 'bound', - 'parameter' => array( - array('type' => 'value', 'value' => '?s', 'quoted' => false) - ), - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -SELECT ?s, ?o -{ ?s foaf:name ?o . FILTER(?date < xsd:dateTime("2005-01-01T00:00:00Z"))} -EOT -, - array( - 'type' => 'equation', - 'operator' => '<', - 'operand1' => array('type' => 'value', 'value' => '?date', 'quoted' => false), - 'operand2' => array( - 'type' => 'function', - 'name' => 'xsd:dateTime', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => '2005-01-01T00:00:00Z', - 'quoted' => true - ) - ) - ) - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -SELECT ?mbox1 -{ ?name1 foaf:mbox ?mbox1 . FILTER ( (?mbox1 = ?mbox2) && (?name1 != ?name2) )} -EOT -, - array( - 'type' => 'equation', - 'operator' => '&&', - 'operand1' => array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false), - 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false) - ), - 'operand2' => array( - 'type' => 'equation', - 'operator' => '!=', - 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false), - 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false) - ) - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -SELECT ?mbox1 -{ ?name1 foaf:mbox ?mbox1 . FILTER ( ?mbox1 = ?mbox2 && ?name1 != ?name2 )} -EOT -, - array( - 'type' => 'equation', - 'operator' => '&&', - 'operand1' => array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array('type' => 'value', 'value' => '?mbox1', 'quoted' => false), - 'operand2' => array('type' => 'value', 'value' => '?mbox2', 'quoted' => false) - ), - 'operand2' => array( - 'type' => 'equation', - 'operator' => '!=', - 'operand1' => array('type' => 'value', 'value' => '?name1', 'quoted' => false), - 'operand2' => array('type' => 'value', 'value' => '?name2', 'quoted' => false) - ) - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -SELECT ?mbox1 -{ ?name1 foaf:mbox ?mbox1 . FILTER regex(str(?mbox), "@work.example")} -EOT -, - array( - 'type' => 'function', - 'name' => 'regex', - 'parameter' => array( - array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array('type' => 'value', 'value' => '?mbox', 'quoted' => false) - ) - ), - array( - 'type' => 'value', - 'value' => '@work.example', - 'quoted' => true - ) - ), - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -SELECT ?mbox1 -{ ?name1 foaf:mbox ?mbox1 . FILTER str(str(str(str(?mbox))))} -EOT -, - array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => '?mbox', - 'quoted' => false - ) - ) - ) - ) - ) - ) - ) - ) - ) - ), - - array( -<<<EOT -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -PREFIX : <http://example.org/things#> -SELECT ?x -WHERE - { ?x :p ?v . - FILTER (?v = 1.0) - } -EOT -, - array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array('type' => 'value', 'value' => '?v', 'quoted' => false), - 'operand2' => array('type' => 'value', 'value' => '1.0', 'quoted' => false), - ) - ), - - array( -<<<EOT -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -PREFIX : <http://example.org/ns#> -SELECT ?a -WHERE - { ?a :p ?v . - FILTER (?v) . - } -EOT -, - array( - 'type' => 'value', - 'value' => '?v', - 'quoted' => false - ) - ), - - array( -<<<EOT -PREFIX a: <http://www.w3.org/2000/10/annotation-ns#> -PREFIX dc: <http://purl.org/dc/elements/1.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> - -SELECT ?annot -WHERE { ?annot a:annotates <http://www.w3.org/TR/rdf-sparql-query/> . - ?annot dc:created ?date . - FILTER ( xsd:dateTime(?date) < xsd:dateTime("2005-01-01T00:00:00Z") ) - } -EOT -, - array( - 'type' => 'equation', - 'operator' => '<', - 'operand1' => array( - 'type' => 'function', - 'name' => 'xsd:dateTime', - 'parameter' => array( - array('type' => 'value', 'value' => '?date', 'quoted' => false), - ) - ), - 'operand2' => array( - 'type' => 'function', - 'name' => 'xsd:dateTime', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => '2005-01-01T00:00:00Z', - 'quoted' => true - ) - ) - ) - ) - ), - - array( -<<<EOT -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> - -SELECT ?p, ?o - { ?s ?p ?o . FILTER (!!!isLiteral(?o)). } -EOT -, - array( - 'negated' => true, - 'type' => 'function', - 'name' => 'isLiteral', - 'parameter' => array( - array('type' => 'value', 'value' => '?o', 'quoted' => false) - ), - ) - ), - - array( -<<<EOT -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -PREFIX : <http://example.org/ns#> -SELECT ?a -WHERE { ?a :p ?v . FILTER ( ! ?v ) . } -EOT -, - array( - 'negated' => true, - 'type' => 'value', - 'value' => '?v', - 'quoted' => false - ) - ), -/**/ - array( -<<<EOT -PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> -PREFIX : <http://example.org/ns#> -SELECT ?a -WHERE { ?a :p ?v . FILTER ("true"^^xsd:boolean && ?v) .} -EOT -, - array( - 'type' => 'equation', - 'operator' => '&&', - 'operand1' => array( - 'type' => 'value', - 'value' => 'true', - 'quoted' => true, - 'datatype' => 'http://www.w3.org/2001/XMLSchema#boolean' - ), - 'operand2' => array('type' => 'value', 'value' => '?v', 'quoted' => false), - ) - ), - array( -<<<EOT -SELECT * -WHERE - { ?x ?y ?z . - FILTER ( str(?z) = str("value"@en) ) . - } -EOT -, - array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => '?z', - 'quoted' => false - ) - ) - ), - 'operand2' => array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => 'value', - 'quoted' => true, - 'language' => 'en' - ) - ) - ) - ) - ), - array( -<<<EOT -SELECT * WHERE - { ?x ?y ?z . - FILTER ( str(?x) = str(<http://rdf.hp.com/r-1>) ) . - } -EOT -, - array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => '?x', - 'quoted' => false - ) - ) - ), - 'operand2' => array( - 'type' => 'function', - 'name' => 'str', - 'parameter' => array( - array( - 'type' => 'value', - 'value' => '<http://rdf.hp.com/r-1>', - 'quoted' => false - ) - ) - ) - ) - ), - array( -<<<EOT -SELECT DISTINCT ?Res -WHERE { -?Res rdf:type ?_v1 FILTER (?Res = <ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>) -} -ORDER BY ?Res -EOT -, - array( - 'type' => 'equation', - 'operator' => '=', - 'operand1' => array('type' => 'value', 'value' => '?Res', 'quoted' => false), - 'operand2' => array( - 'type' => 'value', - 'value' => '<ldap://ldap.seerose.biz/dc=biz,dc=seerose,ou=People>', - 'quoted'=> false - ) - ) - ), -); -?> \ No newline at end of file Added: trunk/rdfapi-php/test/unit/sparqlParserTests.php =================================================================== --- trunk/rdfapi-php/test/unit/sparqlParserTests.php (rev 0) +++ trunk/rdfapi-php/test/unit/sparqlParserTests.php 2007-06-21 15:52:53 UTC (rev 463) @@ -0,0 +1,34 @@ +<?php + +if (!@include_once(dirname(__FILE__) . '/../config.php')) { + die('Make a copy of test/config.php.dist, change it and save it as test/config.php'); +} + +require_once( SIMPLETEST_INCLUDE_DIR . 'unit_tester.php'); +require_once( SIMPLETEST_INCLUDE_DIR . 'reporter.php'); +require_once('show_passes.php'); +require(RDFAPI_INCLUDE_DIR . 'RdfAPI.php'); + +$_SESSION['passes'] = 0; +$_SESSION['fails'] = 0; + +if(LOG){ + $file = fopen ("testlog.log", "a"); + $time= strftime('%d.%m.%y %H:%M:%S' ); + fputs($file,"\r\n".'-----'.$time.'-----'."\r\n"); +} + +$test_sparql= &new GroupTest('Sparql Parser Testcases'); +$test_sparql->addTestFile(RDFAPI_TEST_INCLUDE_DIR. 'test/unit/Sparql/SparqlParserTests_test.php'); +//$test_sparql->run(new ShowPasses()); +$test_sparql->run(new TextReporter()); + + +if(LOG){ + $file = fopen ("testlog.log", "a"); + $time= strftime('%d.%m.%y %H:%M:%S' ); + fputs($file,"\r\n".' Passes: '.$_SESSION['passes'].' Fails: '.$_SESSION['fails']."\r\n"); + fclose($file); +} + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |