コード例 #1
0
ファイル: SMW_Exporter.php プロジェクト: Tjorriemorrie/app
 /**
  * Try to find an SMWDataItem that the given SMWExpElement might
  * represent. Returns null if this attempt failed.
  *
  * @param SMWExpElement $expElement
  * @return SMWDataItem or null
  */
 public static function findDataItemForExpElement(SMWExpElement $expElement)
 {
     global $wgContLang;
     $dataItem = null;
     if ($expElement instanceof SMWExpResource) {
         $uri = $expElement->getUri();
         $wikiNamespace = self::getNamespaceUri('wiki');
         if (strpos($uri, $wikiNamespace) === 0) {
             $localName = substr($uri, strlen($wikiNamespace));
             $dbKey = urldecode(self::decodeURI($localName));
             $parts = explode('-23', $dbKey, 2);
             if (count($parts) == 2) {
                 $subobjectname = $parts[1];
             } else {
                 $subobjectname = '';
             }
             $parts = explode(':', $dbKey, 2);
             if (count($parts) == 1) {
                 $dataItem = new SMWDIWikiPage($dbKey, NS_MAIN, '', $subobjectname);
             } else {
                 // try the by far most common cases directly before using Title
                 $namespaceName = str_replace('_', ' ', $parts[0]);
                 $namespaceId = -1;
                 foreach (array(SMW_NS_PROPERTY, NS_CATEGORY, NS_USER, NS_HELP) as $nsId) {
                     if ($namespaceName == $wgContLang->getNsText($nsId)) {
                         $namespaceId = $nsId;
                         break;
                     }
                 }
                 if ($namespaceId != -1) {
                     $dataItem = new SMWDIWikiPage($parts[1], $namespaceId, '', $subobjectname);
                 } else {
                     $title = Title::newFromDBkey($dbKey);
                     if (!is_null($title)) {
                         $dataItem = new SMWDIWikiPage($title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), $subobjectname);
                     }
                 }
             }
         }
         // else: not in wiki namespace -- TODO: this could be an imported URI
     } else {
         // TODO (currently not needed, but will be useful for displaying external SPARQL results)
     }
     return $dataItem;
 }
コード例 #2
0
 /**
  * Get the Turtle serialization string for the given SMWExpElement. The
  * method just computes a name, and does not serialize triples, so the
  * parameter must be an SMWExpResource or SMWExpLiteral, no SMWExpData.
  *
  * @param $expElement SMWExpElement being SMWExpLiteral or SMWExpResource
  * @return string
  */
 public static function getTurtleNameForExpElement(SMWExpElement $expElement)
 {
     if ($expElement instanceof SMWExpResource) {
         if ($expElement->isBlankNode()) {
             return '[]';
         } elseif ($expElement instanceof SMWExpNsResource && $expElement->hasAllowedLocalName()) {
             return $expElement->getQName();
         } else {
             return '<' . str_replace('>', '\\>', SMWExporter::getInstance()->expandURI($expElement->getUri())) . '>';
         }
     } elseif ($expElement instanceof SMWExpLiteral) {
         $dataType = $expElement->getDatatype();
         $lexicalForm = self::getCorrectLexicalForm($expElement);
         if ($dataType !== '' && $dataType != 'http://www.w3.org/2001/XMLSchema#string') {
             $count = 0;
             $newdt = str_replace('http://www.w3.org/2001/XMLSchema#', 'xsd:', $dataType, $count);
             return $count == 1 ? "{$lexicalForm}^^{$newdt}" : "{$lexicalForm}^^<{$dataType}>";
         } else {
             return $lexicalForm;
         }
     } else {
         throw new InvalidArgumentException('The method can only serialize atomic elements of type SMWExpResource or SMWExpLiteral.');
     }
 }