Add another
[apertium.git] / apertium-tagger-training-tools / src / Translations.H
blobefa8adc283cb7f0bef0cd1578ba2cea5e513ac11
1 /*
2  * Copyright (C) 2004-2006 Felipe Sánchez-Martínez
3  * Copyright (C) 2006 Universitat d'Alacant
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 /**
21  * Class Translations (header file)
22  *
23  *  @author   Felipe Sánchez-Martínez - fsanchez@dlsi.ua.es
24  */
26 #ifndef __TRANSLATIONS_H
27 #define __TRANSLATIONS_H
29 #include <map>
30 #include <iostream>
31 #include <string>
32 #include <cmath>
33 #include <vector>
35 #include "StringCollection.H"
36 #include "Segment.H"
37 #include "TransferRules.H"
39 #define TRANSLATION_UNIQUE_PATH "___UNIQUE___"
40 #define TRANSLATION_NOT_USED "___NOTUSED___"
42 using namespace std;
44 class Translations  {
45 private:
46   map<int, int> path_translation; //For a given path g_i it stores the
47                                   //index of its translation tau(g_i,s) in the
48                                   //StringCollection translations
50   map<int, double>  path_weigh; //For a given path g_i, it stores the
51                                 //weigh p(g_i | tau(g_i,s)), i.e. the
52                                 //contribution of g_i to the
53                                 //translation tau(g_i,s)
55   map<int, double> path_prob; //For a given path g_i it stores the final
56                               //probability of g_i, i.e.
57                               //p(g_i|s,M_tag)
59   map<int, double> translation_likelihood; 
61   StringCollection translations;
63   Segment* segment;
65   string get_translation_at(int pos);
66   string get_path_translation(int path);
67   int get_index_path_translation(int path);  
68   void set_path_weigh(int path, double weigh);
69   double get_path_weigh(int path);
70   void set_translation_likelihood(int index_trans, double likelihood);
71   double get_translation_likelihood(int index_trans);
72   vector<int> get_paths_same_translation(int index_trans);
74   bool all_translations_ok;
75   regex_t regex_wrongly_translated_word;
76 public:
77   Translations(Segment* seg);
79   ~Translations();
81   int get_number_translations();
83   void set_path_translation(string trans, int path);
85   void evaluate_translations_likelihood(string likelihood_script);
86   void set_previoulsy_evaluated_translations_likelihood(map<string, double>& translations_likelihoods);
88   void calculate_probability_each_path();
90   double get_path_probability(int path);
92   bool are_translations_ok();
95 #endif