From 0ab0c587d353fd2c631027a8ea3aeea59335fb0f Mon Sep 17 00:00:00 2001 From: dcz <dcz@ipipan.waw.pl> Date: Fri, 1 Jul 2022 11:58:59 +0200 Subject: [PATCH] Import bigger data bugfix. --- importer/Argument.py | 7 +++++-- importer/Example.py | 4 ++-- importer/Frame.py | 2 +- importer/Meanings.py | 6 ++++-- importer/WalentyPreprocessXML.py | 2 +- .../commands/add_predefined_preferences.py | 2 +- syntax/management/commands/import_tei.py | 4 ++-- unifier/views.py | 16 ++++++++++++++++ 8 files changed, 32 insertions(+), 11 deletions(-) diff --git a/importer/Argument.py b/importer/Argument.py index 7cf48ff..5b09f2a 100644 --- a/importer/Argument.py +++ b/importer/Argument.py @@ -73,8 +73,11 @@ class SelectionalPreference: def store(self, frame, argument): if self._type == 'predef': - pref = PredefinedSelectionalPreference.objects.get(name=self._value) - argument.predefined.add(pref) + pref = PredefinedSelectionalPreference.objects.filter(name=self._value) + if len(pref) > 0: + argument.predefined.add(pref[0]) + else: + print('PredefinedSelectionalPreference not found: {}', self._value) elif self._type == 'synset': pref = Synset.objects.get(id=self._value) argument.synsets.add(pref) diff --git a/importer/Example.py b/importer/Example.py index 4623bd1..73dd243 100644 --- a/importer/Example.py +++ b/importer/Example.py @@ -29,7 +29,7 @@ class Example: eid = int(example_tree._attrs['xml:id'].split('.')[1].split('-')[0]) if len(example_tree._children) == 6: # both meaning and note - meaning = example_tree._children[0]._children[0]._attrs['sameAs'][1:] + meaning = int(example_tree._children[0]._children[0]._attrs['sameAs'][1:].split("_")[1].split("-")[0]) sentence = clean_sentence(example_tree._children[2]._children[0]._content) illustrated_syntax = IllustratesSyntax.fromTree(example_tree._children[1], phrases, base, sentence, out_file) illustrated_semantics = IllustratesSemantics.interfere(sentence, base, meaning, illustrated_syntax, entry_semantics, meanings, eid, in_data, out_file, misconnected) @@ -38,7 +38,7 @@ class Example: note = example_tree._children[5]._children[0]._content elif len(example_tree._children) == 5 and example_tree._children[0]._attrs['name'] == 'meaning': # meaning and no note - meaning = example_tree._children[0]._children[0]._attrs['sameAs'][1:] + meaning = int(example_tree._children[0]._children[0]._attrs['sameAs'][1:].split("_")[1].split("-")[0]) sentence = clean_sentence(example_tree._children[2]._children[0]._content) illustrated_syntax = IllustratesSyntax.fromTree(example_tree._children[1], phrases, base, sentence, out_file) illustrated_semantics = IllustratesSemantics.interfere(sentence, base, meaning, illustrated_syntax, entry_semantics, meanings, eid, in_data, out_file, misconnected) diff --git a/importer/Frame.py b/importer/Frame.py index ee6f94b..bdf3ddf 100644 --- a/importer/Frame.py +++ b/importer/Frame.py @@ -31,7 +31,7 @@ class Frame: opinion = frame_tree._children[0]._children[0]._attrs['value'] if opinion == 'unk': opinion = 'cer' - meanings = [meaning._attrs['sameAs'][1:] for meaning in frame_tree._children[1]._children[0]._children] + meanings = [int(meaning._attrs['sameAs'][1:].split("_")[1].split("-")[0]) for meaning in frame_tree._children[1]._children[0]._children] for argument_tree in frame_tree._children[2]._children[0]._children: argument = Argument.fromTree(argument_tree) arguments[argument.getId()] = argument diff --git a/importer/Meanings.py b/importer/Meanings.py index 5cb7b87..77ecb74 100644 --- a/importer/Meanings.py +++ b/importer/Meanings.py @@ -17,7 +17,7 @@ class Meaning: @classmethod def fromTree(cls, meaning_tree): - id = meaning_tree._attrs['xml:id'] + id = int(meaning_tree._attrs['xml:id'].split("_")[1].split("-")[0]) name = meaning_tree._children[0]._children[0]._content variant = meaning_tree._children[1]._children[0]._content luid = int(meaning_tree._children[2]._children[0]._attrs['value']) @@ -37,7 +37,9 @@ class Meaning: def save(self, pos): synset = Synset(id=self._sid) synset.save() - unit = LexicalUnit(entry=None, + unit = LexicalUnit( + pk=self._id, + entry=None, base=self._name, sense=self._variant, pos=pos, diff --git a/importer/WalentyPreprocessXML.py b/importer/WalentyPreprocessXML.py index f3b0c61..fb0b8a2 100644 --- a/importer/WalentyPreprocessXML.py +++ b/importer/WalentyPreprocessXML.py @@ -93,7 +93,7 @@ class WalentyPreprocessTeiHandler(handler.ContentHandler): if changed: lu.save() else: - print(' new lu: {}-{}'.format(meaning._name, meaning._variant)) + print(' new lu: {}-{}-{}-{}'.format(meaning._id, meaning._name, meaning._variant, pos)) meaning.save(pos) print("Stored") diff --git a/syntax/management/commands/add_predefined_preferences.py b/syntax/management/commands/add_predefined_preferences.py index d9b06b4..f8fd1b8 100644 --- a/syntax/management/commands/add_predefined_preferences.py +++ b/syntax/management/commands/add_predefined_preferences.py @@ -223,7 +223,7 @@ def create_predefined_preferences(): czemu_members.generals.add(cecha) czemu_members.generals.add(sytuacja) czemu_members.generals.add(ludzie) - czemu, xx = PredefinedSelectionalPreference.objects.get_or_create(name='CZEM', + czemu, xx = PredefinedSelectionalPreference.objects.get_or_create(name='CZEMU', members=czemu_members) # ILOŚĆ: ilość-1, rozmiar-1, rozmiar-2, jednostka-4, wielkość-6 diff --git a/syntax/management/commands/import_tei.py b/syntax/management/commands/import_tei.py index 2962e08..98c3916 100644 --- a/syntax/management/commands/import_tei.py +++ b/syntax/management/commands/import_tei.py @@ -34,8 +34,8 @@ def import_tei(): logging.basicConfig(filename='import.log', level=logging.DEBUG) #xml_file = os.path.join(BASE_DIR, 'data', 'walenty', 'walenty_20200926_smaller.xml') - # xml_file = os.path.join(BASE_DIR, 'data', 'walenty', 'walenty_20210913_smaller.xml') - xml_file = os.path.join(BASE_DIR, 'data', 'walenty', 'walenty_20210913_smallest.xml') + xml_file = os.path.join(BASE_DIR, 'data', 'walenty', 'walenty_20210913_smaller.xml') + # xml_file = os.path.join(BASE_DIR, 'data', 'walenty', 'walenty_20210913_smallest.xml') xml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), xml_file) diff --git a/unifier/views.py b/unifier/views.py index 0b3fbd1..abe7ec8 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -388,3 +388,19 @@ def change_unified_frame_status_to_ready(request): unifiedFrame.save() return JsonResponse({}) + +@ajax_required +@transaction.atomic +def create_simple_unified_frame(request): + if request.method == 'POST': + lu_id = request.POST['lu_id'] + # unifiedFrame = UnifiedFrame.objects.get(pk=unified_frame_id) + # unifiedFrame.status = choices.UnifiedFrameStatus.READY + # + # for mapping in unifiedFrame.unified_frame_2_slowal_frame.all(): + # mapping.verified = True + # mapping.save() + # + # unifiedFrame.save() + return JsonResponse({}) + -- GitLab