def run_ace(sentence):
    ace_bin = "/home/wlane/Programs/ace-0.9.22/ace"
    erg_file = "/home/wlane/Programs/ace-0.9.22/erg-1214-x86-64-0.9.22.dat"
    # ace_bin = "/Applications/ace/ace-0.9.22/ace"
    # erg_file = "/Applications/ace/ace-0.9.22/erg-1214-osx-0.9.22.dat"
    results = ace.parse(erg_file, sentence, cmdargs=['-n', '1'], executable=ace_bin)['RESULTS']
    if results:
        res1 = ace.parse(erg_file, sentence, cmdargs=['-n', '1'], executable=ace_bin)['RESULTS'][0]['MRS']
    else:
        res1 = None

    return res1
Esempio n. 2
0
def test_start(ace_mismatch, tmpdir, monkeypatch):
    popen = mock_popen(pid=10,
                       returncode=255,
                       stdout=io.StringIO(),
                       stderr=io.StringIO(ace_mismatch))
    grm = tmpdir.join('grm.dat')
    grm.write('')
    with monkeypatch.context() as m:
        m.setattr(ace, 'Popen', popen)
        m.setattr(ace, '_ace_version', lambda x: (0, 9, 29))
        with pytest.raises(ace.AceProcessError):
            ace.AceParser(str(grm))
        with pytest.raises(ace.AceProcessError):
            ace.parse(str(grm), 'Dogs sleep.')
Esempio n. 3
0
def node_api(request):
    try:
        # Get User from sessionid
        session = Session.objects.get(
            session_key=request.POST.get('sessionid'))
        user_id = session.get_decoded().get('_auth_user_id')
        user = User.objects.get(id=user_id)

        # Parse text
        text = request.POST.get('comment')
        parse = ace.parse("/home/dantiston/delphin/erg.dat", text)
        results = parse['RESULTS']
        html = []
        for result in results:
            tree = result['DERIV']
            mrs = result['MRS']
            html.append((tree, mrs))
        #     Comments.objects.create(user=user, text=text, tree=tree, mrs=mrs)
        #Comments.objects.create(user=user, text=str(parse))

        resultFormat = "<ul><li>%s</li><li>%s</li></ul>"
        result = "<ul>%s</ul>" % "".join(resultFormat % pair for pair in html)

        # Once comment has been created post it to the chat channel
        r = redis.StrictRedis(host='localhost', port=6379, db=0)
        #r.publish('chat', request.POST.get('comment'))
        r.publish('chat', result)

        return HttpResponse("Everything worked :)")
    except Exception as e:
        return HttpResponseServerError(str(e))
Esempio n. 4
0
def parse(sentence, cls=ListDmrs, erg_file=DEFAULT_ERG_FILE):
    results = []
    for result in ace.parse(erg_file, sentence)['RESULTS']:  # cmdargs=['-r', 'root_informal']
        mrs = result['MRS']
        xmrs = simplemrs.loads_one(mrs)
        dmrs_xml = dmrx.dumps_one(xmrs)[11:-12]
        dmrs = cls.loads_xml(dmrs_xml)
        results.append(dmrs)
    return results
Esempio n. 5
0
def parse(sentence, cls=ListDmrs, erg_file=DEFAULT_ERG_FILE):
    results = []
    for result in ace.parse(
            erg_file, sentence).results():  # cmdargs=['-r', 'root_informal']
        xmrs = result.mrs()
        dmrs_xml = dmrx.dumps_one(xmrs)[11:-12]
        dmrs = cls.loads_xml(dmrs_xml)
        results.append(dmrs)
    return results
def run_ace(sentence):
    ace_bin = "/Applications/ace/ace-0.9.22/ace"
    erg_file = "/Applications/ace/ace-0.9.22/erg-1214-osx-0.9.22.dat"
    results = ace.parse(erg_file, sentence, cmdargs=['-n', '1'], executable=ace_bin)['RESULTS']
    if results:
        res1 = results[0]['MRS']
        with open("Data/demo_mrs.txt", 'w') as demo:
            demo.write(res1 + "\n")
    else:
        res1 = None

    return res1
Esempio n. 7
0
def one_response(inp, timeout=60):
    inp = inp.strip()
    response = ace.parse('ace/erg-1214-x86-64-0.9.28.dat',
                         inp,
                         executable='ace/ace-0.9.28/ace',
                         cmdargs=['--timeout', str(timeout)])

    with i.get_lock():
        i.value += 1
        print('Parsed %d sentence: %s' % (i.value, inp))

    return response.result(0)
Esempio n. 8
0
def parse(grmkey):
    grm = get_grammar(grmkey)
    query = request.query.decode()
    params = get_params(query, parse_params)
    inp = query['input']
    opts = dict(ace_options)
    opts['cmdargs'] = opts.get('cmdargs', []) + ['-n', str(params['results'])]
    ace_response = ace.parse(
        grm['path'],
        inp,
        **opts
    )
    return parse_response(inp, ace_response, params)
Esempio n. 9
0
def parse(grmkey):
    if request.method == 'GET':
        args = request.args
    else:
        args = request.get_json() or {}
    grm = _get_grammar(grmkey)
    params = _get_params(args, PARSE_PARAMS)
    inp = args.get('input', '')
    opts = dict(ACE_OPTIONS)
    opts['cmdargs'] = opts.get('cmdargs', []) + ['-n', str(params['results'])]
    ace_response = ace.parse(
        grm['path'],
        inp,
        **opts
    )
    return jsonify(_parse_repsonse(inp, ace_response, params))
Esempio n. 10
0
def parse(datum):
    ace_args = os.getenv('ACE_ARGS')

    if ace_args:
        ace_args = re.split('\s+', ace_args)
    else:
        ace_args = [
            '--timeout=60', '--max-words=150', '--rooted-derivations', '--udx',
            '--disable-generalization'
        ]

    res = ace.parse(os.getenv('ERG_DAT', '/root/erg-2018-x86-64-0.9.30.dat'),
                    datum['sent'],
                    cmdargs=ace_args + ['-1'])

    res["line_num"] = datum["line_num"]
    res["doc"] = datum["doc"]
    save(res)
    return True
def run_ace(sentence):
    global COUNT
    ace_bin = "/Applications/ace/ace-0.9.22/ace"
    erg_file = "/Applications/ace/ace-0.9.22/erg-1214-osx-0.9.22.dat"
    # ace_bin = "/home/wlane/Applications/ace-0.9.23/ace"
    # erg_file = "/home/wlane/Applications/ace-0.9.23/erg-1214-x86-64-0.9.23.dat"
    # ace_bin = "/home2/wlane/mrs-575/ace/ace"
    # erg_file = "/home2/wlane/mrs-575/ace/erg-1214-x86-64-0.9.22.dat"

    # ace_bin = "/Applications/ace/ace-0.9.22/ace"
    # erg_file = "/Applications/ace/ace-0.9.22/erg-1214-osx-0.9.22.dat"

    print("Running Ace " + str(COUNT))
    COUNT += 1
    results = ace.parse(erg_file, sentence, cmdargs=['-n', '1'], executable=ace_bin)['RESULTS']
    if results:
        res1 = results[0]['MRS']
    else:
        res1 = None

    return res1
Esempio n. 12
0
def parse_sentence2(sentence, grammar = '/home/mappelgren/Desktop/ace-0.9.30/erg-2018-x86-64-0.9.30.dat'):#'../ace-0.9.26/erg-1214-x86-64-0.9.26.dat'):
    p = ace.parse(grammar, sentence)
    top_result = p['results'][0]['mrs']
    dmrx = convert(top_result, 'simplemrs', 'dmrx')
    dmrxx = loads(dmrx, single=True)
    return dmrxx.to_dict()