/**
  * Adds the given Statement's main Snak to the RDF graph.
  *
  * @todo share more of this code with FullStatementRdfBuilder
  *
  * @param EntityId $entityId
  * @param Statement $statement
  *
  * @throws InvalidArgumentException
  */
 private function addMainSnak(EntityId $entityId, Statement $statement)
 {
     $snak = $statement->getMainSnak();
     $entityLName = $this->vocabulary->getEntityLName($entityId);
     $this->writer->about(RdfVocabulary::NS_ENTITY, $entityLName);
     $this->snakBuilder->addSnak($this->writer, $snak, RdfVocabulary::NSP_DIRECT_CLAIM);
 }
コード例 #2
0
 /**
  * Declares $from to be an alias for $to, using the owl:sameAs relationship.
  *
  * @param EntityId $from
  * @param EntityId $to
  */
 public function addEntityRedirect(EntityId $from, EntityId $to)
 {
     $fromLName = $this->vocabulary->getEntityLName($from);
     $toLName = $this->vocabulary->getEntityLName($to);
     $this->writer->about(RdfVocabulary::NS_ENTITY, $fromLName)->say('owl', 'sameAs')->is(RdfVocabulary::NS_ENTITY, $toLName);
     $this->entityResolved($from);
     if ($this->shouldProduce(RdfProducer::PRODUCE_RESOLVED_ENTITIES)) {
         $this->entityToResolve($to);
     }
 }
コード例 #3
0
 /**
  * Add the entity's terms to the RDF graph.
  *
  * @param EntityDocument $entity the entity to output.
  */
 public function addEntity(EntityDocument $entity)
 {
     if ($entity instanceof FingerprintProvider) {
         $fingerprint = $entity->getFingerprint();
         /** @var EntityDocument $entity */
         $entityLName = $this->vocabulary->getEntityLName($entity->getId());
         $this->addLabels($entityLName, $fingerprint->getLabels());
         $this->addDescriptions($entityLName, $fingerprint->getDescriptions());
         $this->addAliases($entityLName, $fingerprint->getAliasGroups());
     }
 }
コード例 #4
0
 /**
  * Adds the site links of the given item to the RDF graph.
  *
  * @param Item $item
  */
 public function addSiteLinks(Item $item)
 {
     $entityLName = $this->vocabulary->getEntityLName($item->getId());
     /** @var SiteLink $siteLink */
     foreach ($item->getSiteLinkList() as $siteLink) {
         if (!$this->isSiteIncluded($siteLink->getSiteId())) {
             continue;
         }
         // FIXME: we should check the site exists using hasGlobalId here before asuming it does
         $site = $this->siteLookup->getSite($siteLink->getSiteId());
         // XXX: ideally, we'd use https if the target site supports it.
         $baseUrl = str_replace('$1', rawurlencode($siteLink->getPageName()), $site->getLinkPath());
         // $site->getPageUrl( $siteLink->getPageName() );
         if (!parse_url($baseUrl, PHP_URL_SCHEME)) {
             $url = "http:" . $baseUrl;
         } else {
             $url = $baseUrl;
         }
         $this->writer->about($url)->a(RdfVocabulary::NS_SCHEMA_ORG, 'Article')->say(RdfVocabulary::NS_SCHEMA_ORG, 'about')->is(RdfVocabulary::NS_ENTITY, $entityLName)->say(RdfVocabulary::NS_SCHEMA_ORG, 'inLanguage')->text($this->vocabulary->getCanonicalLanguageCode($site->getLanguageCode()));
         foreach ($siteLink->getBadges() as $badge) {
             $this->writer->say(RdfVocabulary::NS_ONTOLOGY, 'badge')->is(RdfVocabulary::NS_ENTITY, $this->vocabulary->getEntityLName($badge));
         }
     }
 }
コード例 #5
0
 /**
  * Adds the value of the given property to the RDF graph.
  *
  * @param RdfWriter $writer
  * @param PropertyValueSnak $snak
  * @param string $propertyNamespace The property namespace for this snak
  */
 private function addSnakValue(RdfWriter $writer, PropertyValueSnak $snak, $propertyNamespace)
 {
     $propertyId = $snak->getPropertyId();
     $propertyValueLName = $this->vocabulary->getEntityLName($propertyId);
     $propertyKey = $propertyId->getSerialization();
     // cache data type for all properties we encounter
     if (!isset($this->propertyTypes[$propertyKey])) {
         try {
             $this->propertyTypes[$propertyKey] = $this->propertyLookup->getDataTypeIdForProperty($propertyId);
         } catch (PropertyDataTypeLookupException $e) {
             $this->propertyTypes[$propertyKey] = "unknown";
         }
     }
     $dataType = $this->propertyTypes[$propertyKey];
     $this->valueBuilder->addValue($writer, $propertyNamespace, $propertyValueLName, $dataType, $snak);
 }
 /**
  * Adds the given Statement's main Snak to the RDF graph.
  *
  * @param EntityId $entityId
  * @param string $statementLName
  * @param Statement $statement
  * @param bool $isBest Is this best ranked statement?
  */
 private function addMainSnak(EntityId $entityId, $statementLName, Statement $statement, $isBest)
 {
     $snak = $statement->getMainSnak();
     $entityLName = $this->vocabulary->getEntityLName($entityId);
     $propertyLName = $this->vocabulary->getEntityLName($snak->getPropertyId());
     $this->statementWriter->about(RdfVocabulary::NS_ENTITY, $entityLName)->say(RdfVocabulary::NSP_CLAIM, $propertyLName)->is(RdfVocabulary::NS_STATEMENT, $statementLName);
     $this->statementWriter->about(RdfVocabulary::NS_STATEMENT, $statementLName)->a(RdfVocabulary::NS_ONTOLOGY, 'Statement');
     $rank = $statement->getRank();
     if (isset(RdfVocabulary::$rankMap[$rank])) {
         if ($isBest) {
             $this->statementWriter->a(RdfVocabulary::NS_ONTOLOGY, RdfVocabulary::WIKIBASE_RANK_BEST);
         }
         $this->statementWriter->about(RdfVocabulary::NS_STATEMENT, $statementLName)->say(RdfVocabulary::NS_ONTOLOGY, 'rank')->is(RdfVocabulary::NS_ONTOLOGY, RdfVocabulary::$rankMap[$rank]);
     } else {
         wfLogWarning("Unknown rank {$rank} encountered for {$entityId}:{$statement->getGuid()}");
     }
     $this->snakBuilder->addSnak($this->statementWriter, $snak, RdfVocabulary::NSP_CLAIM_STATEMENT);
 }
 /**
  * @dataProvider provideAddValue
  */
 public function testAddValue(PropertyValueSnak $snak, $complex, array $expected)
 {
     $vocab = new RdfVocabulary('http://acme.com/item/', 'http://acme.com/data/');
     $snakWriter = new NTriplesRdfWriter();
     $snakWriter->prefix('www', "http://www/");
     $snakWriter->prefix('acme', "http://acme/");
     $snakWriter->prefix(RdfVocabulary::NSP_CLAIM_VALUE, "http://acme/statement/value/");
     $snakWriter->prefix(RdfVocabulary::NSP_CLAIM_STATEMENT, "http://acme/statement/");
     $snakWriter->prefix(RdfVocabulary::NS_VALUE, "http://acme/value/");
     $snakWriter->prefix(RdfVocabulary::NS_ONTOLOGY, "http://acme/onto/");
     if ($complex) {
         $valueWriter = $snakWriter->sub();
         $helper = new ComplexValueRdfHelper($vocab, $valueWriter, new HashDedupeBag());
     } else {
         $helper = null;
     }
     $builder = new QuantityRdfBuilder($helper);
     $snakWriter->start();
     $snakWriter->about('www', 'Q1');
     $builder->addValue($snakWriter, RdfVocabulary::NSP_CLAIM_STATEMENT, $vocab->getEntityLName($snak->getPropertyid()), 'DUMMY', $snak);
     $this->helper->assertNTriplesEquals($expected, $snakWriter->drain());
 }