Commit ae00e34b4af4b4a9271a17725bad0308d2b75453
1 parent
1e554291
Powiązanie frazeologii ze Słowosiecią
Showing
6 changed files
with
100 additions
and
20 deletions
semantics/phraseology_generator.py
@@ -7,7 +7,7 @@ def lexicalisation(argument, categories, base): | @@ -7,7 +7,7 @@ def lexicalisation(argument, categories, base): | ||
7 | subj = is_subj(categories) | 7 | subj = is_subj(categories) |
8 | b = argument.type | 8 | b = argument.type |
9 | if b == 'fixed': | 9 | if b == 'fixed': |
10 | - return get_words(sortatributes(argument)[-1]) | 10 | + return (get_words(sortatributes(argument)[-1]), []) |
11 | attributes = sortatributes(argument) | 11 | attributes = sortatributes(argument) |
12 | lexicalisation_type = attributes[0].values.all()[0].argument.type | 12 | lexicalisation_type = attributes[0].values.all()[0].argument.type |
13 | lexicalisation_parameters = sortatributes(attributes[0].values.all()[0].argument) | 13 | lexicalisation_parameters = sortatributes(attributes[0].values.all()[0].argument) |
@@ -21,8 +21,8 @@ def lexicalisation(argument, categories, base): | @@ -21,8 +21,8 @@ def lexicalisation(argument, categories, base): | ||
21 | prepnps = get_prepnps(get_preposition(lexicalisation_parameters[0]), get_case(lexicalisation_parameters[1], subj), get_number(attributes[1], subj), get_words(attributes[2]), attributes[3]) | 21 | prepnps = get_prepnps(get_preposition(lexicalisation_parameters[0]), get_case(lexicalisation_parameters[1], subj), get_number(attributes[1], subj), get_words(attributes[2]), attributes[3]) |
22 | return (prepnps, []) | 22 | return (prepnps, []) |
23 | else: | 23 | else: |
24 | - return [] | ||
25 | - return [] | 24 | + return ([], []) |
25 | + return ([], []) | ||
26 | 26 | ||
27 | def is_subj(categories): | 27 | def is_subj(categories): |
28 | for cat in categories: | 28 | for cat in categories: |
semantics/saving.py
@@ -95,7 +95,7 @@ def make_operations(lemma_id, operations): | @@ -95,7 +95,7 @@ def make_operations(lemma_id, operations): | ||
95 | else: | 95 | else: |
96 | frame_id = int(operation['frame_id']) | 96 | frame_id = int(operation['frame_id']) |
97 | luids = [translation['unit_id'][int(m)] if int(m) in translation['unit_id'] else int(m) for m in operation['units']] | 97 | luids = [translation['unit_id'][int(m)] if int(m) in translation['unit_id'] else int(m) for m in operation['units']] |
98 | - change_units(frame_id, luids) | 98 | + change_units(lemma_id, frame_id, luids) |
99 | elif operation['operation'] == "set_opinion": | 99 | elif operation['operation'] == "set_opinion": |
100 | if int(operation['frame_id']) in translation['frame_id']: | 100 | if int(operation['frame_id']) in translation['frame_id']: |
101 | frame_id = translation['frame_id'][int(operation['frame_id'])] | 101 | frame_id = translation['frame_id'][int(operation['frame_id'])] |
@@ -207,11 +207,13 @@ def validate_roles(roles): | @@ -207,11 +207,13 @@ def validate_roles(roles): | ||
207 | ok = not ok | 207 | ok = not ok |
208 | return ok | 208 | return ok |
209 | 209 | ||
210 | -def change_units(frame_id, luids): | 210 | +def change_units(lemma_id, frame_id, luids): |
211 | frame = SemanticFrame.objects.get(id=frame_id) | 211 | frame = SemanticFrame.objects.get(id=frame_id) |
212 | frame.lexical_units = [] | 212 | frame.lexical_units = [] |
213 | for id in luids: | 213 | for id in luids: |
214 | lu = LexicalUnit.objects.get(id=id) | 214 | lu = LexicalUnit.objects.get(id=id) |
215 | + lu.entry = Lemma.objects.get(id=lemma_id).entry_obj | ||
216 | + lu.save() | ||
215 | frame.lexical_units.add(lu) | 217 | frame.lexical_units.add(lu) |
216 | 218 | ||
217 | def set_opinion(frame_id, opinion): | 219 | def set_opinion(frame_id, opinion): |
semantics/sem_urls.py
@@ -25,4 +25,5 @@ SEMANTIC_PATTERNS = patterns('semantics.views', | @@ -25,4 +25,5 @@ SEMANTIC_PATTERNS = patterns('semantics.views', | ||
25 | url(r'^ajax/general_preference_form/$', 'general_preference_form'), | 25 | url(r'^ajax/general_preference_form/$', 'general_preference_form'), |
26 | url(r'^ajax/synset_preference_form/$', 'synset_preference_form'), | 26 | url(r'^ajax/synset_preference_form/$', 'synset_preference_form'), |
27 | url(r'^ajax/relational_preference_form/$', 'relational_preference_form'), | 27 | url(r'^ajax/relational_preference_form/$', 'relational_preference_form'), |
28 | + url(r'^ajax/get_mwe_list/$', 'ajax_get_mwes'), | ||
28 | ) | 29 | ) |
semantics/static/js/semantics_lexical_units.js
@@ -228,7 +228,8 @@ function getMeaningsSelectionForFrame(frame_id) { | @@ -228,7 +228,8 @@ function getMeaningsSelectionForFrame(frame_id) { | ||
228 | for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) { | 228 | for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) { |
229 | var proper = schemas_content[sch].display.arguments[0][k].csv_id + "alt_" + sid_alt[1] + "_"; | 229 | var proper = schemas_content[sch].display.arguments[0][k].csv_id + "alt_" + sid_alt[1] + "_"; |
230 | if (connected[lem].indexOf(proper) != -1) { | 230 | if (connected[lem].indexOf(proper) != -1) { |
231 | - if (schemas_content[sch].display.arguments[0][k].vrb.length > 0) { | 231 | + if (schemas_content[sch].display.arguments[0][k].vrb != null && |
232 | + schemas_content[sch].display.arguments[0][k].vrb.length > 0) { | ||
232 | pre.push(schemas_content[sch].display.arguments[0][k].lex); | 233 | pre.push(schemas_content[sch].display.arguments[0][k].lex); |
233 | vrb = schemas_content[sch].display.arguments[0][k].vrb; | 234 | vrb = schemas_content[sch].display.arguments[0][k].vrb; |
234 | } else { | 235 | } else { |
@@ -329,17 +330,28 @@ function lexicalisationForm(lemma, pre, tokenised) { | @@ -329,17 +330,28 @@ function lexicalisationForm(lemma, pre, tokenised) { | ||
329 | list = subjUnits(pre, lemma, tokenised); | 330 | list = subjUnits(pre, lemma, tokenised); |
330 | } | 331 | } |
331 | 332 | ||
333 | + $.ajax({ | ||
334 | + type: "GET", | ||
335 | + dataType: "json", | ||
336 | + url: ajax_get_mwes, | ||
337 | + data: {"options": JSON.stringify(list)}, | ||
338 | + success: function(data){ | ||
339 | + list = data.mwes; | ||
340 | + }, | ||
341 | + async: false | ||
342 | + }); | ||
343 | + | ||
332 | var display = ""; | 344 | var display = ""; |
333 | var i, j; | 345 | var i, j; |
334 | for (i = 0; i < list.length; i++) { | 346 | for (i = 0; i < list.length; i++) { |
335 | var included = false; | 347 | var included = false; |
336 | for (j = 0; j < lexical_units.length; j++) { | 348 | for (j = 0; j < lexical_units.length; j++) { |
337 | - if (list[i] == lexical_units[j].base) { | 349 | + if (list[i].base == lexical_units[j].base) { |
338 | included = true; | 350 | included = true; |
339 | } | 351 | } |
340 | } | 352 | } |
341 | if (!included) { | 353 | if (!included) { |
342 | - display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + list[i] + "\">" + list[i] + "<br\>"; | 354 | + display += "<input type = \"checkbox\" name = \"mwe\" value = \"" + list[i].base + list[i].sense + "_" + list[i].id + "_" + list[i].luid + "_" + list[i].sid + "\">" + list[i].base + list[i].sense + "<br\>"; |
343 | } | 355 | } |
344 | } | 356 | } |
345 | return display; | 357 | return display; |
@@ -353,7 +365,7 @@ function noSubjUnits(lemmata, dependants) { | @@ -353,7 +365,7 @@ function noSubjUnits(lemmata, dependants) { | ||
353 | result.push(lemmata[i]); | 365 | result.push(lemmata[i]); |
354 | } else { | 366 | } else { |
355 | for (j = 0; j < dependants.length; j++) { | 367 | for (j = 0; j < dependants.length; j++) { |
356 | - result.push(lemmata[i] + dependants[j].join(" ")); | 368 | + result.push(lemmata[i] + " " + dependants[j].join(" ")); |
357 | } | 369 | } |
358 | } | 370 | } |
359 | } | 371 | } |
@@ -414,13 +426,22 @@ function addPhraseologicalUnit(mwe, glossa, relation, to) { | @@ -414,13 +426,22 @@ function addPhraseologicalUnit(mwe, glossa, relation, to) { | ||
414 | return (free_luid + 1); | 426 | return (free_luid + 1); |
415 | } | 427 | } |
416 | 428 | ||
417 | -function addPhraseologicalUnits(frame_id, old_units, mwes, glossa, relation, to) { | 429 | +function unlockPhraseologicalUnit(mwe) { |
430 | + var lu = {base: mwe.lu.split('-')[0], glossa: "", definition: "", id: mwe.id, luid: mwe.luid, refl: false, glossa: "", pos: "czasownik", sense: mwe.lu.split('-')[1], relation: 2, to: -1, location: ""}; | ||
431 | + lexical_units.push(lu); | ||
432 | + return mwe.id; | ||
433 | +} | ||
434 | + | ||
435 | +function addPhraseologicalUnits(frame_id, old_units, old_mwes, new_mwes, glossa, relation, to) { | ||
418 | var i; | 436 | var i; |
419 | - var units = []; | ||
420 | - for (i = 0; i < mwes.length; i++) { | ||
421 | - units.push(addPhraseologicalUnit(mwes[i], glossa, relation, to)); | 437 | + var units = old_units.slice(); |
438 | + for (i = 0; i < old_mwes.length; i++) { | ||
439 | + units.push(unlockPhraseologicalUnit(old_mwes[i])); | ||
440 | + } | ||
441 | + for (i = 0; i < new_mwes.length; i++) { | ||
442 | + units.push(addPhraseologicalUnit(new_mwes[i], glossa, relation, to)); | ||
422 | } | 443 | } |
423 | - changeUnits(frame_id, old_units.concat(units)); | 444 | + changeUnits(frame_id, units); |
424 | } | 445 | } |
425 | 446 | ||
426 | 447 | ||
@@ -431,7 +452,7 @@ function getPhraseologicalAlternations(frame_id) { | @@ -431,7 +452,7 @@ function getPhraseologicalAlternations(frame_id) { | ||
431 | var i; | 452 | var i; |
432 | for (i = 0; i < connected[lem].length; i++) { | 453 | for (i = 0; i < connected[lem].length; i++) { |
433 | var ids = connected[lem][i].split('_'); | 454 | var ids = connected[lem][i].split('_'); |
434 | - result.push(ids[1] + "_" + ids[7]) | 455 | + result.push(ids[1] + "_" + ids[7]); |
435 | } | 456 | } |
436 | } | 457 | } |
437 | return unique(result); | 458 | return unique(result); |
semantics/static/js/semantics_view.js
@@ -397,6 +397,8 @@ function changeLexicalUnits() { | @@ -397,6 +397,8 @@ function changeLexicalUnits() { | ||
397 | 397 | ||
398 | var units = []; | 398 | var units = []; |
399 | var mwes = []; | 399 | var mwes = []; |
400 | + var new_mwes = []; | ||
401 | + var old_mwes = []; | ||
400 | var a = ""; | 402 | var a = ""; |
401 | var gloss = ""; | 403 | var gloss = ""; |
402 | 404 | ||
@@ -411,7 +413,7 @@ function changeLexicalUnits() { | @@ -411,7 +413,7 @@ function changeLexicalUnits() { | ||
411 | if (v == 1) { | 413 | if (v == 1) { |
412 | changeUnits(highlighted_id, units); | 414 | changeUnits(highlighted_id, units); |
413 | 415 | ||
414 | - addPhraseologicalUnits(highlighted_id, units, mwes, f.glossa, f.relation, f.synset); | 416 | + addPhraseologicalUnits(highlighted_id, units, old_mwes, new_mwes, f.glossa, f.relation, f.synset); |
415 | 417 | ||
416 | frameClick(""); | 418 | frameClick(""); |
417 | displayFrames(); | 419 | displayFrames(); |
@@ -445,8 +447,46 @@ function changeLexicalUnits() { | @@ -445,8 +447,46 @@ function changeLexicalUnits() { | ||
445 | frameClick(a); | 447 | frameClick(a); |
446 | $.prompt.close(); | 448 | $.prompt.close(); |
447 | } else { | 449 | } else { |
448 | - $.prompt.goToState('state1'); | ||
449 | - attachPlWNContextAutocomplete(); | 450 | + |
451 | + var i; | ||
452 | + for (i = 0; i < mwes.length; i++) { | ||
453 | + var lu = mwes[i].split('_')[0]; | ||
454 | + var id = mwes[i].split('_')[1]; | ||
455 | + var luid = mwes[i].split('_')[2]; | ||
456 | + var sid = mwes[i].split('_')[3]; | ||
457 | + if (sid == '') { | ||
458 | + new_mwes.push(lu); | ||
459 | + } else { | ||
460 | + old_mwes.push({lu: lu, id: parseInt(id), luid: parseInt(luid), sid: parseInt(sid)}); | ||
461 | + } | ||
462 | + } | ||
463 | + | ||
464 | + if (old_mwes.length > 0) { | ||
465 | + var sid = old_mwes[0].sid | ||
466 | + var ok = true; | ||
467 | + for (i = 0; i < old_mwes.length; i++) { | ||
468 | + if (old_mwes[i].sid != sid) { | ||
469 | + ok = false; | ||
470 | + } | ||
471 | + } | ||
472 | + if (ok) { | ||
473 | + changeUnits(highlighted_id, units); | ||
474 | + | ||
475 | + | ||
476 | + addPhraseologicalUnits(highlighted_id, units, old_mwes, new_mwes, old_mwes[0].lu, 1, sid); | ||
477 | + | ||
478 | + frameClick(""); | ||
479 | + displayFrames(); | ||
480 | + frameClick(a); | ||
481 | + $.prompt.close(); | ||
482 | + } else { | ||
483 | + $.prompt.goToState('state1'); | ||
484 | + attachPlWNContextAutocomplete(); | ||
485 | + } | ||
486 | + } else { | ||
487 | + $.prompt.goToState('state1'); | ||
488 | + attachPlWNContextAutocomplete(); | ||
489 | + } | ||
450 | } | 490 | } |
451 | 491 | ||
452 | } | 492 | } |
@@ -482,7 +522,7 @@ function changeLexicalUnits() { | @@ -482,7 +522,7 @@ function changeLexicalUnits() { | ||
482 | $.prompt.goToState('state2'); | 522 | $.prompt.goToState('state2'); |
483 | } else { | 523 | } else { |
484 | /* zignorowane umiejscowienie w Słowosieci */ | 524 | /* zignorowane umiejscowienie w Słowosieci */ |
485 | - addPhraseologicalUnits(highlighted_id, units, mwes, f.glossa, f.relation, -1); | 525 | + addPhraseologicalUnits(highlighted_id, units, old_mwes, new_mwes, f.glossa, f.relation, -1); |
486 | frameClick(""); | 526 | frameClick(""); |
487 | displayFrames(); | 527 | displayFrames(); |
488 | frameClick(a) | 528 | frameClick(a) |
semantics/views.py
@@ -48,6 +48,7 @@ def ajax_semantics(request, id): | @@ -48,6 +48,7 @@ def ajax_semantics(request, id): | ||
48 | 'ajax_relations': reverse('ajax_relations'), | 48 | 'ajax_relations': reverse('ajax_relations'), |
49 | 'ajax_predefined_preferences': reverse('ajax_predefined_preferences'), | 49 | 'ajax_predefined_preferences': reverse('ajax_predefined_preferences'), |
50 | 'ajax_plWN_context_lookup': reverse('ajax_plWN_context_lookup'), | 50 | 'ajax_plWN_context_lookup': reverse('ajax_plWN_context_lookup'), |
51 | + 'ajax_get_mwes': reverse('ajax_get_mwes'), | ||
51 | } | 52 | } |
52 | return context | 53 | return context |
53 | 54 | ||
@@ -453,7 +454,8 @@ def ajax_schemas(request, lemma_id): | @@ -453,7 +454,8 @@ def ajax_schemas(request, lemma_id): | ||
453 | for i, c, a, p in zip(idents, schema_ids, row, ordered_positions): | 454 | for i, c, a, p in zip(idents, schema_ids, row, ordered_positions): |
454 | astr, aobj = a | 455 | astr, aobj = a |
455 | if aobj is not None and aobj.is_phraseologic(): | 456 | if aobj is not None and aobj.is_phraseologic(): |
456 | - lex, vrb = lexicalisation(aobj, p.categories.all(), lemma.entry_obj.name) | 457 | + tmp = lexicalisation(aobj, p.categories.all(), lemma.entry_obj.name) |
458 | + lex, vrb = tmp | ||
457 | else: | 459 | else: |
458 | lex, vrb = ([], []) | 460 | lex, vrb = ([], []) |
459 | arg.append({"csv_id": i, "csv_class": c, "argument": astr, "lex": lex, "vrb": vrb}) | 461 | arg.append({"csv_id": i, "csv_class": c, "argument": astr, "lex": lex, "vrb": vrb}) |
@@ -643,3 +645,17 @@ def synset_preference_form(request): | @@ -643,3 +645,17 @@ def synset_preference_form(request): | ||
643 | def relational_preference_form(request): | 645 | def relational_preference_form(request): |
644 | form = RelationalSelPrefForm() | 646 | form = RelationalSelPrefForm() |
645 | return {'form': form} | 647 | return {'form': form} |
648 | + | ||
649 | +@ajax(method='get', encode_result=True) | ||
650 | +def ajax_get_mwes(request, options): | ||
651 | + results = [] | ||
652 | + for term in options: | ||
653 | + term = unicode(term) | ||
654 | + if len(term) > 0: | ||
655 | + obj_results = LexicalUnit.objects.filter(base=term) | ||
656 | + if len(obj_results) > 0: | ||
657 | + for lu in obj_results: | ||
658 | + results.append({'base': lu.base, 'sense': '-' + str(lu.sense), 'id': lu.id, 'luid': lu.luid, 'sid': lu.synset.id}) | ||
659 | + else: | ||
660 | + results.append({'base': term, 'sense': '', 'id': term, 'luid': -1, 'sid': ''}) | ||
661 | + return {'mwes': results} |