/**
  * Create an Condition from a NamespaceDescription
  *
  * @param NamespaceDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     $nspropExpElement = $this->exporter->getSpecialNsResource('swivt', 'wikiNamespace');
     $nsExpElement = new ExpLiteral(strval($description->getNamespace()), 'http://www.w3.org/2001/XMLSchema#integer');
     $nsName = TurtleSerializer::getTurtleNameForExpElement($nsExpElement);
     $condition = "{ ?{$joinVariable} " . $nspropExpElement->getQName() . " {$nsName} . }\n";
     $result = new WhereCondition($condition, true, array());
     $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE);
     return $result;
 }
 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;
 }
Beispiel #3
0
 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 SMWSparqlCondition from an SMWNamespaceDescription.
  *
  * @param $description SMWNamespaceDescription
  * @param $joinVariable string name, see buildSparqlCondition()
  * @param $orderByProperty mixed SMWDIProperty or null, see buildSparqlCondition()
  * @return SMWSparqlCondition
  */
 protected function buildNamespaceCondition(SMWNamespaceDescription $description, $joinVariable, $orderByProperty)
 {
     $nspropExpElement = SMWExporter::getSpecialNsResource('swivt', 'wikiNamespace');
     $nsExpElement = new SMWExpLiteral($description->getNamespace(), 'http://www.w3.org/2001/XMLSchema#integer');
     $nsName = SMWTurtleSerializer::getTurtleNameForExpElement($nsExpElement);
     $condition = "{ ?{$joinVariable} " . $nspropExpElement->getQName() . " {$nsName} . }\n";
     $result = new SMWSparqlWhereCondition($condition, true, array());
     $this->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, SMWDataItem::TYPE_WIKIPAGE);
     return $result;
 }
 /**
  * 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'));
     $ed = new SMWExpData(SMWExporter::getSpecialNsResource('swivt', 'Wikisite'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdf', 'type'), $ed);
     // basic wiki information
     $ed = new SMWExpData(new SMWExpLiteral($wgSitename));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdfs', 'label'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral($wgSitename, null, 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'siteName'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SMWExporter::expandURI('&wikiurl;'), null, 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'pagePrefix'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SMW_VERSION, null, 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'smwVersion'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral($wgLanguageCode, null, 'http://www.w3.org/2001/XMLSchema#string'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'langCode'), $ed);
     $mainpage = Title::newMainPage();
     if (!is_null($mainpage)) {
         $ed = new SMWExpData(new SMWExpResource($mainpage->getFullURL()));
         $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'mainPage'), $ed);
     }
     // statistical information
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::pages(), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'pageCount'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::articles(), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'contentPageCount'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::images(), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'mediaCount'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::edits(), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'editCount'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::views(), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'viewCount'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::users(), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'userCount'), $ed);
     $ed = new SMWExpData(new SMWExpLiteral(SiteStats::numberingroup('sysop'), null, 'http://www.w3.org/2001/XMLSchema#int'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('swivt', 'adminCount'), $ed);
     $this->serializer->startSerialization();
     $this->serializer->serializeExpData(SMWExporter::getOntologyExpData(''));
     $this->serializer->serializeExpData($expData);
     // link to list of existing pages:
     if (strpos(SMWExporter::expandURI('&wikiurl;'), '?') === false) {
         // check whether we have title as a first parameter or in URL
         $nexturl = SMWExporter::expandURI('&export;?offset=0');
     } else {
         $nexturl = SMWExporter::expandURI('&export;&amp;offset=0');
     }
     $expData = new SMWExpData(new SMWExpResource($nexturl));
     $ed = new SMWExpData(SMWExporter::getSpecialNsResource('owl', 'Thing'));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdf', 'type'), $ed);
     $ed = new SMWExpData(new SMWExpResource($nexturl));
     $expData->addPropertyObjectValue(SMWExporter::getSpecialNsResource('rdfs', 'isDefinedBy'), $ed);
     $this->serializer->serializeExpData($expData);
     $this->serializer->finishSerialization();
     $this->flush(true);
 }
Beispiel #6
0
 /**
  * Delete from the SPARQL database all data that is associated with the
  * given resource.
  *
  * @since 1.6
  * @param $expResource SMWExpResource
  * @return boolean success
  */
 protected function deleteSparqlData(SMWExpResource $expResource)
 {
     $resourceUri = SMWTurtleSerializer::getTurtleNameForExpElement($expResource);
     if ($expResource instanceof SMWExpNsResource) {
         $extraNamespaces = array($expResource->getNamespaceId() => $expResource->getNamespace());
     } else {
         $extraNamespaces = array();
     }
     $masterPageProperty = SMWExporter::getSpecialNsResource('swivt', 'masterPage');
     $masterPagePropertyUri = SMWTurtleSerializer::getTurtleNameForExpElement($masterPageProperty);
     $success = smwfGetSparqlDatabase()->deleteContentByValue($masterPagePropertyUri, $resourceUri, $extraNamespaces);
     if ($success) {
         return smwfGetSparqlDatabase()->delete("{$resourceUri} ?p ?o", "{$resourceUri} ?p ?o", $extraNamespaces);
     } else {
         return false;
     }
 }
 public function resourceProvider()
 {
     $provider[] = array(Exporter::getSpecialNsResource('rdf', 'type'));
     $provider[] = array(new ExpNsResource('FooRedirectLookup', Exporter::getNamespaceUri('property'), 'property', new DIWikiPage('FooRedirectLookup', SMW_NS_PROPERTY, '')));
     return $provider;
 }
Beispiel #8
0
 /**
  * Check if this element encodes an RDF list, and if yes return an
  * array of SMWExpElements corresponding to the collection elements in
  * the specified order. Otherwise return false.
  * The method only returns lists that can be encoded using
  * parseType="Collection" in RDF/XML, i.e. only lists of non-literal
  * resources.
  *
  * @return mixed array of SMWExpElement (but not SMWExpLiteral) or false
  */
 public function getCollection()
 {
     $rdftypeUri = SMWExporter::getSpecialNsResource('rdf', 'type')->getUri();
     $rdffirstUri = SMWExporter::getSpecialNsResource('rdf', 'first')->getUri();
     $rdfrestUri = SMWExporter::getSpecialNsResource('rdf', 'rest')->getUri();
     $rdfnilUri = SMWExporter::getSpecialNsResource('rdf', 'nil')->getUri();
     // first check if we are basically an RDF List:
     if ($this->m_subject->isBlankNode() && count($this->m_children) == 3 && array_key_exists($rdftypeUri, $this->m_children) && count($this->m_children[$rdftypeUri]) == 1 && array_key_exists($rdffirstUri, $this->m_children) && count($this->m_children[$rdffirstUri]) == 1 && !end($this->m_children[$rdffirstUri]) instanceof SMWExpLiteral && array_key_exists($rdfrestUri, $this->m_children) && count($this->m_children[$rdfrestUri]) == 1) {
         $typedata = end($this->m_children[$rdftypeUri]);
         $rdflistUri = SMWExporter::getSpecialNsResource('rdf', 'List')->getUri();
         if ($typedata->getSubject()->getUri() == $rdflistUri) {
             $first = end($this->m_children[$rdffirstUri]);
             $rest = end($this->m_children[$rdfrestUri]);
             if ($rest instanceof SMWExpData) {
                 $restlist = $rest->getCollection();
                 if ($restlist === false) {
                     return false;
                 } else {
                     array_unshift($restlist, $first);
                     return $restlist;
                 }
             } elseif ($rest instanceof SMWExpResource && $rest->getUri() == $rdfnilUri) {
                 return array($first);
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } elseif (count($this->m_children) == 0 && $this->m_subject->getUri() == $rdfnilUri) {
         return array();
     } else {
         return false;
     }
 }
	/**
	 * Delete from the SPARQL database all data that is associated with the
	 * given resource.
	 *
	 * @param $expResource SMWExpResource
	 * @return boolean success
	 */
	protected function deleteSparqlData( SMWExpResource $expResource ) {
		$resourceUri = SMWTurtleSerializer::getTurtleNameForExpElement( $expResource );
		$masterPageProperty = SMWExporter::getSpecialNsResource( 'swivt', 'masterPage' );
		$masterPagePropertyUri = SMWTurtleSerializer::getTurtleNameForExpElement( $masterPageProperty );

		$success = smwfGetSparqlDatabase()->deleteContentByValue( $masterPagePropertyUri, $resourceUri );
		if ( $success ) {
			return smwfGetSparqlDatabase()->delete( "$resourceUri ?p ?o", "$resourceUri ?p ?o"  );
		} else {
			return false;
		}
	}
 public function testExportSubSemanticData()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
     $factsheet = $this->fixturesProvider->getFactsheet('berlin');
     $factsheet->setTargetSubject($semanticData->getSubject());
     $demographicsSubobject = $factsheet->getDemographics();
     $semanticData->addPropertyObjectValue($demographicsSubobject->getProperty(), $demographicsSubobject->getContainer());
     $exportData = Exporter::makeExportData($semanticData->findSubSemanticData($demographicsSubobject->getSubobjectId()));
     $this->assertCount(1, $exportData->getValues(Exporter::getSpecialPropertyResource('_SKEY')));
     $this->assertCount(1, $exportData->getValues(Exporter::getSpecialNsResource('swivt', 'wikiNamespace')));
 }
 /**
  * Build the condition (WHERE) string for a given Condition.
  * The function also expresses the single value of
  * SingletonCondition objects in the condition, which may
  * lead to additional namespaces for serializing its URI.
  *
  * @param Condition $condition
  *
  * @return string
  */
 public function convertConditionToString(Condition &$condition)
 {
     $conditionAsString = $condition->getWeakConditionString();
     if ($conditionAsString === '' && !$condition->isSafe()) {
         $swivtPageResource = Exporter::getSpecialNsResource('swivt', 'page');
         $conditionAsString = '?' . $this->resultVariable . ' ' . $swivtPageResource->getQName() . " ?url .\n";
     }
     $conditionAsString .= $condition->getCondition();
     if ($condition instanceof SingletonCondition) {
         // prepare for ASK, maybe rather use BIND?
         $matchElement = $condition->matchElement;
         if ($matchElement instanceof ExpElement) {
             $matchElementName = TurtleSerializer::getTurtleNameForExpElement($matchElement);
         } else {
             $matchElementName = $matchElement;
         }
         if ($matchElement instanceof ExpNsResource) {
             $condition->namespaces[$matchElement->getNamespaceId()] = $matchElement->getNamespace();
         }
         $conditionAsString = str_replace('?' . $this->resultVariable . ' ', "{$matchElementName} ", $conditionAsString);
     }
     return $conditionAsString;
 }