コード例 #1
0
 /**
  * @see superclass
  */
 function getPropertySubjects(SMWPropertyValue $property, $value, $requestoptions = NULL)
 {
     if (!$property->isUserDefined()) {
         return parent::getPropertySubjects($property, $value, $requestoptions);
     }
     if (smwfCheckIfPredefinedSMWHaloProperty($property)) {
         return parent::getPropertyValues($subject, $property, $requestoptions, $outputformat);
     }
     global $smwgTripleStoreGraph;
     $client = TSConnection::getConnector();
     $client->connect();
     $values = array();
     $propertyName = $property->getWikiPageValue()->getTitle()->getDBkey();
     $limit = isset($requestoptions->limit) ? " LIMIT " . $requestoptions->limit : "";
     $offset = isset($requestoptions->offset) ? " OFFSET " . $requestoptions->offset : "";
     $nsPrefixProp = $this->tsNamespace->getNSPrefix($property->getWikiPageValue()->getTitle()->getNamespace());
     try {
         if (is_null($value)) {
             $response = $client->query("SELECT ?s WHERE { GRAPH ?g { ?s <{$smwgTripleStoreGraph}/{$nsPrefixProp}#{$propertyName}> ?o. } } {$limit} {$offset}", "merge=false|graph={$smwgTripleStoreGraph}");
         } else {
             if ($value instanceof SMWWikiPageValue) {
                 $objectName = $value->getTitle()->getDBkey();
                 $nsPrefixObj = $this->tsNamespace->getNSPrefix($value->getTitle()->getNamespace());
                 $response = $client->query("SELECT ?s WHERE { GRAPH ?g { ?s <{$smwgTripleStoreGraph}/{$nsPrefixProp}#{$propertyName}> <{$smwgTripleStoreGraph}/{$nsPrefixObj}#{$objectName}>. } } {$limit} {$offset}", "merge=false");
             } else {
                 $objectvalue = str_replace('"', '\\"', array_shift($value->getDBkeys()));
                 $objecttype = WikiTypeToXSD::getXSDType($value->getTypeID());
                 $response = $client->query("SELECT ?s WHERE { GRAPH ?g { ?s <{$smwgTripleStoreGraph}/{$nsPrefixProp}#{$propertyName}> \"{$objectvalue}\"^^{$objecttype}. } } {$limit} {$offset}", "merge=false");
             }
         }
     } catch (Exception $e) {
         wfDebug("Triplestore does probably not run.\n");
         $response = TSNamespaces::$EMPTY_SPARQL_XML;
     }
     // query
     global $smwgSPARQLResultEncoding;
     // PHP strings are always interpreted in ISO-8859-1 but may be actually encoded in
     // another charset.
     if (isset($smwgSPARQLResultEncoding) && $smwgSPARQLResultEncoding == 'UTF-8') {
         $response = utf8_decode($response);
     }
     $dom = simplexml_load_string($response);
     $annotations = array();
     $results = $dom->xpath('//result');
     foreach ($results as $r) {
         $children = $r->children();
         // binding nodes
         $b = $children->binding[0];
         // predicate
         $sv = $b->children()->uri[0];
         $title = $this->getTitleFromURI((string) $sv);
         $value = SMWWikiPageValue::makePage($title->getDBkey(), $title->getNamespace());
         $metadata = $sv->attributes();
         foreach ($metadata as $mdProperty => $mdValue) {
             if (strpos($mdProperty, "_meta_") === 0) {
                 $value->setMetadata(substr($mdProperty, 6), explode("|||", $mdValue));
             }
         }
         $values[] = $value;
     }
     return $values;
 }
コード例 #2
0
ファイル: SMW_Initialize.php プロジェクト: seedbank/old-repo
/**
 * Parses additinal semantic data need for a triple store:
 *
 *  1. categories
 *  2. rules (optional)
 */
function smwfTripleStoreParserHook(&$parser, &$text, &$strip_state = null)
{
    global $smwgIP, $smwgTripleStoreGraph;
    global $wgContLang;
    include_once $smwgIP . '/includes/SMW_Factbox.php';
    SMWTripleStore::$fullSemanticData = new SMWFullSemanticData();
    $categoryText = $wgContLang->getNsText(NS_CATEGORY);
    // parse categories:
    $categoryLinkPattern = '/\\[\\[\\s*                   # Beginning of the link
                            ' . $categoryText . '\\s*:      # category link (case insensitive!)
                            ([^\\[\\]]*)                 # category
                            \\]\\]                       # End of link
                            /ixu';
    # case-insensitive, ignore whitespaces, UTF-8 compatible
    $categories = array();
    $matches = array();
    preg_match_all($categoryLinkPattern, $text, $matches);
    if (isset($matches[1])) {
        foreach ($matches[1] as $m) {
            $labelIndex = strpos($m, '|');
            $m = $labelIndex !== false ? substr($m, 0, $labelIndex) : $m;
            $categories[] = Title::newFromText(trim($m), NS_CATEGORY);
        }
    }
    // parse redirects
    $redirectLinkPattern = '/\\#REDIRECT          # REDIRECT command
                            \\[\\[                # Beginning of the link
                            ([^]]+)               # target
                            \\]\\]                # End of link
                            /ixu';
    # case-insensitive, ignore whitespaces, UTF-8 compatible
    $redirects = array();
    $matches = array();
    preg_match_all($redirectLinkPattern, $text, $matches);
    if (isset($matches[1])) {
        foreach ($matches[1] as $m) {
            $redirects[] = Title::newFromText($m);
        }
    }
    SMWTripleStore::$fullSemanticData->setCategories($categories);
    SMWTripleStore::$fullSemanticData->setRedirects($redirects);
    return true;
}