コード例 #1
0
 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;
 }
コード例 #2
0
 protected function addResourceHelperValue(ExpData $expData, DIProperty $property, DataItem $dataItem)
 {
     $expElementHelper = $this->exporter->getDataItemHelperExpElement($dataItem);
     if ($expElementHelper !== null) {
         $expData->addPropertyObjectValue($this->getResourceElementHelperForProperty($property), $expElementHelper);
     }
 }
コード例 #3
0
 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;
 }
 /**
  * @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);
 }
コード例 #6
0
ファイル: SMW_Exp_Data.php プロジェクト: whysasse/kmwiki
 /**
  * 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;
     }
 }
コード例 #7
0
 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;
 }
 /**
  * @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)
 {
     $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);
 }
コード例 #10
0
 /**
  * @since 2.0
  *
  * @param mixed $expected
  * @param ExpResource $selectedElement
  * @param ExpData $exportData
  */
 public function assertThatExportDataContainsResource($expectedResources, ExpResource $selectedElement, ExpData $exportData)
 {
     $expElements = $exportData->getValues($selectedElement);
     $this->assertNotEmpty($expElements);
     $expectedResources = is_array($expectedResources) ? $expectedResources : array($expectedResources);
     $expectedToCount = count($expectedResources);
     $actualComparedToCount = 0;
     $assertThatExportDataContainsResource = false;
     foreach ($expElements as $expElement) {
         foreach ($expectedResources as $expectedResource) {
             if ($expectedResource->getHash() === $expElement->getHash()) {
                 $actualComparedToCount++;
                 $assertThatExportDataContainsResource = true;
             }
         }
     }
     $this->assertTrue($assertThatExportDataContainsResource, 'Asserts that a resource is set');
     $this->assertEquals($expectedToCount, $actualComparedToCount, 'Asserts that all listed resources are set');
 }
 /**
  * @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));
 }
コード例 #12
0
 /**
  * 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;&amp;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);
 }
コード例 #13
0
ファイル: SMW_SparqlStore.php プロジェクト: Tjorriemorrie/app
 /**
  * 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;
 }
コード例 #14
0
ファイル: SMW_Serializer.php プロジェクト: whysasse/kmwiki
 /**
  * Update the declaration "todo" and "done" lists for the case that the
  * given data has been serialized with the type information it provides.
  *  
  * @param $expData specifying the type data upon which declarations are based
  */
 protected function recordDeclarationTypes(SMWExpData $expData)
 {
     foreach ($expData->getSpecialValues('rdf', 'type') as $typeresource) {
         if ($typeresource instanceof SMWExpNsResource) {
             switch ($typeresource->getQName()) {
                 case 'owl:Class':
                     $typeflag = SMW_SERIALIZER_DECL_CLASS;
                     break;
                 case 'owl:ObjectProperty':
                     $typeflag = SMW_SERIALIZER_DECL_OPROP;
                     break;
                 case 'owl:DatatypeProperty':
                     $typeflag = SMW_SERIALIZER_DECL_APROP;
                     break;
                 default:
                     $typeflag = 0;
             }
             if ($typeflag != 0) {
                 $this->declarationDone($expData->getSubject(), $typeflag);
             }
         }
     }
 }
コード例 #15
0
ファイル: SMW_DV_Concept.php プロジェクト: Tjorriemorrie/app
 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;
 }
コード例 #16
0
ファイル: SMW_Exporter.php プロジェクト: Tjorriemorrie/app
 /**
  * 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;
 }
コード例 #17
0
 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;
 }
コード例 #18
0
 /**
  * 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;
 }
コード例 #19
0
 /**
  * Serialize the given SMWExpData object, possibly recursively with
  * increased indentation.
  *
  * @param $data SMWExpData containing the data to be serialised.
  * @param $indent string specifying a prefix for indentation (usually a sequence of tabs)
  */
 protected function serializeNestedExpData(SMWExpData $data, $indent)
 {
     if (count($data->getProperties()) == 0) {
         return;
         // nothing to export
     }
     // Avoid posting turtle property declarations already known for the
     // subject more than once
     if ($data->getSubject()->getDataItem() !== null && $data->getSubject()->getDataItem()->getNamespace() === SMW_NS_PROPERTY) {
         $hash = $data->getHash();
         $poolCache = InMemoryPoolCache::getInstance()->getPoolCacheFor('turtle.serializer');
         if ($poolCache->contains($hash) && $poolCache->fetch($hash)) {
             return;
         }
         $poolCache->save($hash, true);
     }
     $this->recordDeclarationTypes($data);
     $bnode = false;
     $this->post_ns_buffer .= $indent;
     if (!$data->getSubject()->isBlankNode()) {
         $this->serializeExpResource($data->getSubject());
     } else {
         // blank node
         $bnode = true;
         $this->post_ns_buffer .= "[";
     }
     if ($indent !== '' && !$bnode) {
         // called to generate a nested descripion; but Turtle cannot nest non-bnode descriptions, do this later
         $this->subexpdata[] = $data;
         return;
     } elseif (!$bnode) {
         $this->post_ns_buffer .= "\n ";
     }
     $firstproperty = true;
     foreach ($data->getProperties() as $property) {
         $this->post_ns_buffer .= $firstproperty ? "\t" : " ;\n {$indent}\t";
         $firstproperty = false;
         $prop_decl_queued = false;
         $class_type_prop = $this->isOWLClassTypeProperty($property);
         $this->serializeExpResource($property);
         $firstvalue = true;
         foreach ($data->getValues($property) as $value) {
             $this->post_ns_buffer .= $firstvalue ? '  ' : ' ,  ';
             $firstvalue = false;
             if ($value instanceof SMWExpLiteral) {
                 $prop_decl_type = SMW_SERIALIZER_DECL_APROP;
                 $this->serializeExpLiteral($value);
             } elseif ($value instanceof SMWExpResource) {
                 $prop_decl_type = SMW_SERIALIZER_DECL_OPROP;
                 $this->serializeExpResource($value);
             } elseif ($value instanceof SMWExpData) {
                 // resource (maybe blank node), could have subdescriptions
                 $prop_decl_type = SMW_SERIALIZER_DECL_OPROP;
                 $collection = $value->getCollection();
                 if ($collection !== false) {
                     // RDF-style collection (list)
                     $this->post_ns_buffer .= "( ";
                     foreach ($collection as $subvalue) {
                         $this->serializeNestedExpData($subvalue, $indent . "\t\t");
                         if ($class_type_prop) {
                             $this->requireDeclaration($subvalue->getSubject(), SMW_SERIALIZER_DECL_CLASS);
                         }
                     }
                     $this->post_ns_buffer .= " )";
                 } else {
                     if ($class_type_prop) {
                         $this->requireDeclaration($value->getSubject(), SMW_SERIALIZER_DECL_CLASS);
                     }
                     if (count($value->getProperties()) > 0) {
                         // resource with data: serialise
                         $this->post_ns_buffer .= "\n";
                         $this->serializeNestedExpData($value, $indent . "\t\t");
                     } else {
                         // resource without data: may need to be queued
                         $this->serializeExpResource($value->getSubject());
                     }
                 }
             }
             if (!$prop_decl_queued) {
                 $this->requireDeclaration($property, $prop_decl_type);
                 $prop_decl_queued = true;
             }
         }
     }
     $this->post_ns_buffer .= ($bnode ? " ]" : " .") . ($indent === '' ? "\n\n" : '');
 }