/**
  * 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);
 }
 /**
  * Creates a value node for $value, and attaches it to the current subject of $writer.
  * If a value node for $value was already created, null is returned. Otherwise, the
  * value node's lname is returned, which should be used to generate detailed about the
  * value into the writer returned by getValueNodeWriter().
  *
  * When this method returns a non-null lname, the current subject of the RdfWriter returned by
  * getValueNodeWriter() will the be value node with that lname.
  *
  * @param RdfWriter $writer
  * @param string $propertyValueNamespace Property value relation namespace
  * @param string $propertyValueLName Property value relation name
  * @param string $dataType Property data type (unused, passed here for symmetry
  *        with the signature of ValueSnakRdfBuilder::addValue).
  * @param DataValue $value
  *
  * @return string|null The LName of the value node (in the RdfVocabulary::NS_VALUE namespace),
  *  or null if the value node should not be processed (generally, because it already has
  *  been processed).
  */
 public function attachValueNode(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, DataValue $value)
 {
     $valueLName = $value->getHash();
     $writer->say(RdfVocabulary::$claimToValue[$propertyValueNamespace], $propertyValueLName)->is(RdfVocabulary::NS_VALUE, $valueLName);
     if ($this->dedupeBag->alreadySeen($valueLName, 'V') !== false) {
         return null;
     }
     $this->valueNodeWriter->about(RdfVocabulary::NS_VALUE, $valueLName)->a(RdfVocabulary::NS_ONTOLOGY, $this->vocabulary->getValueTypeName($value));
     return $valueLName;
 }
 /**
  * Adds the aliases of the given entity to the RDF graph.
  *
  * @param string $entityLName
  * @param AliasGroupList $aliases
  */
 public function addAliases($entityLName, AliasGroupList $aliases)
 {
     /** @var AliasGroup $aliasGroup */
     foreach ($aliases as $aliasGroup) {
         $languageCode = $aliasGroup->getLanguageCode();
         if ($this->languages !== null && !isset($this->languages[$languageCode])) {
             continue;
         }
         foreach ($aliasGroup->getAliases() as $alias) {
             $this->writer->about(RdfVocabulary::NS_ENTITY, $entityLName)->say(RdfVocabulary::NS_SKOS, 'altLabel')->text($alias, $languageCode);
         }
     }
 }
 /**
  * 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));
         }
     }
 }
 /**
  * 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);
 }
 /**
  * Create header structure for the dump
  *
  * @param int $timestamp Timestamp (for testing)
  */
 public function addDumpHeader($timestamp = 0)
 {
     // TODO: this should point to "this document"
     $this->writer->about(RdfVocabulary::NS_ONTOLOGY, 'Dump')->a(RdfVocabulary::NS_SCHEMA_ORG, "Dataset")->a('owl', 'Ontology')->say(RdfVocabulary::NS_CC, 'license')->is(RdfVocabulary::LICENSE)->say(RdfVocabulary::NS_SCHEMA_ORG, 'softwareVersion')->value(RdfVocabulary::FORMAT_VERSION)->say(RdfVocabulary::NS_SCHEMA_ORG, 'dateModified')->value(wfTimestamp(TS_ISO_8601, $timestamp), 'xsd', 'dateTime')->say('owl', 'imports')->is(RdfVocabulary::getOntologyURI());
 }