@@ -36,6 +36,9 @@ public class StatAlign<T extends NtoNTranslation> implements Aligner {
36
36
private WordParser wordParser ;
37
37
private CognateModel cognateModel = new CognateModel (4 , 0.10 );
38
38
39
+ private int candidateLimit = 6 ;
40
+ private int pruneMatches = 3 ;
41
+
39
42
ExecutorService exec = Executors .newFixedThreadPool (
40
43
Runtime .getRuntime ().availableProcessors (),
41
44
new ThreadFactory () {
@@ -93,10 +96,10 @@ public Tuple<Sentences, Sentences> getSentences(int startIndex, int length) {
93
96
* @param maxTranslationDistance Maximum token distance before discarding suggested translations due to wrapping infeasability.
94
97
*/
95
98
public Tuple <Sentences , Sentences > getSentences (int startIndex , int length , double maxTranslationDistance ) {
96
- List <PossibleTranslations > pts = associate (startIndex , 6 );
99
+ List <PossibleTranslations > pts = associate (startIndex , getCandidateLimit () );
97
100
98
101
for (int i = 1 ; i < length ; ++i ) {
99
- pts .addAll (associate (startIndex + i , 6 ));
102
+ pts .addAll (associate (startIndex + i , getCandidateLimit () ));
100
103
try {
101
104
Thread .sleep (250 ); // concurrency bug (during evaluation) workaround
102
105
} catch (InterruptedException e ) {
@@ -121,10 +124,6 @@ public Tuple<Sentences, Sentences> getSentences(int startIndex, int length, doub
121
124
return Sentences .wire (de .toString (), en .toString (), pts , maxTranslationDistance , getWordParser ());
122
125
}
123
126
124
- public List <PossibleTranslations > associate (NtoNTranslation translation ) {
125
- return associate (translation , 6 , 3 , true );
126
- }
127
-
128
127
/**
129
128
* Computes a word alignment for a given translation. Each word of the source sentence is associated with a number
130
129
* of candidates that are possible translations in the target sentence. The alignment is based both on the basic
@@ -180,16 +179,24 @@ public List<PossibleTranslations> associate(NtoNTranslation translation, int lim
180
179
return matches ;
181
180
}
182
181
182
+ public List <PossibleTranslations > associate (NtoNTranslation translation ) {
183
+ return associate (translation , getCandidateLimit (), getPruneMatches (), true );
184
+ }
185
+
186
+ public List <PossibleTranslations > associate (NtoNTranslation translation , int limit ) {
187
+ return associate (translation , limit , getPruneMatches (), true );
188
+ }
189
+
183
190
public List <PossibleTranslations > associate (int index ) {
184
- return associate (index , 6 );
191
+ return associate (index , getCandidateLimit () );
185
192
}
186
193
187
194
public List <PossibleTranslations > associateRetainingAll (int index ) {
188
- return associate (index , 6 , 3 , false );
195
+ return associate (index , getCandidateLimit (), getPruneMatches () , false );
189
196
}
190
197
191
198
public List <PossibleTranslations > associate (int index , int limit ) {
192
- return associate (index , limit , 3 , true );
199
+ return associate (index , limit , getPruneMatches () , true );
193
200
}
194
201
195
202
public List <PossibleTranslations > associate (int index , int limit , int prune , boolean retainMostLikely ) {
@@ -210,8 +217,8 @@ public List<PossibleTranslations> associate(int index, int limit, int prune, boo
210
217
*/
211
218
public List <PossibleTranslations > matches (NtoNTranslation translation , int limit ) {
212
219
List <PossibleTranslations > result = new LinkedList <PossibleTranslations >();
213
- List <PossibleTranslations > forth = possibleTranslations (translation , limit != -1 ? limit : 3 );
214
- List <PossibleTranslations > back = reversePossibleTranslations (translation , limit != -1 ? limit : 3 );
220
+ List <PossibleTranslations > forth = possibleTranslations (translation , limit != -1 ? limit : getCandidateLimit () );
221
+ List <PossibleTranslations > back = reversePossibleTranslations (translation , limit != -1 ? limit : getCandidateLimit () );
215
222
216
223
for (PossibleTranslations ptForth : forth ) {
217
224
List <Candidate > candidates = new LinkedList <Candidate >();
@@ -238,7 +245,7 @@ public List<PossibleTranslations> matches(NtoNTranslation translation, int limit
238
245
}
239
246
240
247
public List <PossibleTranslations > matches (int index ) {
241
- return matches (index , 3 );
248
+ return matches (index , getCandidateLimit () );
242
249
}
243
250
244
251
public List <PossibleTranslations > matches (int index , int limit ) {
@@ -699,6 +706,22 @@ public int getTargetWordCount() {
699
706
return targetWordCount ;
700
707
}
701
708
709
+ public void setCandidateLimit (int limit ) {
710
+ this .candidateLimit = limit ;
711
+ }
712
+
713
+ public int getCandidateLimit () {
714
+ return candidateLimit ;
715
+ }
716
+
717
+ public void setPruneMatches (int pruneTo ) {
718
+ this .pruneMatches = pruneTo ;
719
+ }
720
+
721
+ public int getPruneMatches () {
722
+ return pruneMatches ;
723
+ }
724
+
702
725
public void setWordParser (WordParser wordParser ) {
703
726
this .wordParser = wordParser ;
704
727
}
0 commit comments