public function aggregate($taxamatch = null)
 {
     $taxamatch_result = $taxamatch->getData();
     $parsed = array();
     $parsed["family"] = $taxamatch->this_search_family;
     $parsed["genus"] = $taxamatch->this_search_genus;
     $parsed["species"] = $taxamatch->this_search_species;
     $parsed["infra1"] = $taxamatch->this_search_infra1;
     $parsed["infra2"] = $taxamatch->this_search_infra2;
     $parsed["authority"] = $taxamatch->this_authority;
     $parsed["authorities"] = $taxamatch->this_authorities;
     $parsed["rank1"] = $taxamatch->this_search_rank1;
     $parsed["rank2"] = $taxamatch->this_search_rank2;
     $start_string = $taxamatch->this_start_string;
     $family_string = $taxamatch->this_family_string;
     $family_unmatched = $taxamatch->this_family_unmatched;
     $status_string = $taxamatch->this_status_string;
     $cleaned_txt = $taxamatch->this_cleaned_txt;
     $preprocessed_txt = $taxamatch->this_preprocessed_txt;
     $scientificname = $taxamatch->searchtxt;
     if ($taxamatch->parse_only) {
         $unparsed = $preprocessed_txt;
         foreach (array_keys($parsed) as $pk) {
             if ($pk == 'authority') {
                 continue;
             } elseif ($pk == 'authorities') {
                 foreach ($parsed[$pk] as $auth) {
                     if ($auth) {
                         $unparsed = str_ireplace_first($auth, '', $unparsed);
                     }
                 }
             } elseif ($parsed[$pk]) {
                 $unparsed = str_ireplace_first($parsed[$pk], '', $unparsed);
                 if ($parsed[$pk] == 'f.' && ($pk == "rank1" || $pk == "rank2")) {
                     $unparsed = str_ireplace_first(self::$forma, '', $unparsed);
                 }
             }
         }
         if (isset($start_string)) {
             $unparsed = $start_string . $unparsed;
         }
         $unparsed = trim($unparsed);
         $parsed_rank1 = array_key_exists($parsed["rank1"], self::$standard_rank) ? self::$standard_rank[$parsed["rank1"]] : $parsed["rank1"];
         $parsed_rank2 = array_key_exists($parsed["rank2"], self::$standard_rank) ? self::$standard_rank[$parsed["rank2"]] : $parsed["rank2"];
         $this->data[] = array('Name_submitted' => $scientificname, 'Family' => $parsed["family"], 'Genus' => $parsed["genus"], 'Specific_epithet' => $parsed["species"], 'Infraspecific_rank' => $parsed_rank1, 'Infraspecific_epithet' => $parsed["infra1"], 'Infraspecific_rank_2' => $parsed_rank2, 'Infraspecific_epithet_2' => $parsed["infra2"], 'Author' => $parsed["authority"], 'Annotations' => $status_string, 'Unmatched_terms' => $unparsed);
         return true;
     }
     $lowest_parsed_rank = '';
     $lowest_matched_rank = '';
     foreach (array_keys(self::$rank) as $rk) {
         if ($parsed[$rk]) {
             $lowest_parsed_rank = $rk;
         }
     }
     $gni_parser_result = null;
     if (isset($taxamatch_result["gni_parser_result"])) {
         $gni_parser_result = $taxamatch_result["gni_parser_result"];
     }
     $all_id = array();
     $all_name = array();
     $matched = array();
     $matched_by_source = array();
     $synonym = array();
     $name_source_data = array();
     $classification_family = array();
     $phonetic_id = array();
     $alt_accepted_family = array();
     $family_matched = array();
     $genus_matched = array();
     $species_matched = array();
     $infra1_matched = array();
     $infra2_matched = array();
     $all_matched = array();
     $best_ed = array();
     $higher_taxa_ed = array();
     foreach (array_keys(self::$rank) as $rk) {
         $all_matched[$rk] = array();
         if (isset($taxamatch_result[$rk]) && count($taxamatch_result[$rk])) {
             foreach (array_keys(self::$match_type) as $type) {
                 if (isset($taxamatch_result[$rk][$type])) {
                     if (!isset($best_ed[$rk]) || $best_ed[$rk] > self::$match_type[$type]) {
                         $best_ed[$rk] = self::$match_type[$type];
                     }
                     foreach ($taxamatch_result[$rk][$type] as &$match) {
                         $match["match_type"] = $type;
                         $match["match_score"] = 0;
                         $match["Lowest_matched_rank"] = $rk;
                         $match["Name_matched_id"] = $match[$rk . "_id"];
                         $all_id[] = $match["Name_matched_id"];
                         if ($type == 'exact' || $type == 'phonetic') {
                             $phonetic_id[$match["Name_matched_id"]] = 1;
                         }
                     }
                     $all_matched[$rk] = array_merge($all_matched[$rk], $taxamatch_result[$rk][$type]);
                 }
             }
         }
     }
     if (count($all_id)) {
         $name_res = $this->db->getScientificName($all_id);
         $accepted_name_id = array();
         foreach ($name_res as $nm) {
             $all_name[$nm->nameID] = $nm;
             $name_source_data[$nm->nameID][$nm->sourceID]['url'] = $nm->name_source_url;
             $name_source_data[$nm->nameID][$nm->sourceID]['lsid'] = $nm->lsid;
         }
         $miss_accepted_name_id = array();
         $synonym_res = $this->db->getSynonym($all_id);
         foreach ($synonym_res as $sn) {
             $nid = $sn->nameID;
             $sid = $sn->sourceID;
             if ($sn->acceptance == 'Accepted') {
                 $synonym[$nid][$sid]["accepted_name_id"] = $nid;
                 $synonym[$nid][$sid]["acceptance"] = $sn->acceptance;
                 //} elseif ($sn->acceptance == 'Synonym' || $sn->acceptance == 'Invalid' || $sn->acceptance == 'Illegitimate') {
             } elseif (!is_null($sn->acceptance)) {
                 if ($sn->accepted_name_id) {
                     $accepted_name_id[] = $sn->accepted_name_id;
                     $synonym[$nid][$sid]["accepted_name_id"] = $sn->accepted_name_id;
                 }
                 $synonym[$nid][$sid]["acceptance"] = $sn->acceptance;
             }
         }
         //print_r($synonym);
         if (count($accepted_name_id)) {
             $name_res = $this->db->getScientificName($accepted_name_id);
             foreach ($name_res as $nm) {
                 $all_name[$nm->nameID] = $nm;
                 $name_source_data[$nm->nameID][$nm->sourceID]['url'] = $nm->name_source_url;
                 $name_source_data[$nm->nameID][$nm->sourceID]['lsid'] = $nm->lsid;
             }
         }
         //print_r($all_name);
         $classificationfamily_res = $this->db->getClassificationFamily(array_keys($all_name));
         $cl_fam = array();
         foreach ($classificationfamily_res as $cf) {
             $cl_fam[$cf->nameID][$cf->sourceID] = $cf->family;
         }
         $source_id = array();
         if (isset($this->db->classification_id)) {
             $source_id[] = $this->db->classification_id;
         } else {
             $source_id = array_keys($this->db->source_name);
         }
         foreach (array_keys($cl_fam) as $nid) {
             foreach ($source_id as $sid) {
                 if (isset($cl_fam[$nid][$sid])) {
                     $classification_family[$nid] = $cl_fam[$nid][$sid];
                     break;
                 }
             }
         }
     }
     //print_r($name_source_data);
     //print_r($classification_family);
     if (count($all_matched['family'])) {
         $fm = array();
         foreach ($all_matched['family'] as $fam) {
             $fm[] = $fam['family'];
         }
         $fam_res = $this->db->getFamilyAcceptedFamily($fm);
         foreach ($fam_res as $fam) {
             $alt_accepted_family[$fam->family] = $fam->accepted_family;
         }
     }
     foreach (array_keys(self::$rank) as $rk) {
         foreach ($all_matched[$rk] as &$match) {
             if (self::$rank[$rk] > self::$rank['family']) {
                 $match["Family_matched"] = "";
                 $match["family_ed"] = 0;
                 if ($parsed["family"]) {
                     $match["family_ed"] = strlen($parsed["family"]);
                     $accepted_family = isset($classification_family[$match["Name_matched_id"]]) ? $classification_family[$match["Name_matched_id"]] : '';
                     $genus = $all_name[$match["Name_matched_id"]]->genus;
                     $family_filtered = $this->filterFamily($all_matched["family"], $accepted_family, $genus, $alt_accepted_family);
                     if (count($family_filtered)) {
                         $match["family_ed"] = $family_filtered[0]["family_ed"];
                         $match["Family_matched"] = $family_filtered[0]["family"];
                         $match["Family_score"] = self::getEDScore($match["family_ed"], $match["Family_matched"], $parsed["family"]);
                         $match["match_score"] += $match["Family_score"];
                     }
                 }
             }
         }
     }
     if (count($all_matched["infra2"])) {
         foreach ($all_matched["infra2"] as &$match) {
             if (isset($higher_taxa_ed["infra2"]) && $higher_taxa_ed["infra2"] <= $match["infra2_ed"]) {
                 continue;
             }
             $name = $all_name[$match["Name_matched_id"]];
             $match["Genus_matched"] = $name->genus;
             $match["Specific_epithet_matched"] = $name->specificEpithet;
             $match["Infraspecific_rank"] = $name->rankIndicator;
             $match["Infraspecific_epithet_matched"] = $name->infraspecificEpithet;
             $match["Infraspecific_rank_2"] = $name->infraspecificRank2;
             $match["Infraspecific_epithet_2_matched"] = $name->infraspecificEpithet2;
             $match["Genus_score"] = self::getEDScore($match["genus_ed"], $match["Genus_matched"], $parsed["genus"]);
             $match["Specific_epithet_score"] = self::getEDScore($match["species_ed"], $match["Specific_epithet_matched"], $parsed["species"]);
             $match["Infraspecific_epithet_score"] = self::getEDScore($match["infra1_ed"], $match["Infraspecific_epithet_matched"], $parsed["infra1"]);
             $match["Infraspecific_epithet_2_score"] = self::getEDScore($match["infra2_ed"], $match["Infraspecific_epithet_2_matched"], $parsed["infra2"]);
             $match["Name_matched"] = $match["genus_species_infra1_infra2"];
             if (!isset($higher_taxa_ed["infra1"]) || $higher_taxa_ed["infra1"] > $match["infra1_ed"]) {
                 $higher_taxa_ed["infra1"] = $match["infra1_ed"];
             }
             if (!isset($higher_taxa_ed["species"]) || $higher_taxa_ed["species"] > $match["species_ed"]) {
                 $higher_taxa_ed["species"] = $match["species_ed"];
             }
             if (!isset($higher_taxa_ed["genus"]) || $higher_taxa_ed["genus"] > $match["genus_ed"]) {
                 $higher_taxa_ed["genus"] = $match["genus_ed"];
             }
             if (isset($match["family_ed"]) && (!isset($higher_taxa_ed["family"]) || $higher_taxa_ed["family"] > $match["family_ed"])) {
                 $higher_taxa_ed["family"] = $match["family_ed"];
             }
             if (self::cmpRank($match["Infraspecific_rank"], $parsed["rank1"]) !== true) {
                 $match["Infraspecific_epithet_score"] -= self::$rank_penalty;
             }
             if (self::cmpRank($match["Infraspecific_rank_2"], $parsed["rank2"]) !== true) {
                 $match["Infraspecific_epithet_2_score"] -= self::$rank_penalty;
             }
             $match["match_score"] += $match["Specific_epithet_score"] + $match["Genus_score"] + $match["Infraspecific_epithet_score"] + $match["Infraspecific_epithet_2_score"];
             $matched[] = $match;
         }
     }
     if (count($all_matched["infra1"]) && (!isset($higher_taxa_ed["infra1"]) || isset($best_ed["infra1"]) && $higher_taxa_ed["infra1"] > $best_ed["infra1"])) {
         foreach ($all_matched["infra1"] as &$match) {
             if (isset($higher_taxa_ed["infra1"]) && $higher_taxa_ed["infra1"] <= $match["infra1_ed"]) {
                 continue;
             }
             $name = $all_name[$match["Name_matched_id"]];
             $match["Genus_matched"] = $name->genus;
             $match["Specific_epithet_matched"] = $name->specificEpithet;
             $match["Infraspecific_rank"] = $name->rankIndicator;
             $match["Infraspecific_epithet_matched"] = $name->infraspecificEpithet;
             $match["Genus_score"] = self::getEDScore($match["genus_ed"], $match["Genus_matched"], $parsed["genus"]);
             $match["Specific_epithet_score"] = self::getEDScore($match["species_ed"], $match["Specific_epithet_matched"], $parsed["species"]);
             $match["Infraspecific_epithet_score"] = self::getEDScore($match["infra1_ed"], $match["Infraspecific_epithet_matched"], $parsed["infra1"]);
             $match["Name_matched"] = $match["genus_species_infra1"];
             if (!isset($higher_taxa_ed["species"]) || $higher_taxa_ed["species"] > $match["species_ed"]) {
                 $higher_taxa_ed["species"] = $match["species_ed"];
             }
             if (!isset($higher_taxa_ed["genus"]) || $higher_taxa_ed["genus"] > $match["genus_ed"]) {
                 $higher_taxa_ed["genus"] = $match["genus_ed"];
             }
             if (isset($match["family_ed"]) && (!isset($higher_taxa_ed["family"]) || $higher_taxa_ed["family"] > $match["family_ed"])) {
                 $higher_taxa_ed["family"] = $match["family_ed"];
             }
             if (self::cmpRank($match["Infraspecific_rank"], $parsed["rank1"]) !== true) {
                 $match["Infraspecific_epithet_score"] -= self::$rank_penalty;
             }
             $match["match_score"] += $match["Specific_epithet_score"] + $match["Genus_score"] + $match["Infraspecific_epithet_score"];
             $matched[] = $match;
         }
     }
     if (count($all_matched["species"]) && (!isset($higher_taxa_ed["species"]) || isset($best_ed["species"]) && $higher_taxa_ed["species"] > $best_ed["species"])) {
         foreach ($all_matched["species"] as &$match) {
             if (isset($higher_taxa_ed["species"]) && $higher_taxa_ed["species"] <= $match["species_ed"]) {
                 continue;
             }
             $name = $all_name[$match["Name_matched_id"]];
             $match["Genus_matched"] = $name->genus;
             $match["Specific_epithet_matched"] = $name->specificEpithet;
             $match["Genus_score"] = self::getEDScore($match["genus_ed"], $match["Genus_matched"], $parsed["genus"]);
             $match["Specific_epithet_score"] = self::getEDScore($match["species_ed"], $match["Specific_epithet_matched"], $parsed["species"]);
             $match["Name_matched"] = $match["genus_species"];
             if (!isset($higher_taxa_ed["genus"]) || $higher_taxa_ed["genus"] > $match["genus_ed"]) {
                 $higher_taxa_ed["genus"] = $match["genus_ed"];
             }
             if (isset($match["family_ed"]) && (!isset($higher_taxa_ed["family"]) || $higher_taxa_ed["family"] > $match["family_ed"])) {
                 $higher_taxa_ed["family"] = $match["family_ed"];
             }
             $match["match_score"] += $match["Genus_score"] + $match["Specific_epithet_score"];
             $matched[] = $match;
         }
     }
     if (count($all_matched["genus"]) && (!isset($higher_taxa_ed["genus"]) || isset($best_ed["genus"]) && $higher_taxa_ed["genus"] > $best_ed["genus"])) {
         foreach ($all_matched["genus"] as &$match) {
             if (isset($higher_taxa_ed["genus"]) && $higher_taxa_ed["genus"] <= $match["genus_ed"]) {
                 continue;
             }
             $name = $all_name[$match["Name_matched_id"]];
             $match["Genus_matched"] = $name->genus;
             $match["Specific_epithet_matched"] = '';
             $match["Genus_score"] = self::getEDScore($match["genus_ed"], $match["Genus_matched"], $parsed["genus"]);
             $match["Specific_epithet_score"] = '';
             $match["Name_matched"] = $match["Genus_matched"];
             if (isset($match["family_ed"]) && (!isset($higher_taxa_ed["family"]) || $higher_taxa_ed["family"] > $match["family_ed"])) {
                 $higher_taxa_ed["family"] = $match["family_ed"];
             }
             $match["match_score"] += $match["Genus_score"];
             $matched[] = $match;
         }
     }
     if (count($all_matched["family"]) && (!isset($higher_taxa_ed["family"]) || isset($best_ed["family"]) && $higher_taxa_ed["family"] > $best_ed["family"])) {
         foreach ($all_matched["family"] as &$match) {
             if (isset($higher_taxa_ed["family"]) && $higher_taxa_ed["family"] <= $match["family_ed"]) {
                 continue;
             }
             $match["Family_matched"] = $match["family"];
             $match["Specific_epithet_matched"] = '';
             $match["Genus_matched"] = '';
             $match["Family_score"] = self::getEDScore($match["family_ed"], $match["Family_matched"], $parsed["family"]);
             $match["Genus_score"] = '';
             $match["Specific_epithet_score"] = '';
             $match["Name_matched"] = $match["Family_matched"];
             $match["match_score"] += $match["Family_score"];
             $matched[] = $match;
         }
     }
     if (!count($matched)) {
         $matched[] = array("Lowest_matched_rank" => "", "Name_score" => "", "Family_matched" => "", "Author_score" => "", "Name_matched_accepted_family" => "", "Warnings" => 0);
     }
     $status = $status_string;
     if ($status) {
         if (preg_match("/vel\\.? sp\\.? aff\\.?/i", $status)) {
             $status = "vel. sp. aff.";
         } elseif (preg_match("/\\-?aff?\\.?/i", $status)) {
             $status = "aff.";
         } elseif (preg_match("/\\-?cf\\.?/i", $status) || $status == '?') {
             $status = "cf.";
         }
     }
     $unmatched = array();
     foreach ($matched as &$match) {
         $match["Name_submitted"] = $scientificname;
         $match["Family_submitted"] = $parsed["family"];
         $match["Genus_submitted"] = $parsed["genus"];
         $match["Specific_epithet_submitted"] = $parsed["species"];
         $match["Author_submitted"] = $parsed["authority"];
         $match["Annotations"] = $status;
         $rk = $match["Lowest_matched_rank"];
         $parsed_part = 0;
         $matched_part = 0;
         if ($rk) {
             $matched_part = self::$rank[$rk];
             if ($match["Family_matched"]) {
                 $matched_part++;
             }
         }
         if ($lowest_parsed_rank) {
             $parsed_part = self::$rank[$lowest_parsed_rank];
         }
         if ($parsed["family"]) {
             $parsed_part++;
         }
         $unmatched = '';
         $unmatched_part = 0;
         $extra_part = 0;
         if (!$rk || self::$rank[$rk] < self::$rank['genus'] || $gni_parser_result && $gni_parser_result->scientificName->parsed) {
             $unmatched = $preprocessed_txt;
         } elseif ($preprocessed_txt != $cleaned_txt) {
             $unmatched = str_ireplace_first($cleaned_txt, '', $preprocessed_txt);
         }
         if ($match["Family_matched"]) {
             $unmatched = str_ireplace_first($parsed['family'], '', $unmatched);
         }
         if ($rk && $gni_parser_result && $gni_parser_result->scientificName->parsed) {
             foreach (array_keys(self::$rank) as $rki) {
                 if (self::$rank[$rki] >= self::$rank['genus'] && self::$rank[$rki] <= self::$rank[$rk]) {
                     $unmatched = str_ireplace_first($parsed[$rki], '', $unmatched);
                 }
             }
             foreach ($parsed["authorities"] as $auth) {
                 if ($auth) {
                     $unmatched = str_ireplace_first($auth, '', $unmatched);
                 }
             }
             if (($rk == 'infra1' || $rk == 'infra2') && $parsed["rank1"]) {
                 $unmatched = str_ireplace_first($parsed["rank1"], '', $unmatched);
                 $matched_part++;
                 if ($parsed["rank1"] == 'f.') {
                     $unmatched = str_ireplace_first(self::$forma, '', $unmatched);
                 }
             }
             if ($rk == 'infra2' && $parsed["rank2"]) {
                 $unmatched = str_ireplace_first($parsed["rank2"], '', $unmatched);
                 $matched_part++;
                 if ($parsed["rank2"] == 'f.') {
                     $unmatched = str_ireplace_first(self::$forma, '', $unmatched);
                 }
             }
             if ($all_name[$match["Name_matched_id"]]->isHybrid) {
                 $unmatched = str_ireplace_first(' x', ' ', $unmatched);
                 $unmatched = str_ireplace_first(' ×', ' ', $unmatched);
             }
         }
         //print_r($matched);
         if (strlen($unmatched)) {
             $unmatched = trim(preg_replace("/ {2,}/", ' ', $unmatched));
         }
         if (strlen($unmatched)) {
             $unmatched_part = count(explode(" ", $unmatched));
             $extra_part = $unmatched_part + $matched_part - $parsed_part;
             if ($parsed["rank1"]) {
                 $extra_part--;
             }
             if ($parsed["rank2"]) {
                 $extra_part--;
             }
             if ($extra_part > 1) {
                 $unmatched_part -= $extra_part - 1;
             }
         }
         if (isset($start_string)) {
             $unmatched = $start_string . $unmatched;
         }
         $match["Unmatched_terms"] = trim($unmatched);
         if ($rk) {
             $matched_id[] = $match["Name_matched_id"];
             $match["Canonical_author"] = $match["temp_authority"];
             if (array_key_exists($match[$rk . "_id"], $phonetic_id)) {
                 $match["Phonetic"] = 'Y';
             } else {
                 $match["Phonetic"] = "";
             }
             if (!isset($match["Warnings"])) {
                 $match["Warnings"] = 0;
             }
             if (isset($gni_parser_result) && $lowest_parsed_rank != $match["Lowest_matched_rank"]) {
                 $match["Warnings"] |= self::$flag_def['Partial'];
             }
             if (!$lowest_matched_rank || self::$rank[$match["Lowest_matched_rank"]] > self::$rank[$lowest_matched_rank]) {
                 $lowest_matched_rank = $match["Lowest_matched_rank"];
             }
             if ($parsed["authority"] && !($match["Warnings"] & self::$flag_def['Partial'])) {
                 $match["Author_matched"] = $match["temp_authority"];
                 $match["Author_score"] = $match["auth_similarity"];
             } else {
                 $match["Author_matched"] = '';
                 $match["Author_score"] = '';
             }
             #$match["Name_score"]=$match["match_score"]/$parsed_part;
             $match["Name_score"] = self::num_to_score($match["match_score"], $parsed_part, 2, 1);
             #$match["Overall_score"]=self::getOverallScore($match["match_score"], $match["Author_score"], $matched_part+$unmatched_part);
             $match["Overall_score"] = self::getOverallScore($match["Name_score"], $match["Author_score"], $extra_part);
         }
     }
     $source_order = 0;
     foreach ($this->db->source as $so) {
         $source_order++;
         $matched_by_source[$so] = array();
         $sid = $this->db->source_id[$so];
         foreach ($matched as &$match) {
             if (isset($match["Name_matched_id"])) {
                 $nid = $match["Name_matched_id"];
                 if (array_key_exists($sid, $name_source_data[$nid])) {
                     $match["Source"] = $so;
                     $match["Source_order"] = $source_order;
                     $match["Name_matched_rank"] = $all_name[$nid]->nameRank;
                     $match["Name_matched_accepted_family"] = isset($classification_family[$nid]) ? $classification_family[$nid] : '';
                     $match["Name_matched_url"] = $name_source_data[$nid][$sid]['url'];
                     $match["Name_matched_lsid"] = $name_source_data[$nid][$sid]['lsid'];
                     $match["Taxonomic_status"] = isset($synonym[$nid][$sid]["acceptance"]) ? $synonym[$nid][$sid]["acceptance"] : 'No opinion';
                     $match["Accepted_name"] = '';
                     if (isset($synonym[$nid][$sid]["accepted_name_id"])) {
                         $match["Accepted_name_id"] = $synonym[$nid][$sid]["accepted_name_id"];
                         $accepted_name = $all_name[$match["Accepted_name_id"]];
                         $match["Accepted_name"] = $accepted_name->scientific_name;
                         $match["Accepted_name_author"] = $accepted_name->author;
                         $match["Accepted_name_url"] = $name_source_data[$match["Accepted_name_id"]][$sid]['url'];
                         $match["Accepted_name_lsid"] = $name_source_data[$match["Accepted_name_id"]][$sid]['lsid'];
                         $match["Accepted_name_rank"] = $accepted_name->nameRank;
                         $match["Accepted_family"] = isset($classification_family[$match["Accepted_name_id"]]) ? $classification_family[$match["Accepted_name_id"]] : "";
                     }
                     $match["Accepted_species"] = "";
                     if ($match["Accepted_name"] && self::$rank[$match["Lowest_matched_rank"]] >= self::$rank["species"]) {
                         if ($all_name[$match["Accepted_name_id"]]->isHybrid) {
                             $match["Accepted_species"] = $all_name[$match["Accepted_name_id"]]->scientific_name;
                         } else {
                             $match["Accepted_species"] = $all_name[$match["Accepted_name_id"]]->genus . ' ' . $all_name[$match["Accepted_name_id"]]->specificEpithet;
                         }
                     }
                     $matched_by_source[$so][] = $match;
                 }
             } else {
                 $matched_by_source[""] = $match;
             }
         }
     }
     $matched = array();
     if (isset($matched_by_source[""])) {
         $matched[] = $matched_by_source[""];
     } else {
         foreach ($this->db->source as $so) {
             foreach ($matched_by_source[$so] as &$match) {
                 $matched[] = $match;
             }
         }
     }
     self::$sort_scheme = 'overall';
     usort($matched, array($this, "cmpMatched"));
     $order = 1;
     foreach ($matched as &$match) {
         $match["Overall_score_order"] = $order++;
     }
     self::$sort_scheme = 'highertaxa';
     usort($matched, array($this, "cmpMatched"));
     $order = 1;
     foreach ($matched as &$match) {
         $match["Highertaxa_score_order"] = $order++;
     }
     foreach ($matched as &$match) {
         if (isset($match['Name_matched_id']) && isset(self::$ambiguous[$match['Name_matched_id']])) {
             $match['Warnings'] |= self::$flag_def['Ambiguous'];
         }
         if ($match["Highertaxa_score_order"] > $match["Overall_score_order"]) {
             $match['Warnings'] |= self::$flag_def['HigherTaxa'];
         } elseif ($match["Highertaxa_score_order"] < $match["Overall_score_order"]) {
             $match['Warnings'] |= self::$flag_def['Overall'];
         }
     }
     foreach ($matched as &$match) {
         $result = array();
         foreach (self::$field as $fd) {
             if (array_key_exists($fd, $match) && !is_null($match[$fd])) {
                 $result[$fd] = $match[$fd];
             } else {
                 $result[$fd] = '';
             }
         }
         $this->data[] = $result;
     }
 }
$outfile = isset($options["o"]) ? $options["o"] : "";
$cache = false;
$source = explode(",", $source);
$db = select_source($source, $classification);
$header = TnrsAggregator::$field;
if (isset($count)) {
    array_unshift($header, "ID");
}
$outfh = fopen($outfile, 'w') or die("can't open outputfile");
fputcsv($outfh, $header);
$handle = fopen($file, "r");
while (($field = fgetcsv($handle, 1000, ",")) !== FALSE) {
    if (!isset($field[0]) || $field[0] == '') {
        continue;
    }
    $ta = new TnrsAggregator($db);
    $tm = new Taxamatch($db);
    $tm->set('debug_flag', '');
    $tm->set('output_type', '');
    $tm->set('cache_flag', false);
    $tm->set('cache_path', CACHE_PATH);
    $tm->set('name_parser', NAME_PARSER);
    $tm->set('chop_overload', CHOP_OVERLOAD);
    $tm->set('parse_only', $parse_only);
    $name = escapeshellarg($field[0]);
    if ($tm->process($name, $search_mode, $cache) && !$parse_only) {
        $tm->generateResponse($cache);
    }
    $ta->aggregate($tm);
    $result = $ta->getData();
    foreach ($result as $re) {
Example #3
0
     $data = array();
     $names = preg_split("/[\r\n;]+/u", $str);
     if (is_array($names)) {
         foreach ($names as $name) {
             $tm = new Taxamatch($db);
             $tm->set('debug_flag', $debug);
             $tm->set('output_type', strtolower($output));
             $tm->set('cache_flag', $authorities[$source]['cache_flag']);
             $tm->set('cache_path', CACHE_PATH);
             $tm->set('name_parser', NAME_PARSER);
             $tm->set('chop_overload', CHOP_OVERLOAD);
             $tm->set('parse_only', $parse_only);
             if ($tm->process($name, $search_mode, $cache)) {
                 $tm->generateResponse($cache);
             }
             $ta = new TnrsAggregator($db);
             $ta->aggregate($tm);
             $data[] = $ta->getData();
         }
     }
     //$debug = $tm->debug;
     //if($output == 'xml') {
     //	$data = $tm->getXML();
     //}
     break;
 case 'sources':
     $db = select_source($source, $classification);
     $data = $db->getSources();
     break;
     //case 'sources':
     //	$sources = getSources();