Home>

I'm new to Python.
I would like to guide you without knowing where i am going.

Developing web applications using the web framework bottle in Python3.
What I want to do is as follows.

I want to embed brat in a WEB application and retrieve and display the data stored in SQLite.

Error message
Traceback (most recent call last):
  File "/Users/Username/nlp/py3env/lib/python3.7/site-packages/bottle.py", line 862, in _handle
    return route.call (** args)
  File "/Users/Username/nlp/py3env/lib/python3.7/site-packages/bottle.py", line 1742, in wrapper
    rv = callback (* a, ** ka)
  File "src/sample_06_08.py", line 23, in get
    row = datastore.get (doc_id, fl = ['content'])
  File "/Users/Username/nlp/src/sqlitedatastore.py", line 40, in get
    for key, value in zip (fl, row_ls):
TypeError: zip argument # 2 must support iteration
Applicable source code
# sqlitedatastore.py
def get (doc_id, fl):
    row_ls = conn.execute (
        'SELECT {} FROM docs WHERE id =?'. Format (','. Join (fl)),
        (doc_id,)). fetchone ()
    row_dict = {}
    for key, value in zip (fl, row_ls):
        row_dict [key] = value
    return row_dict
# sample_06_08.py
@ bottle.get ('/ get')
def get ():
    doc_id = bottle.request.params.id
    names = bottle.request.params.names.split ()
    row = datastore.get (doc_id, fl = ['content'])
    text = row ['content']
    text = re.sub (r '[.!]', '\ n', text)
    data = {
        'collection': {
            'entity_types': [],
        },
        'annotation': {
            'text': text,
            'entities': [],
            'relations': [],
        },
    }
    mapping = {}
    for name in names:
        annos = datastore.get_annotation (doc_id, name)
        for i, anno in enumerate (annos):
            data ['collection'] ['entity_types']. append ({
                'type': name,
                'bgColor': '# 7fa2ff',
                'borderColor': 'darken'
            })
            Ti = 'T {0: d}'. Format (len (data ['annotation'] ['entities']) + 1)
            data ['annotation'] ['entities']. append ([
                Ti,
                name,
                [[anno ['begin'], anno ['end']]]
            ])
            mapping [(name, i)] = Ti
    for name in names:
        annos = datastore.get_annotation (doc_id, name)
        for i, anno in enumerate (annos):
            if 'link' not in anno:
                continue
            name_linked, i_linked = anno ['link']
            if (name, i) not in mapping or (name_linked, i_linked) not in mapping:
                continue
            data ['annotation'] ['relations']. append ([
                'R {0: d}'. Format (len (data ['annotation'] ['relations']) + 1),
                'arg',
                [['src', mapping [(name, i)]], ['tgt', mapping [(name_linked, i_linked)]]]
            ])
    return json.dumps (data, ensure_ascii = False)

Execute [sample_06_08.py] from the terminal.
Access the specified localhost.

Result: No data is displayed and an error is returned.

Supplemental information (FW/tool version etc.)

[Environment]
・ MacOS Catalina (10.15.1)
・ Python 3.7.4
・ Bottle 0.12.17