from .name import SIMPLE_NAME
from .person import POSITION_NAME

from yargy_uk.rule.transformators import RuleTransformator


class StripInterpretationTransformator(RuleTransformator):
    def visit_InterpretationRule(self, item):
        return self.visit(item.rule)


NAME = SIMPLE_NAME.transform(StripInterpretationTransformator)
PERSON = POSITION_NAME.transform(StripInterpretationTransformator)


Organisation = fact('Organisation', ['name'])


TYPE = morph_pipeline([
    'АО',
    'ОАО',
    'ООО',
    'ЗАО',
    'ПАО',

    # TODO Check abbrs
    # 'ик',
    # 'нк',
    # 'хк',
    # 'ип',
    # 'чп',
Beispiel #2
0
from yargy_uk.predicates import (
    gram, tag,
    is_capitalized, vesum_tag
)
from yargy_uk.predicates.bank import DictionaryPredicate as dictionary
from yargy_uk.relations import gnc_relation

from natasha_uk.data import load_dict

from yargy_uk.rule.transformators import RuleTransformator
from yargy_uk.rule.constructors import Rule
from yargy_uk.predicates.constructors import AndPredicate


Name = fact(
    'Name',
    ['first', 'middle', 'last', 'nick']
)


FIRST_DICT = set(load_dict('first_uk.txt'))
MAYBE_FIRST_DICT = set(load_dict('maybe_first.txt'))
LAST_DICT = set(load_dict('last_uk.txt'))


##########
#
#  COMPONENTS
#
###########

Beispiel #3
0
# coding: utf-8
from __future__ import unicode_literals

from yargy_uk import (rule, or_, and_)
from yargy_uk.interpretation import fact, attribute
from yargy_uk.predicates import (eq, lte, gte, gram, type, tag, length_eq, in_,
                                 in_caseless, dictionary, normalized, caseless,
                                 is_title)
from yargy_uk.pipelines import morph_pipeline
from yargy_uk.tokenizer import QUOTES

Address = fact('Address', [attribute('parts').repeatable()])
Index = fact('Index', ['value'])
Country = fact('Country', ['name'])
Region = fact('Region', ['name', 'type'])
Settlement = fact('Settlement', ['name', 'type'])
Street = fact('Street', ['name', 'type'])
Building = fact('Building', ['number', 'type'])
Room = fact('Room', ['number', 'type'])

DASH = eq('-')
DOT = eq('.')

ADJF = gram('ADJF')
NOUN = gram('NOUN')
INT = type('INT')
TITLE = is_title()

ANUM = rule(INT, DASH.optional(),
            in_caseless({'я', 'й', 'е', 'ое', 'ая', 'ий', 'ой'}))
Beispiel #4
0
# coding: utf-8
from __future__ import unicode_literals

from yargy_uk import (rule, and_, or_)
from yargy_uk.interpretation import fact, attribute
from yargy_uk.predicates import (
    eq,
    gte,
    lte,
    length_eq,
    dictionary,
    normalized,
)

Date = fact('Date', ['year', 'month', 'day', attribute('current_era', True)])

MONTHS = {
    'січень': 1,
    'лютий': 2,
    'березень': 3,
    'квітень': 4,
    'травень': 5,
    'червень': 6,
    'липень': 7,
    'серпень': 8,
    'вересень': 9,
    'жовтень': 10,
    'листопад': 11,
    'грудень': 12,
}
Beispiel #5
0
from __future__ import unicode_literals, division

import re

from yargy_uk import (
    rule,
    and_,
    or_,
)
from yargy_uk.interpretation import (fact, const)
from yargy_uk.predicates import (eq, length_eq, in_, in_caseless, gram, type,
                                 normalized, caseless, dictionary)

from natasha_uk.dsl import (Normalizable, money as dsl)

Money = fact('Money',
             ['integer', 'fraction', 'multiplier', 'currency', 'coins'])


class Money(Money, Normalizable):
    @property
    def normalized(self):
        amount = self.integer
        if self.fraction:
            amount += self.fraction / 100
        if self.multiplier:
            amount *= self.multiplier
        if self.coins:
            amount += self.coins / 100
        return dsl.Money(amount, self.currency)

Beispiel #6
0
# coding: utf-8
from __future__ import unicode_literals

from yargy_uk import (rule, and_, or_, not_)
from yargy_uk.interpretation import fact
from yargy_uk.predicates import (
    gram,
    dictionary,
    vesum_tag,
)

Location = fact(
    'Location',
    ['name'],
)

ADJECTIVE_TAG = or_(gram('ADJF'), vesum_tag('adj'))

GENITIVE_TAG = or_(gram('gent'), vesum_tag('v_rod'))

REGION = rule(
    ADJECTIVE_TAG,
    dictionary({
        'край',
        'район',
        'область',
        'губернія',
    }),
).interpretation(Location.name.inflected())

AUTONOMOUS_DISTRICT = rule(
Beispiel #7
0
from yargy_uk import (
    rule,
    or_
)
from yargy_uk.interpretation import fact
from yargy_uk.predicates import gram, vesum_tag
from yargy_uk.pipelines import morph_pipeline

from .name import (
    NAME,
    SIMPLE_NAME
)


Person = fact(
    'Person',
    ['position', 'name']
)


POSITION = morph_pipeline([
    'святий',
    'патріарх',
    'митрополит',

    'цар',
    'король',
    'цариця',
    'імператор',
    'імператриця',
    'принц',
    'принцеса',