forked from gilnoh/gigaword-lm-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgigaword_dexml.pl
54 lines (46 loc) · 895 Bytes
/
gigaword_dexml.pl
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
#!/usr/bin/perl
# This small script de-xml a GigaWord news-month XML document.
# Mainly for sentence split input, and for LM making.
use warnings;
use strict;
die "Usage: perl dexml.pl [giga word file]" unless ($ARGV[0] and -e $ARGV[0]);
my $infile = $ARGV[0];
if ($infile =~ /\.gz$/)
{
open (IN, "gunzip -c $infile |") || die "can't open pipe to $infile";
}
else
{
open (IN, $infile) || die "can't open $infile";
}
while(<IN>)
{
# "header" mode --- process before <TEXT>
while(<IN>)
{
if (/<DOC id=/)
{
print;
print "\n";
}
last if (/<TEXT>/);
if (/<HEADLINE>/)
{
my $next = <IN>; print $next;
}
}
print "\n"; # now text
# "text" mode --- process <TEXT> content
while(<IN>)
{
next if (/<P>/);
if (/<\/P>/)
{
print "\n";
next;
}
last if (/<\/TEXT>/);
print;
}
print "\n";
}