Source code for germanetpy.wiktionaryLoader
from germanetpy.wiktionaryparaphrase import WiktionaryParaphrase
from germanetpy.utils import convert_to_boolean
LEXID = 'lexUnitId'
ID = 'wiktionaryId'
SENSEID = 'wiktionarySenseId'
SENSE = 'wiktionarySense'
EDITED = 'edited'
[docs]
def create_wiktionary(attributes) -> WiktionaryParaphrase:
"""
Creates a wiktionary object given the XML attributes that contain the required information
:param attributes: XML attributes that contain information about the wiktionary paraphrase
:return: a wiktionary object
"""
lex_id = attributes[LEXID]
wiktionary_id = attributes[ID]
wiktionary_sense_id = int(attributes[SENSEID])
wiktionary_sense = attributes[SENSE]
edited = convert_to_boolean(attributes[EDITED])
wiki = WiktionaryParaphrase(lexunit_id=lex_id, wiktionary_id=wiktionary_id, wiktionary_sense_id=wiktionary_sense_id,
wiktionary_sense=wiktionary_sense, edited=edited)
return wiki
[docs]
def load_wiktionary(germanet, tree):
"""
Given a XML tree this method initialized the wiktionary objects and adds them to the germanet object and the
corresponding lexunits
:type tree: etree
:type germanet: Germanet
:param germanet: The germane object
:param tree: The XML tree of the wiktionary file
"""
root = tree.getroot()
for child in root:
attributes = child.attrib
wiktionary = create_wiktionary(attributes)
lexunit = germanet.get_lexunit_by_id(wiktionary.lexunit_id)
lexunit.wiktionary_paraphrases.append(wiktionary)
germanet.wiktionary_entries.append(wiktionary)