Commit f8298e06c221a46f07c70a291ee7ad18dbb56cf8
1 parent
665a23d5
adding missing file
Showing
1 changed file
with
67 additions
and
0 deletions
semantics/phraseology_generator.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | ||
2 | + | ||
3 | +from dictionary.models import sort_arguments, sort_positions, sortatributes | ||
4 | +from settings import MORFEUSZ2 | ||
5 | + | ||
6 | +def lexicalisation(argument): | ||
7 | + b = argument.type | ||
8 | + if b == 'fixed': | ||
9 | + return get_words(sortatributes(argument)[-1]) | ||
10 | + attributes = sortatributes(argument) | ||
11 | + lexicalisation_type = attributes[0].values.all()[0].argument.type | ||
12 | + lexicalisation_parameters = sortatributes(attributes[0].values.all()[0].argument) | ||
13 | + if lexicalisation_type == 'xp': # xp(...)[np/prepnp], ... | ||
14 | + lexicalisation_type = lexicalisation_parameters[0].values.all()[0].argument.type | ||
15 | + lexicalisation_parameters = sortatributes(lexicalisation_parameters[0].values.all()[0].argument) | ||
16 | + if lexicalisation_type == 'np': # np(case), number, nouns, atr | ||
17 | + nps = get_nps(get_case(lexicalisation_parameters[0]), get_number(attributes[1]), get_words(attributes[2]), attributes[3]) | ||
18 | + return nps | ||
19 | + elif lexicalisation_type == 'prepnp': #prepnp(prep, case), number, nouns, atr | ||
20 | + prepnps = get_prepnps(get_preposition(lexicalisation_parameters[0]), get_case(lexicalisation_parameters[1]), get_number(attributes[1]), get_words(attributes[2]), attributes[3]) | ||
21 | + return prepnps | ||
22 | + else: | ||
23 | + return [] | ||
24 | + return [] | ||
25 | + | ||
26 | +def get_preposition(attribute): | ||
27 | + return attribute.values.all()[0].parameter.type.name | ||
28 | + | ||
29 | +def get_words(attribute): | ||
30 | + words = [word.text[1:-1] for word in attribute.values.all()] | ||
31 | + return words | ||
32 | + | ||
33 | +def get_case(attribute): | ||
34 | + case = attribute.values.all()[0].parameter.type.name | ||
35 | + if case == u'str': | ||
36 | + case = u'acc' | ||
37 | + return case | ||
38 | + | ||
39 | +def get_number(attribute): | ||
40 | + number = attribute.values.all()[0].parameter.type.name | ||
41 | + return number | ||
42 | + | ||
43 | +def get_nps(case, number, nouns, _atr): | ||
44 | + result = [] | ||
45 | + for noun in nouns: | ||
46 | + options = [(interp.orth, interp.getTag(MORFEUSZ2)) for interp in MORFEUSZ2.generate(noun.encode('utf8'))] | ||
47 | + if case != u'_': | ||
48 | + filtered = [] | ||
49 | + for option in options: | ||
50 | + (orth, tag) = option | ||
51 | + if case in tag: | ||
52 | + filtered.append(option) | ||
53 | + options = filtered | ||
54 | + if number != u'_': | ||
55 | + filtered = [] | ||
56 | + for option in options: | ||
57 | + (orth, tag) = option | ||
58 | + if number in tag: | ||
59 | + filtered.append(option) | ||
60 | + options = filtered | ||
61 | + return [orth for orth, _ in options] | ||
62 | + | ||
63 | +def get_prepnps(prep, case, number, nouns, _atr): | ||
64 | + # ala["ma"] = kot | ||
65 | + nps = get_nps(case, number, nouns, _atr) | ||
66 | + return [prep + ' ' + np for np in nps] | ||
67 | + |