Moving transfer tools
[apertium.git] / apertium-multiple-translations / apertium-multiple-translations / TransferMult.H
blob141b4944a789c50f4fa59a4e76933f07e5270aa8
1 /*
2  * Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _TRANSFER_MULT_
20 #define _TRANSFER_MULT_
22 #include <apertium/TransferInstr.H>
23 #include <apertium/TransferToken.H>
24 #include <apertium/TransferWord.H>
25 #include <lttoolbox/Alphabet.H>
26 #include <lttoolbox/Buffer.H>
27 #include <lttoolbox/FSTProcessor.H>
28 #include <lttoolbox/MatchExe.H>
29 #include <lttoolbox/MatchState.H>
31 #include <cstdio>
32 #include <map>
33 #include <set>
34 #include <vector>
36 using namespace std;
38 class TransferMult
40 private:
41   
42   Alphabet alphabet;
43   MatchExe *me;
44   MatchState ms;
45   map<string, string> attr_items;
46   map<string, string> variables;
47   map<string, int> macros;
48   map<string, set<string> > lists;
49   map<string, set<string> > listslow;
50   TransferWord **word;
51   string **blank;
52   Buffer<TransferToken> input_buffer;
53   vector<string *> tmpword;
54   vector<string *> tmpblank;
55   
57   FSTProcessor fstp;
58   FILE *output;
59   int any_char;
60   int any_tag;
61   bool isRule;
62   unsigned int numwords;
63   
64   unsigned int nwords;
65   
66   enum OutputType{lu,chunk};
67   
68   OutputType defaultAttrs;
69   
70   void copy(TransferMult const &o);
71   void destroy();
72   void readData(FILE *input);
73   void readBil(string const &filename);
74   string caseOf(string const &str);
75   string copycase(string const &source_word, string const &target_word);
77   bool beginsWith(string const &str1, string const &str2) const;
78   bool endsWith(string const &str1, string const &str2) const;
79   string tolower(string const &str) const;
80   string tags(string const &str) const;
81   string readWord(FILE *in);
82   string readBlank(FILE *in);
83   string readUntil(FILE *in, int const symbol) const;
84   void applyWord(string const &word_str);
85   void applyRule();
86   TransferToken & readToken(FILE *in);
87   void writeMultiple(list<vector<string> >::iterator itwords,
88                      list<string>::iterator itblanks, 
89                      list<vector<string> >::const_iterator limitwords, 
90                      string acum = "", bool multiple = false);
91   vector<string> acceptions(string const &str);
92   bool isDefaultWord(string const &str);
93 public:
94   TransferMult();
95   ~TransferMult();
96   TransferMult(TransferMult const &o);
97   TransferMult & operator =(TransferMult const &o);
98   
99   void read(string const &datafile, string const &fstfile);
100   void transfer(FILE *in, FILE *out);
103 #endif