Пример #1
0
def main(arguments):
    if not (arguments["--corenlp-json-input"]):
        #Initialize Berekeley parser when using raw input
        load_berkeley(not arguments["--tokenized"])

    outputType = 'html'
    sep = "<br>"
    if arguments['-t']:
        outputType = 'pdf'
        sep = "\n"

    graphical = (outputType == 'html')

    # Parse according to source input
    if arguments["--corenlp-json-input"]:
        # Parse accroding to input method
        sents = (json.loads("".join(arguments["FILE"])) \
                 if isinstance(arguments["FILE"], list) \
                 else json.load(arguments["FILE"]))["sentences"]

    elif arguments["--dontfilter"]:
        sents = [x for x in arguments["FILE"]]
    else:
        sents = [[x for x in s if x in string.printable]
                 for s in arguments["FILE"]]

    for sent in sents:
        gs = parseSentences(
            sent,
            HOME_DIR,
            stanford_json_sent=arguments["--corenlp-json-input"])
        g, tree = gs[0]
        dot = g.drawToFile("", "svg")

        # deptree to svg file
        d = DepTreeVisualizer.from_conll_str(tree)

        # print sentence (only if in graphical mode)
        if (arguments["--original"]):
            print((sent + sep))

        #print dependency tree
        if (arguments['--dep']):
            if graphical:
                print((d.as_svg(compact=True, flat=True) + sep))
            else:
                print(tree)

        #print PropS output
        if graphical:
            print((dot.create(format='svg') + sep))
        else:
            print(g)

        #print open ie like extractions
        if (arguments["--oie"]):
            print((sep.join(
                [str(prop) for prop in g.getPropositions(outputType)])))
Пример #2
0
def main(arguments):
    if not(arguments["--corenlp-json-input"]):
        #Initialize Berekeley parser when using raw input 
        load_berkeley(not arguments["--tokenized"])

    outputType = 'html'
    sep = "<br>"
    if arguments['-t']:
        outputType = 'pdf'
        sep = "\n"
        
    graphical = (outputType=='html')

    # Parse according to source input
    if arguments["--corenlp-json-input"]:
        # Parse accroding to input method
        sents = (json.loads("".join(arguments["FILE"])) \
                 if isinstance(arguments["FILE"], list) \
                 else json.load(arguments["FILE"]))["sentences"]

    elif arguments["--dontfilter"]:
        sents = [x for x in arguments["FILE"]]
    else:
        sents = [filter(lambda x: x in string.printable, s) for s in arguments["FILE"]] 

    
    for sent in sents:
        gs = parseSentences(sent,
                            HOME_DIR,
                            stanford_json_sent = arguments["--corenlp-json-input"])
        g,tree = gs[0]
        dot = g.drawToFile("","svg")   
        
        # deptree to svg file
        d = DepTreeVisualizer.from_conll_str(tree)
        
        # print sentence (only if in graphical mode)
        if (arguments["--original"]):
            print(sent+sep)
            
        #print dependency tree
        if (arguments['--dep']):
            if graphical:
                print(d.as_svg(compact=True,flat=True)+sep)
            else:
                print(tree)
        
        #print PropS output
        if graphical:        
            print(dot.create(format='svg')+sep)
        else:
            print(g)
        
        #print open ie like extractions
        if (arguments["--oie"]):
            print(sep.join([str(prop) for prop in g.getPropositions(outputType)]))
Пример #3
0
def main(arguments):

    load_berkeley(not arguments["--tokenized"])

    outputType = 'html'
    sep = "<br>"
    if arguments['-t']:
        outputType = 'pdf'
        sep = "\n"

    graphical = (outputType == 'html')

    if arguments["--dontfilter"]:
        sents = [x for x in arguments["FILE"]]
    else:
        sents = [
            filter(lambda x: x in string.printable, s)
            for s in arguments["FILE"]
        ]

    for sent in sents:

        gs = parseSentences(sent, HOME_DIR)
        g, tree = gs[0]
        dot = g.drawToFile("", "svg")

        # deptree to svg file
        d = DepTreeVisualizer.from_conll_str(tree)

        # print sentence (only if in graphical mode)
        if (arguments["--original"]):
            print(sent + sep)

        #print dependency tree
        if (arguments['--dep']):
            if graphical:
                print(d.as_svg(compact=True, flat=True) + sep)
            else:
                print(tree)

        #print PropS output
        if graphical:
            print(dot.create(format='svg') + sep)
        else:
            print(g)

        #print open ie like extractions
        if (arguments["--oie"]):
            print(
                sep.join([str(prop)
                          for prop in g.getPropositions(outputType)]))
Пример #4
0
def gparse():
    print "in gparse"
    sent = request.GET.get('text','').strip()
    b = BratVisualizer()
    print sent
    sents = sent.strip().replace(". ",".\n").replace("? ","?\n").replace("! ","!\n").split("\n")
    sent = sents[0]
    gs = parseSentences(sent)
    g,tree = gs[0]
    
    ret = b.to_html(g)
       
    ret = ret.replace('PROPOSITIONS_STUB', '<br>'.join([str(prop) for prop in g.getPropositions('html')]))
    print "returning...." 
    return ret
Пример #5
0
def gparse():
    print "in gparse"
    sent = request.GET.get('text','').strip()
    b = BratVisualizer()
    print sent
    sents = sent.strip().replace(". ",".\n").replace("? ","?\n").replace("! ","!\n").split("\n")
    sent = sents[0]
    gs = parseSentences(sent)
    g,tree = gs[0]
    
    ret = b.to_html(g)
       
    ret = ret.replace('PROPOSITIONS_STUB', '<br>'.join([str(prop) for prop in g.getPropositions('html')]))
    print "returning...." 
    return ret
Пример #6
0
def main(arguments):
    
    load_berkeley(not arguments["--tokenized"])
    
    outputType = 'html'
    sep = "<br>"
    if arguments['-t']:
        outputType = 'pdf'
        sep = "\n"
        
    graphical = (outputType=='html')
    
    if arguments["--dontfilter"]:
        sents = [x for x in arguments["FILE"]]
    else:    
        sents = [filter(lambda x: x in string.printable, s) for s in arguments["FILE"]] 
        
    for sent in sents:
        
        gs = parseSentences(sent,HOME_DIR)
        g,tree = gs[0]
        dot = g.drawToFile("","svg")   
        
        # deptree to svg file
        d = DepTreeVisualizer.from_conll_str(tree)
        
        # print sentence (only if in graphical mode)
        if (arguments["--original"]):
            print(sent+sep)
            
        #print dependency tree
        if (arguments['--dep']):
            if graphical:
                print(d.as_svg(compact=True,flat=True)+sep)
            else:
                print(tree)
        
        #print PropS output
        if graphical:        
            print(dot.create(format='svg')+sep)
        else:
            print(g)
        
        #print open ie like extractions
        if (arguments["--oie"]):
            print(sep.join([str(prop) for prop in g.getPropositions(outputType)]))
def single_sentence_props(sent):
    """
    Return a graph representation of a single sentence with PropS
    """
    g, tree = parseSentences(sent, props_path)[0]
    return g
Пример #8
0
 def getProps(self, sent):
     ''' returns the textual props representation of an input sentence '''
     g, tree = parseSentences(sent)[0]
     return str(g)
Пример #9
0
def main(arguments):

    load_berkeley(not arguments["--tokenized"])

    outputType = 'html'
    sep = "<br>"
    if True or arguments['-t']:
        outputType = 'pdf'
        sep = "\n"

    graphical = (outputType == 'html')

    if arguments["--dontfilter"]:
        sents = [x for x in arguments["FILE"]]
    else:
        sents = [
            filter(lambda x: x in string.printable, s)
            for s in arguments["FILE"]
        ]

    numSent = 0
    for sent in sents:
        # be kind to the downstream chain -- do not send blank lines!
        if sent.strip() == '':
            continue
        numSent = numSent + 1
        # print sentence (only if in graphical mode)
        if (arguments["--original"]):
            print(sent)

        gs = parseSentences(sent, HOME_DIR)
        g, tree = gs[0]
        dot = g.drawToFile("", "svg")

        # deptree to svg file
        d = DepTreeVisualizer.from_conll_str(tree)

        #print dependency tree
        if (arguments['--dep']):
            if graphical:
                print(d.as_svg(compact=True, flat=True) + sep)
            else:
                print(tree)
        if (arguments['-t']):
            print(dot.create(format='svg') + sep if graphical else g)

        if arguments['-l'] or arguments['-c']:
            lf = g.toLogicForm()  # to_de_bruijn(g.toLogicForm())
            if arguments['-l']:
                pprint(lf)
            if arguments['-c']:
                lf = lf_clean(lf)
                pprint(lf)

        #print open ie like extractions
        if (arguments["--oie"]):
            print(
                sep.join([str(prop)
                          for prop in g.getPropositions(outputType)]))
    #end for loop
    print('Processed {0} sentences.'.format(numSent))
Пример #10
0
def main(arguments):
    if not(arguments["--corenlp-json-input"]):
        #Initialize Berekeley parser when using raw input 
        load_berkeley(not arguments["--tokenized"])

    outputType = 'html'
    sep = "<br>"
    if arguments['-t']:
        outputType = 'pdf'
        sep = "\n"
        
    graphical = (outputType=='html')

    # Parse according to source input
    if arguments["--corenlp-json-input"]:
        # Parse accroding to input method
        sents = (json.loads("".join(arguments["FILE"])) \
                 if isinstance(arguments["FILE"], list) \
                 else json.load(arguments["FILE"]))["sentences"]

    elif arguments["--dontfilter"]:
        sents = [x for x in arguments["FILE"]]
    else:
        sents = [filter(lambda x: x in string.printable, s) for s in arguments["FILE"]] 


    numSent = 0
    for sent in sents:
        # be kind to the downstream chain -- do not send blank lines!
        if isinstance(sent, basestring) and sent.strip() == '':
            continue
        numSent=numSent+1
        # print sentence (only if in graphical mode)
        if (arguments["--original"]):
            print(sent)

        gs = parseSentences(sent,
                            HOME_DIR,
                            stanford_json_sent = arguments["--corenlp-json-input"])

        g,tree = gs[0]
        dot = g.drawToFile("","svg")   
        
        # deptree to svg file
        d = DepTreeVisualizer.from_conll_str(tree)
        
            
        #print dependency tree
        if (arguments['--dep']):
            if graphical:
                print(d.as_svg(compact=True,flat=True)+sep)
            else:
                print(tree)
        if (arguments['-t']):
            print(dot.create(format='svg')+sep if graphical else g)

        if arguments['-l'] or arguments['-c']:
            lf = g.toLogicForm() # to_de_bruijn(g.toLogicForm())
            if arguments['-l']:
                pprint(lf)
            if arguments['-c']:
                lf = lf_clean(lf)
                pprint(lf)
        
        #print open ie like extractions
        if (arguments["--oie"]):
            print(sep.join([str(prop) for prop in g.getPropositions(outputType)]))
    #end for loop
    print('Processed {0} sentences.'.format(numSent))