public function testAttachValueNode() { $vocab = new RdfVocabulary('http://acme.com/item/', 'http://acme.com/data/'); $snakWriter = new NTriplesRdfWriter(); $snakWriter->prefix('www', "http://www/"); $snakWriter->prefix(RdfVocabulary::NSP_CLAIM_VALUE, "http://acme/statement/value/"); $snakWriter->prefix(RdfVocabulary::NS_VALUE, "http://acme/value/"); $valueWriter = new NTriplesRdfWriter(); $valueWriter->prefix(RdfVocabulary::NS_VALUE, "http://acme/value/"); $valueWriter->prefix(RdfVocabulary::NS_ONTOLOGY, "http://acme/onto/"); $helper = new ComplexValueRdfHelper($vocab, $valueWriter, new HashDedupeBag()); // check we get the correct value writer $this->assertSame($valueWriter, $helper->getValueNodeWriter()); $snakWriter->start(); $snakWriter->about('www', 'Q1'); $valueWriter->start(); // attach a value node $value = new StringValue('http://en.wikipedia.org/wiki/Wikidata'); $lvalue = $helper->attachValueNode($snakWriter, RdfVocabulary::NSP_CLAIM_STATEMENT, 'testing', 'DUMMY', $value); $this->assertEquals('e93b68fef814eb52e813bb72e6867432', $lvalue); // do it again, tests dedupe $snakWriter->about('www', 'Q2'); $lvalue = $helper->attachValueNode($snakWriter, RdfVocabulary::NSP_CLAIM_STATEMENT, 'testing', 'DUMMY', $value); $this->assertNull($lvalue, 'lvalue produced by adding a value a second time should be null'); // check the triples written to the snak writer $expected = array('<http://www/Q1> <http://acme/statement/value/testing> <http://acme/value/e93b68fef814eb52e813bb72e6867432> .', '<http://www/Q2> <http://acme/statement/value/testing> <http://acme/value/e93b68fef814eb52e813bb72e6867432> .'); $this->helper->assertNTriplesEquals($expected, $snakWriter->drain()); // check the triples written to the value writer $expected = '<http://acme/value/e93b68fef814eb52e813bb72e6867432> ' . '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ' . '<http://acme/onto/StringValue> .'; $this->helper->assertNTriplesEquals($expected, $valueWriter->drain()); }
/** * Adds a value node representing all details of $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 GlobeCoordinateValue $value */ private function addValueNode(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, GlobeCoordinateValue $value) { $valueLName = $this->complexValueHelper->attachValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); if ($valueLName === null) { // The value node is already present in the output, don't create it again! return; } $valueWriter = $this->complexValueHelper->getValueNodeWriter(); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoLatitude')->value($value->getLatitude(), 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoLongitude')->value($value->getLongitude(), 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoPrecision')->value($value->getPrecision(), 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoGlobe')->is(trim($value->getGlobe())); }
/** * Adds a value node representing all details of $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 TimeValue $value */ private function addValueNode(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, TimeValue $value) { $valueLName = $this->complexValueHelper->attachValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); if ($valueLName === null) { // The value node is already present in the output, don't create it again! return; } $valueWriter = $this->complexValueHelper->getValueNodeWriter(); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'timeValue'); $this->sayDateLiteral($valueWriter, $value); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'timePrecision')->value($value->getPrecision(), 'xsd', 'integer'); //TODO: use identifiers $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'timeTimezone')->value($value->getTimezone(), 'xsd', 'integer'); //XXX: underspecified $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'timeCalendarModel')->is(trim($value->getCalendarModel())); }
/** * Adds a value node representing all details of $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 QuantityValue $value */ private function addValueNode(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, QuantityValue $value) { $valueLName = $this->complexValueHelper->attachValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); if ($valueLName === null) { // The value node is already present in the output, don't create it again! return; } $valueWriter = $this->complexValueHelper->getValueNodeWriter(); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'quantityAmount')->value($value->getAmount(), 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'quantityUpperBound')->value($value->getUpperBound(), 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'quantityLowerBound')->value($value->getLowerBound(), 'xsd', 'decimal'); $unitUri = trim($value->getUnit()); if ($unitUri === '1') { $unitUri = RdfVocabulary::ONE_ENTITY; } $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'quantityUnit')->is($unitUri); }
/** * Adds a value node representing all details of $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 GlobeCoordinateValue $value */ private function addValueNode(RdfWriter $writer, $propertyValueNamespace, $propertyValueLName, $dataType, GlobeCoordinateValue $value) { $valueLName = $this->complexValueHelper->attachValueNode($writer, $propertyValueNamespace, $propertyValueLName, $dataType, $value); if ($valueLName === null) { // The value node is already present in the output, don't create it again! return; } $valueWriter = $this->complexValueHelper->getValueNodeWriter(); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoLatitude')->value($value->getLatitude(), 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoLongitude')->value($value->getLongitude(), 'xsd', 'decimal'); // Disallow nulls in precision, see T123392 $precision = $value->getPrecision(); if (is_null($precision)) { $valueWriter->a(RdfVocabulary::NS_ONTOLOGY, 'GeoAutoPrecision'); // 1/3600 comes from GeoCoordinateFormatter.php default value for no prcision $precision = 1 / 3600; } $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoPrecision')->value($precision, 'xsd', 'decimal'); $valueWriter->say(RdfVocabulary::NS_ONTOLOGY, 'geoGlobe')->is(trim($value->getGlobe())); }