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

berkeleyparsed2mosesxml_PTB.perl « wrappers « training « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8ba146c969dc089da934a8d84f0563eb5126e6d (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
#!/usr/bin/env perl
#
# This file is part of moses.  Its use is licensed under the GNU Lesser General
# Public License version 2.1 or, at your option, any later version.

use warnings;
use strict;

while(<STDIN>) {
  if (/^\(\(\)\)/) {
    print "\n"; # parse failures
    next;
  }

  # prep
  s/^\( /\(TOP /;

  # escape words
  s/\&/\&amp;/g;   # escape escape
  s/\|/\&bar;/g;   # factor separator
  s/\|/\&#124;/g;  # factor separator
  s/\</\&lt;/g;    # xml
  s/\>/\&gt;/g;    # xml
  s/\'\'/\&quot;/g;
  s/``/\&quot;/g;
  s/\'/\&apos;/g;  # xml
  s/\"/\&quot;/g;  # xml
  s/\[/\&#91;/g;   # syntax non-terminal
  s/\]/\&#93;/g;   # syntax non-terminal


  # escape parentheses that were part of the input text
  s/(\(\S+ )\(\)/$1\&openingparenthesis;\)/g;
  s/(\(\S+ )\)\)/$1\&closingparenthesis;\)/g;



  # convert into tree
  s/\((\S+) /<tree label=\"$1\"> /g;
  s/\)/ <\/tree> /g;
  s/\"\-LRB\-\"/\"LRB\"/g; # labels
  s/\"\-RRB\-\"/\"RRB\"/g;
  s/\-LRB\-/\(/g; # tokens
  s/\-RRB\-/\)/g;
  s/ +/ /g;
  s/ $//g;

  # de-escape parentheses that were part of the input text
  s/\&openingparenthesis;/\(/g;
  s/\&closingparenthesis;/\)/g;

  s/tree label=\"\&quot;\"/tree label=\"QUOT\"/g;
  #s/tree label=\"''\"/tree label=\"QUOT\"/g;
  #s/tree label=\"``\"/tree label=\"QUOT\"/g;

  # output, replace words with original
  print $_;
}