Skip to content

Commit

Permalink
SentenceFilterLength: fix min sentence length and max/min index (#401)
Browse files Browse the repository at this point in the history
* fix min sentence length and max/min index

* correct implementation of index calculation

* SentenceFiltererLength inherits from SentenceFilterer
  • Loading branch information
gmwe authored and msperber committed May 19, 2018
1 parent 3704b20 commit d41fd64
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions xnmt/preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def from_spec(spec):
raise RuntimeError("Unknown preprocessing type {}".format(my_spec["type"]))
return preproc_list

class SentenceFiltererLength(object):
class SentenceFiltererLength(SentenceFilterer):
"""Filters sentences by length"""

def __init__(self, spec):
Expand All @@ -299,10 +299,14 @@ def __init__(self, spec):
self.overall_min = v
else:
direc, idx = k.split('_')
idx = idx_map.get(idx_map, int(idx))
idx_tmp = idx_map.get(idx)
if idx_tmp is None:
idx_tmp = int(idx)
idx = idx_tmp

if direc == "max":
self.each_max[idx] = v
elif direc == "max":
elif direc == "min":
self.each_min[idx] = v
else:
raise RuntimeError("Unknown limitation type {} in length-based sentence filterer".format(k))
Expand Down

0 comments on commit d41fd64

Please sign in to comment.