function testGetInstanceAsTarget() { $exp_values = array("Kai"); $domainRangeAnnotations = smwfGetStore()->getPropertyValues(Title::newFromText("Has Child", SMW_NS_PROPERTY), smwfGetSemanticStore()->domainRangeHintProp); $values = smwfGetAutoCompletionStore()->getInstanceAsTarget("K", $domainRangeAnnotations); foreach ($values as $v) { $this->assertContains($v->getText(), $exp_values, $v->getText() . " missing"); } }
function testCheckIfCategoryRenamed() { // do some checks $exp_category = array("Sports coupe", "Coupé"); $page = Title::newFromText("Audi TT", NS_MAIN); $values = smwfGetSemanticStore()->getCategoriesForInstance($page); foreach ($values as $v) { $this->assertContains(utf8_decode($v->getText()), $exp_category); } }
/** * Called when category annotations get updated in a triple store. * * @param $subject Title with category link * @param $c Title of category * @param $triplesFromHook Triples which are returned. * * @return Array of triples or false */ function smwfTripleStoreCategoryUpdate(&$subject, &$c, &$triplesFromHook) { global $smwgTripleStoreGraph; // serialize transitive or symetric property triples if ($subject->getNamespace() == SMW_NS_PROPERTY && smwfGetSemanticStore()->transitiveCat->equals($c)) { $triplesFromHook[] = array("<{$smwgTripleStoreGraph}/property#" . $subject->getDBkey() . ">", "rdf:type", "owl:TransitiveProperty"); } elseif ($subject->getNamespace() == SMW_NS_PROPERTY && smwfGetSemanticStore()->symetricalCat->equals($c)) { $triplesFromHook[] = array("<{$smwgTripleStoreGraph}/property#" . $subject->getDBkey() . ">", "rdf:type", "owl:SymmetricProperty"); } return true; }
/** * Extracts pages from the given namespace. Creates for * every page an article with the given extension containing all * the wiki markup. * * @param $type namespace * @param $fext file extension */ function extractFromNamespace($type, $fext) { global $helpDirectory, $dbr; print "\nExtracting pages from namespace {$type}..."; $helpPages = smwfGetSemanticStore()->getPages(array($type)); foreach ($helpPages as $hp) { print "\nExtract: " . $hp->getText() . "..."; $rev = Revision::loadFromTitle($dbr, $hp); $wikitext = $rev->getText(); $fname = rawurlencode($hp->getDBKey()); $handle = fopen($helpDirectory . "/" . $fname . "." . $fext, "w"); fwrite($handle, $wikitext); fclose($handle); extractImages($hp); print "done!"; } print "\n\nAll pages from namespace {$type} extracted!\n"; }
public function getSubProperties($p_array) { // param0 : attribute // param1 : limit // param2 : partitionNum $reqfilter = new SMWRequestOptions(); $reqfilter->sort = true; $reqfilter->limit = intval($p_array[1]); $partitionNum = isset($p_array[2]) ? intval($p_array[2]) : 0; $reqfilter->offset = $partitionNum * $reqfilter->limit; $superatt = Title::newFromText($p_array[0], SMW_NS_PROPERTY); $directsubatts = smwfGetSemanticStore()->getDirectSubProperties($superatt, $reqfilter); $resourceAttachments = array(); wfRunHooks('smw_ob_attachtoresource', array($directsubatts, &$resourceAttachments, SMW_NS_PROPERTY)); return SMWOntologyBrowserXMLGenerator::encapsulateAsPropertyPartition($directsubatts, $resourceAttachments, $reqfilter->limit, $partitionNum, false); }
/** * Detrmines all attribute paths from root to the given entity. * May be more than one in case of multiple inheritance. * * @param $cat The category to determine path for * @param $path Must be an empty array * @param $allPaths Must be an empty array */ private function getAllPropertyPaths($att, &$path, &$allPaths, &$visitedNodes) { $path[] = $att; $superProps = smwfGetSemanticStore()->getDirectSuperProperties($att); array_push($visitedNodes, $att->getDBkey()); $cycleFound = false; foreach ($superProps as $superProp) { if (in_array($superProp->getDBkey(), $visitedNodes)) { $cycleFound = true; break; } $cloneOfPath = array_clone($path); $this->getAllPropertyPaths($superProp, $cloneOfPath, $allPaths, $visitedNodes); } if (count($superProps) == 0 || $cycleFound) { $allPaths[] = $path; } array_pop($visitedNodes); }
public function getWikiPageProperties($sort) { global $smwgHaloContLang; $NSrel = SMW_NS_PROPERTY; $db =& wfGetDB(DB_SLAVE); $sspa = $smwgHaloContLang->getSpecialSchemaPropertyArray(); $smw_ids = $db->tableName('smw_ids'); $smw_spec2 = $db->tableName('smw_spec2'); $smw_atts2 = $db->tableName('smw_atts2'); $smw_rels2 = $db->tableName('smw_rels2'); $page = $db->tableName('page'); $domainAndRange = $db->selectRow($db->tableName('smw_ids'), array('smw_id'), array('smw_title' => smwfGetSemanticStore()->domainRangeHintRelation->getDBkey())); if ($domainAndRange == NULL) { $domainAndRangeID = -1; // does never exist } else { $domainAndRangeID = $domainAndRange->smw_id; } switch ($sort) { case 0: // fall through // fall through case 1: //fall through //fall through case 2: return "(SELECT 'Relations' as type,\r\n {$NSrel} as namespace,\r\n q.smw_title as title,\r\n s.smw_title as value,\r\n s.smw_namespace as obns,\r\n COUNT(q.smw_title) as count,\r\n p.page_touched as touch\r\n FROM {$smw_ids} q\r\n JOIN {$smw_rels2} n ON q.smw_id = n.p_id\r\n LEFT JOIN {$page} p ON n.p_id = p.page_id\r\n LEFT JOIN {$smw_rels2} m ON n.p_id = m.s_id AND m.p_id = {$domainAndRangeID}\r\n LEFT JOIN {$smw_ids} r ON m.o_id = r.smw_id\r\n LEFT JOIN {$smw_rels2} o ON m.o_id = o.s_id AND m.p_id = {$domainAndRangeID}\r\n LEFT JOIN {$smw_ids} s ON o.o_id = s.smw_id\r\n LEFT JOIN {$smw_ids} t ON o.p_id = t.smw_id\r\n WHERE q.smw_namespace = 102 AND q.smw_iw != \":smw\" AND t.smw_sortkey = \"_2\"\r\n GROUP BY title) \r\n UNION DISTINCT\r\n (SELECT 'Relations' as type,\r\n {$NSrel} as namespace,\r\n q.smw_title as title,\r\n NULL as value, \r\n '-1' as obns, \r\n COUNT(*) as count ,\r\n p.page_touched as touch\r\n FROM {$smw_ids} q \r\n JOIN {$smw_rels2} n ON q.smw_id = n.p_id\r\n LEFT JOIN {$page} p ON n.s_id = p.page_id\r\n LEFT JOIN {$smw_rels2} m ON n.p_id = m.s_id AND m.p_id = {$domainAndRangeID}\r\n WHERE q.smw_namespace = 102 AND q.smw_iw != \":smw\" AND m.s_id IS NULL\r\n GROUP BY title)"; } }
/** * Checks if the given property is predefined by SMWHalo * @param SMWPropertyValue $property */ function smwfCheckIfPredefinedSMWHaloProperty(SMWPropertyValue $property) { if (smwfGetSemanticStore()->domainRangeHintRelation->getDBkey() == $property->getDBkey() || smwfGetSemanticStore()->minCard->getDBkey() == $property->getDBkey() || smwfGetSemanticStore()->maxCard->getDBkey() == $property->getDBkey() || smwfGetSemanticStore()->inverseOf->getDBkey() == $property->getDBkey()) { return true; } return false; }
/** * Gets a list of all available SFs for a page or for the whole wiki. * * @param string $page The namespace:title of the page or ''(blank) for all SFs in the wiki * @param string $substring Subtsting to search upon in the names of the SFs. * @return array A list of SF names. */ public function getSFList($page, $substring) { $__sfList = array(); $__tmpListAlternateSF = array(); $__tmpDefaultSF = NULL; if (strstr($page, ':') !== false) { list($__pageNamespace, $__pageTitle) = split(':', $page); } else { $__pageTitle = $page; $__pageNamespace = 0; } if ($__pageTitle == '') { // return all SFs, top element is 'root' $__tmpList = SFUtils::getAllForms(); if ($substring != '') { // check if the substring matches foreach ($__tmpList as $__tmpListEntry) { if (stristr($__tmpListEntry, $substring) !== false) { $__sfList['root'][str_ireplace(' ', '_', $__tmpListEntry)] = array(); } } } else { foreach ($__tmpList as $__tmpListEntry) { $__sfList['root'][str_ireplace(' ', '_', $__tmpListEntry)] = array(); } } } else { $result = array(); if ($__pageNamespace !== 0) { global $wgContLang; $__pageNamespace = $wgContLang->getLocalNsIndex($__pageNamespace); } $sfList = SFLinkUtils::getFormsForArticle(new Article(Title::newFromText($__pageTitle, $__pageNamespace))); foreach ($sfList as $key => $sf) { if ($substring != '') { if (stristr($sf, $substring) !== false) { $result[str_ireplace(' ', '_', $sf)] = array(); } } else { $result[str_ireplace(' ', '_', $sf)] = array(); } } return array($__pageTitle => array('def' => $result)); // get all SFs for the particular page // TODO: does alternate include the default form? global $wgContLang; // retrieve the store first $__store = smwfGetSemanticStore(); // first determine which categories the page is assigned to $__pageCats = $__store->getCategoriesForInstance(Title::newFromText($__pageTitle, $wgContLang->getLocalNsIndex($__pageNamespace))); // for each category only a default form should exist foreach ($__pageCats as $__pageCat) { $__tmpDefaultSFs = SFLinkUtils::getFormsThatPagePointsTo($__pageCat->getText(), NS_CATEGORY, '_SF_DF', '_SF_DF_BACKUP', SF_SP_HAS_DEFAULT_FORM); if (count($__tmpDefaultSFs) > 0) { $__tmpDefaultSF = $__tmpDefaultSFs[0]; if ($substring != '') { // check if the substring matches if (stristr($__tmpDefaultSF, $substring) !== false) { $__sfList[$__pageTitle]['def'][str_ireplace(' ', '_', $__tmpDefaultSF)] = array(); } } else { $__sfList[$__pageTitle]['def'][str_ireplace(' ', '_', $__tmpDefaultSF)] = array(); } } } $__tmpDefaultSF = NULL; // change the store - getProperties is supported by the SMW store only ... $__store = smwfGetStore(); // second determine which properties are defined on the page // default forms are only set via categories $__semData = $__store->getSemanticData(Title::newFromText($__pageTitle, $wgContLang->getLocalNsIndex($__pageNamespace))); $__pageProps = $__semData->getProperties(); // for each property a default and alternate forms may exist foreach ($__pageProps as $__pageProp) { if ($__pageProp->isVisible()) { // exclude internal set properties $__tmpListAlternateSF = SFLinkUtils::getAlternateForms($__pageProp->getWikiPageValue()->getTitle()->getText(), $__pageProp->getWikiPageValue()->getNamespace()); $__tmpDefaultSFs = SFLinkUtils::getDefaultForms($__pageProp->getWikiPageValue()->getTitle()->getText(), $__pageProp->getWikiPageValue()->getNamespace()); if (count($__tmpDefaultSFs) > 0) { $__tmpDefaultSF = $__tmpDefaultSFs[0]; if ($substring != '') { // check if the substring matches foreach ($__tmpListAlternateSF as $__tmpListEntry) { if (stristr($__tmpListEntry, $substring) !== false) { $__sfList[$__pageTitle]['alt'][str_ireplace(' ', '_', $__tmpListEntry)] = array(); } } // ... and for the default form if (stristr($__tmpDefaultSF, $substring) !== false) { $__sfList[$__pageTitle]['alt'][str_ireplace(' ', '_', $__tmpDefaultSF)] = array(); } } else { foreach ($__tmpListAlternateSF as $__tmpListEntry) { $__sfList[$__pageTitle]['alt'][str_ireplace(' ', '_', $__tmpListEntry)] = array(); } if ($__tmpDefaultSF != NULL) { $__sfList[$__pageTitle]['alt'][str_ireplace(' ', '_', $__tmpDefaultSF)] = array(); } } } } } } return $__sfList; }
/** * Returns all domain categories for a given property. */ function getDomainCategories($propertyTitle, $reqfilter) { $db =& wfGetDB(DB_SLAVE); $page = $db->tableName('page'); $domainRangeRelation = smwfGetSemanticStore()->domainRangeHintRelation; $categories = smwfGetStore()->getPropertyValues($propertyTitle, smwfGetSemanticStore()->domainRangeHintProp, $reqfilter); $result = array(); foreach ($categories as $value) { $dvs = $value->getDVs(); if ($dvs[0] instanceof SMWWikiPageValue) { $t = $dvs[0]->getTitle(); if (!SMWSemanticStoreSQL::isRedirect($t, $page, $db)) { $result[] = $t; } } } return $result; }
* @author: Kai K�hn * * Created on: 3.07.2009 */ if (array_key_exists('SERVER_NAME', $_SERVER) && $_SERVER['SERVER_NAME'] != NULL) { echo "Invalid access! A maintenance script MUST NOT accessed from remote."; return; } $mediaWikiLocation = dirname(__FILE__) . '/../../..'; require_once "{$mediaWikiLocation}/maintenance/commandLine.inc"; $help = array_key_exists('h', $options); $delete = array_key_exists('delete', $options); if ($help) { echo "\nUsage: php setup.php [ -h This help ]\n"; die; } if ($delete) { print "\\Drop SMWHalo.\n\n"; smwfGetSemanticStore()->drop(true); //deal with the query results cache global $smwgHaloIP; require_once "{$smwgHaloIP}/includes/QueryResultsCache/SMW_QRC_Store.php"; SMWQRCStore::getInstance()->getDB()->dropTables(); die; } print "\nSetup SMWHalo.\n\n"; global $smwgHaloIP; require_once "{$smwgHaloIP}/includes/QueryResultsCache/SMW_QRC_Store.php"; SMWQRCStore::getInstance()->getDB()->initDatabaseTables(); smwfGetSemanticStore()->setup(true); //deal with the query results cache
/** * Returns true, if $t is a pre-defined title. */ private static function isPredefined($t) { return $t->getDBkey() == smwfGetSemanticStore()->domainRangeHintRelation->getDBkey() || $t->getDBkey() == smwfGetSemanticStore()->minCard->getDBkey() || $t->getDBkey() == smwfGetSemanticStore()->maxCard->getDBkey() || $t->getDBkey() == smwfGetSemanticStore()->transitiveCat->getDBkey() || $t->getDBkey() == smwfGetSemanticStore()->symetricalCat->getDBkey(); }
public function testNumber() { $exp_usage = 17; $usage = smwfGetSemanticStore()->getNumber(NS_CATEGORY); $this->assertEquals($exp_usage, $usage); }
private function getPropertyData(Title $property) { $ranges = array(); $pv = SMWPropertyValue::makeUserProperty($property->getText()); $typesValue = $pv->getTypesValue(); $typeString = implode(',', $typesValue->getTypeLabels()); $hasWikiPageType = false; $typeValues = $typesValue->getTypeValues(); foreach ($typeValues as $tv) { $hasWikiPageType |= array_shift($tv->getDBkeys()) == '_wpg'; } $rangeString = NULL; if ($hasWikiPageType) { $domainRangeAnnotations = smwfGetStore()->getPropertyValues($property, smwfGetSemanticStore()->domainRangeHintProp); foreach ($domainRangeAnnotations as $a) { $dvs = $a->getDVs(); $domain = reset($dvs); $range = next($dvs); if (!is_null($range) && $range !== false) { $ranges[] = $range->getTitle()->getText(); } } $rangeString = implode(',', array_unique($ranges)); } return array($typeString, $rangeString); }
/** * Executes a series of auto-completion commands and stops when it * has a found at least one result. Except when it matches local values. * * @param string $command * @param substring $userInput * @return array of Title, array of (Title, inferred) or array of (Title, inferred, extraContent) */ public static function executeCommand($command, $userInput) { $parsedCommands = self::parseCommand($command); $acStore = smwfGetAutoCompletionStore(); $result = array(); foreach ($parsedCommands as $c) { list($commandText, $params) = $c; if ($commandText == 'values') { foreach ($params as $p) { if (stripos($p, $userInput) !== false) { $result[] = $p; } } // continue to fill in results if possible } else { if ($commandText == 'fixvalues') { foreach ($params as $p) { $result[] = $p; } // continue to fill in results if possible } else { if ($commandText == 'schema-property-domain') { if (empty($params[0]) || is_null($params[0])) { continue; } if (smwf_om_userCan($params[0], 'read') == 'true') { $category = Title::newFromText($params[0]); if (!is_null($category)) { $result = self::mergeResults($result, $acStore->getPropertyForCategory($userInput, $category)); } } if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'schema-property-range-instance') { if (empty($params[0]) || is_null($params[0])) { continue; } if (smwf_om_userCan($params[0], 'read') == 'true') { $instance = Title::newFromText($params[0]); if (!is_null($instance)) { $result = self::mergeResults($result, $acStore->getPropertyForInstance($userInput, $instance, false)); } } if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'annotation-property') { if (empty($params[0]) || is_null($params[0])) { continue; } if (smwf_om_userCan($params[0], 'read') == 'true') { $category = Title::newFromText($params[0]); if (!is_null($category)) { $result = self::mergeResults($result, $acStore->getPropertyForAnnotation($userInput, $category, false)); } } if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'annotation-value') { if (empty($params[0]) || is_null($params[0])) { continue; } if (smwf_om_userCan($params[0], 'read') == 'true') { $property = Title::newFromText($params[0]); if (!is_null($property)) { $result = self::mergeResults($result, $acStore->getValueForAnnotation($userInput, $property)); } } if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'instance-property-range') { if (empty($params[0]) || is_null($params[0])) { continue; } if (smwf_om_userCan($params[0], 'read') == 'true') { $property = Title::newFromText($params[0]); if (!is_null($property)) { $domainRangeAnnotations = smwfGetStore()->getPropertyValues($property, smwfGetSemanticStore()->domainRangeHintProp); $result = self::mergeResults($result, $acStore->getInstanceAsTarget($userInput, $domainRangeAnnotations)); } } if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'namespace') { $result = self::mergeResults($result, smwfGetAutoCompletionStore()->getPages($userInput, $params)); if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'lexical') { $result = self::mergeResults($result, smwfGetAutoCompletionStore()->getPages($userInput)); if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'schema-property-type') { if (empty($params[0]) || is_null($params[0])) { continue; } $datatype = $params[0]; $result = self::mergeResults($result, smwfGetAutoCompletionStore()->getPropertyWithType($userInput, $datatype)); if (count($result) >= SMW_AC_MAX_RESULTS) { break; } global $smwgContLang; $dtl = $smwgContLang->getDatatypeLabels(); $result = self::mergeResults($result, smwfGetAutoCompletionStore()->getPropertyWithType($userInput, $dtl['_str'])); if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } else { if ($commandText == 'ask') { if (empty($params[0]) || is_null($params[0])) { continue; } $query = $params[0]; if (!isset($params[1]) || $params[1] == 'main') { $column = "_var0"; } else { $column = strtoupper(substr($params[1], 0, 1)) . substr($params[1], 1); $column = str_replace(" ", "_", $column); } $xmlResult = self::runASKQuery($query, $column, $userInput); $dom = simplexml_load_string($xmlResult); $queryResults = $dom->xpath('//binding[@name="' . $column . '"]'); // make titles but eliminate duplicates before $textTitles = array(); foreach ($queryResults as $r) { if (empty($userInput) || stripos((string) $r[0], $userInput) !== false) { $textTitles[] = (string) $r[0]; if (count($textTitles) >= SMW_AC_MAX_RESULTS) { break; } } } $textTitles = array_unique($textTitles); $titles = array(); foreach ($textTitles as $r) { if (smwf_om_userCan($r, 'read') == 'true') { $titles[] = Title::newFromText($r); } } self::mergeResults($result, $titles); if (count($result) >= SMW_AC_MAX_RESULTS) { break; } } } } } } } } } } } } } return $result; }
/** * Format a list of the category's properties. * * Lists the following information: * - Relations of this category * - Attributes of this category * - Articles that have a domain hint, but are neither relation nor attribute. * This is probably an error in the user's model. * * Redirects: * If a normal article has a domain hint and is redirected from a relation or * attribute it is listed with the corresponding kind of property. But this * also indicates an error in the user's model. * * @param SMWRequestOptions $options Search options for the database query * @param boolean $domain If <true> the properties whose domain is this * category are listed. Otherwise those whose range is this * category. * */ private function getShortRelationList($options, $domain) { global $smwgHaloContLang; $ti = htmlspecialchars($this->title->getText()); // retrieve all properties of this category $properties = $domain ? smwfGetSemanticStore()->getPropertiesWithDomain($this->title) : smwfGetSemanticStore()->getPropertiesWithRange($this->title); $r = $this->getPropertyList(SMW_NS_PROPERTY, $properties, $domain); //$r .= $this->getPropertyList(SMW_NS_ATTRIBUTE, $properties, $domain); $r .= $this->getPropertyList(-1, $properties, $domain); return $r; }
function smwf_om_invalidateAllPages() { smwfGetSemanticStore()->invalidateAllPages(); return "true"; }