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 | subj = is_subj(categories) |
8 | 8 | b = argument.type |
9 | 9 | if b == 'fixed': |
10 | - return get_words(sortatributes(argument)[-1]) | |
10 | + return (get_words(sortatributes(argument)[-1]), []) | |
11 | 11 | attributes = sortatributes(argument) |
12 | 12 | lexicalisation_type = attributes[0].values.all()[0].argument.type |
13 | 13 | lexicalisation_parameters = sortatributes(attributes[0].values.all()[0].argument) |
... | ... | @@ -21,8 +21,8 @@ def lexicalisation(argument, categories, base): |
21 | 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 | 22 | return (prepnps, []) |
23 | 23 | else: |
24 | - return [] | |
25 | - return [] | |
24 | + return ([], []) | |
25 | + return ([], []) | |
26 | 26 | |
27 | 27 | def is_subj(categories): |
28 | 28 | for cat in categories: |
... | ... |
semantics/saving.py
... | ... | @@ -95,7 +95,7 @@ def make_operations(lemma_id, operations): |
95 | 95 | else: |
96 | 96 | frame_id = int(operation['frame_id']) |
97 | 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 | 99 | elif operation['operation'] == "set_opinion": |
100 | 100 | if int(operation['frame_id']) in translation['frame_id']: |
101 | 101 | frame_id = translation['frame_id'][int(operation['frame_id'])] |
... | ... | @@ -207,11 +207,13 @@ def validate_roles(roles): |
207 | 207 | ok = not ok |
208 | 208 | return ok |
209 | 209 | |
210 | -def change_units(frame_id, luids): | |
210 | +def change_units(lemma_id, frame_id, luids): | |
211 | 211 | frame = SemanticFrame.objects.get(id=frame_id) |
212 | 212 | frame.lexical_units = [] |
213 | 213 | for id in luids: |
214 | 214 | lu = LexicalUnit.objects.get(id=id) |
215 | + lu.entry = Lemma.objects.get(id=lemma_id).entry_obj | |
216 | + lu.save() | |
215 | 217 | frame.lexical_units.add(lu) |
216 | 218 | |
217 | 219 | def set_opinion(frame_id, opinion): |
... | ... |
semantics/sem_urls.py
... | ... | @@ -25,4 +25,5 @@ SEMANTIC_PATTERNS = patterns('semantics.views', |
25 | 25 | url(r'^ajax/general_preference_form/$', 'general_preference_form'), |
26 | 26 | url(r'^ajax/synset_preference_form/$', 'synset_preference_form'), |
27 | 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 | 228 | for (k = 0; k < schemas_content[sch].display.arguments[0].length; k++) { |
229 | 229 | var proper = schemas_content[sch].display.arguments[0][k].csv_id + "alt_" + sid_alt[1] + "_"; |
230 | 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 | 233 | pre.push(schemas_content[sch].display.arguments[0][k].lex); |
233 | 234 | vrb = schemas_content[sch].display.arguments[0][k].vrb; |
234 | 235 | } else { |
... | ... | @@ -329,17 +330,28 @@ function lexicalisationForm(lemma, pre, tokenised) { |
329 | 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 | 344 | var display = ""; |
333 | 345 | var i, j; |
334 | 346 | for (i = 0; i < list.length; i++) { |
335 | 347 | var included = false; |
336 | 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 | 350 | included = true; |
339 | 351 | } |
340 | 352 | } |
341 | 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 | 357 | return display; |
... | ... | @@ -353,7 +365,7 @@ function noSubjUnits(lemmata, dependants) { |
353 | 365 | result.push(lemmata[i]); |
354 | 366 | } else { |
355 | 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 | 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 | 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 | 452 | var i; |
432 | 453 | for (i = 0; i < connected[lem].length; i++) { |
433 | 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 | 458 | return unique(result); |
... | ... |
semantics/static/js/semantics_view.js
... | ... | @@ -397,6 +397,8 @@ function changeLexicalUnits() { |
397 | 397 | |
398 | 398 | var units = []; |
399 | 399 | var mwes = []; |
400 | + var new_mwes = []; | |
401 | + var old_mwes = []; | |
400 | 402 | var a = ""; |
401 | 403 | var gloss = ""; |
402 | 404 | |
... | ... | @@ -411,7 +413,7 @@ function changeLexicalUnits() { |
411 | 413 | if (v == 1) { |
412 | 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 | 418 | frameClick(""); |
417 | 419 | displayFrames(); |
... | ... | @@ -445,8 +447,46 @@ function changeLexicalUnits() { |
445 | 447 | frameClick(a); |
446 | 448 | $.prompt.close(); |
447 | 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 | 522 | $.prompt.goToState('state2'); |
483 | 523 | } else { |
484 | 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 | 526 | frameClick(""); |
487 | 527 | displayFrames(); |
488 | 528 | frameClick(a) |
... | ... |
semantics/views.py
... | ... | @@ -48,6 +48,7 @@ def ajax_semantics(request, id): |
48 | 48 | 'ajax_relations': reverse('ajax_relations'), |
49 | 49 | 'ajax_predefined_preferences': reverse('ajax_predefined_preferences'), |
50 | 50 | 'ajax_plWN_context_lookup': reverse('ajax_plWN_context_lookup'), |
51 | + 'ajax_get_mwes': reverse('ajax_get_mwes'), | |
51 | 52 | } |
52 | 53 | return context |
53 | 54 | |
... | ... | @@ -453,7 +454,8 @@ def ajax_schemas(request, lemma_id): |
453 | 454 | for i, c, a, p in zip(idents, schema_ids, row, ordered_positions): |
454 | 455 | astr, aobj = a |
455 | 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 | 459 | else: |
458 | 460 | lex, vrb = ([], []) |
459 | 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 | 645 | def relational_preference_form(request): |
644 | 646 | form = RelationalSelPrefForm() |
645 | 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} | |
... | ... |