| 1 | // ========================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : LabelTranslator.h // |
|---|
| 4 | // Purpose : Translate tree labels // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in Sep 21 // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ========================================================= // |
|---|
| 10 | |
|---|
| 11 | #ifndef LABELTRANSLATOR_H |
|---|
| 12 | #define LABELTRANSLATOR_H |
|---|
| 13 | |
|---|
| 14 | #ifndef ARBDB_BASE_H |
|---|
| 15 | #include <arbdb_base.h> |
|---|
| 16 | #endif |
|---|
| 17 | #ifndef ARB_UNORDERED_MAP_H |
|---|
| 18 | #include <arb_unordered_map.h> |
|---|
| 19 | #endif |
|---|
| 20 | #ifndef _GLIBCXX_STRING |
|---|
| 21 | #include <string> |
|---|
| 22 | #endif |
|---|
| 23 | #ifndef ERRORORTYPE_H |
|---|
| 24 | #include <ErrorOrType.h> |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 27 | typedef arb_unordered_map<std::string, std::string> StringMap; |
|---|
| 28 | typedef ErrorOr<std::string> ErrorOrLabel; |
|---|
| 29 | |
|---|
| 30 | class TranslationReport; |
|---|
| 31 | |
|---|
| 32 | class LabelTranslator { |
|---|
| 33 | virtual ErrorOrLabel translate(const char *label) const = 0; // @@@ require two translate() methods: 1. for label->identifier, 2. for species->identifier |
|---|
| 34 | |
|---|
| 35 | public: |
|---|
| 36 | virtual ~LabelTranslator() {} |
|---|
| 37 | |
|---|
| 38 | virtual GB_ERROR generate_species_identifiers(GBDATA *gb_main) const = 0; |
|---|
| 39 | GB_ERROR translate_unlinked_labels_in_tree(TreeNode *tree, TranslationReport& report) const; |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | class LabelForwarder : public LabelTranslator { |
|---|
| 43 | // does not translate anything, just forwards Labels as found. |
|---|
| 44 | |
|---|
| 45 | ErrorOrLabel translate(const char *label) const OVERRIDE { |
|---|
| 46 | return ErrorOrLabel(NULp, label); // performs no translation |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public: |
|---|
| 50 | GB_ERROR generate_species_identifiers(GBDATA *) const OVERRIDE { |
|---|
| 51 | return NULp; |
|---|
| 52 | } |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | class ACI_LabelTranslator : public LabelTranslator { |
|---|
| 56 | std::string species_aci; // ACI that translates each species in DB into unique identifier |
|---|
| 57 | mutable StringMap identifier2shortname; // identifier is result of 'species_aci' (key=identifier, value=comma-separated list of shortname generated from) |
|---|
| 58 | |
|---|
| 59 | ErrorOrLabel translate(const char *label) const OVERRIDE; |
|---|
| 60 | |
|---|
| 61 | public: |
|---|
| 62 | ACI_LabelTranslator(const char *species_aci_) : |
|---|
| 63 | species_aci(species_aci_) |
|---|
| 64 | {} |
|---|
| 65 | GB_ERROR generate_species_identifiers(GBDATA *gb_main) const OVERRIDE; |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | GB_ERROR TREE_translate_labels(GBDATA *gb_main, TreeNode *tree, const LabelTranslator& translator); |
|---|
| 69 | |
|---|
| 70 | #else |
|---|
| 71 | #error LabelTranslator.h included twice |
|---|
| 72 | #endif // LABELTRANSLATOR_H |
|---|
| 73 | |
|---|
| 74 | |
|---|