Delphin.web client usage example

For this example from here Walkthrough of PyDelphin Features — PyDelphin 1.9.1 documentation

from delphin.web import client
response = client.parse('Abrams chased Browne', params={'mrs': 'json'})
response.result(0).mrs()
<MRS object (proper_q named chase_v_1 proper_q named) at 139897112151488>

Anything else is needed for it to work? I am currently getting empty results lists whatever I try to parse. Perhaps something is missing, like a parameter with some necessary paths/info?

UiO’s LOGON ERG demo is the default server for delphin.web.client. Unfortunately, the LOGON demo appears to be down (see the error message at the bottom of http://erg.delph-in.net/logon).

The UW server that runs Demo (delphin-viz) is up and working, but whenever I try to call it from PyDelphin, it hangs. I’m not sure why.

An alternative is to start up a server yourself, which may be fine for a demo. If you just want to parse, all you need is a wsgi.py file like this:

import falcon

from delphin.web import server

application = falcon.API()

server.configure(
    application,
    parser='~/delphin/erg-2018.dat',  # adjust path accordingly
)

You’ll need an environment with PyDelphin with the web extra and a server like Gunicorn installed:

$ pip install "pydelphin[web]" gunicorn

Then you can run the server:

$ gunicorn wsgi  # leave off the .py

Then in Python you can do this (change the port number if gunicorn reports something different from 8000):

>>> from delphin.web import client
>>> client.parse("Abrams chased Browne.", server="http://localhost:8000/", params={"mrs": "json"})
Response({'input': 'Abrams chased Browne.', 'readings': 1, 'results': [{'result-id': 0, 'mrs': {'top': 'h0', 'index': 'e2', 'relations': [{'label': 'h4', 'predicate': 'proper_q', 'arguments': {'ARG0': 'x3', 'RSTR': 'h5', 'BODY': 'h6'}, 'lnk': {'from': 0, 'to': 6}}, {'label': 'h7', 'predicate': 'named', 'arguments': {'CARG': 'Abrams', 'ARG0': 'x3'}, 'lnk': {'from': 0, 'to': 6}}, {'label': 'h1', 'predicate': '_chase_v_1', 'arguments': {'ARG0': 'e2', 'ARG1': 'x3', 'ARG2': 'x9'}, 'lnk': {'from': 7, 'to': 13}}, {'label': 'h10', 'predicate': 'proper_q', 'arguments': {'ARG0': 'x9', 'RSTR': 'h11', 'BODY': 'h12'}, 'lnk': {'from': 14, 'to': 21}}, {'label': 'h13', 'predicate': 'named', 'arguments': {'CARG': 'Browne', 'ARG0': 'x9'}, 'lnk': {'from': 14, 'to': 21}}], 'constraints': [{'relation': 'qeq', 'high': 'h0', 'low': 'h1'}, {'relation': 'qeq', 'high': 'h5', 'low': 'h7'}, {'relation': 'qeq', 'high': 'h11', 'low': 'h13'}], 'variables': {'e2': {'type': 'e', 'properties': {'SF': 'prop', 'TENSE': 'past', 'MOOD': 'indicative', 'PROG': '-', 'PERF': '-'}}, 'x3': {'type': 'x', 'properties': {'PERS': '3', 'NUM': 'sg', 'IND': '+'}}, 'h5': {'type': 'h'}, 'h6': {'type': 'h'}, 'x9': {'type': 'x', 'properties': {'PERS': '3', 'NUM': 'sg', 'IND': '+'}}, 'h11': {'type': 'h'}, 'h12': {'type': 'h'}, 'h0': {'type': 'h'}, 'h1': {'type': 'h'}, 'h7': {'type': 'h'}, 'h13': {'type': 'h'}, 'h4': {'type': 'h'}, 'h10': {'type': 'h'}}}}], 'tcpu': 15, 'pedges': 79})
1 Like