from osm.osm import describe_objects
from yandex import get_text_by_coordinates
+from stemmer import stemming
import itertools
import bottle
+import re
cities = {
"Екатеринбург": (56.807556, 56.847826, 60.570744, 60.657791),
success, summary = parse_summary(
s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip())
- if success and 'улица' not in summary:
+ if success and 'улица' not in summary and not re.search(stemming(s['name']), stemming(summary), re.IGNORECASE):
game.tips.append(f'{summary.capitalize()}. Это как-то связано с названием ближайшей улицы 🤔')
buildings = near_objects['buildings']
--- /dev/null
+import snowballstemmer
+stemmer = snowballstemmer.stemmer('russian');
+import sys, re
+bad_characters_regex = re.compile(r'[^a-zа-я0-9-+,.;"\'()/!?\s]')
+punctuation_regex = re.compile(r'[-+,.;"\'()/!?]')
+many_spaces_regex = re.compile(r' +')
+
+def normalize(line):
+ result = line.lower()
+ result = result.replace('ё', 'е')
+ result = re.sub(punctuation_regex, ' \g<0> ', result)
+ result = re.sub(bad_characters_regex, ' ', result)
+ result = re.sub(many_spaces_regex, ' ', result)
+
+ return result.strip()
+
+
+def stemming(word):
+ return stemmer.stemWord(word)
+
+def text_stemming(text):
+ normilized_text = normalize(text)
+ return ' '.join(stemmer.stemWords(normilized_text.split()))
+
+
+print(text_stemming('Народной воли'))
\ No newline at end of file