Welcome to mirror list, hosted at ThFree Co, Russian Federation.

getSentence.h « src « bidirectional « experimental - github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 424c49e35c25609b10451028492b223853b77795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*

EGYPT Toolkit for Statistical Machine Translation
Written by Yaser Al-Onaizan, Jan Curin, Michael Jahr, Kevin Knight, John Lafferty, Dan Melamed, David Purdy, Franz Och, Noah Smith, and David Yarowsky.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
USA.

*/
/* --------------------------------------------------------------------------*
 *                                                                           *
 * Module : getSentence                                                      *
 *                                                                           *
 * Prototypes File: getSentence.h                                            *
 *                                                                           *
 * Objective: Defines clases and methods for handling I/O for the parallel   *
 *            corpus.                                                        *
 *****************************************************************************/





#ifndef _sentenceHandler_h
#define _sentenceHandler_h 1


#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "Vector.h"
#include "defs.h"
#include "vocab.h"
#include "Globals.h"
/*----------------------- Class Prototype Definition ------------------------*
 Class Name: sentenceHandleer 
 Objective: This class is defined to handle training sentece pairs from the 
 parallel corpus. Each pair has: a target sentece, called here French; a 
 source sentece, called here English sentece; and an integer number denoting
 the number of times this pair occured in trining corpus. Both source and 
 target senteces are represented as integer vector (variable size arrays), 
 each entry is a numeric value which is the token id for the particular token
 in the sentece.

 *---------------------------------------------------------------------------*/

class sentPair{
 public:
  int sentenceNo ;
  float noOcc;
  float realCount;
  Vector<WordIndex> eSent ;
  Vector<WordIndex> fSent;

 public:
  sentPair(){};
  void clear(){ eSent.clear(); fSent.clear(); noOcc=0; realCount=0; sentenceNo=0;};
  const Vector<WordIndex>&get_eSent()const
    { return eSent; }
  const Vector<WordIndex>&get_fSent()const
    { return fSent; }
  int getSentenceNo()const
    { return sentenceNo; }
  double getCount()const
    { return realCount; }
    
};

inline ostream&operator<<(ostream&of,const sentPair&s)
{
  of << "Sent No: " << s.sentenceNo << " , No. Occurrences: " << s.noOcc << '\n';
  if( s.noOcc!=s.realCount )
    of << " Used No. Occurrences: " << s.realCount << '\n';
  unsigned int i;
  for(i=0; i < s.eSent.size(); i++)
    of << s.eSent[i] << ' ';
  of <<  '\n';
  for(i=1; i < s.fSent.size(); i++)
    of << s.fSent[i] << ' ';
  of << '\n';
  return of;
}

/*Thread-safe version of sentence handler*/
class sentenceHandler{
public:
    const char * inputFilename;   // parallel corpus file name, similar for all 
                            // sentence pair objects
    ifstream *inputFile;     // parallel corpus file handler
    Vector<sentPair> Buffer;
    int noSentInBuffer ;
    int currentSentence ;
    int position; /*Sentence position (will be returned)*/
    int totalPairs1 ;
    double totalPairs2;
    bool readflag ; // true if you reach the end of file
    bool allInMemory ;
    int pair_no ;
    Vector<double> *realCount;
  
    Vector<sentPair> oldPairs;
    Vector<double> oldProbs;
	sentenceHandler(){};
    sentenceHandler(const char* filename, vcbList* elist=0, vcbList* flist=0);
    sentenceHandler(const char* filename, vcbList* elist, vcbList* flist,set<WordIndex>& eapp, set<WordIndex>& fapp);
    void rewind();
    int getNextSentence(sentPair&, vcbList* = 0, vcbList* = 0);  // will be defined in the definition file, this
    int getTotalNoPairs1()const {return totalPairs1;};
    double getTotalNoPairs2()const {return totalPairs2;};
    // method will read the next pair of sentence from memory buffer
    void setProbOfSentence(const sentPair&s,double d);
private:    
    pthread_mutex_t readsent_mutex; 
    pthread_mutex_t setprob_mutex;
    bool readNextSentence(sentPair&);  // will be defined in the definition file, this
};

#endif