Skip to content

Commit

Permalink
new version 0.3.25
Browse files Browse the repository at this point in the history
  • Loading branch information
falgore88 committed Apr 13, 2016
1 parent 83f6ec9 commit a396b83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
from setuptools import setup


VERSION = "0.3.24"
VERSION = "0.3.25"

setup(
name='ta4',
Expand Down
10 changes: 5 additions & 5 deletions ta4/analyzer.py
@@ -1,16 +1,16 @@
#! coding: utf-8
from operator import attrgetter


class ExactAnalyzer(object):
def get_sentence_placeholders(self, sentence):
return filter(attrgetter('is_word'), sentence.place_holders)

def mark(self, keyword, sentence, number, should_mark=True):
placeholders = self.get_sentence_placeholders(sentence)
stop = len(placeholders) - len(keyword.place_holders)
placeholders_count = len(placeholders)
stop = placeholders_count - len(keyword.place_holders)
i = 0
while i < len(placeholders):
while i < placeholders_count:
if i > stop:
break
skipped_words = 0
Expand All @@ -22,7 +22,7 @@ def mark(self, keyword, sentence, number, should_mark=True):
if placeholders[i+j].is_important:
meaning_word += 1
# если встретили уже второе значимое слово
if meaning_word == 2 or i == len(placeholders) - j - 1:
if meaning_word == 2 or i == placeholders_count - j - 1:
i -= 1
skipped_words -= 1
meaning_word -= 1
Expand All @@ -33,7 +33,7 @@ def mark(self, keyword, sentence, number, should_mark=True):
break
else:
index = i+j
if index >= len(placeholders) or not self.equals(ph, placeholders[index]):
if index >= placeholders_count or not self.equals(ph, placeholders[index]):
break
else:
if should_mark:
Expand Down
24 changes: 7 additions & 17 deletions ta4/placeholder.py
Expand Up @@ -83,7 +83,7 @@ def simple_hash(self):


class PlaceHolder(object):
__slots__ = ('word', 'gram_infos', 'markers', 'position', 'is_subform_word', '_lexemes')
__slots__ = ('word', 'gram_infos', 'markers', 'position', 'is_subform_word', '_lexemes', 'is_word', 'is_special', 'is_important')

def __init__(self, word, position, gram_infos, is_subform):
self.word = word.upper()
Expand All @@ -92,6 +92,12 @@ def __init__(self, word, position, gram_infos, is_subform):
self.markers = []
self.is_subform_word = is_subform
self._lexemes = None
self.is_word = self.word not in {u'–'}
self.is_special = self.word in SPECIAL_WORDS
if self.is_special:
self.is_important = False
else:
self.is_important = all(map(attrgetter('is_important_pos'), self.gram_infos))

def add_marker(self, word, position, marker_id):
marker = Marker(word, position, marker_id)
Expand All @@ -100,21 +106,6 @@ def add_marker(self, word, position, marker_id):
def clean(self):
self.markers = []

@property
def is_special(self):
return self.word in SPECIAL_WORDS

@property
def is_word(self):
return self.word not in {u'–'}

@property
def is_important(self):
u"""Не важная часть речи, например предлоги или частицы, не учавствуют в сравнениях"""
if self.is_special:
return False
return all(map(attrgetter('is_important_pos'), self.gram_infos))

def get_all_normal_phorms(self):
return set(map(attrgetter('normal_form'), self.gram_infos))

Expand All @@ -129,7 +120,6 @@ def lexemes(self):
return self._lexemes



class GramInfo(object):
__slots__ = ('normal_form', 'part_of_speech')

Expand Down

0 comments on commit a396b83

Please sign in to comment.