/** * Parse a source text and return a ConceptSearchSource object if exists. * @param string $source_text */ public function parse($source_text) { $matches = array(); if ($source_text == '*') { $css = new ConceptSearchSource(); $css->setSourceAllDictionaries(); return $css; } elseif (preg_match('/^(.+):map\\((\\d+)\\)/', $source_text, $matches)) { $css = $this->getMapSource($matches[2], $matches[1]); return $css; } elseif (preg_match('/^list\\((\\d+)\\)/', $source_text, $matches)) { $css = $this->getConceptList($matches[1]); return $css; } else { $css = $this->getDictionary($source_text); return $css; } return null; }
/** * Load concept sets. * @param ConceptSearchSource $css_dict * @param ConceptSearch $cs * @param ConceptCollection $cc */ private function _loadConceptSets(ConceptSearchSource $css_dict, ConceptSearch $cs, ConceptCollection $cc) { // load the ENTIRE concept set hierarchy for this dictionary source $sql_concept_set = 'select concept_id, concept_set ' . 'from concept_set ' . 'order by sort_weight'; if ($this->debug) { echo '<p><b>Loading concept set hierarchy for ' . $css_dict->dict_db . ':</b><br> ' . $sql_concept_set . '</p>'; } $rsc_concept_set = mysql_query($sql_concept_set, $css_dict->getConnection()); if (!$rsc_concept_set) { echo "could not query db in ConceptSearchFactory::_loadConceptSets: " . mysql_error(); } // build the ENTIRE concept set hierarchy for this dictionary source $arr_child_parent = array(); $arr_parent_child = array(); while ($row = mysql_fetch_assoc($rsc_concept_set)) { $child_id = $row['concept_id']; $parent_id = $row['concept_set']; $arr_child_parent[$child_id][] = $parent_id; $arr_parent_child[$parent_id][] = $child_id; } // add parents to the children for the concepts in this ConceptCollection foreach (array_keys($arr_child_parent) as $_child_id) { if (!($_child_concept = $cc->getConcept($_child_id, $css_dict))) { $_child_concept = new Concept($_child_id); $_child_concept->display = false; $_child_concept->css_dict = $css_dict; $cc->addConcept($_child_concept); } foreach ($arr_child_parent[$_child_id] as $_parent_id) { $_child_concept->addParent($_parent_id); } } // add children to the parents for the concepts in this ConceptCollection foreach (array_keys($arr_parent_child) as $_parent_id) { if (!($_parent_concept = $cc->getConcept($_parent_id, $css_dict))) { $_parent_concept = new Concept($_parent_id); $_parent_concept->display = false; $_parent_concept->css_dict = $css_dict; $cc->addConcept($_parent_concept); } foreach ($arr_parent_child[$_parent_id] as $_child_id) { $_parent_concept->addChild($_child_id); } } }
/** * Loads the concept classes from the specified dictionary. * @return ConceptClassCollection */ public function loadConceptClasses(ConceptSearchSource $css_dict) { // get the data $sql_classes = 'select concept_class_id, name, description, uuid ' . 'from concept_class ' . 'where retired != 1 ' . 'order by name'; if ($this->debug) { echo '<p><b>Loading concept classes for <strong>' . $css_dict->dict_db . '</strong>:</b><br> ' . $sql_classes . '</p>'; } $rsc_classes = mysql_query($sql_classes, $css_dict->getConnection()); if (!$rsc_classes) { echo "could not query db: " . mysql_error(); } // Create the class collection $ccc = new ConceptClassCollection(); while ($row = mysql_fetch_assoc($rsc_classes)) { $cd = new ConceptClass($row['concept_class_id'], $row['name'], $row['description'], $row['uuid']); $cd->setSourceDictionary($css_dict); // $key = '<database_name>:class(<concept_class_id>) $key = $css_dict->dict_db . ':class(' . $row['concept_class_id'] . ')'; $ccc->Add($key, $cd); } return $ccc; }