Commit 044a6cbfdf7c24c0d020c06991cc206b4d713541
1 parent
4c2dc86c
Added script for creating TEI xml Walenty file.
Showing
6 changed files
with
167 additions
and
132 deletions
dictionary/ajax_vocabulary_management.py
... | ... | @@ -127,15 +127,12 @@ def create_tei_walenty(lemmas, form_dict): |
127 | 127 | os.chdir(tmp_folder) |
128 | 128 | tmpfile, tmpfilename = mkstemp(dir=tmp_folder) |
129 | 129 | os.close(tmpfile) |
130 | - q_frame_opinions = [] | |
130 | + frame_opinion_values = Frame_Opinion_Value.objects.none() | |
131 | 131 | if form_dict['frame_opinions']: |
132 | - for pk in form_dict['frame_opinions']: | |
133 | - q_frame_opinions.append(Q(value__pk=pk)) | |
132 | + frame_opinion_values = Frame_Opinion_Value.objects.filter(pk__in=form_dict['frame_opinions']) | |
134 | 133 | createteixml(tmpfilename, |
135 | 134 | lemmas, |
136 | - frame_char_models=[], | |
137 | - form_dict=form_dict, | |
138 | - q_frame_opinions=q_frame_opinions) | |
135 | + frame_opinion_values) | |
139 | 136 | file_name = tmpfilename + '.xml' |
140 | 137 | os.rename(tmpfilename, file_name) |
141 | 138 | return file_name |
... | ... |
dictionary/management/commands/create_TEI_walenty.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | |
2 | + | |
3 | +#Copyright (c) 2015, Bartłomiej Nitoń | |
4 | +#All rights reserved. | |
5 | + | |
6 | +#Redistribution and use in source and binary forms, with or without modification, are permitted provided | |
7 | +#that the following conditions are met: | |
8 | + | |
9 | +# Redistributions of source code must retain the above copyright notice, this list of conditions and | |
10 | +# the following disclaimer. | |
11 | +# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | |
12 | +# and the following disclaimer in the documentation and/or other materials provided with the distribution. | |
13 | + | |
14 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | |
15 | +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
16 | +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | |
17 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | |
18 | +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
19 | +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
20 | +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
21 | +# POSSIBILITY OF SUCH DAMAGE. | |
22 | + | |
23 | +import datetime | |
24 | +import os | |
25 | + | |
26 | +from django.core.management.base import BaseCommand | |
27 | + | |
28 | +from dictionary.models import Lemma, Frame_Opinion_Value, \ | |
29 | + get_checked_statuses | |
30 | +from dictionary.teixml import createteixml | |
31 | +from settings import WALENTY_PATH | |
32 | + | |
33 | +class Command(BaseCommand): | |
34 | + args = 'none' | |
35 | + | |
36 | + def handle(self, *args, **options): | |
37 | + now = datetime.datetime.now().strftime('%Y%m%d') | |
38 | + filename_base = '%s_%s.xml' % ('walenty', now) | |
39 | + outpath = os.path.join(WALENTY_PATH, filename_base) | |
40 | + checked_statuses = get_checked_statuses() | |
41 | + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name') | |
42 | + checked_lemmas = lemmas.filter(status__in=checked_statuses) | |
43 | + frame_opinion_values = Frame_Opinion_Value.objects.all() | |
44 | + createteixml(outpath, checked_lemmas, frame_opinion_values) | |
45 | + | |
0 | 46 | \ No newline at end of file |
... | ... |
dictionary/management/commands/create_walenty.py renamed to dictionary/management/commands/create_text_walenty.py
dictionary/models.py
... | ... | @@ -936,6 +936,12 @@ class Atribute_Model(Model): |
936 | 936 | # priorytet prezentowania atrybutow w argumencie |
937 | 937 | priority = PositiveIntegerField(db_column='priorytet', primary_key=True) |
938 | 938 | |
939 | + def use_subparams(self): | |
940 | + if (self.possible_parameters.exists() and | |
941 | + self.possible_parameters.annotate(subparams_count=Count('possible_subparams')).filter(subparams_count__gt=0).exists()): | |
942 | + return True | |
943 | + return False | |
944 | + | |
939 | 945 | def __unicode__(self): |
940 | 946 | return '%s' % (self.atr_model_name) |
941 | 947 | |
... | ... |
dictionary/static/js/argument_form_utils.js
... | ... | @@ -268,8 +268,8 @@ function argument_form_submit() { |
268 | 268 | } |
269 | 269 | // tworzymy typy fraz |
270 | 270 | else { |
271 | - arguments_form_change(1, null, dialogParent.closest(".argument-add-form"), ''); | |
272 | - // realization_arguments_form_change(1, '', false, dialogParent.closest(".argument-add-form")); | |
271 | + //arguments_form_change(1, null, dialogParent.closest(".argument-add-form"), ''); | |
272 | + realization_arguments_form_change(1, '', false, dialogParent.closest(".argument-add-form")); | |
273 | 273 | } |
274 | 274 | } |
275 | 275 | this_dialog.dialog('close'); |
... | ... |
dictionary/teixml.py
... | ... | @@ -25,7 +25,6 @@ from semantics.models import LexicalUnitExamples |
25 | 25 | File with functions responsible for creating TEI xml. |
26 | 26 | ''' |
27 | 27 | |
28 | -import codecs | |
29 | 28 | import datetime |
30 | 29 | import operator |
31 | 30 | |
... | ... | @@ -39,20 +38,20 @@ from dictionary.models import Atribute_Model, Frame_Opinion_Value, Frame_Char_Mo |
39 | 38 | XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace' |
40 | 39 | |
41 | 40 | |
42 | -def createteixml(outpath, lemmas, frame_char_models, | |
43 | - form_dict, q_frame_opinions): | |
41 | +def createteixml(outpath, lemmas, frame_opinion_values): | |
44 | 42 | root = write_root() |
45 | 43 | write_header(root) |
46 | - #lemmas = lemmas.filter(entry=u'administrować') | |
47 | - write_entries(root, lemmas, frame_char_models, | |
48 | - form_dict, q_frame_opinions) | |
49 | - with codecs.open(outpath, 'wt', 'utf-8') as output_file: | |
50 | - output_file.write(etree.tostring(root, pretty_print = True)) | |
44 | + #lemmas = lemmas.filter(entry=u'brnąć') | |
45 | + write_entries(root, lemmas, frame_opinion_values) | |
46 | + with open(outpath, 'w') as output_file: | |
47 | + output_file.write(etree.tostring(root, pretty_print=True, | |
48 | + xml_declaration=True, encoding='UTF-8', | |
49 | + doctype=u'<!DOCTYPE TEI SYSTEM "tei_all.dtd">')) | |
51 | 50 | |
52 | 51 | def write_root(): |
53 | 52 | root = etree.Element('TEI') |
54 | - root.attrib[etree.QName(XML_NAMESPACE, 'lang')] = 'pl' | |
55 | - root.attrib['xmlns'] = 'http://www.tei-c.org/ns/1.0' | |
53 | + root.attrib[etree.QName(XML_NAMESPACE, 'lang')] = u'pl' | |
54 | + root.attrib['xmlns'] = u'http://www.tei-c.org/ns/1.0' | |
56 | 55 | return root |
57 | 56 | |
58 | 57 | def write_header(root): |
... | ... | @@ -61,30 +60,26 @@ def write_header(root): |
61 | 60 | |
62 | 61 | title_stmt = etree.SubElement(file_desc, 'titleStmt') |
63 | 62 | title = etree.SubElement(title_stmt, 'title') |
64 | - title.text = 'Polish Valence Dictionary (Walenty)' | |
65 | -# | |
63 | + title.text = u'Polish Valence Dictionary (Walenty)' | |
64 | + | |
66 | 65 | publication_stmt = etree.SubElement(file_desc, 'publicationStmt') |
67 | 66 | publisher = etree.SubElement(publication_stmt, 'publisher') |
68 | - publisher.text = 'IPI PAN ZIL' | |
67 | + publisher.text = u'IPI PAN ZIL' | |
69 | 68 | date = etree.SubElement(publication_stmt, 'date') |
70 | 69 | date.attrib['when'] = datetime.datetime.now().strftime('%Y-%m-%d') |
71 | 70 | |
72 | 71 | source_desc = etree.SubElement(file_desc, 'sourceDesc') |
73 | 72 | p = etree.SubElement(source_desc, 'p') |
74 | - p.text = 'File generated using Slowal. Mentioned tool available at: walenty.ipipan.waw.pl.' | |
73 | + p.text = u'File generated using Slowal. Mentioned tool available at: walenty.ipipan.waw.pl.' | |
75 | 74 | |
76 | -def write_entries(root, lemmas, frame_char_models, | |
77 | - form_dict, q_frame_opinions): | |
75 | +def write_entries(root, lemmas, frame_opinion_values): | |
78 | 76 | text = etree.SubElement(root, 'text') |
79 | 77 | body = etree.SubElement(text, 'body') |
80 | 78 | for lemma in lemmas: |
81 | - frame_opinions = None | |
82 | - if q_frame_opinions: | |
83 | - frame_opinions = lemma.frame_opinions.filter(reduce(operator.or_, q_frame_opinions)) | |
84 | - write_entry(body, lemma, frame_char_models, | |
85 | - form_dict, frame_opinions) | |
79 | + frame_opinions = lemma.frame_opinions.filter(value__in=frame_opinion_values) | |
80 | + write_entry(body, lemma, frame_opinions, frame_opinion_values) | |
86 | 81 | |
87 | -def write_entry(body_elem, lemma, frame_char_models, form_dict, frame_opinions): | |
82 | +def write_entry(body_elem, lemma, frame_opinions, frame_opinion_values): | |
88 | 83 | entry_xml_id = 'wal_%s-ent' % str(lemma.entry_obj.id) |
89 | 84 | entry_elem = etree.SubElement(body_elem, 'entry') |
90 | 85 | 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): |
95 | 90 | pos_elem = etree.SubElement(form_elem, 'pos') |
96 | 91 | pos_elem.text = lemma.entry_obj.pos.tag |
97 | 92 | |
98 | - write_syntactic_layer(entry_elem, lemma, form_dict, frame_opinions) | |
93 | + write_syntactic_layer(entry_elem, lemma, frame_opinions, frame_opinion_values) | |
99 | 94 | write_examples_layer(entry_elem, lemma) |
100 | 95 | write_semantic_layer(entry_elem, lemma) |
101 | 96 | write_meanings_layer(entry_elem, lemma) |
102 | 97 | write_connections_layer(entry_elem, lemma) |
103 | 98 | |
104 | -def write_syntactic_layer(entry_elem, lemma, form_dict, frame_opinions): | |
99 | +def write_syntactic_layer(entry_elem, lemma, frame_opinions, frame_opinion_values): | |
105 | 100 | synt_layer_fs_elem = etree.SubElement(entry_elem, 'fs') |
106 | - synt_layer_fs_elem.attrib['type'] = 'syntacticLayer' | |
101 | + synt_layer_fs_elem.attrib['type'] = 'syntactic_layer' | |
107 | 102 | schemata_f_elem = etree.SubElement(synt_layer_fs_elem, 'f') |
108 | 103 | schemata_f_elem.attrib['name'] = 'schemata' |
109 | 104 | vColl_elem = etree.SubElement(schemata_f_elem, 'vColl') |
... | ... | @@ -118,7 +113,8 @@ def write_syntactic_layer(entry_elem, lemma, form_dict, frame_opinions): |
118 | 113 | pred_val=pred_val, |
119 | 114 | aspect_val=aspect_val).order_by('text_rep') |
120 | 115 | for frame in matchingframes: |
121 | - if not form_dict['frame_opinions'] or (frame_opinions and frame_opinions.filter(frame=frame).count() > 0): | |
116 | + if (not frame_opinion_values.exists() or | |
117 | + frame_opinions.filter(frame=frame).exists()): | |
122 | 118 | write_schema(vColl_elem, frame, lemma) |
123 | 119 | |
124 | 120 | def write_schema(parent_elem, schema, lemma): |
... | ... | @@ -139,13 +135,14 @@ def write_schema(parent_elem, schema, lemma): |
139 | 135 | opinion_symbol.attrib['value'] = schema_opinion |
140 | 136 | |
141 | 137 | # zwrotnosc |
142 | - reflex = 'false' | |
143 | - if schema.characteristics.filter(type=u'ZWROTNOŚĆ', value__value=u'się').exists(): | |
144 | - reflex = 'true' | |
138 | + reflex = schema.characteristics.get(type=u'ZWROTNOŚĆ') | |
145 | 139 | selfmark_f_elem = etree.SubElement(schema_fs_elem, 'f') |
146 | - selfmark_f_elem.attrib['name'] = 'selfMark' | |
140 | + selfmark_f_elem.attrib['name'] = 'reflexive_mark' | |
147 | 141 | selfmark_binary = etree.SubElement(selfmark_f_elem, 'binary') |
148 | - selfmark_binary.attrib['value'] = reflex | |
142 | + if reflex.value.value: | |
143 | + selfmark_binary.attrib['value'] = 'true' | |
144 | + else: | |
145 | + selfmark_binary.attrib['value'] = 'false' | |
149 | 146 | |
150 | 147 | # aspekt |
151 | 148 | aspect = schema.characteristics.get(type=u'ASPEKT').value.value |
... | ... | @@ -167,9 +164,11 @@ def write_schema(parent_elem, schema, lemma): |
167 | 164 | predicativity = schema.characteristics.get(type=u'PREDYKATYWNOŚĆ').value.value |
168 | 165 | predicativity_f_elem = etree.SubElement(schema_fs_elem, 'f') |
169 | 166 | predicativity_f_elem.attrib['name'] = 'predicativity' |
167 | + predicativity_binary = etree.SubElement(predicativity_f_elem, 'binary') | |
170 | 168 | if predicativity: |
171 | - predicativity_symbol = etree.SubElement(predicativity_f_elem, 'symbol') | |
172 | - predicativity_symbol.attrib['value'] = predicativity | |
169 | + predicativity_binary.attrib['value'] = 'true' | |
170 | + else: | |
171 | + predicativity_binary.attrib['value'] = 'false' | |
173 | 172 | |
174 | 173 | # pozycje składniowe |
175 | 174 | write_positions_feature(schema, schema_xml_id, schema_fs_elem) |
... | ... | @@ -204,20 +203,20 @@ def write_position_elem(parent_elem, schema_xml_id, position): |
204 | 203 | |
205 | 204 | def write_control_features(parent_elem, position): |
206 | 205 | controls1 = position.categories.filter(control=True).exclude(category__endswith='2') |
207 | - if controls1.exists(): | |
208 | - control = controls1[0].category | |
209 | - control1_f_elem = etree.SubElement(parent_elem, 'f') | |
210 | - control1_f_elem.attrib['name'] = 'control1' | |
211 | - control1_symbol_elem = etree.SubElement(control1_f_elem, 'symbol') | |
212 | - control1_symbol_elem.attrib['value'] = control | |
213 | - | |
214 | 206 | controls2 = position.categories.filter(control=True, category__endswith='2') |
215 | - if controls2.exists(): | |
216 | - control = controls2[0].category | |
217 | - control2_f_elem = etree.SubElement(parent_elem, 'f') | |
218 | - control2_f_elem.attrib['name'] = 'control2' | |
219 | - control2_symbol_elem = etree.SubElement(control2_f_elem, 'symbol') | |
220 | - control2_symbol_elem.attrib['value'] = control | |
207 | + if controls1.exists() or controls2.exists(): | |
208 | + control_f_elem = etree.SubElement(parent_elem, 'f') | |
209 | + control_f_elem.attrib['name'] = 'control' | |
210 | + vColl_elem = etree.SubElement(control_f_elem, 'vColl') | |
211 | + vColl_elem.attrib['org'] = 'set' | |
212 | + if controls1.exists(): | |
213 | + control = controls1[0].category | |
214 | + control1_symbol_elem = etree.SubElement(vColl_elem, 'symbol') | |
215 | + control1_symbol_elem.attrib['value'] = control | |
216 | + if controls2.exists(): | |
217 | + control = controls2[0].category | |
218 | + control2_symbol_elem = etree.SubElement(vColl_elem, 'symbol') | |
219 | + control2_symbol_elem.attrib['value'] = control | |
221 | 220 | |
222 | 221 | def write_phrases_feature(parent_elem, position, position_xml_id): |
223 | 222 | sorted_phrases = sortArguments(position.arguments.all()) |
... | ... | @@ -246,19 +245,17 @@ def write_attribute(parent_elem, attribute): |
246 | 245 | attribute_model = Atribute_Model.objects.get(atr_model_name=attribute.type) |
247 | 246 | attr_f_elem = etree.SubElement(parent_elem, 'f') |
248 | 247 | attr_f_elem.attrib['name'] = attribute_model.sym_name |
249 | -# attr_f_elem.text = unicode(attribute) | |
250 | 248 | |
251 | 249 | attribute_type = attribute_model.type.sym_name |
252 | 250 | selection_modes = attribute_model.values_selection_modes |
253 | - if (attribute_type == 'text' and | |
254 | - (not selection_modes.exists() or attribute.values.count() == 1)): | |
251 | + if attribute_type == 'text' and not selection_modes.exists(): | |
255 | 252 | write_simple_text_attr(attr_f_elem, attribute) |
256 | 253 | elif attribute_type == 'text' and selection_modes.exists(): |
257 | - write_complex_text_attr(attr_f_elem, attribute) | |
254 | + write_complex_text_attr(attr_f_elem, attribute_model, attribute) | |
258 | 255 | elif attribute_type == 'parameter' and not selection_modes.exists(): |
259 | - write_simple_parameter_attr(attr_f_elem, attribute) | |
256 | + write_simple_parameter_attr(attr_f_elem, attribute_model, attribute) | |
260 | 257 | elif attribute_type == 'parameter' and selection_modes.exists(): |
261 | - write_complex_parameter_attr(attr_f_elem, attribute) | |
258 | + write_complex_parameter_attr(attr_f_elem, attribute_model, attribute) | |
262 | 259 | elif attribute_type == 'argument' and not selection_modes.exists(): |
263 | 260 | write_simple_phrase_type_attr(attr_f_elem, attribute) |
264 | 261 | elif attribute_type == 'argument' and selection_modes.exists(): |
... | ... | @@ -270,22 +267,32 @@ def write_simple_text_attr(parent_elem, attribute): |
270 | 267 | string_elem = etree.SubElement(parent_elem, 'string') |
271 | 268 | string_elem.text = unicode(attribute).strip("'") |
272 | 269 | |
273 | -def write_complex_text_attr(parent_elem, attribute): | |
270 | +def write_complex_text_attr(parent_elem, attribute_model, attribute): | |
274 | 271 | complex_lemma_fs_elem = etree.SubElement(parent_elem, 'fs') |
275 | - complex_lemma_fs_elem.attrib['type'] = 'complexLemma' | |
276 | - write_selection_mode_and_separator(complex_lemma_fs_elem, attribute) | |
272 | + complex_lemma_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] | |
273 | + write_selection_mode_and_separator(complex_lemma_fs_elem, attribute_model, attribute) | |
277 | 274 | write_lemmas(complex_lemma_fs_elem, attribute) |
278 | 275 | |
279 | -def write_selection_mode_and_separator(parent_elem, attribute): | |
280 | - selection_mode = attribute.selection_mode.name | |
276 | +def write_selection_mode_and_separator(parent_elem, attr_model, attribute): | |
277 | + if attribute.selection_mode: | |
278 | + selection_mode = attribute.selection_mode.name | |
279 | + else: | |
280 | + selection_mode = attr_model.values_selection_modes.order_by('priority')[0].name | |
281 | 281 | sel_mode_f_elem = etree.SubElement(parent_elem, 'f') |
282 | - sel_mode_f_elem.attrib['name'] = 'selectionMode' | |
282 | + sel_mode_f_elem.attrib['name'] = 'selection_mode' | |
283 | 283 | sel_mode_symbol_elem = etree.SubElement(sel_mode_f_elem, 'symbol') |
284 | 284 | sel_mode_symbol_elem.attrib['value'] = selection_mode |
285 | 285 | |
286 | - separator = attribute.separator.symbol | |
286 | + if attribute.separator: | |
287 | + separator = attribute.separator.symbol | |
288 | + else: | |
289 | + separator = attr_model.value_separators.order_by('priority')[0].symbol | |
290 | + if separator == ';': | |
291 | + separator = 'coord' | |
292 | + elif separator == ',': | |
293 | + separator = 'concat' | |
287 | 294 | separator_f_elem = etree.SubElement(parent_elem, 'f') |
288 | - separator_f_elem.attrib['name'] = 'separator' | |
295 | + separator_f_elem.attrib['name'] = 'cooccurrence' | |
289 | 296 | separator_symbol_elem = etree.SubElement(separator_f_elem, 'symbol') |
290 | 297 | separator_symbol_elem.attrib['value'] = separator |
291 | 298 | |
... | ... | @@ -297,58 +304,54 @@ def write_lemmas(parent_elem, attribute): |
297 | 304 | vColl_elem.attrib['org'] = 'set' |
298 | 305 | |
299 | 306 | for lemma in lemmas: |
300 | -# lemma_fs_elem = etree.SubElement(vColl_elem, 'fs') | |
301 | -# lemma_fs_elem.attrib['type'] = 'lemma' | |
302 | -# lemma_f_elem = etree.SubElement(lemma_fs_elem, 'f') | |
303 | -# lemma_f_elem.attrib['name'] = 'base' | |
304 | 307 | string_elem = etree.SubElement(vColl_elem, 'string') |
305 | 308 | string_elem.text = lemma.strip("'") |
306 | 309 | |
307 | -def write_simple_parameter_attr(parent_elem, attribute): | |
310 | +def write_simple_parameter_attr(parent_elem, attribute_model, attribute): | |
308 | 311 | param_value = attribute.values.all()[0] |
309 | - write_parameter(parent_elem, param_value) | |
312 | + write_parameter(parent_elem, attribute_model, param_value) | |
310 | 313 | |
311 | -def write_parameter(parent_elem, param_value): | |
312 | - if param_value.parameter.subparameters.exists(): | |
314 | +def write_parameter(parent_elem, attribute_model, param_value): | |
315 | + if attribute_model.use_subparams(): | |
313 | 316 | param_fs_elem = etree.SubElement(parent_elem, 'fs') |
314 | - param_fs_elem.attrib['type'] = 'complexAttr'#param_value.type.sym_name | |
317 | + param_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] | |
315 | 318 | |
316 | - value_f_elem = etree.SubElement(param_fs_elem, 'f') # TODO: powininen byc symbol, ale takie comprepnp ma spacje | |
317 | - value_f_elem.attrib['name'] = 'value' | |
318 | - #value_f_elem.text = param_value.parameter.type.name | |
319 | - value = param_value.parameter.type.name.replace(' ', '_') | |
319 | + value_f_elem = etree.SubElement(param_fs_elem, 'f') | |
320 | + value_f_elem.attrib['name'] = 'conjunction' | |
321 | + value = param_value.parameter.type.name | |
320 | 322 | symbol_elem = etree.SubElement(value_f_elem, 'symbol') |
321 | 323 | symbol_elem.attrib['value'] = value |
322 | - write_parameter_subparameters(param_fs_elem, param_value.parameter) | |
324 | + if param_value.parameter.subparameters.exists(): | |
325 | + write_parameter_subparameters(param_fs_elem, param_value.parameter) | |
323 | 326 | else: |
324 | 327 | value = unicode(param_value) |
325 | - if value: | |
326 | - value = value.replace(' ', '_') | |
328 | + if attribute_model.sym_name == 'reflexive_mark': | |
329 | + selfmark_binary = etree.SubElement(parent_elem, 'binary') | |
330 | + if value: | |
331 | + selfmark_binary.attrib['value'] = 'true' | |
332 | + else: | |
333 | + selfmark_binary.attrib['value'] = 'false' | |
334 | + elif value: | |
327 | 335 | symbol_elem = etree.SubElement(parent_elem, 'symbol') |
328 | 336 | symbol_elem.attrib['value'] = value |
329 | - #parent_elem.text = unicode(param_value) # TODO: powininen byc symbol, ale takie comprepnp ma spacje | |
330 | - | |
337 | + | |
331 | 338 | def write_parameter_subparameters(parent_elem, parameter): |
332 | 339 | subparams_f_elem = etree.SubElement(parent_elem, 'f') |
333 | - subparams_f_elem.attrib['name'] = 'subparameters' | |
340 | + subparams_f_elem.attrib['name'] = 'constraints' | |
334 | 341 | vColl_elem = etree.SubElement(subparams_f_elem, 'vColl') |
335 | 342 | vColl_elem.attrib['org'] = 'set' |
336 | 343 | for subparameter in parameter.subparameters.order_by('name'): |
337 | 344 | write_subparameter(vColl_elem, subparameter) |
338 | 345 | |
339 | 346 | def write_subparameter(parent_elem, subparameter): |
340 | -# subparam_fs_elem = etree.SubElement(parent_elem, 'fs') | |
341 | -# subparam_fs_elem.attrib['type'] = 'subparameter' | |
342 | -# value_f_elem = etree.SubElement(subparam_fs_elem, 'f') | |
343 | -# value_f_elem.attrib['name'] = 'value' | |
344 | 347 | symbol_elem = etree.SubElement(parent_elem, 'symbol') |
345 | 348 | symbol_elem.attrib['value'] = subparameter.name |
346 | 349 | |
347 | -def write_complex_parameter_attr(parent_elem, attribute): | |
350 | +def write_complex_parameter_attr(parent_elem, attribute_model, attribute): | |
348 | 351 | vColl_elem = etree.SubElement(parent_elem, 'vColl') |
349 | 352 | vColl_elem.attrib['org'] = 'set' |
350 | 353 | for value in attribute.values.order_by('parameter__type'): |
351 | - write_parameter(vColl_elem, value) | |
354 | + write_parameter(vColl_elem, attribute_model, value) | |
352 | 355 | |
353 | 356 | def write_simple_phrase_type_attr(parent_elem, attribute): |
354 | 357 | write_phrase(parent_elem, attribute.values.all()[0].argument, None) |
... | ... | @@ -360,7 +363,7 @@ def write_complex_phrase_type_attr(parent_elem, attribute): |
360 | 363 | write_phrases_set(parent_elem, phrases) |
361 | 364 | else: |
362 | 365 | complex_phrase_fs_elem = etree.SubElement(parent_elem, 'fs') |
363 | - complex_phrase_fs_elem.attrib['type'] = 'complexPhraseAttr' | |
366 | + complex_phrase_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] | |
364 | 367 | write_typed_phrase_attr(complex_phrase_fs_elem, attribute) |
365 | 368 | |
366 | 369 | def write_phrases_set(parent_elem, phrases): |
... | ... | @@ -373,19 +376,19 @@ def write_phrases_set(parent_elem, phrases): |
373 | 376 | def write_typed_phrase_attr(parent_elem, attribute): |
374 | 377 | selection_mode = attribute.selection_mode |
375 | 378 | type_f_elem = etree.SubElement(parent_elem, 'f') |
376 | - type_f_elem.attrib['name'] = 'type' | |
379 | + type_f_elem.attrib['name'] = 'name' | |
377 | 380 | symbol_elem = etree.SubElement(type_f_elem, 'symbol') |
378 | 381 | symbol_elem.attrib['value'] = selection_mode.name |
379 | 382 | |
380 | 383 | if attribute.values.exists(): |
381 | 384 | phrases_f_elem = etree.SubElement(parent_elem, 'f') |
382 | - phrases_f_elem.attrib['name'] = 'phrases' | |
385 | + phrases_f_elem.attrib['name'] = 'constraints' | |
383 | 386 | phrases = [value.argument for value in attribute.values.all()] |
384 | 387 | write_phrases_set(phrases_f_elem, phrases) |
385 | 388 | |
386 | 389 | def write_complex_position_attr(parent_elem, attribute): |
387 | 390 | complex_positions_fs_elem = etree.SubElement(parent_elem, 'fs') |
388 | - complex_positions_fs_elem.attrib['type'] = 'complexPositionsAttr' | |
391 | + complex_positions_fs_elem.attrib['type'] = '%s_def' % parent_elem.attrib['name'] | |
389 | 392 | |
390 | 393 | selection_mode = attribute.selection_mode |
391 | 394 | type_f_elem = etree.SubElement(complex_positions_fs_elem, 'f') |
... | ... | @@ -406,7 +409,7 @@ def write_complex_position_attr(parent_elem, attribute): |
406 | 409 | |
407 | 410 | def write_examples_layer(parent_elem, lemma): |
408 | 411 | examples_layer_elem = etree.SubElement(parent_elem, 'fs') |
409 | - examples_layer_elem.attrib['type'] = 'examplesLayer' | |
412 | + examples_layer_elem.attrib['type'] = 'examples_layer' | |
410 | 413 | |
411 | 414 | examples_f_elem = etree.SubElement(examples_layer_elem, 'f') |
412 | 415 | examples_f_elem.attrib['name'] = 'examples' |
... | ... | @@ -415,7 +418,7 @@ def write_examples_layer(parent_elem, lemma): |
415 | 418 | vColl_elem.attrib['org'] = 'set' |
416 | 419 | |
417 | 420 | write_examples_feature(vColl_elem, lemma) |
418 | - | |
421 | + | |
419 | 422 | def write_examples_feature(parent_elem, lemma): |
420 | 423 | entry = lemma.entry_obj |
421 | 424 | 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): |
467 | 470 | |
468 | 471 | meaning_link_elem = etree.SubElement(meaning_f_elem, 'fs') |
469 | 472 | meaning_link_elem.attrib['sameAs'] = meaning_xml_id |
470 | - meaning_link_elem.attrib['type'] = 'lexicalUnit' | |
473 | + meaning_link_elem.attrib['type'] = 'lexical_unit' | |
471 | 474 | except LexicalUnitExamples.DoesNotExist: |
472 | 475 | pass |
473 | 476 | |
... | ... | @@ -492,7 +495,7 @@ def create_and_write_phrase_link(parent_elem, entry, example, phrase_selection): |
492 | 495 | |
493 | 496 | def write_semantic_layer(parent_elem, lemma): |
494 | 497 | semantic_layer_elem = etree.SubElement(parent_elem, 'fs') |
495 | - semantic_layer_elem.attrib['type'] = 'semanticLayer' | |
498 | + semantic_layer_elem.attrib['type'] = 'semantic_layer' | |
496 | 499 | |
497 | 500 | frames_f_elem = etree.SubElement(semantic_layer_elem, 'f') |
498 | 501 | frames_f_elem.attrib['name'] = 'frames' |
... | ... | @@ -532,7 +535,7 @@ def write_frame_meaning_link(parent_elem, entry, meaning): |
532 | 535 | link = u'#wal_%d.%d-mng' % (entry.id, meaning.id) |
533 | 536 | lex_unit_link_elem = etree.SubElement(parent_elem, 'fs') |
534 | 537 | lex_unit_link_elem.attrib['sameAs'] = link |
535 | - lex_unit_link_elem.attrib['type'] = 'lexicalUnit' | |
538 | + lex_unit_link_elem.attrib['type'] = 'lexical_unit' | |
536 | 539 | |
537 | 540 | def write_frame_arguments(parent_elem, entry, frame): |
538 | 541 | arguments_f_elem = etree.SubElement(parent_elem, 'f') |
... | ... | @@ -559,7 +562,7 @@ def write_roles(parent_elem, arg): |
559 | 562 | for role in arg.roles.order_by('gradient'): |
560 | 563 | if role.gradient: |
561 | 564 | attribute_f_elem = etree.SubElement(parent_elem, 'f') |
562 | - attribute_f_elem.attrib['name'] = 'roleAttribute' | |
565 | + attribute_f_elem.attrib['name'] = 'role_attribute' | |
563 | 566 | attribute_symbol_elem = etree.SubElement(attribute_f_elem, 'symbol') |
564 | 567 | attribute_symbol_elem.attrib['value'] = unicode(role) |
565 | 568 | else: |
... | ... | @@ -571,10 +574,10 @@ def write_roles(parent_elem, arg): |
571 | 574 | def write_selective_preferences(parent_elem, arg, arg_base_id): |
572 | 575 | if(arg.selective_preference): |
573 | 576 | sel_prefs_f_elem = etree.SubElement(parent_elem, 'f') |
574 | - sel_prefs_f_elem.attrib['name'] = 'selPrefs' | |
577 | + sel_prefs_f_elem.attrib['name'] = 'sel_prefs' | |
575 | 578 | |
576 | 579 | sel_prefs_groups_fs_elem = etree.SubElement(sel_prefs_f_elem, 'fs') |
577 | - sel_prefs_groups_fs_elem.attrib['type'] = 'selPrefsGroups' | |
580 | + sel_prefs_groups_fs_elem.attrib['type'] = 'sel_prefs_groups' | |
578 | 581 | |
579 | 582 | write_synsets_sel_prefs(sel_prefs_groups_fs_elem, arg) |
580 | 583 | write_predefined_sel_prefs(sel_prefs_groups_fs_elem, arg) |
... | ... | @@ -594,12 +597,6 @@ def write_synsets_sel_prefs(parent_elem, arg): |
594 | 597 | write_synset(vColl_elem, synset) |
595 | 598 | |
596 | 599 | def write_synset(parent_elem, synset): |
597 | -# synset_fs_elem = etree.SubElement(parent_elem, 'fs') | |
598 | -# synset_fs_elem.attrib['type'] = 'synset' | |
599 | -# | |
600 | -# plWN_id_elem = etree.SubElement(synset_fs_elem, 'f') | |
601 | -# plWN_id_elem.attrib['name'] = 'plwnid' | |
602 | - | |
603 | 600 | id_numeric_elem = etree.SubElement(parent_elem, 'numeric') |
604 | 601 | id_numeric_elem.attrib['value'] = str(synset.id) |
605 | 602 | |
... | ... | @@ -616,12 +613,6 @@ def write_predefined_sel_prefs(parent_elem, arg): |
616 | 613 | write_predef(vColl_elem, predef) |
617 | 614 | |
618 | 615 | def write_predef(parent_elem, predef): |
619 | -# predef_fs_elem = etree.SubElement(parent_elem, 'fs') | |
620 | -# predef_fs_elem.attrib['type'] = 'predef' | |
621 | -# | |
622 | -# name_f_elem = etree.SubElement(predef_fs_elem, 'f') | |
623 | -# name_f_elem.attrib['name'] = 'name' | |
624 | - | |
625 | 616 | name_symbol_elem = etree.SubElement(parent_elem, 'symbol') |
626 | 617 | name_symbol_elem.attrib['value'] = predef.name |
627 | 618 | |
... | ... | @@ -644,10 +635,8 @@ def write_relation(parent_elem, relation, arg_base_id): |
644 | 635 | relation_f_elem = etree.SubElement(relation_fs_elem, 'f') |
645 | 636 | relation_f_elem.attrib['name'] = 'type' |
646 | 637 | |
647 | - type_string_elem = etree.SubElement(relation_f_elem, 'string') # TODO: tak ni powinno byc | |
648 | - type_string_elem.text = relation.relation.name | |
649 | -# type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') # @TODO: tak powinno byc zamiast stringa | |
650 | -# type_symbol_elem.attrib['value'] = relation.relation.name | |
638 | + type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') | |
639 | + type_symbol_elem.attrib['value'] = relation.relation.name | |
651 | 640 | |
652 | 641 | to_f_elem = etree.SubElement(relation_fs_elem, 'f') |
653 | 642 | to_f_elem.attrib['name'] = 'to' |
... | ... | @@ -661,7 +650,7 @@ def write_synset_relation_sel_prefs(parent_elem, arg): |
661 | 650 | relations = arg.selective_preference.synset_relations |
662 | 651 | if relations.exists(): |
663 | 652 | relations_f_elem = etree.SubElement(parent_elem, 'f') |
664 | - relations_f_elem.attrib['name'] = 'synsetRelations' | |
653 | + relations_f_elem.attrib['name'] = 'synset_relations' | |
665 | 654 | |
666 | 655 | vColl_elem = etree.SubElement(relations_f_elem, 'vColl') |
667 | 656 | vColl_elem.attrib['org'] = 'set' |
... | ... | @@ -671,15 +660,13 @@ def write_synset_relation_sel_prefs(parent_elem, arg): |
671 | 660 | |
672 | 661 | def write_synset_relation(parent_elem, relation): |
673 | 662 | relation_fs_elem = etree.SubElement(parent_elem, 'fs') |
674 | - relation_fs_elem.attrib['type'] = 'synsetRelation' | |
663 | + relation_fs_elem.attrib['type'] = 'synset_relation' | |
675 | 664 | |
676 | 665 | relation_f_elem = etree.SubElement(relation_fs_elem, 'f') |
677 | 666 | relation_f_elem.attrib['name'] = 'type' |
678 | 667 | |
679 | - type_string_elem = etree.SubElement(relation_f_elem, 'string') | |
680 | - type_string_elem.text = relation.relation.name | |
681 | -# type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') # @TODO: tak powinno byc zamiast stringa | |
682 | -# type_symbol_elem.attrib['value'] = relation.relation.name | |
668 | + type_symbol_elem = etree.SubElement(relation_f_elem, 'symbol') | |
669 | + type_symbol_elem.attrib['value'] = relation.relation.name | |
683 | 670 | |
684 | 671 | to_f_elem = etree.SubElement(relation_fs_elem, 'f') |
685 | 672 | to_f_elem.attrib['name'] = 'to' |
... | ... | @@ -687,7 +674,7 @@ def write_synset_relation(parent_elem, relation): |
687 | 674 | |
688 | 675 | def write_meanings_layer(parent_elem, lemma): |
689 | 676 | meanings_layer_elem = etree.SubElement(parent_elem, 'fs') |
690 | - meanings_layer_elem.attrib['type'] = 'meaningsLayer' | |
677 | + meanings_layer_elem.attrib['type'] = 'meanings_layer' | |
691 | 678 | |
692 | 679 | meanings_f_elem = etree.SubElement(meanings_layer_elem, 'f') |
693 | 680 | meanings_f_elem.attrib['name'] = 'meanings' |
... | ... | @@ -708,7 +695,7 @@ def write_meaning(parent_elem, entry, lex_unit): |
708 | 695 | |
709 | 696 | meaning_fs_elem = etree.SubElement(parent_elem, 'fs') |
710 | 697 | meaning_fs_elem.attrib[etree.QName(XML_NAMESPACE, 'id')] = meaning_xml_id |
711 | - meaning_fs_elem.attrib['type'] = 'lexicalUnit' | |
698 | + meaning_fs_elem.attrib['type'] = 'lexical_unit' | |
712 | 699 | |
713 | 700 | name_f_elem = etree.SubElement(meaning_fs_elem, 'f') |
714 | 701 | name_f_elem.attrib['name'] = 'name' |
... | ... | @@ -717,8 +704,8 @@ def write_meaning(parent_elem, entry, lex_unit): |
717 | 704 | |
718 | 705 | variant_f_elem = etree.SubElement(meaning_fs_elem, 'f') |
719 | 706 | variant_f_elem.attrib['name'] = 'variant' |
720 | - variant_symbol_elem = etree.SubElement(variant_f_elem, 'symbol') | |
721 | - variant_symbol_elem.attrib['value'] = lex_unit.sense | |
707 | + variant_string_elem = etree.SubElement(variant_f_elem, 'string') | |
708 | + variant_string_elem.text = lex_unit.sense | |
722 | 709 | |
723 | 710 | plwnluid_f_elem = etree.SubElement(meaning_fs_elem, 'f') |
724 | 711 | plwnluid_f_elem.attrib['name'] = 'plwnluid' |
... | ... | @@ -733,7 +720,7 @@ def write_meaning(parent_elem, entry, lex_unit): |
733 | 720 | |
734 | 721 | def write_connections_layer(parent_elem, lemma): |
735 | 722 | connections_layer_elem = etree.SubElement(parent_elem, 'fs') |
736 | - connections_layer_elem.attrib['type'] = 'connectionsLayer' | |
723 | + connections_layer_elem.attrib['type'] = 'connections_layer' | |
737 | 724 | |
738 | 725 | alternations_f_elem = etree.SubElement(connections_layer_elem, 'f') |
739 | 726 | alternations_f_elem.attrib['name'] = 'alternations' |
... | ... |