diff --git a/dictionary/ajax_vocabulary_management.py b/dictionary/ajax_vocabulary_management.py index b5c52ec..9f3505c 100644 --- a/dictionary/ajax_vocabulary_management.py +++ b/dictionary/ajax_vocabulary_management.py @@ -127,15 +127,12 @@ def create_tei_walenty(lemmas, form_dict): os.chdir(tmp_folder) tmpfile, tmpfilename = mkstemp(dir=tmp_folder) os.close(tmpfile) - q_frame_opinions = [] + frame_opinion_values = Frame_Opinion_Value.objects.none() if form_dict['frame_opinions']: - for pk in form_dict['frame_opinions']: - q_frame_opinions.append(Q(value__pk=pk)) + frame_opinion_values = Frame_Opinion_Value.objects.filter(pk__in=form_dict['frame_opinions']) createteixml(tmpfilename, lemmas, - frame_char_models=[], - form_dict=form_dict, - q_frame_opinions=q_frame_opinions) + frame_opinion_values) file_name = tmpfilename + '.xml' os.rename(tmpfilename, file_name) return file_name diff --git a/dictionary/management/commands/create_TEI_walenty.py b/dictionary/management/commands/create_TEI_walenty.py new file mode 100644 index 0000000..cd0b5f3 --- /dev/null +++ b/dictionary/management/commands/create_TEI_walenty.py @@ -0,0 +1,45 @@ +#-*- coding:utf-8 -*- + +#Copyright (c) 2015, Bartłomiej Nitoń +#All rights reserved. + +#Redistribution and use in source and binary forms, with or without modification, are permitted provided +#that the following conditions are met: + +# Redistributions of source code must retain the above copyright notice, this list of conditions and +# the following disclaimer. +# Redistributions in binary form must reproduce the above copyright notice, this list of conditions +# and the following disclaimer in the documentation and/or other materials provided with the distribution. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +import datetime +import os + +from django.core.management.base import BaseCommand + +from dictionary.models import Lemma, Frame_Opinion_Value, \ + get_checked_statuses +from dictionary.teixml import createteixml +from settings import WALENTY_PATH + +class Command(BaseCommand): + args = 'none' + + def handle(self, *args, **options): + now = datetime.datetime.now().strftime('%Y%m%d') + filename_base = '%s_%s.xml' % ('walenty', now) + outpath = os.path.join(WALENTY_PATH, filename_base) + checked_statuses = get_checked_statuses() + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name') + checked_lemmas = lemmas.filter(status__in=checked_statuses) + frame_opinion_values = Frame_Opinion_Value.objects.all() + createteixml(outpath, checked_lemmas, frame_opinion_values) + \ No newline at end of file diff --git a/dictionary/management/commands/create_walenty.py b/dictionary/management/commands/create_text_walenty.py index 8e33057..8e33057 100644 --- a/dictionary/management/commands/create_walenty.py +++ b/dictionary/management/commands/create_text_walenty.py diff --git a/dictionary/models.py b/dictionary/models.py index c3235ac..8b35f9b 100644 --- a/dictionary/models.py +++ b/dictionary/models.py @@ -936,6 +936,12 @@ class Atribute_Model(Model): # priorytet prezentowania atrybutow w argumencie priority = PositiveIntegerField(db_column='priorytet', primary_key=True) + def use_subparams(self): + if (self.possible_parameters.exists() and + self.possible_parameters.annotate(subparams_count=Count('possible_subparams')).filter(subparams_count__gt=0).exists()): + return True + return False + def __unicode__(self): return '%s' % (self.atr_model_name) diff --git a/dictionary/static/js/argument_form_utils.js b/dictionary/static/js/argument_form_utils.js index be4dbb5..0f849ed 100644 --- a/dictionary/static/js/argument_form_utils.js +++ b/dictionary/static/js/argument_form_utils.js @@ -268,8 +268,8 @@ function argument_form_submit() { } // tworzymy typy fraz else { - arguments_form_change(1, null, dialogParent.closest(".argument-add-form"), ''); - // realization_arguments_form_change(1, '', false, dialogParent.closest(".argument-add-form")); + //arguments_form_change(1, null, dialogParent.closest(".argument-add-form"), ''); + realization_arguments_form_change(1, '', false, dialogParent.closest(".argument-add-form")); } } this_dialog.dialog('close'); diff --git a/dictionary/teixml.py b/dictionary/teixml.py index c91fa35..ebbf17f 100644 --- a/dictionary/teixml.py +++ b/dictionary/teixml.py @@ -25,7 +25,6 @@ from semantics.models import LexicalUnitExamples File with functions responsible for creating TEI xml. ''' -import codecs import datetime import operator @@ -39,20 +38,20 @@ from dictionary.models import Atribute_Model, Frame_Opinion_Value, Frame_Char_Mo XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace' -def createteixml(outpath, lemmas, frame_char_models, - form_dict, q_frame_opinions): +def createteixml(outpath, lemmas, frame_opinion_values): root = write_root() write_header(root) - #lemmas = lemmas.filter(entry=u'administrować') - write_entries(root, lemmas, frame_char_models, - form_dict, q_frame_opinions) - with codecs.open(outpath, 'wt', 'utf-8') as output_file: - output_file.write(etree.tostring(root, pretty_print = True)) + #lemmas = lemmas.filter(entry=u'brnąć') + write_entries(root, lemmas, frame_opinion_values) + with open(outpath, 'w') as output_file: + output_file.write(etree.tostring(root, pretty_print=True, + xml_declaration=True, encoding='UTF-8', + doctype=u'<!DOCTYPE TEI SYSTEM "tei_all.dtd">')) def write_root(): root = etree.Element('TEI') - root.attrib[etree.QName(XML_NAMESPACE, 'lang')] = 'pl' - root.attrib['xmlns'] = 'http://www.tei-c.org/ns/1.0' + root.attrib[etree.QName(XML_NAMESPACE, 'lang')] = u'pl' + root.attrib['xmlns'] = u'http://www.tei-c.org/ns/1.0' return root def write_header(root): @@ -61,30 +60,26 @@ def write_header(root): title_stmt = etree.SubElement(file_desc, 'titleStmt') title = etree.SubElement(title_stmt, 'title') - title.text = 'Polish Valence Dictionary (Walenty)' -# + title.text = u'Polish Valence Dictionary (Walenty)' + publication_stmt = etree.SubElement(file_desc, 'publicationStmt') publisher = etree.SubElement(publication_stmt, 'publisher') - publisher.text = 'IPI PAN ZIL' + publisher.text = u'IPI PAN ZIL' date = etree.SubElement(publication_stmt, 'date') date.attrib['when'] = datetime.datetime.now().strftime('%Y-%m-%d') source_desc = etree.SubElement(file_desc, 'sourceDesc') p = etree.SubElement(source_desc, 'p') - p.text = 'File generated using Slowal. Mentioned tool available at: walenty.ipipan.waw.pl.' + p.text = u'File generated using Slowal. Mentioned tool available at: walenty.ipipan.waw.pl.' -def write_entries(root, lemmas, frame_char_models, - form_dict, q_frame_opinions): +def write_entries(root, lemmas, frame_opinion_values): text = etree.SubElement(root, 'text') body = etree.SubElement(text, 'body') for lemma in lemmas: - frame_opinions = None - if q_frame_opinions: - frame_opinions = lemma.frame_opinions.filter(reduce(operator.or_, q_frame_opinions)) - write_entry(body, lemma, frame_char_models, - form_dict, frame_opinions) + frame_opinions = lemma.frame_opinions.filter(value__in=frame_opinion_values) + write_entry(body, lemma, frame_opinions, frame_opinion_values) -def write_entry(body_elem, lemma, frame_char_models, form_dict, frame_opinions): +def write_entry(body_elem, lemma, frame_opinions, frame_opinion_values): entry_xml_id = 'wal_%s-ent' % str(lemma.entry_obj.id) entry_elem = etree.SubElement(body_elem, 'entry') entry_elem.attrib[etree.QName(XML_NAMESPACE, 'id')] = entry_xml_id @@ -95,15 +90,15 @@ def write_entry(body_elem, lemma, frame_char_models, form_dict, frame_opinions): pos_elem = etree.SubElement(form_elem, 'pos') pos_elem.text = lemma.entry_obj.pos.tag - write_syntactic_layer(entry_elem, lemma, form_dict, frame_opinions) + write_syntactic_layer(entry_elem, lemma, frame_opinions, frame_opinion_values) write_examples_layer(entry_elem, lemma) write_semantic_layer(entry_elem, lemma) write_meanings_layer(entry_elem, lemma) write_connections_layer(entry_elem, lemma) -def write_syntactic_layer(entry_elem, lemma, form_dict, frame_opinions): +def write_syntactic_layer(entry_elem, lemma, frame_opinions, frame_opinion_values): synt_layer_fs_elem = etree.SubElement(entry_elem, 'fs') - synt_layer_fs_elem.attrib['type'] = 'syntacticLayer' + synt_layer_fs_elem.attrib['type'] = 'syntactic_layer' schemata_f_elem = etree.SubElement(synt_layer_fs_elem, 'f') schemata_f_elem.attrib['name'] = 'schemata' vColl_elem = etree.SubElement(schemata_f_elem, 'vColl') @@ -118,7 +113,8 @@ def write_syntactic_layer(entry_elem, lemma, form_dict, frame_opinions): pred_val=pred_val, aspect_val=aspect_val).order_by('text_rep') for frame in matchingframes: - if not form_dict['frame_opinions'] or (frame_opinions and frame_opinions.filter(frame=frame).count() > 0): + if (not frame_opinion_values.exists() or + frame_opinions.filter(frame=frame).exists()): write_schema(vColl_elem, frame, lemma) def write_schema(parent_elem, schema, lemma): @@ -139,13 +135,14 @@ def write_schema(parent_elem, schema, lemma): opinion_symbol.attrib['value'] = schema_opinion # zwrotnosc - reflex = 'false' - if schema.characteristics.filter(type=u'ZWROTNOŚĆ', value__value=u'się').exists(): - reflex = 'true' + reflex = schema.characteristics.get(type=u'ZWROTNOŚĆ') selfmark_f_elem = etree.SubElement(schema_fs_elem, 'f') - selfmark_f_elem.attrib['name'] = 'selfMark' + selfmark_f_elem.attrib['name'] = 'reflexive_mark' selfmark_binary = etree.SubElement(selfmark_f_elem, 'binary') - selfmark_binary.attrib['value'] = reflex + if reflex.value.value: + selfmark_binary.attrib['value'] = 'true' + else: + selfmark_binary.attrib['value'] = 'false' # aspekt aspect = schema.characteristics.get(type=u'ASPEKT').value.value @@ -167,9 +164,11 @@ def write_schema(parent_elem, schema, lemma): predicativity = schema.characteristics.get(type=u'PREDYKATYWNOŚĆ').value.value predicativity_f_elem = etree.SubElement(schema_fs_elem, 'f') predicativity_f_elem.attrib['name'] = 'predicativity' + predicativity_binary = etree.SubElement(predicativity_f_elem, 'binary') if predicativity: - predicativity_symbol = etree.SubElement(predicativity_f_elem, 'symbol') - predicativity_symbol.attrib['value'] = predicativity + predicativity_binary.attrib['value'] = 'true' + else: + predicativity_binary.attrib['value'] = 'false' # pozycje składniowe write_positions_feature(schema, schema_xml_id, schema_fs_elem) @@ -204,20 +203,20 @@ def write_position_elem(parent_elem, schema_xml_id, position): def write_control_features(parent_elem, position): controls1 = position.categories.filter(control=True).exclude(category__endswith='2') - if controls1.exists(): - control = controls1[0].category - control1_f_elem = etree.SubElement(parent_elem, 'f') - control1_f_elem.attrib['name'] = 'control1' - control1_symbol_elem = etree.SubElement(control1_f_elem, 'symbol') - control1_symbol_elem.attrib['value'] = control - controls2 = position.categories.filter(control=True, category__endswith='2') - if controls2.exists(): - control = controls2[0].category - control2_f_elem = etree.SubElement(parent_elem, 'f') - control2_f_elem.attrib['name'] = 'control2' - control2_symbol_elem = etree.SubElement(control2_f_elem, 'symbol') - control2_symbol_elem.attrib['value'] = control + if controls1.exists() or controls2.exists(): + control_f_elem = etree.SubElement(parent_elem, 'f') + control_f_elem.attrib['name'] = 'control' + vColl_elem = etree.SubElement(control_f_elem, 'vColl') + vColl_elem.attrib['org'] = 'set' + if controls1.exists(): + control = controls1[0].category + control1_symbol_elem = etree.SubElement(vColl_elem, 'symbol') + control1_symbol_elem.attrib['value'] = control + if controls2.exists(): + control = controls2[0].category + control2_symbol_elem = etree.SubElement(vColl_elem, 'symbol') + control2_symbol_elem.attrib['value'] = control def write_phrases_feature(parent_elem, position, position_xml_id): sorted_phrases = sortArguments(position.arguments.all()) @@ -246,19 +245,17 @@ def write_attribute(parent_elem, attribute): attribute_model = Atribute_Model.objects.get(atr_model_name=attribute.type) attr_f_elem = etree.SubElement(parent_elem, 'f') attr_f_elem.attrib['name'] = attribute_model.sym_name -# attr_f_elem.text = unicode(attribute) attribute_type = attribute_model.type.sym_name selection_modes = attribute_model.values_selection_modes - if (attribute_type == 'text' and - (not selection_modes.exists() or attribute.values.count() == 1)): + if attribute_type == 'text' and not selection_modes.exists(): write_simple_text_attr(attr_f_elem, attribute) elif attribute_type == 'text' and selection_modes.exists(): - write_complex_text_attr(attr_f_elem, attribute) + write_complex_text_attr(attr_f_elem, attribute_model, attribute) elif attribute_type == 'parameter' and not selection_modes.exists(): - write_simple_parameter_attr(attr_f_elem, attribute) + write_simple_parameter_attr(attr_f_elem, attribute_model, attribute) elif attribute_type == 'parameter' and selection_modes.exists(): - write_complex_parameter_attr(attr_f_elem, attribute) + write_complex_parameter_attr(attr_f_elem, attribute_model, attribute) elif attribute_type == 'argument' and not selection_modes.exists(): write_simple_phrase_type_attr(attr_f_elem, attribute) elif attribute_type == 'argument' and selection_modes.exists(): @@ -270,22 +267,32 @@ def write_simple_text_attr(parent_elem, attribute): string_elem = etree.SubElement(parent_elem, 'string') string_elem.text = unicode(attribute).strip("'") -def write_complex_text_attr(parent_elem, attribute): +def write_complex_text_attr(parent_elem, attribute_model, attribute): complex_lemma_fs_elem = etree.SubElement(parent_elem, 'fs') - complex_lemma_fs_elem.attrib['type'] = 'complexLemma' - write_selection_mode_and_separator(complex_lemma_fs_elem, attribute) + complex_lemma_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] + write_selection_mode_and_separator(complex_lemma_fs_elem, attribute_model, attribute) write_lemmas(complex_lemma_fs_elem, attribute) -def write_selection_mode_and_separator(parent_elem, attribute): - selection_mode = attribute.selection_mode.name +def write_selection_mode_and_separator(parent_elem, attr_model, attribute): + if attribute.selection_mode: + selection_mode = attribute.selection_mode.name + else: + selection_mode = attr_model.values_selection_modes.order_by('priority')[0].name sel_mode_f_elem = etree.SubElement(parent_elem, 'f') - sel_mode_f_elem.attrib['name'] = 'selectionMode' + sel_mode_f_elem.attrib['name'] = 'selection_mode' sel_mode_symbol_elem = etree.SubElement(sel_mode_f_elem, 'symbol') sel_mode_symbol_elem.attrib['value'] = selection_mode - separator = attribute.separator.symbol + if attribute.separator: + separator = attribute.separator.symbol + else: + separator = attr_model.value_separators.order_by('priority')[0].symbol + if separator == ';': + separator = 'coord' + elif separator == ',': + separator = 'concat' separator_f_elem = etree.SubElement(parent_elem, 'f') - separator_f_elem.attrib['name'] = 'separator' + separator_f_elem.attrib['name'] = 'cooccurrence' separator_symbol_elem = etree.SubElement(separator_f_elem, 'symbol') separator_symbol_elem.attrib['value'] = separator @@ -297,58 +304,54 @@ def write_lemmas(parent_elem, attribute): vColl_elem.attrib['org'] = 'set' for lemma in lemmas: -# lemma_fs_elem = etree.SubElement(vColl_elem, 'fs') -# lemma_fs_elem.attrib['type'] = 'lemma' -# lemma_f_elem = etree.SubElement(lemma_fs_elem, 'f') -# lemma_f_elem.attrib['name'] = 'base' string_elem = etree.SubElement(vColl_elem, 'string') string_elem.text = lemma.strip("'") -def write_simple_parameter_attr(parent_elem, attribute): +def write_simple_parameter_attr(parent_elem, attribute_model, attribute): param_value = attribute.values.all()[0] - write_parameter(parent_elem, param_value) + write_parameter(parent_elem, attribute_model, param_value) -def write_parameter(parent_elem, param_value): - if param_value.parameter.subparameters.exists(): +def write_parameter(parent_elem, attribute_model, param_value): + if attribute_model.use_subparams(): param_fs_elem = etree.SubElement(parent_elem, 'fs') - param_fs_elem.attrib['type'] = 'complexAttr'#param_value.type.sym_name + param_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] - value_f_elem = etree.SubElement(param_fs_elem, 'f') # TODO: powininen byc symbol, ale takie comprepnp ma spacje - value_f_elem.attrib['name'] = 'value' - #value_f_elem.text = param_value.parameter.type.name - value = param_value.parameter.type.name.replace(' ', '_') + value_f_elem = etree.SubElement(param_fs_elem, 'f') + value_f_elem.attrib['name'] = 'conjunction' + value = param_value.parameter.type.name symbol_elem = etree.SubElement(value_f_elem, 'symbol') symbol_elem.attrib['value'] = value - write_parameter_subparameters(param_fs_elem, param_value.parameter) + if param_value.parameter.subparameters.exists(): + write_parameter_subparameters(param_fs_elem, param_value.parameter) else: value = unicode(param_value) - if value: - value = value.replace(' ', '_') + if attribute_model.sym_name == 'reflexive_mark': + selfmark_binary = etree.SubElement(parent_elem, 'binary') + if value: + selfmark_binary.attrib['value'] = 'true' + else: + selfmark_binary.attrib['value'] = 'false' + elif value: symbol_elem = etree.SubElement(parent_elem, 'symbol') symbol_elem.attrib['value'] = value - #parent_elem.text = unicode(param_value) # TODO: powininen byc symbol, ale takie comprepnp ma spacje - + def write_parameter_subparameters(parent_elem, parameter): subparams_f_elem = etree.SubElement(parent_elem, 'f') - subparams_f_elem.attrib['name'] = 'subparameters' + subparams_f_elem.attrib['name'] = 'constraints' vColl_elem = etree.SubElement(subparams_f_elem, 'vColl') vColl_elem.attrib['org'] = 'set' for subparameter in parameter.subparameters.order_by('name'): write_subparameter(vColl_elem, subparameter) def write_subparameter(parent_elem, subparameter): -# subparam_fs_elem = etree.SubElement(parent_elem, 'fs') -# subparam_fs_elem.attrib['type'] = 'subparameter' -# value_f_elem = etree.SubElement(subparam_fs_elem, 'f') -# value_f_elem.attrib['name'] = 'value' symbol_elem = etree.SubElement(parent_elem, 'symbol') symbol_elem.attrib['value'] = subparameter.name -def write_complex_parameter_attr(parent_elem, attribute): +def write_complex_parameter_attr(parent_elem, attribute_model, attribute): vColl_elem = etree.SubElement(parent_elem, 'vColl') vColl_elem.attrib['org'] = 'set' for value in attribute.values.order_by('parameter__type'): - write_parameter(vColl_elem, value) + write_parameter(vColl_elem, attribute_model, value) def write_simple_phrase_type_attr(parent_elem, attribute): write_phrase(parent_elem, attribute.values.all()[0].argument, None) @@ -360,7 +363,7 @@ def write_complex_phrase_type_attr(parent_elem, attribute): write_phrases_set(parent_elem, phrases) else: complex_phrase_fs_elem = etree.SubElement(parent_elem, 'fs') - complex_phrase_fs_elem.attrib['type'] = 'complexPhraseAttr' + complex_phrase_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] write_typed_phrase_attr(complex_phrase_fs_elem, attribute) def write_phrases_set(parent_elem, phrases): @@ -373,19 +376,19 @@ def write_phrases_set(parent_elem, phrases): def write_typed_phrase_attr(parent_elem, attribute): selection_mode = attribute.selection_mode type_f_elem = etree.SubElement(parent_elem, 'f') - type_f_elem.attrib['name'] = 'type' + type_f_elem.attrib['name'] = 'name' symbol_elem = etree.SubElement(type_f_elem, 'symbol') symbol_elem.attrib['value'] = selection_mode.name if attribute.values.exists(): phrases_f_elem = etree.SubElement(parent_elem, 'f') - phrases_f_elem.attrib['name'] = 'phrases' + phrases_f_elem.attrib['name'] = 'constraints' phrases = [value.argument for value in attribute.values.all()] write_phrases_set(phrases_f_elem, phrases) def write_complex_position_attr(parent_elem, attribute): complex_positions_fs_elem = etree.SubElement(parent_elem, 'fs') - complex_positions_fs_elem.attrib['type'] = 'complexPositionsAttr' + complex_positions_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] selection_mode = attribute.selection_mode type_f_elem = etree.SubElement(complex_positions_fs_elem, 'f') @@ -406,7 +409,7 @@ def write_complex_position_attr(parent_elem, attribute): def write_examples_layer(parent_elem, lemma): examples_layer_elem = etree.SubElement(parent_elem, 'fs') - examples_layer_elem.attrib['type'] = 'examplesLayer' + examples_layer_elem.attrib['type'] = 'examples_layer' examples_f_elem = etree.SubElement(examples_layer_elem, 'f') examples_f_elem.attrib['name'] = 'examples' @@ -415,7 +418,7 @@ def write_examples_layer(parent_elem, lemma): vColl_elem.attrib['org'] = 'set' write_examples_feature(vColl_elem, lemma) - + def write_examples_feature(parent_elem, lemma): entry = lemma.entry_obj for example in lemma.nkjp_examples.order_by('opinion__priority').all(): @@ -467,7 +470,7 @@ def get_and_write_meaning_link(parent_elem, entry, example): meaning_link_elem = etree.SubElement(meaning_f_elem, 'fs') meaning_link_elem.attrib['sameAs'] = meaning_xml_id - meaning_link_elem.attrib['type'] = 'lexicalUnit' + meaning_link_elem.attrib['type'] = 'lexical_unit' except LexicalUnitExamples.DoesNotExist: pass @@ -492,7 +495,7 @@ def create_and_write_phrase_link(parent_elem, entry, example, phrase_selection): def write_semantic_layer(parent_elem, lemma): semantic_layer_elem = etree.SubElement(parent_elem, 'fs') - semantic_layer_elem.attrib['type'] = 'semanticLayer' + semantic_layer_elem.attrib['type'] = 'semantic_layer' frames_f_elem = etree.SubElement(semantic_layer_elem, 'f') frames_f_elem.attrib['name'] = 'frames' @@ -532,7 +535,7 @@ def write_frame_meaning_link(parent_elem, entry, meaning): link = u'#wal_%d.%d-mng' % (entry.id, meaning.id) lex_unit_link_elem = etree.SubElement(parent_elem, 'fs') lex_unit_link_elem.attrib['sameAs'] = link - lex_unit_link_elem.attrib['type'] = 'lexicalUnit' + lex_unit_link_elem.attrib['type'] = 'lexical_unit' def write_frame_arguments(parent_elem, entry, frame): arguments_f_elem = etree.SubElement(parent_elem, 'f') @@ -559,7 +562,7 @@ def write_roles(parent_elem, arg): for role in arg.roles.order_by('gradient'): if role.gradient: attribute_f_elem = etree.SubElement(parent_elem, 'f') - attribute_f_elem.attrib['name'] = 'roleAttribute' + attribute_f_elem.attrib['name'] = 'role_attribute' attribute_symbol_elem = etree.SubElement(attribute_f_elem, 'symbol') attribute_symbol_elem.attrib['value'] = unicode(role) else: @@ -571,10 +574,10 @@ def write_roles(parent_elem, arg): def write_selective_preferences(parent_elem, arg, arg_base_id): if(arg.selective_preference): sel_prefs_f_elem = etree.SubElement(parent_elem, 'f') - sel_prefs_f_elem.attrib['name'] = 'selPrefs' + sel_prefs_f_elem.attrib['name'] = 'sel_prefs' sel_prefs_groups_fs_elem = etree.SubElement(sel_prefs_f_elem, 'fs') - sel_prefs_groups_fs_elem.attrib['type'] = 'selPrefsGroups' + sel_prefs_groups_fs_elem.attrib['type'] = 'sel_prefs_groups' write_synsets_sel_prefs(sel_prefs_groups_fs_elem, arg) write_predefined_sel_prefs(sel_prefs_groups_fs_elem, arg) @@ -594,12 +597,6 @@ def write_synsets_sel_prefs(parent_elem, arg): write_synset(vColl_elem, synset) def write_synset(parent_elem, synset): -# synset_fs_elem = etree.SubElement(parent_elem, 'fs') -# synset_fs_elem.attrib['type'] = 'synset' -# -# plWN_id_elem = etree.SubElement(synset_fs_elem, 'f') -# plWN_id_elem.attrib['name'] = 'plwnid' - id_numeric_elem = etree.SubElement(parent_elem, 'numeric') id_numeric_elem.attrib['value'] = str(synset.id) @@ -616,12 +613,6 @@ def write_predefined_sel_prefs(parent_elem, arg): write_predef(vColl_elem, predef) def write_predef(parent_elem, predef): -# predef_fs_elem = etree.SubElement(parent_elem, 'fs') -# predef_fs_elem.attrib['type'] = 'predef' -# -# name_f_elem = etree.SubElement(predef_fs_elem, 'f') -# name_f_elem.attrib['name'] = 'name' - name_symbol_elem = etree.SubElement(parent_elem, 'symbol') name_symbol_elem.attrib['value'] = predef.name @@ -644,10 +635,8 @@ def write_relation(parent_elem, relation, arg_base_id): relation_f_elem = etree.SubElement(relation_fs_elem, 'f') relation_f_elem.attrib['name'] = 'type' - type_string_elem = etree.SubElement(relation_f_elem, 'string') # TODO: tak ni powinno byc - type_string_elem.text = relation.relation.name -# type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') # @TODO: tak powinno byc zamiast stringa -# type_symbol_elem.attrib['value'] = relation.relation.name + type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') + type_symbol_elem.attrib['value'] = relation.relation.name to_f_elem = etree.SubElement(relation_fs_elem, 'f') to_f_elem.attrib['name'] = 'to' @@ -661,7 +650,7 @@ def write_synset_relation_sel_prefs(parent_elem, arg): relations = arg.selective_preference.synset_relations if relations.exists(): relations_f_elem = etree.SubElement(parent_elem, 'f') - relations_f_elem.attrib['name'] = 'synsetRelations' + relations_f_elem.attrib['name'] = 'synset_relations' vColl_elem = etree.SubElement(relations_f_elem, 'vColl') vColl_elem.attrib['org'] = 'set' @@ -671,15 +660,13 @@ def write_synset_relation_sel_prefs(parent_elem, arg): def write_synset_relation(parent_elem, relation): relation_fs_elem = etree.SubElement(parent_elem, 'fs') - relation_fs_elem.attrib['type'] = 'synsetRelation' + relation_fs_elem.attrib['type'] = 'synset_relation' relation_f_elem = etree.SubElement(relation_fs_elem, 'f') relation_f_elem.attrib['name'] = 'type' - type_string_elem = etree.SubElement(relation_f_elem, 'string') - type_string_elem.text = relation.relation.name -# type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') # @TODO: tak powinno byc zamiast stringa -# type_symbol_elem.attrib['value'] = relation.relation.name + type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') + type_symbol_elem.attrib['value'] = relation.relation.name to_f_elem = etree.SubElement(relation_fs_elem, 'f') to_f_elem.attrib['name'] = 'to' @@ -687,7 +674,7 @@ def write_synset_relation(parent_elem, relation): def write_meanings_layer(parent_elem, lemma): meanings_layer_elem = etree.SubElement(parent_elem, 'fs') - meanings_layer_elem.attrib['type'] = 'meaningsLayer' + meanings_layer_elem.attrib['type'] = 'meanings_layer' meanings_f_elem = etree.SubElement(meanings_layer_elem, 'f') meanings_f_elem.attrib['name'] = 'meanings' @@ -708,7 +695,7 @@ def write_meaning(parent_elem, entry, lex_unit): meaning_fs_elem = etree.SubElement(parent_elem, 'fs') meaning_fs_elem.attrib[etree.QName(XML_NAMESPACE, 'id')] = meaning_xml_id - meaning_fs_elem.attrib['type'] = 'lexicalUnit' + meaning_fs_elem.attrib['type'] = 'lexical_unit' name_f_elem = etree.SubElement(meaning_fs_elem, 'f') name_f_elem.attrib['name'] = 'name' @@ -717,8 +704,8 @@ def write_meaning(parent_elem, entry, lex_unit): variant_f_elem = etree.SubElement(meaning_fs_elem, 'f') variant_f_elem.attrib['name'] = 'variant' - variant_symbol_elem = etree.SubElement(variant_f_elem, 'symbol') - variant_symbol_elem.attrib['value'] = lex_unit.sense + variant_string_elem = etree.SubElement(variant_f_elem, 'string') + variant_string_elem.text = lex_unit.sense plwnluid_f_elem = etree.SubElement(meaning_fs_elem, 'f') plwnluid_f_elem.attrib['name'] = 'plwnluid' @@ -733,7 +720,7 @@ def write_meaning(parent_elem, entry, lex_unit): def write_connections_layer(parent_elem, lemma): connections_layer_elem = etree.SubElement(parent_elem, 'fs') - connections_layer_elem.attrib['type'] = 'connectionsLayer' + connections_layer_elem.attrib['type'] = 'connections_layer' alternations_f_elem = etree.SubElement(connections_layer_elem, 'f') alternations_f_elem.attrib['name'] = 'alternations'