Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -c option to split-sentences.perl #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions moses/ems/support/split-sentences.perl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
my $NOP = 0;
my $KEEP_LINES = 0;
my $MODE = "singledocument";
my $LIMIT = 0;

while (@ARGV) {
$_ = shift;
Expand All @@ -40,17 +41,19 @@
/^-k$/ && ($KEEP_LINES = 1, next);
/^-b$/ && ($|++, next); # no output buffering
/^-d$/ && ($MODE = "base64documents", next);
/^-c$/ && ($LIMIT = shift, next);
}

if ($HELP) {
print "Usage ./split-sentences.perl (-l [en|de|...]) [-p prefix-file] [-q] [-b] < textfile > splitfile\n";
print "Usage ./split-sentences.perl (-l [en|de|...]) [-p prefix-file] [-q] [-b] [-c limit]< textfile > splitfile\n";
print "-q: quiet mode\n";
print "-b: no output buffering (for use in bidirectional pipes)\n";
print "-p: use a custom prefix file, overriding the installed one\n";
print "-i: avoid splitting on list items (e.g. 1. This is the first)\n";
print "-n: do not emit <P> after paragraphs\n";
print "-k: keep existing line boundaries\n";
print "-d: work on multiple base64 encoded documents\n";
print "-c: skip lines longer than char count entirely\n";
exit;
}
if (!$QUIET) {
Expand Down Expand Up @@ -115,7 +118,10 @@ sub split_single_document {
# Loop over text, add lines together until we get a blank line or a <p>
while (<$fh>) {
chomp;
if ($KEEP_LINES) {
if ($LIMIT > 0 && length() > $LIMIT) {
# Skip extremely long lines entirely.
next;
} elsif ($KEEP_LINES) {
$out .= &split_block($_,"");
} elsif (/^<.+>$/ || /^\s*$/) {
# Time to process this block; we've hit a blank or <p>
Expand Down Expand Up @@ -268,7 +274,9 @@ sub preprocess {

# We stopped one token from the end to allow for easy look-ahead.
# Append it now.
$text = $text.$words[$i];
if (scalar(@words) > 0) {
$text = $text.$words[$i];
}
Comment on lines -271 to +279
Copy link
Contributor Author

@jelmervdl jelmervdl Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It apparently also contains a fix for warnings caused by blank (or only whitespace) lines in the input.


# Clean up spaces at head and tail of each line as well as any double-spacing
$text =~ s/ +/ /g;
Expand Down