Moving non-unicode apertium to branches
[apertium.git] / branches / apertium / non-unicode / apertium / TaggerUtils.C
blob544439f603eaa696ffcd9d5bd271df70429ae6a7
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 #include <apertium/TaggerUtils.H>
21 #include <stdio.h>
23 void fatal_error (string s) {
24   cerr<<"Error: "<<s<<"\n";
25   exit(1);
28 void file_name_error (string s) { 
29   fatal_error(s+" in not a valid file");
32 char *itoa(int i) {                 
33   static char buf[512];
34   sprintf(buf,"%d",i);
35   return buf;
38 void clear_array_double(double a[], int l) {
39   for(int i=0; i<l; i++)
40     a[i]=0.0;
43 void clear_array_vector(vector<TTag> v[], int l) {
44   for(int i=0; i<l; i++)
45     v[i].clear();
48 int ntokens_multiword(string s) {
49    char *news = strdup((char*) s.c_str());
50    char *delim ="_";
51    int n=0;
52    
53    if (strtok(news,delim))
54      n++;  
55    while (strtok(NULL, delim))
56      n++;
57      
58    return n;   
61 int nguiones_fs(string s) {
62    char *news = strdup((char*) s.c_str());
63    char *delim ="-";
64    int n=0;
66    if (strtok(news,delim))
67      n++;  
68    while (strtok(NULL, delim))
69      n++;
70    return n;   
71
73 string trim(string s) {
74   if (s.length()==0)
75     return s;
77   for (unsigned int i=0; i<(s.length()-1); i++) {
78     if ((s.at(i)==' ')&&(s.at(i+1)==' ')) {
79       s.erase(i,1);
80       i--;
81     }
82   }
84   if ((s.length()>0)&&(s.at(s.length()-1)==' '))
85     s.erase(s.length()-1,1);
86   if ((s.length()>0)&&(s.at(0)==' '))
87     s.erase(0,1);
89   return s;