Commit 665a23d592e3ebb777407beaa64da01f5b382bfc

Authored by Tomasz Bartosiak
1 parent a2a93359

xp in phraseology

Showing 1 changed file with 2 additions and 58 deletions
semantics/views.py
... ... @@ -19,6 +19,8 @@ from semantics.forms import GeneralSelPrefForm, RelationalSelPrefForm, RoleForm,
19 19 from semantics.saving import modify_frames, update_meanings
20 20 from semantics.validation import validate_schemas, validate_frames, validate_lexical_units
21 21  
  22 +from semantics.phraseology_generator import lexicalisation
  23 +
22 24 from settings import MORFEUSZ2
23 25  
24 26 ####################################### render #####################################
... ... @@ -476,64 +478,6 @@ def ajax_schemas(request, lemma_id):
476 478  
477 479 return context
478 480  
479   -def lexicalisation(argument):
480   - b = argument.type
481   - if b == 'fixed':
482   - return get_words(sortatributes(argument)[-1])
483   - attributes = sortatributes(argument)
484   - lexicalisation_type = attributes[0].values.all()[0].argument.type
485   - lexicalisation_parameters = sortatributes(attributes[0].values.all()[0].argument)
486   - if lexicalisation_type == 'np': # np(case), number, nouns, atr
487   - nps = get_nps(get_case(lexicalisation_parameters[0]), get_number(attributes[1]), get_words(attributes[2]), attributes[3])
488   - return nps
489   - elif lexicalisation_type == 'prepnp': #prepnp(prep, case), number, nouns, atr
490   - prepnps = get_prepnps(get_preposition(lexicalisation_parameters[0]), get_case(lexicalisation_parameters[1]), get_number(attributes[1]), get_words(attributes[2]), attributes[3])
491   - return prepnps
492   - else:
493   - return []
494   - return []
495   -
496   -def get_preposition(attribute):
497   - return attribute.values.all()[0].parameter.type.name
498   -
499   -def get_words(attribute):
500   - words = [word.text[1:-1] for word in attribute.values.all()]
501   - return words
502   -
503   -def get_case(attribute):
504   - case = attribute.values.all()[0].parameter.type.name
505   - if case == u'str':
506   - case = u'acc'
507   - return case
508   -
509   -def get_number(attribute):
510   - number = attribute.values.all()[0].parameter.type.name
511   - return number
512   -
513   -def get_nps(case, number, nouns, _atr):
514   - result = []
515   - for noun in nouns:
516   - options = [(interp.orth, interp.getTag(MORFEUSZ2)) for interp in MORFEUSZ2.generate(noun.encode('utf8'))]
517   - if case != u'_':
518   - filtered = []
519   - for option in options:
520   - (orth, tag) = option
521   - if case in tag:
522   - filtered.append(option)
523   - options = filtered
524   - if number != u'_':
525   - filtered = []
526   - for option in options:
527   - (orth, tag) = option
528   - if number in tag:
529   - filtered.append(option)
530   - options = filtered
531   - return [orth for orth, _ in options]
532   -
533   -def get_prepnps(prep, case, number, nouns, _atr):
534   - nps = get_nps(case, number, nouns, _atr)
535   - return [prep + ' ' + np for np in nps]
536   -
537 481 @render('examples.json')
538 482 @ajax(method='get', encode_result=False)
539 483 def ajax_examples(request, lemma_id):
... ...