Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/64050
Change subject: Work on DescriptionMatchFinder [DO NOT MERGE] ...................................................................... Work on DescriptionMatchFinder [DO NOT MERGE] Change-Id: I0925c4e0df35481fc6e17546536453c32cd1388b --- M QueryEngine/dependencies.txt M QueryEngine/includes/SQLStore/Engine/DescriptionMatchFinder.php M QueryEngine/includes/SQLStore/Engine/Engine.php M QueryEngine/tests/bootstrap.php A QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php 5 files changed, 183 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/50/64050/1 diff --git a/QueryEngine/dependencies.txt b/QueryEngine/dependencies.txt index dea446b..1676559 100644 --- a/QueryEngine/dependencies.txt +++ b/QueryEngine/dependencies.txt @@ -1,8 +1,10 @@ The Wikibase QueryEngine component is dependent on: -* Wikibase DataModel -* WikibaseLib * DataValues * Ask +* Wikibase DataModel +* Wikibase Database -And nothing else. \ No newline at end of file +And nothing else. + +An always up to date list can be found at tests/bootstrap.php. \ No newline at end of file diff --git a/QueryEngine/includes/SQLStore/Engine/DescriptionMatchFinder.php b/QueryEngine/includes/SQLStore/Engine/DescriptionMatchFinder.php index 0f0783e..5da60da 100644 --- a/QueryEngine/includes/SQLStore/Engine/DescriptionMatchFinder.php +++ b/QueryEngine/includes/SQLStore/Engine/DescriptionMatchFinder.php @@ -1,8 +1,92 @@ <?php + +namespace Wikibase\QueryEngine\SQLStore\Engine; + +use Ask\Language\Description\Description; +use Ask\Language\Description\SomeProperty; +use Ask\Language\Description\ValueDescription; +use Ask\Language\Option\QueryOptions; +use Wikibase\Database\QueryInterface; +use Wikibase\Lib\EntityIdParser; +use Wikibase\Lib\EntityRetrievingDataTypeLookup; +use Wikibase\QueryEngine\QueryEngine; +use Wikibase\QueryEngine\SQLStore\Schema; +use Wikibase\SnakRole; + /** - * Created by JetBrains PhpStorm. - * User: j - * Date: 10/05/13 - * Time: 19:38 - * To change this template use File | Settings | File Templates. - */ \ No newline at end of file + * Simple query engine that works on top of the SQLStore. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @since 0.1 + * + * @file + * @ingroup WikibaseSQLStore + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +class DescriptionMatchFinder { + + protected $queryInterface; + protected $schema; + + public function __construct( QueryInterface $queryInterface, Schema $schema ) { + $this->queryInterface = $queryInterface; + $this->schema = $schema; + } + + /** + * Finds all entities that match the selection criteria. + * The matching entities are returned as an array of internal entity ids. + * + * @since 0.1 + * + * @param Description $description + * @param QueryOptions $options + * + * @return int[] + */ + public function findMatchingEntities( Description $description, QueryOptions $options ) { + if ( $description instanceof SomeProperty ) { + $parser = new EntityIdParser(); + $propertyId = $parser->parse( $description->getProperty()->getValue() ); + $typeLookup = new EntityRetrievingDataTypeLookup(); + + $dvHandler = $this->schema->getDataValueHandler( + $typeLookup->getDataTypeIdForProperty( $propertyId ), + SnakRole::MAIN_SNAK + ); + + $subDescription = $description->getDescription(); + + if ( $subDescription instanceof ValueDescription ) { + $dvHandler->getWhereConditions( $subDescription->getValue() ); + } + + + } + + + return array(); + + // SomeProperty[AnyValue]: SELECT entity_id FROM $table WHERE property_id = $id + + // SomeProperty[ValueDescription]: + // SELECT SELECT entity_id FROM $table WHERE property_id = $property_id AND + } + +} diff --git a/QueryEngine/includes/SQLStore/Engine/Engine.php b/QueryEngine/includes/SQLStore/Engine/Engine.php index 12bdece..058c584 100644 --- a/QueryEngine/includes/SQLStore/Engine/Engine.php +++ b/QueryEngine/includes/SQLStore/Engine/Engine.php @@ -73,26 +73,12 @@ * @return QueryEngineResult */ public function runQuery( Query $query ) { + // TODO $internalEntityIds = $this->findQueryMatches( $query->getDescription(), $query->getOptions() ); $result = $this->selectRequestedFields( $internalEntityIds, $query->getSelectionRequests() ); return $result; - } - - /** - * Finds all entities that match the selection criteria. - * The matching entities are returned as an array of internal entity ids. - * - * @since 0.1 - * - * @param Description $description - * @param QueryOptions $options - * - * @return int[] - */ - private function findQueryMatches( Description $description, QueryOptions $options ) { - // TODO } /** diff --git a/QueryEngine/tests/bootstrap.php b/QueryEngine/tests/bootstrap.php index 0c9795b..5cae02a 100644 --- a/QueryEngine/tests/bootstrap.php +++ b/QueryEngine/tests/bootstrap.php @@ -14,6 +14,8 @@ require_once( __DIR__ . '/../../../DataValues/DataValues/DataValues.php' ); +require_once( __DIR__ . '/../../../Ask/Ask.php' ); + require_once( __DIR__ . '/../../DataModel/DataModel.php' ); require_once( __DIR__ . '/../../Database/Database.php' ); @@ -21,3 +23,5 @@ require_once( __DIR__ . '/../QueryEngine.php' ); require_once( __DIR__ . '/testLoader.php' ); + +// If something needs to change here, a reflecting change needs to be added to ../dependencies.txt. \ No newline at end of file diff --git a/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php b/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php new file mode 100644 index 0000000..3a700ed --- /dev/null +++ b/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php @@ -0,0 +1,83 @@ +<?php + +namespace Wikibase\QueryEngine\Tests\SQLStore; + +use Ask\Language\Description\AnyValue; +use Ask\Language\Description\SomeProperty; +use Ask\Language\Option\QueryOptions; +use DataValues\PropertyValue; +use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder; + +/** + * @covers Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @since 0.1 + * + * @ingroup WikibaseQueryEngineTest + * + * @group Wikibase + * @group WikibaseQueryEngine + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +class DescriptionMatchFinderTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + $this->newInstanceWithMocks(); + $this->assertTrue( true ); + } + + protected function newInstanceWithMocks() { + return new DescriptionMatchFinder( + $this->getMock( 'Wikibase\Database\QueryInterface' ), + $this->getMockBuilder( 'Wikibase\QueryEngine\SQLStore\Schema' ) + ->disableOriginalConstructor()->getMock() + ); + } + + public function testFindMatchingEntitiesReturnType() { + $description = new AnyValue(); + $queryOptions = new QueryOptions( 100, 0 ); + + $matchFinder = $this->newInstanceWithMocks(); + + $matchingInternalIds = $matchFinder->findMatchingEntities( $description, $queryOptions ); + + $this->assertInternalType( 'array', $matchingInternalIds ); + $this->assertContainsOnly( 'int', $matchingInternalIds ); + } + + public function testFindMatchingEntitiesWithSomePropertyAnyValue() { + $description = new SomeProperty( new PropertyValue( '42' ), new AnyValue() ); + $queryOptions = new QueryOptions( 100, 0 ); + + $queryEngine = $this->getMock( 'Wikibase\Database\QueryEngine' ); + + $queryEngine->expects( $this->once() ) + ->method( 'select' ) + ->will( $this->returnValue( array() ) ); + + $matchFinder = new DescriptionMatchFinder( $queryEngine ); + + $matchingInternalIds = $matchFinder->findMatchingEntities( $description, $queryOptions ); + + } + +} -- To view, visit https://gerrit.wikimedia.org/r/64050 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0925c4e0df35481fc6e17546536453c32cd1388b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
