public function expDataProvider() { $serializier = new ExpDataSerializer(); #0 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $provider[] = array($serializier->serialize($expData), $expData); #1 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $provider[] = array($serializier->serialize($expData), $expData); #2 Nested $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', new DIBlob('SomeText')), new ExpLiteral('Foo', 'Bar')); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', new DIBlob('SomeOtherText')))); $provider[] = array($serializier->serialize($expData), $expData); #2 Nested level 2+3 $expDataLevel2 = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', new DIBlob('SomeOtherText'))); $expDataLevel2->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', new DIBlob('SomeText')), new ExpLiteral('Foo', 'Bar')); $expDataLevel2->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null))); $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', new DIBlob('SomeText')), new ExpLiteral('Foo', 'Bar')); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), $expDataLevel2); $provider[] = array($serializier->serialize($expData), $expData); return $provider; }
public function expDataHashProvider() { #0 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $provider[] = array($expData, '4dc04c87e9660854a5609ff132175fd5'); #1 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $provider[] = array($expData, '5702e5e8c6145aaf8d89840a4a3b18c2'); #2 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Bar', 'Foo')); $provider[] = array($expData, '13edcedd007979f5638fbc958f0cdaf8'); #3 Same as 2 but different sorting/same hash $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Bar', 'Foo')); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $provider[] = array($expData, '13edcedd007979f5638fbc958f0cdaf8'); #4 Nesting $expDataLevel2 = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expDataLevel2->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), $expDataLevel2); $provider[] = array($expData, 'e684e7640a201d2d33e035aaa866c1ac'); return $provider; }
public function expDataProvider() { #0 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $provider[] = array($expData, array('subject' => array('type' => 1, 'uri' => 'Foo|Bar|Mo', 'dataitem' => null), 'data' => array(), 'serializer' => 'SMW\\Serializers\\ExpDataSerializer', 'version' => 0.1)); #1 $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpLiteral('Foo', 'Bar')); $provider[] = array($expData, array('subject' => array('type' => 1, 'uri' => 'Foo|Bar|Mo', 'dataitem' => null), 'data' => array('LaLi' => array('property' => array('type' => 1, 'uri' => 'Li|La|Lu', 'dataitem' => null), 'children' => array(array('type' => 2, 'lexical' => 'Foo', 'datatype' => 'Bar', 'lang' => '', 'dataitem' => null)))), 'serializer' => 'SMW\\Serializers\\ExpDataSerializer', 'version' => 0.1)); #2 Nested $expData = new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', null)); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', new DIBlob('SomeText')), new ExpLiteral('Foo', 'Bar')); $expData->addPropertyObjectValue(new ExpNsResource('Li', 'La', 'Lu', null), new ExpData(new ExpNsResource('Foo', 'Bar', 'Mo', new DIBlob('SomeOtherText')))); $provider[] = array($expData, array('subject' => array('type' => 1, 'uri' => 'Foo|Bar|Mo', 'dataitem' => null), 'data' => array('LaLi' => array('property' => array('type' => 1, 'uri' => 'Li|La|Lu', 'dataitem' => array('type' => 2, 'item' => 'SomeText')), 'children' => array(array('type' => 2, 'lexical' => 'Foo', 'datatype' => 'Bar', 'lang' => '', 'dataitem' => null), array('subject' => array('type' => 1, 'uri' => 'Foo|Bar|Mo', 'dataitem' => array('type' => 2, 'item' => 'SomeOtherText')), 'data' => array())))), 'serializer' => 'SMW\\Serializers\\ExpDataSerializer', 'version' => 0.1)); return $provider; }
/** * Turn an array of SMWExpElements into an RDF collection. * * @param $elements array of SMWExpElement * @return SMWExpData */ public static function makeCollection(array $elements) { if (count($elements) == 0) { return new SMWExpData(SMWExporter::getSpecialNsResource('rdf', 'nil')); } else { $rdftype = SMWExporter::getSpecialNsResource('rdf', 'type'); $rdffirst = SMWExporter::getSpecialNsResource('rdf', 'first'); $rdfrest = SMWExporter::getSpecialNsResource('rdf', 'rest'); $result = new SMWExpData(new SMWExpResource('')); // bnode $result->addPropertyObjectValue($rdftype, new SMWExpData(SMWExporter::getSpecialNsResource('rdf', 'List'))); $result->addPropertyObjectValue($rdffirst, array_shift($elements)); $result->addPropertyObjectValue($rdfrest, SMWExpData::makeCollection($elements)); return $result; } }
protected function addResourceHelperValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expElementHelper = $this->exporter->getDataItemHelperExpElement($dataItem); if ($expElementHelper !== null) { $expData->addPropertyObjectValue($this->getResourceElementHelperForProperty($property), $expElementHelper); } }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $diSubject = $expData->getSubject()->getDataItem(); if ($diSubject === null) { return; } $expNsResource = $this->exporter->getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace()); $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expElement === null || $expNsResource === null) { return; } $expData->addPropertyObjectValue($expNsResource, $expElement); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expData->getSubject()->getUri() === '' || $expElement === null) { return; } foreach ($expElement->getProperties() as $subp) { if ($subp->getUri() != $this->exporter->getSpecialNsResource('rdf', 'type')->getUri()) { foreach ($expElement->getValues($subp) as $subval) { $expData->addPropertyObjectValue($subp, $subval); } } } $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $diSubject = $expData->getSubject()->getDataItem(); if ($diSubject === null) { return; } $expNsResource = $this->exporter->getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace()); if ($expNsResource === null) { return; } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property); if (!$dataValue instanceof ImportValue) { return; } $expData->addPropertyObjectValue($expNsResource, $this->exporter->getDataItemExpElement(new DIBlob($dataValue->getImportReference()))); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expElement === null) { return; } if ($property->getKey() === $property->findPropertyTypeID()) { // Ensures that Boolean remains Boolean and not localized canonical // representation such as "Booléen" when the content languageis not // English $expNsResource = $this->getResourceElementForProperty(new DIProperty($property->getCanonicalDiWikiPage()->getDBKey())); } else { $expNsResource = $this->getResourceElementHelperForProperty($property); } $expData->addPropertyObjectValue($expNsResource, $expElement); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expResourceElement = $this->exporter->getResourceElementForWikiPage($property->getCanonicalDiWikiPage(), true); // Avoid that an imported vocabulary is pointing to an internal resource. // // For example: <Has_alternative_label> imported from <skos:altLabel> // with "Monolingual text" type is expected to produce: // // - <property:Has_alternative_label rdf:resource="http://example.org/id/Foo_MLa9c103f4379a94bfab97819dacd3c182"/> // - <skos:altLabel xml:lang="en">Foo</skos:altLabel> if ($expResourceElement->isImported()) { $seekImportVocabulary = false; $expData->addPropertyObjectValue($this->exporter->getResourceElementForProperty($property, false, $seekImportVocabulary), $this->exporter->getDataItemExpElement($dataItem)); } else { parent::addResourceValue($expData, $property, $dataItem); } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property); $list = $dataValue->toArray(); if (!isset($list['_TEXT']) || !isset($list['_LCODE'])) { return; } $expData->addPropertyObjectValue($expResourceElement, new ExpLiteral((string) $list['_TEXT'], 'http://www.w3.org/2001/XMLSchema#string', (string) $list['_LCODE'], $dataItem)); }
/** * Print basic information about this site. */ public function printWikiInfo() { global $wgSitename, $wgLanguageCode; $this->prepareSerialization(); $this->delay_flush = 35; // don't do intermediate flushes with default parameters // assemble export data: $expData = new SMWExpData(new SMWExpResource('&wiki;#wiki')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'Wikisite'))); // basic wiki information $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdfs', 'label'), new SMWExpLiteral($wgSitename)); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'siteName'), new SMWExpLiteral($wgSitename, 'http://www.w3.org/2001/XMLSchema#string')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'pagePrefix'), new SMWExpLiteral(SMWExporter::getInstance()->expandURI('&wikiurl;'), 'http://www.w3.org/2001/XMLSchema#string')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'smwVersion'), new SMWExpLiteral(SMW_VERSION, 'http://www.w3.org/2001/XMLSchema#string')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'langCode'), new SMWExpLiteral($wgLanguageCode, 'http://www.w3.org/2001/XMLSchema#string')); $mainpage = Title::newMainPage(); if (!is_null($mainpage)) { $ed = new SMWExpData(new SMWExpResource($mainpage->getFullURL())); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'mainPage'), $ed); } // statistical information $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'pageCount'), new SMWExpLiteral(SiteStats::pages(), 'http://www.w3.org/2001/XMLSchema#int')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'contentPageCount'), new SMWExpLiteral(SiteStats::articles(), 'http://www.w3.org/2001/XMLSchema#int')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'mediaCount'), new SMWExpLiteral(SiteStats::images(), 'http://www.w3.org/2001/XMLSchema#int')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'editCount'), new SMWExpLiteral(SiteStats::edits(), 'http://www.w3.org/2001/XMLSchema#int')); // SiteStats::views was deprecated in MediaWiki 1.25 // "Stop calling this function, it will be removed some time in the future" //$expData->addPropertyObjectValue( // SMWExporter::getInstance()->getSpecialNsResource( 'swivt', 'viewCount' ), // new SMWExpLiteral( SiteStats::views(), 'http://www.w3.org/2001/XMLSchema#int' ) //); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'userCount'), new SMWExpLiteral(SiteStats::users(), 'http://www.w3.org/2001/XMLSchema#int')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('swivt', 'adminCount'), new SMWExpLiteral(SiteStats::numberingroup('sysop'), 'http://www.w3.org/2001/XMLSchema#int')); $this->serializer->startSerialization(); $this->serializer->serializeExpData(SMWExporter::getInstance()->getOntologyExpData('')); $this->serializer->serializeExpData($expData); // link to list of existing pages: if (strpos(SMWExporter::getInstance()->expandURI('&wikiurl;'), '?') === false) { // check whether we have title as a first parameter or in URL $nexturl = SMWExporter::getInstance()->expandURI('&export;?offset=0'); } else { $nexturl = SMWExporter::getInstance()->expandURI('&export;&offset=0'); } $expData = new SMWExpData(new SMWExpResource($nexturl)); $ed = new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('owl', 'Thing')); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), $ed); $ed = new SMWExpData(new SMWExpResource($nexturl)); $expData->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdfs', 'isDefinedBy'), $ed); $this->serializer->serializeExpData($expData); $this->serializer->finishSerialization(); $this->flush(true); }
public function descriptionToExpData($desc, &$exact) { if ($desc instanceof SMWConjunction || $desc instanceof SMWDisjunction) { $result = new SMWExpData(new SMWExpResource('')); $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Class'))); $elements = array(); foreach ($desc->getDescriptions() as $subdesc) { $element = $this->descriptionToExpData($subdesc, $exact); if ($element === false) { $element = new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Thing')); } $elements[] = $element; } $prop = $desc instanceof SMWConjunction ? 'intersectionOf' : 'unionOf'; $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('owl', $prop), SMWExpData::makeCollection($elements)); } elseif ($desc instanceof SMWClassDescription) { if (count($desc->getCategories()) == 1) { // single category $result = new SMWExpData(SMWExporter::getResourceElement(end($desc->getCategories()))); } else { // disjunction of categories $result = new SMWExpData(new SMWExpResource('')); $elements = array(); foreach ($desc->getCategories() as $cat) { $elements[] = new SMWExpData(SMWExporter::getResourceElement($cat)); } $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('owl', 'unionOf'), SMWExpData::makeCollection($elements)); } $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Class'))); } elseif ($desc instanceof SMWConceptDescription) { $result = new SMWExpData(SMWExporter::getResourceElement($desc->getConcept())); } elseif ($desc instanceof SMWSomeProperty) { $result = new SMWExpData(new SMWExpResource('')); $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Restriction'))); $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('owl', 'onProperty'), new SMWExpData(SMWExporter::getResourceElement($desc->getProperty()))); $subdata = $this->descriptionToExpData($desc->getDescription(), $exact); if ($desc->getDescription() instanceof SMWValueDescription && $desc->getDescription()->getComparator() == SMW_CMP_EQ) { $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('owl', 'hasValue'), $subdata); } else { if ($subdata === false) { $owltype = SMWExporter::getOWLPropertyType($desc->getProperty()->getPropertyTypeID()); if ($owltype == 'ObjectProperty') { $subdata = new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Thing')); } elseif ($owltype == 'DatatypeProperty') { $subdata = new SMWExpData(SMWExporter::getSpecialNsResource('rdfs', 'Literal')); } else { // no restrictions at all with annotation properties ... return new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Thing')); } } $result->addPropertyObjectValue(SMWExporter::getSpecialNsResource('owl', 'someValuesFrom'), $subdata); } } elseif ($desc instanceof SMWValueDescription) { if ($desc->getComparator() == SMW_CMP_EQ) { $result = SMWExporter::getDataItemExpElement($desc->getDataItem()); } else { // alas, OWL cannot represent <= and >= ... $exact = false; $result = false; } } elseif ($desc instanceof SMWThingDescription) { $result = false; } else { $result = false; $exact = false; } return $result; }
/** * Create an SMWExpData container that encodes the ontology header for an * SMW exported OWL file. * * @param string $ontologyuri specifying the URI of the ontology, possibly * empty */ public static function getOntologyExpData($ontologyuri) { $data = new SMWExpData(new SMWExpResource($ontologyuri)); $ed = self::getSpecialNsResource('owl', 'Ontology'); $data->addPropertyObjectValue(self::getSpecialNsResource('rdf', 'type'), $ed); $ed = new SMWExpLiteral(date(DATE_W3C), 'http://www.w3.org/2001/XMLSchema#dateTime'); $data->addPropertyObjectValue(self::getSpecialNsResource('swivt', 'creationDate'), $ed); $ed = new SMWExpResource('http://semantic-mediawiki.org/swivt/1.0'); $data->addPropertyObjectValue(self::getSpecialNsResource('owl', 'imports'), $ed); return $data; }
private function doMapConjunctionDisjunction(Description $description, &$exact) { $result = new ExpData(new ExpResource('')); $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('rdf', 'type'), new ExpData($this->exporter->getSpecialNsResource('owl', 'Class'))); $elements = array(); foreach ($description->getDescriptions() as $subdesc) { $element = $this->getExpDataFromDescription($subdesc, $exact); if ($element === false) { $element = new ExpData($this->exporter->getSpecialNsResource('owl', 'Thing')); } $elements[] = $element; } $prop = $description instanceof Conjunction ? 'intersectionOf' : 'unionOf'; $result->addPropertyObjectValue($this->exporter->getSpecialNsResource('owl', $prop), ExpData::makeCollection($elements)); return $result; }
/** * Turn an array of SMWExpElements into an RDF collection. * * @param $elements array of SMWExpElement * @return SMWExpData */ public static function makeCollection(array $elements) { if (count($elements) == 0) { return new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'nil')); } $result = new SMWExpData(new SMWExpResource('')); // bnode $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'type'), new SMWExpData(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'List'))); $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'first'), array_shift($elements)); $result->addPropertyObjectValue(SMWExporter::getInstance()->getSpecialNsResource('rdf', 'rest'), self::makeCollection($elements)); return $result; }
/** * Find a normalized representation of the given SMWExpData that can * be used in an update of the stored data. Normalization uses * redirects. * Moreover, the method records any auxiliary data that should be * written to the store when including this SMWExpElement into updates. * This auxiliary data is collected in a call-by-ref array. * * @since 1.6 * @param $expData SMWExpData object containing the update data * @param $auxiliaryExpData array of SMWExpData * @param $expandSubject boolean controls if redirects/auxiliary data should also be sought for subject * @return SMWExpData */ protected function expandUpdateExpData(SMWExpData $expData, array &$auxiliaryExpData, $expandSubject) { $subjectExpResource = $expData->getSubject(); if ($expandSubject) { $expandedExpElement = $this->expandUpdateExpElement($subjectExpResource, $auxiliaryExpData); if ($expandedExpElement instanceof SMWExpData) { $newExpData = $expandedExpElement; } else { // instanceof SMWExpResource $newExpData = new SMWExpData($subjectExpResource); } } else { $newExpData = new SMWExpData($subjectExpResource); } foreach ($expData->getProperties() as $propertyResource) { $propertyTarget = $this->expandUpdateExpElement($propertyResource, $auxiliaryExpData); foreach ($expData->getValues($propertyResource) as $expElement) { $elementTarget = $this->expandUpdateExpElement($expElement, $auxiliaryExpData); $newExpData->addPropertyObjectValue($propertyTarget, $elementTarget); } } return $newExpData; }