public function valuesOfColumn($column_name) { $list = new FList($this->table); $values = $list->foldl(function ($acc, $record) use($column_name) { $acc[] = $record[$column_name]; return $acc; }, array()); return $values; }
protected function instance_generator_for_fact($term) { $var_list = new FList($term->getVariables()); // TODO: if no fact table found $fact_table = $this->fact_tables[$term->getName()]; $ext_fact_table = isset($this->ext_fact_tables[$term->getName()]) ? $this->ext_fact_tables[$term->getName()] : $fact_table->getEmptyClone(); $select_pattern = $var_list->foldl(function ($acc, $var) { if ($var->hasValue()) { $acc[$var->getName()] = $var->getValue(); } return $acc; }, array()); // if select_pattern == array(), all record of this fact table are selected. $instance_table = $fact_table->select($select_pattern); //$instance_table->view(); $ext_records = $ext_fact_table->select($select_pattern)->records(); $instance_table->insert_array($ext_records, TRUE, TRUE); //$instance_table->view(); // if $instance_table is EMPTY, throw Exception. if ($instance_table->isEmpty()) { throw new LogicException('KBase::instance_generator_for_fact(): no candidates available.'); } return $instance_table->tuples_gen(); /* $candidates_input = $var_list->foldl(function($acc, $var) use ($instance_table) { if($var->hasValue()) { $acc[] = array($var->getValue()); } else { $acc[] = $instance_table->valuesOfColumn($var->getName()); } return $acc; }, array()); return cartesian_product_gen($candidates_input); // yield array(i1, i2, i3, ...) generator */ }