def insert_relation_information(germanet_db, gn_rels_file):
lex_rels, con_rels = read_relation_file(gn_rels_file)<EOL>lexunits = {}<EOL>for lex_rel in lex_rels:<EOL><INDENT>if lex_rel['<STR_LIT>'] not in lexunits:<EOL><INDENT>lexunits[lex_rel['<STR_LIT>']] = germanet_db.lexunits.find_one(<EOL>{'<STR_LIT:id>': lex_rel['<STR_LIT>']})<EOL><DEDENT>from_lexunit = lexunits[lex_rel['<STR_LIT>']]<EOL>if lex_rel['<STR_LIT:to>'] not in lexunits:<EOL><INDENT>lexunits[lex_rel['<STR_LIT:to>']] = germanet_db.lexunits.find_one(<EOL>{'<STR_LIT:id>': lex_rel['<STR_LIT:to>']})<EOL><DEDENT>to_lexunit = lexunits[lex_rel['<STR_LIT:to>']]<EOL>if '<STR_LIT>' not in from_lexunit:<EOL><INDENT>from_lexunit['<STR_LIT>'] = set()<EOL><DEDENT>from_lexunit['<STR_LIT>'].add((lex_rel['<STR_LIT:name>'], to_lexunit['<STR_LIT>']))<EOL>if lex_rel['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' not in to_lexunit:<EOL><INDENT>to_lexunit['<STR_LIT>'] = set()<EOL><DEDENT>to_lexunit['<STR_LIT>'].add((lex_rel['<STR_LIT>'], from_lexunit['<STR_LIT>']))<EOL><DEDENT><DEDENT>for lexunit in lexunits.values():<EOL><INDENT>if '<STR_LIT>' in lexunit:<EOL><INDENT>lexunit['<STR_LIT>'] = sorted(lexunit['<STR_LIT>'])<EOL>germanet_db.lexunits.save(lexunit)<EOL><DEDENT><DEDENT>synsets = {}<EOL>for con_rel in con_rels:<EOL><INDENT>if con_rel['<STR_LIT>'] not in synsets:<EOL><INDENT>synsets[con_rel['<STR_LIT>']] = germanet_db.synsets.find_one(<EOL>{'<STR_LIT:id>': con_rel['<STR_LIT>']})<EOL><DEDENT>from_synset = synsets[con_rel['<STR_LIT>']]<EOL>if con_rel['<STR_LIT:to>'] not in synsets:<EOL><INDENT>synsets[con_rel['<STR_LIT:to>']] = germanet_db.synsets.find_one(<EOL>{'<STR_LIT:id>': con_rel['<STR_LIT:to>']})<EOL><DEDENT>to_synset = synsets[con_rel['<STR_LIT:to>']]<EOL>if '<STR_LIT>' not in from_synset:<EOL><INDENT>from_synset['<STR_LIT>'] = set()<EOL><DEDENT>from_synset['<STR_LIT>'].add((con_rel['<STR_LIT:name>'], to_synset['<STR_LIT>']))<EOL>if con_rel['<STR_LIT>'] in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if '<STR_LIT>' not in to_synset:<EOL><INDENT>to_synset['<STR_LIT>'] = set()<EOL><DEDENT>to_synset['<STR_LIT>'].add((con_rel['<STR_LIT>'], from_synset['<STR_LIT>']))<EOL><DEDENT><DEDENT>for synset in synsets.values():<EOL><INDENT>if '<STR_LIT>' in synset:<EOL><INDENT>synset['<STR_LIT>'] = sorted(synset['<STR_LIT>'])<EOL>germanet_db.synsets.save(synset)<EOL><DEDENT><DEDENT>print('<STR_LIT>'.format(<EOL>len(lex_rels), len(con_rels)))<EOL>
Reads in the given GermaNet relation file and inserts its contents
into the given MongoDB database.

Arguments:
- `germanet_db`: a pymongo.database.Database object
- `gn_rels_file`: