~ubuntu-branches/ubuntu/trusty/frog/trusty

« back to all changes in this revision

Viewing changes to src/mblem_mod.cxx

  • Committer: Package Import Robot
  • Author(s): Ko van der Sloot
  • Date: 2012-02-29 15:42:38 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120229154238-b8pqxykqiiz1l6m4
Tags: 0.12.14-1
* New Upstream Release
* debian/control: removed dependency om libssl-dev
* debian/watch: upload from new location: http://software.ticc.uvt.nl

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  $Id: mblem_mod.cxx 13948 2012-01-11 10:44:24Z sloot $
 
2
  $Id: mblem_mod.cxx 14306 2012-02-22 14:53:00Z sloot $
3
3
  $URL: https://ilk.uvt.nl/svn/sources/Frog/trunk/src/mblem_mod.cxx $
4
4
 
5
5
  Copyright (c) 2006 - 2012
42
42
using namespace folia;
43
43
 
44
44
Mblem::Mblem(): myLex(0),punctuation( "?...,:;\\'`(){}[]%#+-_=/!" ), 
45
 
                history(20), debug(0) {}
 
45
                history(20), debug(0) {
 
46
  mblemLog = new LogStream( theErrLog, "mblem" );
 
47
}
46
48
 
47
49
void Mblem::read_transtable( const string& tableName ) {
48
50
  ifstream bron( tableName.c_str() );
49
51
  if ( !bron ) {
50
 
    *Log(theErrLog) << "translation table file '" << tableName 
 
52
    *Log(mblemLog) << "translation table file '" << tableName 
51
53
                    << "' appears to be missing." << endl;
52
54
    exit(1);
53
55
  }
67
69
}
68
70
 
69
71
bool Mblem::init( const Configuration& config ) {
70
 
  *Log(theErrLog) << "Initiating lemmatizer...\n";
 
72
  *Log(mblemLog) << "Initiating lemmatizer..." << endl;
 
73
  debug = tpDebug;
71
74
  string db = config.lookUp( "debug", "mblem" );
72
75
  if ( !db.empty() )
73
76
    debug = stringTo<int>( db );
92
95
}
93
96
 
94
97
Mblem::~Mblem(){
95
 
  //    *Log(theErrLog) << "cleaning up MBLEM stuff" << endl;
 
98
  //    *Log(mblemLog) << "cleaning up MBLEM stuff" << endl;
96
99
  delete myLex;
97
100
  myLex = 0;
 
101
  delete mblemLog;
98
102
}
99
103
 
100
104
string Mblem::make_instance( const UnicodeString& in ) {
101
105
  if (debug)
102
 
    cout << "making instance from: " << in << endl;
 
106
    *Log(mblemLog) << "making instance from: " << in << endl;
103
107
  UnicodeString instance = "";
104
108
  size_t length = in.length();
105
109
  size_t j;
116
120
  instance += "?";
117
121
  string result = UnicodeToUTF8(instance);
118
122
  if (debug)
119
 
    cout << "inst: " << instance << endl;
 
123
    *Log(mblemLog) << "inst: " << instance << endl;
120
124
  
121
125
  return result;
122
126
}
156
160
 
157
161
void addAnnotation( FoliaElement *word,
158
162
                    const string& cls ){
159
 
  KWargs args = getArgs( "set='mbt-lemma', cls='" 
160
 
                                       + escape(cls) + "', annotator='mblem'" );
 
163
  KWargs args;
 
164
  args["set"]="http://ilk.uvt.nl/folia/sets/frog-mblem-nl";
 
165
  args["cls"]=cls;
161
166
#pragma omp critical(foliaupdate)
162
167
  {
163
168
    word->addLemmaAnnotation( args );
170
175
  {
171
176
    tag = word->pos();
172
177
  }
173
 
  if ( debug ){
174
 
    cout << "\n\tlemmas: ";
175
 
    for( vector<mblemData>::const_iterator it=mblemResult.begin(); 
176
 
         it != mblemResult.end(); ++it)
177
 
      cout << it->getLemma() << "/ "<< it->getTag()<< " ";
178
 
  }
179
178
  string res;
180
179
  size_t index = 0;
181
180
  size_t nrlookup = mblemResult.size();
189
188
  
190
189
  if ( index == nrlookup ) {
191
190
    if (debug)
192
 
      cout << "NO CORRESPONDING TAG! " << tag << endl;
 
191
      *Log(mblemLog) << "NO CORRESPONDING TAG! " << tag << endl;
193
192
    res = mblemResult[0].getLemma();
194
193
  }
195
194
  else {
196
195
    res = mblemResult[index].getLemma();
197
196
  }
198
197
  if (debug)
199
 
    cout << "final MBLEM lemma: " << res << endl;
 
198
    *Log(mblemLog) << "final MBLEM lemma: " << res << endl;
200
199
  addAnnotation( word, res );
201
200
  return res;
202
201
220
219
  string classString;
221
220
  myLex->Classify( inst, classString );
222
221
  if (debug)
223
 
    cout << "class: " << classString  << endl;
 
222
    *Log(mblemLog) << "class: " << classString  << endl;
224
223
  // 1st find all alternatives
225
224
  vector<string> parts;
226
225
  int numParts = split_at( classString, parts, "|" );
227
226
  if ( numParts < 1 ){
228
 
    cout << "no alternatives found" << endl;
 
227
    *Log(mblemLog) << "no alternatives found" << endl;
229
228
  }
230
229
  int index = 0;
231
230
  while ( index < numParts ) {
232
231
    UnicodeString part = UTF8ToUnicode( parts[index++] );
233
232
    if (debug)
234
 
      cout <<"part = " << part << endl;
 
233
      *Log(mblemLog) <<"part = " << part << endl;
235
234
    UnicodeString insstr;
236
235
    UnicodeString delstr;
237
236
    UnicodeString prefix;
259
258
          else 
260
259
            prefix = UnicodeString( part, lpos );
261
260
          if (debug)
262
 
            cout << "prefix=" << prefix << endl;
 
261
            *Log(mblemLog) << "prefix=" << prefix << endl;
263
262
        }
264
263
        break;
265
264
      }
272
271
          else 
273
272
            delstr = UnicodeString( part, lpos );
274
273
          if (debug)
275
 
            cout << "delstr=" << delstr << endl;
 
274
            *Log(mblemLog) << "delstr=" << delstr << endl;
276
275
        }
277
276
        break;
278
277
      }
285
284
          else 
286
285
            insstr = UnicodeString( part, lpos);
287
286
          if (debug)
288
 
            cout << "insstr=" << insstr << endl;
 
287
            *Log(mblemLog) << "insstr=" << insstr << endl;
289
288
        }
290
289
        break;
291
290
      }
296
295
    } // while lpos < pl
297
296
    
298
297
    if (debug){
299
 
      cout << "part: " << part << " split up in: " << endl;
300
 
      cout << "pre-prefix word: '" << uWord << "' prefix: '"
 
298
      *Log(mblemLog) << "part: " << part << " split up in: " << endl;
 
299
      *Log(mblemLog) << "pre-prefix word: '" << uWord << "' prefix: '"
301
300
           << prefix << "'" << endl;
302
301
    }   
303
302
    long prefixpos = 0;
304
303
    if ( !prefix.isEmpty() ) {
305
304
      prefixpos = uWord.indexOf(prefix);
306
305
      if (debug)
307
 
        cout << "prefixpos = " << prefixpos << endl;
 
306
        *Log(mblemLog) << "prefixpos = " << prefixpos << endl;
308
307
      // repair cases where there's actually not a prefix present
309
308
      if (prefixpos > uWord.length()-2) {
310
309
        prefixpos = 0;
313
312
    }
314
313
    
315
314
    if (debug)
316
 
      cout << "prefixpos = " << prefixpos << endl;
 
315
      *Log(mblemLog) << "prefixpos = " << prefixpos << endl;
317
316
    UnicodeString lemma = "";
318
317
    if (prefixpos >= 0) {
319
318
      lemma = UnicodeString( uWord, 0L, prefixpos );
320
319
      prefixpos = prefixpos + prefix.length();
321
320
    }
322
321
    if (debug)
323
 
      cout << "post prefix != 0 word: "<< uWord 
 
322
      *Log(mblemLog) << "post prefix != 0 word: "<< uWord 
324
323
           << " lemma: " << lemma
325
324
           << " prefix: " << prefix
326
325
           << " insstr: " << insstr
348
347
      lemma = uWord;
349
348
    }
350
349
    if ( debug )
351
 
      cout << "appending lemma " << lemma << " and tag " << restag << endl;
 
350
      *Log(mblemLog) << "appending lemma " << lemma << " and tag " << restag << endl;
352
351
    mblemResult.push_back( mblemData( UnicodeToUTF8(lemma), restag ) );
353
352
  } // while
354
353
  if ( debug ){
355
 
    cout << "stored lemma and tag options: " << mblemResult.size() << " lemma's and " << mblemResult.size() << " tags:\n";
 
354
    *Log(mblemLog) << "stored lemma and tag options: " << mblemResult.size() << " lemma's and " << mblemResult.size() << " tags:" << endl;
356
355
    for( size_t index=0; index < mblemResult.size(); ++index ){
357
 
      cout << "lemma alt: " << mblemResult[index].getLemma() << endl;
358
 
      cout << "tag alt: " << mblemResult[index].getTag() << endl;
 
356
      *Log(mblemLog) << "lemma alt: " << mblemResult[index].getLemma()
 
357
                     << "\ttag alt: " << mblemResult[index].getTag() << endl;
359
358
    }
360
 
    cout << "\n\n";
361
359
  }
362
360
  string res = postprocess( sword ); 
363
361
  return res;