/** * 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); }
/** * Extract text test data from RDF builder * * @param RdfWriter $writer * * @return string[] ntriples lines, sorted */ private function getDataFromWriter(RdfWriter $writer) { $ntriples = $writer->drain(); $lines = explode("\n", trim($ntriples)); sort($lines); return $lines; }
/** * Adds specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { $value = $snak->getDataValue(); $entityId = $value->getValue()->getEntityId(); $entityLName = $this->vocabulary->getEntityLName($entityId); $writer->say($propertyValueNamespace, $propertyValueLName)->is(RdfVocabulary::NS_ENTITY, $entityLName); $this->mentionedEntityTracker->entityReferenceMentioned($entityId); }
private function assertOrCreateNTriples($dataSetName, RdfWriter $writer) { $actual = $writer->drain(); $expected = $this->getTestData()->getNTriples($dataSetName); if ($expected === null) { $this->getTestData()->putTestData($dataSetName, $actual, '.actual'); $this->fail("Data set {$dataSetName} not found! Created file with the current data using" . " the suffix .actual"); } $this->helper->assertNTriplesEquals($expected, $actual, "Data set {$dataSetName}"); }
private function sayDateLiteral(RdfWriter $writer, TimeValue $value) { $dateValue = $this->dateCleaner->getStandardValue($value); if (!is_null($dateValue)) { // XXX: type should perhaps depend on precision. $writer->value($dateValue, 'xsd', 'dateTime'); } else { $writer->value($value->getTime()); } }
/** * Adds specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { /** @var GlobeCoordinateValue $value */ $value = $snak->getDataValue(); $point = "Point({$value->getLatitude()} {$value->getLongitude()})"; $writer->say($propertyValueNamespace, $propertyValueLName)->value($point, RdfVocabulary::NS_GEO, "wktLiteral"); if ($this->complexValueHelper !== null) { $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); } }
/** * 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 specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { /** @var QuantityValue $value */ $value = $snak->getDataValue(); $writer->say($propertyValueNamespace, $propertyValueLName)->value($value->getAmount(), 'xsd', 'decimal'); //FIXME: this is meaningless without a unit identifier! if ($this->complexValueHelper !== null) { $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); } }
/** * Adds specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { /** @var GlobeCoordinateValue $value */ $value = $snak->getDataValue(); $point = "Point({$value->getLatitude()} {$value->getLongitude()})"; $globe = $value->getGlobe(); if ($globe && $globe !== GlobeCoordinateValue::GLOBE_EARTH) { $globe = str_replace('>', '%3E', $globe); // Add coordinate system according to http://www.opengeospatial.org/standards/geosparql // Per https://portal.opengeospatial.org/files/?artifact_id=47664 sec 8.5.1 // All RDFS Literals of type geo:wktLiteral shall consist of an optional URI // identifying the coordinate reference system followed by Simple Features Well Known // Text (WKT) describing a geometric value. // Example: "<http://www.opengis.net/def/crs/EPSG/0/4326> Point(33.95 -83.38)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> $point = "<{$globe}> {$point}"; } $writer->say($propertyValueNamespace, $propertyValueLName)->value($point, RdfVocabulary::NS_GEO, "wktLiteral"); if ($this->complexValueHelper !== null) { $this->addValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); } }
/** * 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); }
/** * Adds specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { $uri = $this->getValueUri($snak->getDataValue()); $writer->say($propertyValueNamespace, $propertyValueLName)->is($uri); }
/** * Adds specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { /** @var MonolingualTextValue $value */ $value = $snak->getDataValue(); $writer->say($propertyValueNamespace, $propertyValueLName)->text($value->getText(), $value->getLanguageCode()); }
/** * Adds specific value * * @param RdfWriter $writer * @param string $propertyValueNamespace Property value relation namespace * @param string $propertyValueLName Property value relation name * @param string $dataType Property data type * @param PropertyValueSnak $snak */ public function addValue(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, PropertyValueSnak $snak) { $literalValue = $this->getLiteralValue($snak->getDataValue()); $nsType = $this->typeBase ?: ($this->typeLocal === null ? null : 'xsd'); $writer->say($propertyValueNamespace, $propertyValueLName)->value($literalValue, $nsType, $this->typeLocal); }
/** * 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()); }