function testGetValueForAnnotationInferred()
 {
     $exp_values = array("Jack");
     $values = smwfGetAutoCompletionStore()->getValueForAnnotation("jack", Title::newFromText("Has Child", SMW_NS_PROPERTY));
     foreach ($values as $tuple) {
         list($v, $inferred) = $tuple;
         $text = is_string($v) ? $v : $v->getText();
         $this->assertContains($text, $exp_values, $text . " missing");
     }
 }
Example #2
0
 /**
  * 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;
 }