예제 #1
0
파일: reasoner.php 프로젝트: 318io/318-io
 public function query($relation, array $instances)
 {
     $term = term($relation);
     $letters = up_letter_gen();
     $to_project = array();
     foreach ($instances as $i) {
         if (strcmp($i, '?') == 0) {
             $to_project[] = $letters->current();
             $term->addVariableByName($letters->current());
         } else {
             $v = new Variable($letters->current());
             $v->setValue($i);
             $term->addVariable($v);
         }
         $letters->next();
     }
     // all variables have value, no need to generate/iterate candidates
     if ($term->readyForResolve()) {
         return $this->isTrue($relation, $term->getInstances());
     }
     /* ---------Have to fill the variables with a candidate value ----------- */
     try {
         if ($this->isRule($relation)) {
             $candidates = $this->instance_generator_for_rule($term);
         } else {
             $candidates = $this->instance_generator_for_fact($term);
         }
     } catch (Exception $e) {
         echo "no candidates for: \n";
         echo "  " . $term->toString() . "\n";
         return array();
     }
     //foreach($candidates as $i) print_r($i);
     $candidate_table = $this->getRelationTable($term->arity());
     foreach ($candidates as $_instances) {
         if ($this->isTrue($relation, $_instances)) {
             $candidate_table->insert_row_array($_instances, TRUE);
         }
     }
     return $candidate_table->project($to_project)->tuples();
 }
예제 #2
0
 public function setVariable()
 {
     try {
         if (fRequest::get('remove', 'boolean')) {
             $variable = new Variable(fRequest::get('name'));
             $variable->delete();
             fMessaging::create('success', 'Variable removed successfully.');
         } else {
             try {
                 $variable = new Variable(fRequest::get('name'));
             } catch (fNotFoundException $e) {
                 $variable = new Variable();
                 $variable->setName(fRequest::get('name'));
             }
             $variable->setValue(fRequest::get('value'));
             $variable->store();
             fMessaging::create('success', 'Variable set successfully.');
         }
     } catch (fException $e) {
         fMessaging::create('error', $e->getMessage());
     }
     fURL::redirect(Util::getReferer());
 }