jenkins-bot has submitted this change and it was merged. Change subject: Implement page props in RDF ......................................................................
Implement page props in RDF Adds page props (by configuration) to RDF output like this: wdata:Q2 a schema:Dataset ; schema:about wd:Q2 ; wikibase:sitelinks "1"^^xsd:integer ; wikibase:statements "5"^^xsd:integer . Change-Id: I95868d6ae75c4ebf98ff414200fcdcc2155488f1 Bug: T129046 --- M docs/rdf-binding.txt M repo/config/Wikibase.default.php M repo/includes/Dumpers/DumpGenerator.php M repo/includes/Dumpers/RdfDumpGenerator.php M repo/includes/LinkedData/EntityDataSerializationService.php M repo/includes/Rdf/RdfBuilder.php M repo/includes/Rdf/RdfProducer.php M repo/includes/Rdf/RdfVocabulary.php M repo/includes/WikibaseRepo.php M repo/maintenance/dumpRdf.php M repo/tests/phpunit/data/maintenance/dumpRdf-out.txt M repo/tests/phpunit/data/rdf/RdfBuilder/Q1_info.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q1_simple.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q2_labels.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q3_links.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q4_claims.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q5_badges.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q6_qualifiers.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q7_references.nt M repo/tests/phpunit/data/rdf/RdfBuilder/Q8_baddates.nt M repo/tests/phpunit/data/rdf/RdfBuilder/dumpheader.nt A repo/tests/phpunit/data/rdf/RdfBuilder/prop1.nt A repo/tests/phpunit/data/rdf/RdfBuilder/prop2.nt A repo/tests/phpunit/data/rdf/RdfBuilder/prop3.nt A repo/tests/phpunit/data/rdf/RdfBuilder/prop4.nt M repo/tests/phpunit/data/rdf/RdfDumpGenerator/empty.nt M repo/tests/phpunit/data/rdf/RdfDumpGenerator/entities.nt M repo/tests/phpunit/data/rdf/RdfDumpGenerator/redirect.nt M repo/tests/phpunit/data/rdf/RdfDumpGenerator/refs.nt M repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php M repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php M repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php M repo/tests/phpunit/maintenance/dumpRdfTest.php 33 files changed, 460 insertions(+), 116 deletions(-) Approvals: Hoo man: Looks good to me, approved jenkins-bot: Verified diff --git a/docs/rdf-binding.txt b/docs/rdf-binding.txt index 60e3d09..ff6210a 100644 --- a/docs/rdf-binding.txt +++ b/docs/rdf-binding.txt @@ -7,3 +7,4 @@ 0.0.1 - Initial implementation 0.0.2 - Changed WKT coordinate order (see T130049) +0.0.3 - Added page props option to wdata: (see T129046) diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php index df2305b..0f8f7c9 100644 --- a/repo/config/Wikibase.default.php +++ b/repo/config/Wikibase.default.php @@ -183,4 +183,13 @@ 'http://www.wikidata.org/entity/Q3359' => 'triton', 'http://www.wikidata.org/entity/Q339' => 'pluto' ], + + // Map between page properties and Wikibase predicates + // Maps from database property name to array: + // name => RDF property name (will be prefixed by wikibase:) + // type => type to convert to (optional) + 'pagePropertiesRdf' => [ + 'wb-sitelinks' => [ 'name' => 'sitelinks', 'type' => 'integer' ], + 'wb-claims' => [ 'name' => 'statements', 'type' => 'integer' ], + ] ]; diff --git a/repo/includes/Dumpers/DumpGenerator.php b/repo/includes/Dumpers/DumpGenerator.php index 5a1a31d..65f6323 100644 --- a/repo/includes/Dumpers/DumpGenerator.php +++ b/repo/includes/Dumpers/DumpGenerator.php @@ -29,7 +29,7 @@ * @var int The max number of entities to process in a single batch. * Also controls the interval for progress reports. */ - private $batchSize = 100; + protected $batchSize = 100; /** * @var resource File handle for output @@ -214,6 +214,14 @@ } /** + * Do something before dumping a batch of entities + * @param EntityId[] $entities + */ + protected function preBatchDump( $entities ) { + $this->entityPrefetcher->prefetch( $entities ); + } + + /** * Do something before dumping entity * * @param int $dumpCount @@ -273,7 +281,8 @@ $toLoad[] = $entityId; } } - $this->entityPrefetcher->prefetch( $toLoad ); + + $this->preBatchDump( $toLoad ); foreach ( $toLoad as $entityId ) { try { diff --git a/repo/includes/Dumpers/RdfDumpGenerator.php b/repo/includes/Dumpers/RdfDumpGenerator.php index 673db5f..97cf5ef 100644 --- a/repo/includes/Dumpers/RdfDumpGenerator.php +++ b/repo/includes/Dumpers/RdfDumpGenerator.php @@ -5,12 +5,14 @@ use InvalidArgumentException; use MWContentSerializationException; use MWException; +use PageProps; use SiteList; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Services\Lookup\EntityLookupException; use Wikibase\DataModel\Services\Entity\EntityPrefetcher; use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; use Wikibase\Lib\Store\EntityRevisionLookup; +use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\StorageException; use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException; @@ -49,14 +51,25 @@ private $timestamp; /** - * @param resource $out - * @param EntityRevisionLookup $lookup Must not resolve redirects - * @param RdfBuilder $rdfBuilder - * @param EntityPrefetcher $entityPrefetcher - * - * @throws InvalidArgumentException + * @var PageProps */ - public function __construct( $out, EntityRevisionLookup $lookup, RdfBuilder $rdfBuilder, EntityPrefetcher $entityPrefetcher ) { + private $pageProps; + + /** + * @var EntityTitleLookup + */ + private $titleLookup; + + /** + * @param resource $out + * @param EntityRevisionLookup $lookup Must not resolve redirects + * @param RdfBuilder $rdfBuilder + * @param EntityPrefetcher $entityPrefetcher + * @param EntityTitleLookup $titleLookup + */ + public function __construct( $out, EntityRevisionLookup $lookup, RdfBuilder $rdfBuilder, + EntityPrefetcher $entityPrefetcher, + EntityTitleLookup $titleLookup ) { parent::__construct( $out, $entityPrefetcher ); if ( $lookup instanceof RedirectResolvingEntityLookup ) { throw new InvalidArgumentException( '$lookup must not resolve redirects!' ); @@ -64,12 +77,17 @@ $this->rdfBuilder = $rdfBuilder; $this->entityRevisionLookup = $lookup; + $this->titleLookup = $titleLookup; } /** * Do something before dumping data */ protected function preDump() { + $this->pageProps = PageProps::getInstance(); + $this->pageProps->ensureCacheSize( $this->batchSize ); + $this->rdfBuilder->setPageProps( $this->pageProps ); + $this->rdfBuilder->startDocument(); $this->rdfBuilder->addDumpHeader( $this->timestamp ); @@ -85,6 +103,20 @@ $footer = $this->rdfBuilder->getRDF(); $this->writeToDump( $footer ); + } + + /** + * Do something before dumping a batch of entities + * @param EntityId[] $entities + */ + protected function preBatchDump( $entities ) { + parent::preBatchDump( $entities ); + $titles = array_filter( array_map( [ $this->titleLookup, 'getTitleForId' ], $entities ) ); + $props = array_keys( $this->rdfBuilder->getPageProperties() ); + // Prefetch page props + if ( $titles && $props ) { + $this->pageProps->getProperties( $titles, $props ); + } } /** @@ -109,6 +141,8 @@ $entityRevision->getRevisionId(), $entityRevision->getTimestamp() ); + + $this->rdfBuilder->addEntityPageProps( $entityRevision->getEntity()->getId() ); $this->rdfBuilder->addEntity( $entityRevision->getEntity() @@ -154,16 +188,16 @@ } /** - * @param string $format - * @param resource $output - * @param SiteList $sites - * @param EntityRevisionLookup $entityRevisionLookup - * @param PropertyDataTypeLookup $propertyLookup + * @param string $format + * @param resource $output + * @param SiteList $sites + * @param EntityRevisionLookup $entityRevisionLookup + * @param PropertyDataTypeLookup $propertyLookup * @param ValueSnakRdfBuilderFactory $valueSnakRdfBuilderFactory - * @param EntityPrefetcher $entityPrefetcher - * @param RdfVocabulary $vocabulary - * - * @return self + * @param EntityPrefetcher $entityPrefetcher + * @param RdfVocabulary $vocabulary + * @param EntityTitleLookup $titleLookup + * @return static * @throws MWException */ public static function createDumpGenerator( @@ -174,7 +208,8 @@ PropertyDataTypeLookup $propertyLookup, ValueSnakRdfBuilderFactory $valueSnakRdfBuilderFactory, EntityPrefetcher $entityPrefetcher, - RdfVocabulary $vocabulary + RdfVocabulary $vocabulary, + EntityTitleLookup $titleLookup ) { $rdfWriter = self::getRdfWriter( $format ); if ( !$rdfWriter ) { @@ -183,7 +218,7 @@ $flavor = RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_TRUTHY_STATEMENTS | RdfProducer::PRODUCE_QUALIFIERS | RdfProducer::PRODUCE_REFERENCES | - RdfProducer::PRODUCE_SITELINKS | RdfProducer::PRODUCE_FULL_VALUES; + RdfProducer::PRODUCE_SITELINKS | RdfProducer::PRODUCE_FULL_VALUES | RdfProducer::PRODUCE_PAGE_PROPS; $rdfBuilder = new RdfBuilder( $sites, @@ -192,10 +227,11 @@ $propertyLookup, $flavor, $rdfWriter, - new HashDedupeBag() + new HashDedupeBag(), + $titleLookup ); - return new self( $output, $entityRevisionLookup, $rdfBuilder, $entityPrefetcher ); + return new self( $output, $entityRevisionLookup, $rdfBuilder, $entityPrefetcher, $titleLookup ); } } diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php b/repo/includes/LinkedData/EntityDataSerializationService.php index 00c405b..155cd16 100644 --- a/repo/includes/LinkedData/EntityDataSerializationService.php +++ b/repo/includes/LinkedData/EntityDataSerializationService.php @@ -8,6 +8,7 @@ use DerivativeContext; use DerivativeRequest; use MWException; +use PageProps; use RequestContext; use SiteList; use SiteStore; @@ -222,6 +223,8 @@ $entityRevision->getTimestamp() ); + $rdfBuilder->addEntityPageProps( $entityRevision->getEntity()->getId() ); + $rdfBuilder->addEntity( $entityRevision->getEntity() ); $rdfBuilder->resolveMentionedEntities( $this->entityLookup ); } @@ -323,6 +326,7 @@ | RdfProducer::PRODUCE_REFERENCES | RdfProducer::PRODUCE_SITELINKS | RdfProducer::PRODUCE_FULL_VALUES + | RdfProducer::PRODUCE_PAGE_PROPS | RdfProducer::PRODUCE_VERSION_INFO; case 'long': return RdfProducer::PRODUCE_ALL_STATEMENTS @@ -363,9 +367,12 @@ $this->propertyLookup, $this->getFlavor( $flavorName ), $rdfWriter, - new HashDedupeBag() + new HashDedupeBag(), + $this->entityTitleLookup ); + $rdfBuilder->setPageProps( PageProps::getInstance() ); + return $rdfBuilder; } diff --git a/repo/includes/Rdf/RdfBuilder.php b/repo/includes/Rdf/RdfBuilder.php index 850a9b1..bb38ddc 100644 --- a/repo/includes/Rdf/RdfBuilder.php +++ b/repo/includes/Rdf/RdfBuilder.php @@ -2,6 +2,7 @@ namespace Wikibase\Rdf; +use PageProps; use SiteList; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; @@ -10,6 +11,7 @@ use Wikibase\DataModel\Services\Lookup\EntityLookup; use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; use Wikibase\DataModel\Term\FingerprintProvider; +use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException; use Wikimedia\Purtle\RdfWriter; @@ -82,13 +84,25 @@ private $valueSnakRdfBuilderFactory; /** - * @param SiteList $sites - * @param RdfVocabulary $vocabulary + * @var EntityTitleLookup + */ + private $titleLookup; + + /** + * Page properties handler, can be null if we don't need them. + * @var PageProps|null + */ + private $pageProps; + + /** + * @param SiteList $sites + * @param RdfVocabulary $vocabulary * @param ValueSnakRdfBuilderFactory $valueSnakRdfBuilderFactory - * @param PropertyDataTypeLookup $propertyLookup - * @param int $flavor - * @param RdfWriter $writer - * @param DedupeBag $dedupeBag + * @param PropertyDataTypeLookup $propertyLookup + * @param int $flavor + * @param RdfWriter $writer + * @param DedupeBag $dedupeBag + * @param EntityTitleLookup $titleLookup */ public function __construct( SiteList $sites, @@ -97,7 +111,8 @@ PropertyDataTypeLookup $propertyLookup, $flavor, RdfWriter $writer, - DedupeBag $dedupeBag + DedupeBag $dedupeBag, + EntityTitleLookup $titleLookup ) { $this->vocabulary = $vocabulary; $this->propertyLookup = $propertyLookup; @@ -105,6 +120,7 @@ $this->writer = $writer; $this->produceWhat = $flavor; $this->dedupeBag = $dedupeBag ?: new HashDedupeBag(); + $this->titleLookup = $titleLookup; // XXX: move construction of sub-builders to a factory class. $this->termsBuilder = new TermsRdfBuilder( $vocabulary, $writer ); @@ -221,6 +237,15 @@ } /** + * Get map of page properties used by this builder + * + * @return string[] + */ + public function getPageProperties() { + return $this->vocabulary->getPageProperties(); + } + + /** * Should we produce this aspect? * * @param int $what @@ -307,6 +332,52 @@ } /** + * Set page props handler + * @param PageProps $pageProps + * @return self + */ + public function setPageProps( PageProps $pageProps ) { + $this->pageProps = $pageProps; + return $this; + } + + /** + * Add page props information + * @param EntityId $entityId + */ + public function addEntityPageProps( EntityId $entityId ) { + if ( !$this->pageProps || !$this->shouldProduce( RdfProducer::PRODUCE_PAGE_PROPS ) ) { + return; + } + $title = $this->titleLookup->getTitleForId( $entityId ); + $props = $this->getPageProperties(); + if ( !$title || !$props ) { + return; + } + $propValues = $this->pageProps->getProperties( $title, array_keys( $props ) ); + if ( !$propValues ) { + return; + } + $entityProps = reset( $propValues ); + if ( !$entityProps ) { + return; + } + foreach ( $entityProps as $name => $value ) { + if ( !isset( $props[$name]['name'] ) ) { + continue; + } + + if ( isset( $props[$name]['type'] ) ) { + settype( $value, $props[$name]['type'] ); + } + + $this->writer->about( RdfVocabulary::NS_DATA, $entityId ) + ->say( RdfVocabulary::NS_ONTOLOGY, $props[$name]['name'] ) + ->value( $value ); + } + } + + /** * Write definition for wdno:P123 class to use as novalue * @param string $id */ diff --git a/repo/includes/Rdf/RdfProducer.php b/repo/includes/Rdf/RdfProducer.php index ba954ef..3449fe8 100644 --- a/repo/includes/Rdf/RdfProducer.php +++ b/repo/includes/Rdf/RdfProducer.php @@ -61,6 +61,11 @@ const PRODUCE_RESOLVED_ENTITIES = 256; /** + * Produce page properties + */ + const PRODUCE_PAGE_PROPS = 1024; + + /** * All options turned on. */ const PRODUCE_ALL = 0xFFFF; diff --git a/repo/includes/Rdf/RdfVocabulary.php b/repo/includes/Rdf/RdfVocabulary.php index 44adf71..9e010b1 100644 --- a/repo/includes/Rdf/RdfVocabulary.php +++ b/repo/includes/Rdf/RdfVocabulary.php @@ -22,7 +22,7 @@ class RdfVocabulary { // Change this when changing data format! - const FORMAT_VERSION = '0.0.2'; + const FORMAT_VERSION = '0.0.3'; const ONTOLOGY_VERSION = '1.0'; const ONTOLOGY_BASE_URI = 'http://wikiba.se/ontology'; @@ -115,22 +115,32 @@ private static $canonicalLanguageCodeCache = array(); /** - * @param string $baseUri Base URI for entity concept URIs. - * @param string $dataUri Base URI for entity description URIs. + * Map of the configured page properties. + * @var string[] + */ + private $pagePropertyDefs; + + /** + * @param string $baseUri Base URI for entity concept URIs. + * @param string $dataUri Base URI for entity description URIs. * @param string[] $canonicalLanguageCodes Mapping of non-standard to canonical language codes. * @param string[] $dataTypeUris Mapping of property data type IDs to their URIs, * if different from the default mapping. + * @param string[] $pagePropertyDefs Mapping of page props: pageProp => wikibase predicate + * All predicates will be prefixed with wikibase: */ public function __construct( $baseUri, $dataUri, array $canonicalLanguageCodes = array(), - array $dataTypeUris = array() + array $dataTypeUris = array(), + array $pagePropertyDefs = array() ) { $this->baseUri = $baseUri; $this->dataUri = $dataUri; $this->canonicalLanguageCodes = $canonicalLanguageCodes; $this->dataTypeUris = $dataTypeUris; + $this->pagePropertyDefs = $pagePropertyDefs; if ( substr( $this->baseUri, -7 ) === 'entity/' ) { $topUri = substr( $this->baseUri, 0, -7 ); @@ -300,4 +310,12 @@ return self::ONTOLOGY_BASE_URI . "-" . self::ONTOLOGY_VERSION . ".owl"; } + /** + * Get the map of configured page properties + * @return string[] + */ + public function getPageProperties() { + return $this->pagePropertyDefs; + } + } diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 98888c1..46c875a 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -1006,7 +1006,8 @@ $this->getVocabularyBaseUri(), $entityDataTitle->getCanonicalURL() . '/', $languageCodes, - $this->dataTypeDefinitions->getRdfTypeUris() + $this->dataTypeDefinitions->getRdfTypeUris(), + $this->settings->getSetting( 'pagePropertiesRdf' ) ?: [] ); } diff --git a/repo/maintenance/dumpRdf.php b/repo/maintenance/dumpRdf.php index 6213cbb..c451bcd 100644 --- a/repo/maintenance/dumpRdf.php +++ b/repo/maintenance/dumpRdf.php @@ -8,6 +8,7 @@ use Wikibase\Dumpers\DumpGenerator; use Wikibase\Dumpers\RdfDumpGenerator; use Wikibase\Lib\Store\EntityRevisionLookup; +use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Rdf\RdfVocabulary; use Wikibase\Rdf\ValueSnakRdfBuilderFactory; use Wikibase\Repo\Store\EntityPerPage; @@ -59,19 +60,25 @@ */ private $hasHadServicesSet = false; + /** + * @var EntityTitleLookup + */ + private $titleLookup; + public function __construct() { parent::__construct(); $this->addOption( 'format', "Set the dump format.", false, true ); } /** - * @param EntityPerPage $entityPerPage - * @param EntityPrefetcher $entityPrefetcher - * @param SiteStore $siteStore - * @param PropertyDataTypeLookup $propertyDataTypeLookup + * @param EntityPerPage $entityPerPage + * @param EntityPrefetcher $entityPrefetcher + * @param SiteStore $siteStore + * @param PropertyDataTypeLookup $propertyDataTypeLookup * @param ValueSnakRdfBuilderFactory $valueSnakRdfBuilderFactory - * @param EntityRevisionLookup $entityRevisionLookup - * @param RdfVocabulary $rdfVocabulary + * @param EntityRevisionLookup $entityRevisionLookup + * @param RdfVocabulary $rdfVocabulary + * @param EntityTitleLookup $titleLookup */ public function setServices( EntityPerPage $entityPerPage, @@ -80,7 +87,8 @@ PropertyDataTypeLookup $propertyDataTypeLookup, ValueSnakRdfBuilderFactory $valueSnakRdfBuilderFactory, EntityRevisionLookup $entityRevisionLookup, - RdfVocabulary $rdfVocabulary + RdfVocabulary $rdfVocabulary, + EntityTitleLookup $titleLookup ) { parent::setDumpEntitiesServices( $entityPerPage ); $this->entityPrefetcher = $entityPrefetcher; @@ -89,6 +97,7 @@ $this->valueSnakRdfBuilderFactory = $valueSnakRdfBuilderFactory; $this->revisionLookup = $entityRevisionLookup; $this->rdfVocabulary = $rdfVocabulary; + $this->titleLookup = $titleLookup; $this->hasHadServicesSet = true; } @@ -102,7 +111,8 @@ $wikibaseRepo->getPropertyDataTypeLookup(), $wikibaseRepo->getValueSnakRdfBuilderFactory(), $wikibaseRepo->getEntityRevisionLookup( 'uncached' ), - $wikibaseRepo->getRdfVocabulary() + $wikibaseRepo->getRdfVocabulary(), + $wikibaseRepo->getEntityContentFactory() ); } parent::execute(); @@ -133,7 +143,8 @@ $this->propertyDatatypeLookup, $this->valueSnakRdfBuilderFactory, $this->entityPrefetcher, - $this->rdfVocabulary + $this->rdfVocabulary, + $this->titleLookup ); } diff --git a/repo/tests/phpunit/data/maintenance/dumpRdf-out.txt b/repo/tests/phpunit/data/maintenance/dumpRdf-out.txt index c786c50..5eec6e6 100644 --- a/repo/tests/phpunit/data/maintenance/dumpRdf-out.txt +++ b/repo/tests/phpunit/data/maintenance/dumpRdf-out.txt @@ -1,7 +1,7 @@ <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> . <http://wikiba.se/ontology-beta#Dump> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . -<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.2" . +<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.3" . <http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> "2015-01-01T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/2002/07/owl#imports> <http://wikiba.se/ontology-1.0.owl> . <acme/EntityData/Q1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_info.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_info.nt index 9e4d392..2e9fede 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_info.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_info.nt @@ -2,6 +2,6 @@ <http://data.acme.test/Q1> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q1> <http://schema.org/about> <http://acme.test/Q1> . <http://data.acme.test/Q1> <http://schema.org/dateModified> "2013-10-04T03:31:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q1> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q1> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q1> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . -<http://data.acme.test/Q1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . \ No newline at end of file +<http://data.acme.test/Q1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_simple.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_simple.nt index dafc4f4..2b5e0d6 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_simple.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q1_simple.nt @@ -2,6 +2,6 @@ <http://data.acme.test/Q1> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q1> <http://schema.org/about> <http://acme.test/Q1> . <http://data.acme.test/Q1> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q1> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q1> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q1> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . -<http://data.acme.test/Q1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . \ No newline at end of file +<http://data.acme.test/Q1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q2_labels.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q2_labels.nt index 32efa3f..42e254c 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q2_labels.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q2_labels.nt @@ -13,6 +13,6 @@ <http://data.acme.test/Q2> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q2> <http://schema.org/about> <http://acme.test/Q2> . <http://data.acme.test/Q2> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q2> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q2> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q2> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q3_links.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q3_links.nt index 0ca34d9..48a8346 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q3_links.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q3_links.nt @@ -2,7 +2,7 @@ <http://data.acme.test/Q3> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q3> <http://schema.org/about> <http://acme.test/Q3> . <http://data.acme.test/Q3> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q3> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q3> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q3> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://enwiki.acme.test/San%20Francisco> <http://schema.org/about> <http://acme.test/Q3> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q4_claims.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q4_claims.nt index 1170275..1bbc930 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q4_claims.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q4_claims.nt @@ -73,7 +73,7 @@ <http://data.acme.test/Q4> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q4> <http://schema.org/about> <http://acme.test/Q4> . <http://data.acme.test/Q4> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q4> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q4> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q4> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/value/974afffbe8c12ab5579f4b521ae2bd5d> <http://wikiba.se/ontology-beta#geoGlobe> <http://www.wikidata.org/entity/Q2> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q5_badges.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q5_badges.nt index 8a13732..f1fc114 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q5_badges.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q5_badges.nt @@ -2,7 +2,7 @@ <http://data.acme.test/Q5> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q5> <http://schema.org/about> <http://acme.test/Q5> . <http://data.acme.test/Q5> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q5> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q5> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q5> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q5> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://enwiki.acme.test/San%20Francisco> <http://schema.org/about> <http://acme.test/Q5> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q6_qualifiers.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q6_qualifiers.nt index c5826d8..7d8dbb0 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q6_qualifiers.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q6_qualifiers.nt @@ -24,7 +24,7 @@ <http://data.acme.test/Q6> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q6> <http://schema.org/about> <http://acme.test/Q6> . <http://data.acme.test/Q6> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q6> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q6> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q6> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q6> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/value/aad6b70bccf9875ba61d31c767b7f652> <http://wikiba.se/ontology-beta#geoGlobe> <http://www.wikidata.org/entity/Q2> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q7_references.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q7_references.nt index ab8dde9..761b6ed 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q7_references.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q7_references.nt @@ -32,7 +32,7 @@ <http://data.acme.test/Q7> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q7> <http://schema.org/about> <http://acme.test/Q7> . <http://data.acme.test/Q7> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q7> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q7> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q7> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q7> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/value/aad6b70bccf9875ba61d31c767b7f652> <http://wikiba.se/ontology-beta#geoGlobe> <http://www.wikidata.org/entity/Q2> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/Q8_baddates.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/Q8_baddates.nt index cde2bbe..c35d569 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/Q8_baddates.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/Q8_baddates.nt @@ -145,7 +145,7 @@ <http://data.acme.test/Q8> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://data.acme.test/Q8> <http://schema.org/about> <http://acme.test/Q8> . <http://data.acme.test/Q8> <http://schema.org/dateModified> "2014-11-04T03:11:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://data.acme.test/Q8> <http://schema.org/softwareVersion> "0.0.2" . +<http://data.acme.test/Q8> <http://schema.org/softwareVersion> "0.0.3" . <http://data.acme.test/Q8> <http://schema.org/version> "42"^^<http://www.w3.org/2001/XMLSchema#integer> . <http://data.acme.test/Q8> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/value/c4057818195a6629a7829b03b448a31e> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://wikiba.se/ontology-beta#TimeValue> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/dumpheader.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/dumpheader.nt index ae75679..71b3025 100644 --- a/repo/tests/phpunit/data/rdf/RdfBuilder/dumpheader.nt +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/dumpheader.nt @@ -1,6 +1,6 @@ <http://wikiba.se/ontology-beta#Dump> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> "2015-03-11T21:51:35Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.2" . +<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.3" . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/2002/07/owl#imports> <http://wikiba.se/ontology-1.0.owl> . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/prop1.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/prop1.nt new file mode 100644 index 0000000..2d47934 --- /dev/null +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/prop1.nt @@ -0,0 +1 @@ +<http://data.acme.test/Q9> <http://wikiba.se/ontology-beta#rdf-claims> "testclaims" . \ No newline at end of file diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/prop2.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/prop2.nt new file mode 100644 index 0000000..1e736ca --- /dev/null +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/prop2.nt @@ -0,0 +1,2 @@ +<http://data.acme.test/Q9> <http://wikiba.se/ontology-beta#rdf-claims> "testclaims" . +<http://data.acme.test/Q9> <http://wikiba.se/ontology-beta#rdf-sitelinks> "testsitelinks" . diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/prop3.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/prop3.nt new file mode 100644 index 0000000..b601b9f --- /dev/null +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/prop3.nt @@ -0,0 +1 @@ +<http://data.acme.test/Q9> <http://wikiba.se/ontology-beta#rdf-sitelinks> "testsitelinks" . \ No newline at end of file diff --git a/repo/tests/phpunit/data/rdf/RdfBuilder/prop4.nt b/repo/tests/phpunit/data/rdf/RdfBuilder/prop4.nt new file mode 100644 index 0000000..31887e5 --- /dev/null +++ b/repo/tests/phpunit/data/rdf/RdfBuilder/prop4.nt @@ -0,0 +1,2 @@ +<http://data.acme.test/Q9> <http://wikiba.se/ontology-beta#rdf-claims> "0"^^<http://www.w3.org/2001/XMLSchema#integer> . +<http://data.acme.test/Q9> <http://wikiba.se/ontology-beta#rdf-sitelinks> "0"^^<http://www.w3.org/2001/XMLSchema#double> . \ No newline at end of file diff --git a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/empty.nt b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/empty.nt index 5eae219..76b5e28 100644 --- a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/empty.nt +++ b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/empty.nt @@ -1,6 +1,6 @@ <http://wikiba.se/ontology-beta#Dump> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> "1970-01-12T13:46:40Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.2" . +<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.3" . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/2002/07/owl#imports> <http://wikiba.se/ontology-1.0.owl> . diff --git a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/entities.nt b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/entities.nt index 04f22e3..eb7b7c0 100644 --- a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/entities.nt +++ b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/entities.nt @@ -33,7 +33,7 @@ <http://test.acme.test/> <http://wikiba.se/ontology-beta#wikiGroup> "acmetest" . <http://wikiba.se/ontology-beta#Dump> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> "1970-01-12T13:46:40Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.2" . +<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.3" . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/P10> <http://wikiba.se/ontology-beta#propertyType> <http://wikiba.se/ontology-beta#Wibblywobbly> . <http://acme.test/P10> <http://wikiba.se/ontology-beta#claim> <http://acme.test/prop/P10> . diff --git a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/redirect.nt b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/redirect.nt index 640f519..b783405 100644 --- a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/redirect.nt +++ b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/redirect.nt @@ -15,7 +15,7 @@ <http://data.acme.test/P10> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://wikiba.se/ontology-beta#Dump> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> "1970-01-12T13:46:40Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.2" . +<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.3" . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/P10> <http://wikiba.se/ontology-beta#propertyType> <http://wikiba.se/ontology-beta#Wibblywobbly> . <http://acme.test/P10> <http://wikiba.se/ontology-beta#claim> <http://acme.test/prop/P10> . diff --git a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/refs.nt b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/refs.nt index 8508141..428c5fc 100644 --- a/repo/tests/phpunit/data/rdf/RdfDumpGenerator/refs.nt +++ b/repo/tests/phpunit/data/rdf/RdfDumpGenerator/refs.nt @@ -66,7 +66,7 @@ <http://data.acme.test/Q9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://wikiba.se/ontology-beta#Dump> <http://creativecommons.org/ns#license> <http://creativecommons.org/publicdomain/zero/1.0/> . <http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> "1970-01-12T13:46:40Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . -<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.2" . +<http://wikiba.se/ontology-beta#Dump> <http://schema.org/softwareVersion> "0.0.3" . <http://wikiba.se/ontology-beta#Dump> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Dataset> . <http://acme.test/value/1e09d673624819aacd170165aae555a1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://wikiba.se/ontology-beta#QuantityValue> . <http://acme.test/value/aad6b70bccf9875ba61d31c767b7f652> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://wikiba.se/ontology-beta#GlobecoordinateValue> . diff --git a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php index 9fa1237..5e49928 100644 --- a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php +++ b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php @@ -2,10 +2,11 @@ namespace Wikibase\Test\Dumpers; +use MediaWikiTestCase; use MWException; -use PHPUnit_Framework_TestCase; use Site; use SiteList; +use Title; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\ItemId; @@ -15,6 +16,7 @@ use Wikibase\Dumpers\RdfDumpGenerator; use Wikibase\EntityRevision; use Wikibase\Lib\Store\EntityRevisionLookup; +use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException; use Wikibase\Rdf\RdfVocabulary; use Wikibase\Repo\Tests\Rdf\NTriplesRdfTestHelper; @@ -34,7 +36,7 @@ * @license GPL-2.0+ * @author Stas Malyshev */ -class RdfDumpGeneratorTest extends PHPUnit_Framework_TestCase { +class RdfDumpGeneratorTest extends MediaWikiTestCase { const URI_BASE = 'http://acme.test/'; const URI_DATA = 'http://data.acme.test/'; @@ -83,6 +85,20 @@ __DIR__ . '/../../data/rdf/entities', __DIR__ . '/../../data/rdf/RdfDumpGenerator' ); + } + + /** + * @return EntityTitleLookup + */ + private function getEntityTitleLookup() { + $entityTitleLookup = $this->getMock( EntityTitleLookup::class ); + $entityTitleLookup->expects( $this->any() ) + ->method( 'getTitleForId' ) + ->will( $this->returnCallback( function( EntityId $entityId ) { + return Title::newFromText( $entityId->getSerialization() ); + } ) ); + + return $entityTitleLookup; } /** @@ -143,7 +159,8 @@ self::URI_BASE, self::URI_DATA, array( 'test' => 'en-x-test' ) - ) + ), + $this->getEntityTitleLookup() ); } diff --git a/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php b/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php index 101de2b..4ac18ca 100644 --- a/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php +++ b/repo/tests/phpunit/includes/LinkedData/EntityDataTestProvider.php @@ -442,7 +442,7 @@ array( 'id' => 'Q42', 'format' => 'ntriples', 'flavor' => 'full' ), // parameters array(), // headers '!^<http://data\.acme\.test/Q42> *' - . '<http://schema.org/softwareVersion> *"0\.0\.2" *\.$.*^' + . '<http://schema.org/softwareVersion> *"0\.0\.3" *\.$.*^' . '<http://acme\.test/Q22> *' . '<http://www\.w3\.org/2002/07/owl#sameAs> *' . '<http://acme\.test/Q42> *.$!sm', @@ -454,7 +454,7 @@ array( 'id' => 'Q42', 'format' => 'ntriples', 'flavor' => 'dump' ), // parameters array(), // headers '!^<http://data\.acme\.test/Q42> +' - . '<http://schema.org/softwareVersion> +"0\.0\.2" *\.$' + . '<http://schema.org/softwareVersion> +"0\.0\.3" *\.$' . '!sm', 200, // http code ); diff --git a/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php b/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php index 4b6e27c..37374a2 100644 --- a/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php +++ b/repo/tests/phpunit/includes/Rdf/RdfBuilderTest.php @@ -2,12 +2,17 @@ namespace Wikibase\Test\Rdf; +use PageProps; +use Title; use Wikibase\DataModel\Entity\EntityDocument; +use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\ItemId; +use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Rdf\DedupeBag; use Wikibase\Rdf\HashDedupeBag; use Wikibase\Rdf\RdfBuilder; use Wikibase\Rdf\RdfProducer; +use Wikibase\Rdf\RdfVocabulary; use Wikibase\Repo\Tests\Rdf\NTriplesRdfTestHelper; use Wikibase\Repo\WikibaseRepo; use Wikimedia\Purtle\NTriplesRdfWriter; @@ -48,22 +53,36 @@ */ private function getTestData() { if ( empty( $this->testData ) ) { - $this->testData = new RdfBuilderTestData( - __DIR__ . '/../../data/rdf/entities', - __DIR__ . '/../../data/rdf/RdfBuilder' - ); + $this->testData = + new RdfBuilderTestData( __DIR__ . '/../../data/rdf/entities', + __DIR__ . '/../../data/rdf/RdfBuilder' ); } return $this->testData; } /** - * @param int $produce One of the RdfProducer::PRODUCE_... constants. - * @param DedupeBag|null $dedup - * + * @return EntityTitleLookup + */ + private function getEntityTitleLookup() { + $entityTitleLookup = $this->getMock( EntityTitleLookup::class ); + $entityTitleLookup->expects( $this->any() ) + ->method( 'getTitleForId' ) + ->will( $this->returnCallback( function ( EntityId $entityId ) { + return Title::newFromText( $entityId->getSerialization() ); + } ) ); + + return $entityTitleLookup; + } + + /** + * @param int $produce One of the RdfProducer::PRODUCE_... constants. + * @param DedupeBag $dedup + * @param RdfVocabulary $vocabulary * @return RdfBuilder */ - private function newRdfBuilder( $produce, DedupeBag $dedup = null ) { + private function newRdfBuilder( $produce, DedupeBag $dedup = null, + RdfVocabulary $vocabulary = null ) { if ( $dedup === null ) { $dedup = new HashDedupeBag(); } @@ -72,15 +91,11 @@ $valueBuilderFactory = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory(); $emitter = new NTriplesRdfWriter(); - $builder = new RdfBuilder( - $this->getTestData()->getSiteList(), - $this->getTestData()->getVocabulary(), - $valueBuilderFactory, - $this->getTestData()->getMockRepository(), - $produce, - $emitter, - $dedup - ); + $builder = + new RdfBuilder( $this->getTestData()->getSiteList(), + $vocabulary ?: $this->getTestData()->getVocabulary(), $valueBuilderFactory, + $this->getTestData()->getMockRepository(), $produce, $emitter, $dedup, + $this->getEntityTitleLookup() ); $builder->startDocument(); return $builder; @@ -98,16 +113,16 @@ } public function getRdfTests() { - $rdfTests = array( - array( 'Q1', 'Q1_simple' ), - array( 'Q2', 'Q2_labels' ), - array( 'Q3', 'Q3_links' ), - array( 'Q4', 'Q4_claims' ), - array( 'Q5', 'Q5_badges' ), - array( 'Q6', 'Q6_qualifiers' ), - array( 'Q7', 'Q7_references' ), - array( 'Q8', 'Q8_baddates' ), - ); + $rdfTests = [ + [ 'Q1', 'Q1_simple' ], + [ 'Q2', 'Q2_labels' ], + [ 'Q3', 'Q3_links' ], + [ 'Q4', 'Q4_claims' ], + [ 'Q5', 'Q5_badges' ], + [ 'Q6', 'Q6_qualifiers' ], + [ 'Q7', 'Q7_references' ], + [ 'Q8', 'Q8_baddates' ], + ]; return $rdfTests; } @@ -119,13 +134,13 @@ $entity = $this->getEntityData( $entityName ); $expected = $this->getTestData()->getNTriples( $dataSetName ); - $builder = $this->newRdfBuilder( RdfProducer::PRODUCE_ALL_STATEMENTS | - RdfProducer::PRODUCE_TRUTHY_STATEMENTS | - RdfProducer::PRODUCE_QUALIFIERS | - RdfProducer::PRODUCE_REFERENCES | - RdfProducer::PRODUCE_SITELINKS | - RdfProducer::PRODUCE_VERSION_INFO | - RdfProducer::PRODUCE_FULL_VALUES ); + $builder = + $this->newRdfBuilder( RdfProducer::PRODUCE_ALL_STATEMENTS | + RdfProducer::PRODUCE_TRUTHY_STATEMENTS | + RdfProducer::PRODUCE_QUALIFIERS | + RdfProducer::PRODUCE_REFERENCES | RdfProducer::PRODUCE_SITELINKS | + RdfProducer::PRODUCE_VERSION_INFO | + RdfProducer::PRODUCE_FULL_VALUES ); $builder->addEntity( $entity ); $builder->addEntityRevisionInfo( $entity->getId(), 42, "2014-11-04T03:11:05Z" ); @@ -139,25 +154,50 @@ $q11 = new ItemId( 'Q11' ); $builder->addEntityRedirect( $q11, $q1 ); - $expected = '<http://acme.test/Q11> <http://www.w3.org/2002/07/owl#sameAs> <http://acme.test/Q1> .'; + $expected = + '<http://acme.test/Q11> <http://www.w3.org/2002/07/owl#sameAs> <http://acme.test/Q1> .'; $this->helper->assertNTriplesEquals( $expected, $builder->getRDF() ); } public function getProduceOptions() { - $produceTests = array( - array( 'Q4', RdfProducer::PRODUCE_ALL_STATEMENTS, 'Q4_all_statements' ), - array( 'Q4', RdfProducer::PRODUCE_TRUTHY_STATEMENTS, 'Q4_truthy_statements' ), - array( 'Q6', RdfProducer::PRODUCE_ALL_STATEMENTS, 'Q6_no_qualifiers' ), - array( 'Q6', RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_QUALIFIERS, 'Q6_with_qualifiers' ), - array( 'Q7', RdfProducer::PRODUCE_ALL_STATEMENTS , 'Q7_no_refs' ), - array( 'Q7', RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_REFERENCES, 'Q7_refs' ), - array( 'Q3', RdfProducer::PRODUCE_SITELINKS, 'Q3_sitelinks' ), - array( 'Q4', RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_PROPERTIES, 'Q4_props' ), - array( 'Q4', RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_FULL_VALUES, 'Q4_values' ), - array( 'Q1', RdfProducer::PRODUCE_VERSION_INFO, 'Q1_info' ), - array( 'Q4', RdfProducer::PRODUCE_TRUTHY_STATEMENTS | RdfProducer::PRODUCE_RESOLVED_ENTITIES, 'Q4_resolved' ), - array( 'Q10', RdfProducer::PRODUCE_TRUTHY_STATEMENTS | RdfProducer::PRODUCE_RESOLVED_ENTITIES, 'Q10_redirect' ), - ); + $produceTests = [ + [ 'Q4', RdfProducer::PRODUCE_ALL_STATEMENTS, 'Q4_all_statements' ], + [ 'Q4', RdfProducer::PRODUCE_TRUTHY_STATEMENTS, 'Q4_truthy_statements' ], + [ 'Q6', RdfProducer::PRODUCE_ALL_STATEMENTS, 'Q6_no_qualifiers' ], + [ + 'Q6', + RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_QUALIFIERS, + 'Q6_with_qualifiers' + ], + [ 'Q7', RdfProducer::PRODUCE_ALL_STATEMENTS, 'Q7_no_refs' ], + [ + 'Q7', + RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_REFERENCES, + 'Q7_refs' + ], + [ 'Q3', RdfProducer::PRODUCE_SITELINKS, 'Q3_sitelinks' ], + [ + 'Q4', + RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_PROPERTIES, + 'Q4_props' + ], + [ + 'Q4', + RdfProducer::PRODUCE_ALL_STATEMENTS | RdfProducer::PRODUCE_FULL_VALUES, + 'Q4_values' + ], + [ 'Q1', RdfProducer::PRODUCE_VERSION_INFO, 'Q1_info' ], + [ + 'Q4', + RdfProducer::PRODUCE_TRUTHY_STATEMENTS | RdfProducer::PRODUCE_RESOLVED_ENTITIES, + 'Q4_resolved' + ], + [ + 'Q10', + RdfProducer::PRODUCE_TRUTHY_STATEMENTS | RdfProducer::PRODUCE_RESOLVED_ENTITIES, + 'Q10_redirect' + ], + ]; return $produceTests; } @@ -198,4 +238,99 @@ $this->helper->assertNTriplesEquals( $expected, $data1 . $data2 ); } + public function getProps() { + return [ + 'simple prop' => [ + 'prop1', + [ + 'claims' => [ 'name' => 'rdf-claims' ] + ] + ], + 'two props' => [ + 'prop2', + [ + 'claims' => [ 'name' => 'rdf-claims' ], + 'sitelinks' => [ 'name' => 'rdf-sitelinks' ] + ] + ], + 'unknown prop' => [ + 'prop3', + [ + 'Xclaims' => [ 'name' => 'rdf-claims' ], + 'sitelinks' => [ 'name' => 'rdf-sitelinks' ] + ] + ], + 'types' => [ + 'prop4', + [ + 'claims' => [ 'name' => 'rdf-claims', 'type' => 'integer' ], + 'sitelinks' => [ 'name' => 'rdf-sitelinks', 'type' => 'float' ] + ] + ], + ]; + } + + private function getPropsMock() { + $propsMock = + $this->getMockBuilder( PageProps::class )->disableOriginalConstructor()->getMock(); + $propsMock->method( 'getProperties' )->willReturnCallback( function ( Title $title, + $propertyNames ) { + $props = [ ]; + foreach ( $propertyNames as $prop ) { + if ( $prop[0] == 'X' ) { + continue; + } + $props[$prop] = "test$prop"; + // Numeric one + $props["len$prop"] = strlen( $prop ); + } + return [ 'fakeID' => $props ]; + } ); + return $propsMock; + } + + /** + * @dataProvider getProps + * @param string $name Datafile name + * @param array $props Property config + */ + public function testPageProps( $name, $props ) { + $vocab = new RdfVocabulary( RdfBuilderTestData::URI_BASE, RdfBuilderTestData::URI_DATA, + [], [], $props ); + $builder = $this->newRdfBuilder( RdfProducer::PRODUCE_ALL, null, $vocab ); + + $builder->setPageProps( $this->getPropsMock() ); + + $builder->addEntityPageProps( $this->getEntityData( 'Q9' )->getId() ); + $data = $builder->getRDF(); + + $expected = $this->getTestData()->getNTriples( $name ); + $this->helper->assertNTriplesEquals( $expected, $data ); + } + + public function testPagePropsNone() { + // Props disabled by flag + $props = [ + 'claims' => [ 'name' => 'rdf-claims' ] + ]; + $vocab = new RdfVocabulary( RdfBuilderTestData::URI_BASE, RdfBuilderTestData::URI_DATA, + [], [], $props ); + $builder = $this->newRdfBuilder( RdfProducer::PRODUCE_ALL & ~RdfProducer::PRODUCE_PAGE_PROPS, null, $vocab ); + + $builder->setPageProps( $this->getPropsMock() ); + + $builder->addEntityPageProps( $this->getEntityData( 'Q9' )->getId() ); + $data = $builder->getRDF(); + $this->assertEquals( "", $data, "Should return empty string" ); + + // Props disabled by config of vocabulary + $builder = $this->newRdfBuilder( RdfProducer::PRODUCE_ALL ); + + $builder->setPageProps( $this->getPropsMock() ); + + $builder->addEntityPageProps( $this->getEntityData( 'Q9' )->getId() ); + $data = $builder->getRDF(); + $this->assertEquals( "", $data, "Should return empty string" ); + } + } diff --git a/repo/tests/phpunit/maintenance/dumpRdfTest.php b/repo/tests/phpunit/maintenance/dumpRdfTest.php index ffff3f3..3a084b2 100644 --- a/repo/tests/phpunit/maintenance/dumpRdfTest.php +++ b/repo/tests/phpunit/maintenance/dumpRdfTest.php @@ -6,7 +6,9 @@ use HashSiteStore; use MediaWikiLangTestCase; use TestSites; +use Title; use Wikibase\DataModel\Entity\EntityDocument; +use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\Property; @@ -30,6 +32,7 @@ use Wikibase\DataModel\Term\Term; use Wikibase\DataModel\Term\TermList; use Wikibase\DumpRdf; +use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Tests\MockRepository; use Wikibase\Rdf\RdfVocabulary; use Wikibase\Repo\Tests\MockEntityPerPage; @@ -139,7 +142,8 @@ $this->getMockPropertyDataTypeLookup(), $rdfBuilder, $mockRepo, - new RdfVocabulary( 'fooUri/', 'acme/EntityData/' ) + new RdfVocabulary( 'fooUri/', 'acme/EntityData/' ), + $this->getEntityTitleLookup() ); $logFileName = tempnam( sys_get_temp_dir(), "Wikibase-DumpRdfTest" ); @@ -196,4 +200,18 @@ return preg_replace( '~(*BSR_ANYCRLF)\R~', "\n", $string ); } + /** + * @return EntityTitleLookup + */ + private function getEntityTitleLookup() { + $entityTitleLookup = $this->getMock( EntityTitleLookup::class ); + $entityTitleLookup->expects( $this->any() ) + ->method( 'getTitleForId' ) + ->will( $this->returnCallback( function( EntityId $entityId ) { + return Title::newFromText( $entityId->getSerialization() ); + } ) ); + + return $entityTitleLookup; + } + } -- To view, visit https://gerrit.wikimedia.org/r/305575 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I95868d6ae75c4ebf98ff414200fcdcc2155488f1 Gerrit-PatchSet: 17 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Smalyshev <smalys...@wikimedia.org> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Denny Vrandecic <vrande...@gmail.com> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Markus Kroetzsch <mar...@semantic-mediawiki.org> Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits