File size: 1,306 Bytes
c705f71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# iparser.py
#
# Author:	Yuanbin Wu
#           National University of Singapore (NUS)
# Date:		12 Mar 2013
# Version:      1.0
# 
# Contact:  wuyb@comp.nus.edu.sg
#
# This script is distributed to support the CoNLL-2013 Shared Task.
# It is free for research and educational purposes.

import os
import sys

class stanfordparser:

    def __init__(self):
        pass
		
    def parse_batch(self, sentenceDumpedFileName, parsingDumpedFileName):
        
        if os.path.exists('../stanford-parser-2012-03-09') == False:
            print >> sys.stderr, 'can not find Stanford parser directory'
            sys.exit(1)
        
        # tokenized
        cmd = r'java -server -mx4096m -cp "../stanford-parser-2012-03-09/*:" edu.stanford.nlp.parser.lexparser.LexicalizedParser  -retainTMPSubcategories -sentences newline -tokenized -escaper edu.stanford.nlp.process.PTBEscapingProcessor  -outputFormat "wordsAndTags, penn, typedDependencies" -outputFormatOptions "basicDependencies" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ' + sentenceDumpedFileName

        r = os.popen(cmd).read().strip().decode('utf-8')
        f = open(parsingDumpedFileName, 'w')
        f.write(r.encode('utf-8'))
        f.close()

        rlist = r.replace('\n\n\n', '\n\n\n\n').split('\n\n')
        return rlist