示例#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 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)]))
示例#5
0
import sys,time,datetime
from subprocess import call
import svg_stack as ss
from props.applications.run import parseSentences
from visualizations.brat_visualizer import BratVisualizer

try:
    PORT=int(sys.argv[1])
except:
    PORT=8081

@get('/gparse')
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

load_berkeley()
run(host='',port=PORT)
示例#6
0
from bottle import run, get, request
from props.applications.run import load_berkeley
from props.applications.run import parseSentences
from visualizations.brat_visualizer import BratVisualizer

try:
    PORT=int(sys.argv[1])
except:
    PORT=8081

@get('/gparse')
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

load_berkeley()
run(host='',port=PORT)
    logging.debug(args)

    # Parse arguments
    props_path = args["--props"]
    port = args['--port']
    if port:
        port = int(port)
    else:
        port = TT_PORT
        logging.debug("Using default port: {}".format(TT_PORT))

    # Load server
    # Initialize PropS
    sys.path.insert(0, props_path)
    # After adding the props path we can import its packages and load parsers
    from props.applications.run import load_berkeley
    from props.applications.run import parseSentences
    load_berkeley(
        path_to_berkeley=os.path.join(props_path, 'props/berkeleyparser/'))

    print("sanity check: {}".format(
        Factuality_server._get_props_predicate_indices(
            "John refused to play")))

    server = Factuality_server(props_path)
    logging.debug("Factuality server loaded")
    cherrypy.config.update({"server.socket_port": port})
    cherrypy.config.update({"server.socket_host": "0.0.0.0"})
    cherrypy.quickstart(server)
    logging.debug('running Factuality server on port {}'.format(port))
示例#8
0
 def setUp(self):
     ''' takes care of the needed initializations '''
     logging.info("running tests")
     load_berkeley(tokenize = True)
示例#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))