def read_lexical_file(filename):
with open(filename, '<STR_LIT:rb>') as input_file:<EOL><INDENT>doc = etree.parse(input_file)<EOL><DEDENT>synsets = []<EOL>assert doc.getroot().tag == '<STR_LIT>'<EOL>for synset in doc.getroot():<EOL><INDENT>if synset.tag != '<STR_LIT>':<EOL><INDENT>print('<STR_LIT>', synset)<EOL>continue<EOL><DEDENT>synset_dict = dict(synset.items())<EOL>synloc = '<STR_LIT>'.format(filename,<EOL>synset_dict.get('<STR_LIT:id>', '<STR_LIT>'))<EOL>warn_attribs(synloc, synset, SYNSET_ATTRIBS)<EOL>synset_dict['<STR_LIT>'] = []<EOL>synsets.append(synset_dict)<EOL>for child in synset:<EOL><INDENT>if child.tag == '<STR_LIT>':<EOL><INDENT>lexunit      = child<EOL>lexunit_dict = dict(lexunit.items())<EOL>lexloc       = synloc + '<STR_LIT>'.format(<EOL>lexunit_dict.get('<STR_LIT:id>', '<STR_LIT>'))<EOL>warn_attribs(lexloc, lexunit, LEXUNIT_ATTRIBS)<EOL>for key in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if key in lexunit_dict:<EOL><INDENT>if lexunit_dict[key] not in MAP_YESNO_TO_BOOL:<EOL><INDENT>print(lexloc, ('<STR_LIT>'<EOL>'<STR_LIT>').format(key),<EOL>lexunit_dict[key])<EOL>continue<EOL><DEDENT>lexunit_dict[key] = MAP_YESNO_TO_BOOL[lexunit_dict[key]]<EOL><DEDENT><DEDENT>if '<STR_LIT>' in lexunit_dict:<EOL><INDENT>if lexunit_dict['<STR_LIT>'].isdigit():<EOL><INDENT>lexunit_dict['<STR_LIT>'] = int(lexunit_dict['<STR_LIT>'], <NUM_LIT:10>)<EOL><DEDENT>else:<EOL><INDENT>print(lexloc,<EOL>'<STR_LIT>',<EOL>lexunit_dict['<STR_LIT>'])<EOL><DEDENT><DEDENT>synset_dict['<STR_LIT>'].append(lexunit_dict)<EOL>lexunit_dict['<STR_LIT>'] = []<EOL>lexunit_dict['<STR_LIT>']   = []<EOL>for child in lexunit:<EOL><INDENT>if child.tag in ['<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>warn_attribs(lexloc, child, set())<EOL>if not child.text:<EOL><INDENT>print(lexloc, '<STR_LIT>'.format(child.tag))<EOL>continue<EOL><DEDENT>if child.tag in lexunit_dict:<EOL><INDENT>print(lexloc, '<STR_LIT>'.format(child.tag))<EOL><DEDENT>lexunit_dict[child.tag] = str(child.text)<EOL><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>example = child<EOL>text = [child for child in example<EOL>if child.tag == '<STR_LIT:text>']<EOL>if len(text) != <NUM_LIT:1> or not text[<NUM_LIT:0>].text:<EOL><INDENT>print(lexloc, '<STR_LIT>')<EOL><DEDENT>example_dict = {'<STR_LIT:text>': str(text[<NUM_LIT:0>].text)}<EOL>for child in example:<EOL><INDENT>if child.tag == '<STR_LIT:text>':<EOL><INDENT>continue<EOL><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' in example_dict:<EOL><INDENT>print(lexloc,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>warn_attribs(lexloc, child, set())<EOL>if not child.text:<EOL><INDENT>print(lexloc, '<STR_LIT>')<EOL>continue<EOL><DEDENT>example_dict['<STR_LIT>'] = str(child.text)<EOL><DEDENT>else:<EOL><INDENT>print(lexloc,<EOL>'<STR_LIT>',<EOL>child)<EOL><DEDENT><DEDENT>lexunit_dict['<STR_LIT>'].append(example_dict)<EOL><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>frame = child<EOL>warn_attribs(lexloc, frame, set())<EOL>if <NUM_LIT:0> < len(frame):<EOL><INDENT>print(lexloc, '<STR_LIT>',<EOL>list(frame))<EOL><DEDENT>if not frame.text:<EOL><INDENT>print(lexloc, '<STR_LIT>')<EOL>continue<EOL><DEDENT>lexunit_dict['<STR_LIT>'].append(str(frame.text))<EOL><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>compound = child<EOL>warn_attribs(lexloc, compound, set())<EOL>compound_dict = {}<EOL>for child in compound:<EOL><INDENT>if child.tag == '<STR_LIT>':<EOL><INDENT>modifier_dict = dict(child.items())<EOL>warn_attribs(lexloc, child,<EOL>MODIFIER_ATTRIBS, set())<EOL>if not child.text:<EOL><INDENT>print(lexloc, '<STR_LIT>')<EOL>continue<EOL><DEDENT>modifier_dict['<STR_LIT:text>'] = str(child.text)<EOL>if '<STR_LIT>' not in compound_dict:<EOL><INDENT>compound_dict['<STR_LIT>'] = []<EOL><DEDENT>compound_dict['<STR_LIT>'].append(modifier_dict)<EOL><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>head_dict = dict(child.items())<EOL>warn_attribs(lexloc, child, HEAD_ATTRIBS, set())<EOL>if not child.text:<EOL><INDENT>print(lexloc, '<STR_LIT>')<EOL>continue<EOL><DEDENT>head_dict['<STR_LIT:text>'] = str(child.text)<EOL>if '<STR_LIT>' in compound_dict:<EOL><INDENT>print(lexloc,<EOL>'<STR_LIT>')<EOL><DEDENT>compound_dict['<STR_LIT>'] = head_dict<EOL><DEDENT>else:<EOL><INDENT>print(lexloc,<EOL>'<STR_LIT>',<EOL>child)<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>print(lexloc, '<STR_LIT>', child)<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>elif child.tag == '<STR_LIT>':<EOL><INDENT>paraphrase = child<EOL>warn_attribs(synloc, paraphrase, set())<EOL>paraphrase_text = str(paraphrase.text)<EOL>if not paraphrase_text:<EOL><INDENT>print(synloc, '<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print(synloc, '<STR_LIT>', child)<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>return synsets<EOL>
Reads in a GermaNet lexical information file and returns its
contents as a list of dictionary structures.

Arguments:
- `filename`: the name of the XML file to read