profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/Alica032/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

Alioth6/contact_game_bot 1

CSC NLP project - Contact game-bot

Alica032/contact_game_bot 0

CSC NLP project - Contact game-bot

Alica032/dlcourse_ai 0

Материалы курса Deep Learning на пальцах

Alica032/hpcourse 0

Project is aimed to store student's practical works on high performance computing course

Alica032/nice-text-decoder 0

ODS Pet Project. Main idea is manipulation with the text from the image (Kind of WYSIWYG analog)

Alica032/pretrained-models.pytorch 0

Pretrained ConvNets for pytorch: NASNet, ResNeXt, ResNet, InceptionV4, InceptionResnetV2, Xception, DPN, etc.

startedliuchengxu/space-vim

started time in a day

startedKai-46/PhySG

started time in a day

startedNVlabs/stylegan2

started time in 21 days

startedmitsuba-renderer/enoki

started time in 21 days

startedcgtuebingen/robust-vmm-guiding

started time in 21 days

startedchrislgarry/Apollo-11

started time in 21 days

startedrwightman/pytorch-image-models

started time in 23 days

startedNVlabs/tiny-cuda-nn

started time in a month

startedPurkialo/CrowdDet

started time in a month

startedligang-cs/CSP-Pedestrian-detection

started time in a month

startedfacebookresearch/dino

started time in 2 months

startedbayesiains/nflows

started time in 2 months

startednvbn/thefuck

started time in 2 months

push eventAlioth6/contact_game_bot

PredelinaAsya

commit sha 159ecf23f348ea43232caaa16395ef23f26c7a40

Add analysis of human and formal definitions

view details

PredelinaAsya

commit sha 56e0e9d0635f78240677565e128f323978f8bb15

Add estimation of the LSTM-classifier running time

view details

PredelinaAsya

commit sha 0ab715ea891733015ec524b9eefca37b01f5c1f8

Collect dataset with pairs of cognate words

view details

PredelinaAsya

commit sha 84187fc2e69f2136d1cdb3046c24d8dc90861556

Get rid of duplications in game logic

view details

PredelinaAsya

commit sha c26c9cef4e7cadd815cce6085a9e071db40b88c8

Fixed style mistakes and changed getting rid of duplications a little

view details

PredelinaAsya

commit sha 789b93fa65b9ca3145f553d389729b404ca8d3fa

Cleaned dataset of cognates

view details

PredelinaAsya

commit sha 3c779535c7631c11b9789872d06974f40ac4087b

Collected dataset with pairs of non-cognates

view details

PredelinaAsya

commit sha ac3f2f6fbaf6d35198249f38ad8ea015deff9482

Merged datasets of cognates and non-cognates

view details

PredelinaAsya

commit sha e83a6c37829eeb9f0acd96e4fcbf792bfaa9c084

Added models-classifiers of cognates

view details

PredelinaAsya

commit sha 399278698427cf74c8aab284dc88beb859f17ee8

Changed encoding of csv-files

view details

PredelinaAsya

commit sha 7230f8950e9d7db1ce931d60a79e3f8bb7fec2cd

Merge branch 'master' into master

view details

PredelinaAsya

commit sha 2b0efc7af2e5453119cde3d59d5aa39614434ce4

Merge pull request #18 from PredelinaAsya/master Analysis of datasets and time, new dataset of cognates, change in game logic + first version of cognates classifiers

view details

push time in 2 months

startednmaac/acon

started time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+{+ "cells": [+  {+   "cell_type": "code",+   "execution_count": 1,+   "metadata": {},+   "outputs": [],+   "source": [+    "alphabet = dict() #for each letter save amount of pages and link to the first of these pages\n",+    "alphabet['a'] = [37, \"https://cognates.ru/words\"]\n",+    "alphabet['b'] = [42, \"https://cognates.ru/words/b\"]\n",+    "alphabet['v'] = [66, \"https://cognates.ru/words/v\"]\n",+    "alphabet['g'] = [23, \"https://cognates.ru/words/g\"]\n",+    "alphabet['d'] = [35, \"https://cognates.ru/words/d\"]\n",+    "alphabet['e'] = [3, \"https://cognates.ru/words/e\"]\n",+    "alphabet['yo'] = [1, \"https://cognates.ru/words/yo\"]\n",+    "alphabet['zh'] = [7, \"https://cognates.ru/words/zh\"]\n",+    "alphabet['z'] = [37, \"https://cognates.ru/words/z\"]\n",+    "alphabet['i'] = [21, \"https://cognates.ru/words/i\"]\n",+    "alphabet['yi'] = [1, \"https://cognates.ru/words/yi\"]\n",+    "alphabet['k'] = [57, \"https://cognates.ru/words/k\"]\n",+    "alphabet['l'] = [18, \"https://cognates.ru/words/l\"]\n",+    "alphabet['m'] = [36, \"https://cognates.ru/words/m\"]\n",+    "alphabet['n'] = [47, \"https://cognates.ru/words/n\"]\n",+    "alphabet['o'] = [60, \"https://cognates.ru/words/o\"]\n",+    "alphabet['p'] = [142, \"https://cognates.ru/words/p\"]\n",+    "alphabet['r'] = [42, \"https://cognates.ru/words/r\"]\n",+    "alphabet['s'] = [78, \"https://cognates.ru/words/s\"]\n",+    "alphabet['t'] = [30, \"https://cognates.ru/words/t\"]\n",+    "alphabet['u'] = [22, \"https://cognates.ru/words/u\"]\n",+    "alphabet['f'] = [15, \"https://cognates.ru/words/f\"]\n",+    "alphabet['h'] = [10, \"https://cognates.ru/words/h\"]\n",+    "alphabet['cz'] = [5, \"https://cognates.ru/words/cz\"]\n",+    "alphabet['ch'] = [10, \"https://cognates.ru/words/ch\"]\n",+    "alphabet['sh'] = [12, \"https://cognates.ru/words/sh\"]\n",+    "alphabet['sc'] = [2, \"https://cognates.ru/words/sc\"]\n",+    "alphabet['iy'] = [1, \"https://cognates.ru/words/iy\"]\n",+    "alphabet['ye'] = [12, \"https://cognates.ru/words/ye\"]\n",+    "alphabet['yu'] = [2, \"https://cognates.ru/words/yu\"]\n",+    "alphabet['ya'] = [4, \"https://cognates.ru/words/ya\"]"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 2,+   "metadata": {},+   "outputs": [],+   "source": [+    "from urllib.request import urlopen\n",+    "from bs4 import BeautifulSoup\n",+    "\n",+    "def get_children(link_str):\n",+    "    page = urlopen(link_str)\n",+    "    soup = BeautifulSoup(page)\n",+    "\n",+    "    links = soup.find_all(attrs={\"class\":\"list\"})\n",+    "    if len(links):\n",+    "        arr = str(links[0])\n",+    "        arr = arr.replace(\"</a>\", \"\")\n",+    "        arr = arr.replace(\"</p>\", \"\")\n",+    "        arr = arr.replace('<p class=\"list\">', \"\")\n",+    "        arr = arr.replace(\"<a href=\", \"\")\n",+    "        arr = arr.replace(\">\", \" \")\n",+    "        curr_list = arr.split()\n",+    "\n",+    "        children = []\n",+    "        for i in range(len(curr_list) // 2):\n",+    "            children.append([curr_list[2 * i].replace('\"', ''), curr_list[2 * i + 1]])\n",+    "        return children\n",+    "    return []"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 5,+   "metadata": {},+   "outputs": [+    {+     "name": "stdout",+     "output_type": "stream",+     "text": [+      "Writing complete\n"+     ]+    }+   ],+   "source": [+    "import csv\n",+    "\n",+    "MAXN = 10\n",+    "\n",+    "file = open('cognates_full.csv', 'w')\n",+    "writer = csv.writer(file)\n",+    "writer.writerows([['first_word', 'second_word']])\n",+    "\n",+    "with file:\n",+    "    first_word = list()\n",+    "    second_word = list()\n",+    "    for key in alphabet:\n",+    "        for i in range(alphabet[key][0]):\n",+    "            curr_link = alphabet[key][1]\n",+    "            if i != 0:\n",+    "                curr_link += \"/pn\"\n",+    "                curr_link += str(i + 1)\n",+    "            word_list = get_children(curr_link)\n",+    "            for elem in word_list:\n",+    "                child_page = \"https://cognates.ru\" + elem[0]\n",+    "                cognates = get_children(child_page)\n",+    "                for i in range(min(MAXN, len(cognates))):\n",+    "                    cognate = cognates[i]\n",+    "                    first_word.append(elem[1])\n",+    "                    second_word.append(cognate[1])\n",+    "                    writer = csv.writer(file)\n",+    "                    writer.writerows([[elem[1], cognate[1]]])\n",+    "print(\"Writing complete\")"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 6,+   "metadata": {},+   "outputs": [+    {+     "data": {+      "text/html": [+       "<div>\n",+       "<style scoped>\n",+       "    .dataframe tbody tr th:only-of-type {\n",+       "        vertical-align: middle;\n",+       "    }\n",+       "\n",+       "    .dataframe tbody tr th {\n",+       "        vertical-align: top;\n",+       "    }\n",+       "\n",+       "    .dataframe thead th {\n",+       "        text-align: right;\n",+       "    }\n",+       "</style>\n",+       "<table border=\"1\" class=\"dataframe\">\n",+       "  <thead>\n",+       "    <tr style=\"text-align: right;\">\n",+       "      <th></th>\n",+       "      <th>first_word</th>\n",+       "      <th>second_word</th>\n",+       "    </tr>\n",+       "  </thead>\n",+       "  <tbody>\n",+       "    <tr>\n",+       "      <th>0</th>\n",+       "      <td>А</td>\n",+       "      <td>А-конто</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>1</th>\n",+       "      <td>А</td>\n",+       "      <td>Аканье</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>2</th>\n",+       "      <td>А</td>\n",+       "      <td>Акать</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>3</th>\n",+       "      <td>А</td>\n",+       "      <td>Акающий</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>4</th>\n",+       "      <td>А</td>\n",+       "      <td>Ашка</td>\n",+       "    </tr>\n",+       "  </tbody>\n",+       "</table>\n",+       "</div>"+      ],+      "text/plain": [+       "  first_word second_word\n",+       "0          А     А-конто\n",+       "1          А      Аканье\n",+       "2          А       Акать\n",+       "3          А     Акающий\n",+       "4          А        Ашка"+      ]+     },+     "execution_count": 6,+     "metadata": {},+     "output_type": "execute_result"+    }+   ],+   "source": [+    "import pandas as pd\n",+    "\n",+    "data = pd.read_csv('cognates_full.csv', encoding='utf_8')\n",+    "data.head()"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 7,+   "metadata": {},+   "outputs": [],+   "source": [+    "def dist_Levenshtein(s1, s2):\n",+    "    d = [[0] * (len(s2) + 1) for i in range(len(s1) + 1)]\n",+    "    for i in range(len(s1) + 1):\n",+    "        for j in range(len(s2) + 1):\n",+    "            if i == 0:\n",+    "                d[i][j] = j\n",+    "            elif j == 0:\n",+    "                d[i][j] = i\n",+    "            else:\n",+    "                d[i][j] = min(d[i][j - 1] + 1, d[i - 1][j] + 1)\n",+    "                delta = 0 if s1[i - 1] == s2[j - 1] else 1\n",+    "                d[i][j] = min(d[i][j], d[i - 1][j - 1] + delta)\n",+    "                \n",+    "    return d[len(s1)][len(s2)]"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 8,+   "metadata": {},+   "outputs": [+    {+     "name": "stdout",+     "output_type": "stream",+     "text": [+      "4\n"+     ]+    }+   ],+   "source": [+    "print(dist_Levenshtein('Levenshtein', 'Lenvinsten'))"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 9,+   "metadata": {},+   "outputs": [],+   "source": [+    "def longest_common_substring(s1, s2):\n",+    "    d = [[0] * (len(s2) + 1) for i in range(len(s1) + 1)]\n",+    "    for i in range(len(s1) + 1):\n",+    "        for j in range(len(s2) + 1):\n",+    "            if i and j and s1[i - 1] == s2[j - 1]:\n",+    "                d[i][j] = d[i - 1][j - 1] + 1\n",+    "    max_val = 0\n",

Let's search max_val during the first loop, when we fill our dynamic array. :)

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+{+ "cells": [+  {+   "cell_type": "code",+   "execution_count": 1,+   "metadata": {},+   "outputs": [],+   "source": [+    "alphabet = dict() #for each letter save amount of pages and link to the first of these pages\n",+    "alphabet['a'] = [37, \"https://cognates.ru/words\"]\n",+    "alphabet['b'] = [42, \"https://cognates.ru/words/b\"]\n",+    "alphabet['v'] = [66, \"https://cognates.ru/words/v\"]\n",+    "alphabet['g'] = [23, \"https://cognates.ru/words/g\"]\n",+    "alphabet['d'] = [35, \"https://cognates.ru/words/d\"]\n",+    "alphabet['e'] = [3, \"https://cognates.ru/words/e\"]\n",+    "alphabet['yo'] = [1, \"https://cognates.ru/words/yo\"]\n",+    "alphabet['zh'] = [7, \"https://cognates.ru/words/zh\"]\n",+    "alphabet['z'] = [37, \"https://cognates.ru/words/z\"]\n",+    "alphabet['i'] = [21, \"https://cognates.ru/words/i\"]\n",+    "alphabet['yi'] = [1, \"https://cognates.ru/words/yi\"]\n",+    "alphabet['k'] = [57, \"https://cognates.ru/words/k\"]\n",+    "alphabet['l'] = [18, \"https://cognates.ru/words/l\"]\n",+    "alphabet['m'] = [36, \"https://cognates.ru/words/m\"]\n",+    "alphabet['n'] = [47, \"https://cognates.ru/words/n\"]\n",+    "alphabet['o'] = [60, \"https://cognates.ru/words/o\"]\n",+    "alphabet['p'] = [142, \"https://cognates.ru/words/p\"]\n",+    "alphabet['r'] = [42, \"https://cognates.ru/words/r\"]\n",+    "alphabet['s'] = [78, \"https://cognates.ru/words/s\"]\n",+    "alphabet['t'] = [30, \"https://cognates.ru/words/t\"]\n",+    "alphabet['u'] = [22, \"https://cognates.ru/words/u\"]\n",+    "alphabet['f'] = [15, \"https://cognates.ru/words/f\"]\n",+    "alphabet['h'] = [10, \"https://cognates.ru/words/h\"]\n",+    "alphabet['cz'] = [5, \"https://cognates.ru/words/cz\"]\n",+    "alphabet['ch'] = [10, \"https://cognates.ru/words/ch\"]\n",+    "alphabet['sh'] = [12, \"https://cognates.ru/words/sh\"]\n",+    "alphabet['sc'] = [2, \"https://cognates.ru/words/sc\"]\n",+    "alphabet['iy'] = [1, \"https://cognates.ru/words/iy\"]\n",+    "alphabet['ye'] = [12, \"https://cognates.ru/words/ye\"]\n",+    "alphabet['yu'] = [2, \"https://cognates.ru/words/yu\"]\n",+    "alphabet['ya'] = [4, \"https://cognates.ru/words/ya\"]"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 2,+   "metadata": {},+   "outputs": [],+   "source": [+    "from urllib.request import urlopen\n",+    "from bs4 import BeautifulSoup\n",+    "\n",+    "def get_children(link_str):\n",+    "    page = urlopen(link_str)\n",+    "    soup = BeautifulSoup(page)\n",+    "\n",+    "    links = soup.find_all(attrs={\"class\":\"list\"})\n",+    "    if len(links):\n",+    "        arr = str(links[0])\n",+    "        arr = arr.replace(\"</a>\", \"\")\n",+    "        arr = arr.replace(\"</p>\", \"\")\n",+    "        arr = arr.replace('<p class=\"list\">', \"\")\n",+    "        arr = arr.replace(\"<a href=\", \"\")\n",+    "        arr = arr.replace(\">\", \" \")\n",+    "        curr_list = arr.split()\n",+    "\n",+    "        children = []\n",+    "        for i in range(len(curr_list) // 2):\n",+    "            children.append([curr_list[2 * i].replace('\"', ''), curr_list[2 * i + 1]])\n",+    "        return children\n",+    "    return []"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 5,+   "metadata": {},+   "outputs": [+    {+     "name": "stdout",+     "output_type": "stream",+     "text": [+      "Writing complete\n"+     ]+    }+   ],+   "source": [+    "import csv\n",+    "\n",+    "MAXN = 10\n",+    "\n",+    "file = open('cognates_full.csv', 'w')\n",+    "writer = csv.writer(file)\n",+    "writer.writerows([['first_word', 'second_word']])\n",+    "\n",+    "with file:\n",+    "    first_word = list()\n",+    "    second_word = list()\n",+    "    for key in alphabet:\n",+    "        for i in range(alphabet[key][0]):\n",+    "            curr_link = alphabet[key][1]\n",+    "            if i != 0:\n",+    "                curr_link += \"/pn\"\n",+    "                curr_link += str(i + 1)\n",+    "            word_list = get_children(curr_link)\n",+    "            for elem in word_list:\n",+    "                child_page = \"https://cognates.ru\" + elem[0]\n",+    "                cognates = get_children(child_page)\n",+    "                for i in range(min(MAXN, len(cognates))):\n",+    "                    cognate = cognates[i]\n",+    "                    first_word.append(elem[1])\n",+    "                    second_word.append(cognate[1])\n",+    "                    writer = csv.writer(file)\n",+    "                    writer.writerows([[elem[1], cognate[1]]])\n",+    "print(\"Writing complete\")"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 6,+   "metadata": {},+   "outputs": [+    {+     "data": {+      "text/html": [+       "<div>\n",+       "<style scoped>\n",+       "    .dataframe tbody tr th:only-of-type {\n",+       "        vertical-align: middle;\n",+       "    }\n",+       "\n",+       "    .dataframe tbody tr th {\n",+       "        vertical-align: top;\n",+       "    }\n",+       "\n",+       "    .dataframe thead th {\n",+       "        text-align: right;\n",+       "    }\n",+       "</style>\n",+       "<table border=\"1\" class=\"dataframe\">\n",+       "  <thead>\n",+       "    <tr style=\"text-align: right;\">\n",+       "      <th></th>\n",+       "      <th>first_word</th>\n",+       "      <th>second_word</th>\n",+       "    </tr>\n",+       "  </thead>\n",+       "  <tbody>\n",+       "    <tr>\n",+       "      <th>0</th>\n",+       "      <td>А</td>\n",+       "      <td>А-конто</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>1</th>\n",+       "      <td>А</td>\n",+       "      <td>Аканье</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>2</th>\n",+       "      <td>А</td>\n",+       "      <td>Акать</td>\n",

Let's compute another metric on our dataset: longest common subsequence. Then, we can use it in absolute difference operation between word pairs. I think, this metric can be robust to alternating letters in word's root :)

More information here: https://ru.wikipedia.org/wiki/%D0%9D%D0%B0%D0%B8%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B0%D1%8F_%D0%BE%D0%B1%D1%89%D0%B0%D1%8F_%D0%BF%D0%BE%D0%B4%D0%BF%D0%BE%D1%81%D0%BB%D0%B5%D0%B4%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%BE%D1%81%D1%82%D1%8C

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+{+ "cells": [+  {+   "cell_type": "code",+   "execution_count": 1,+   "metadata": {},+   "outputs": [],+   "source": [+    "alphabet = dict() #for each letter save amount of pages and link to the first of these pages\n",+    "alphabet['a'] = [37, \"https://cognates.ru/words\"]\n",+    "alphabet['b'] = [42, \"https://cognates.ru/words/b\"]\n",+    "alphabet['v'] = [66, \"https://cognates.ru/words/v\"]\n",+    "alphabet['g'] = [23, \"https://cognates.ru/words/g\"]\n",+    "alphabet['d'] = [35, \"https://cognates.ru/words/d\"]\n",+    "alphabet['e'] = [3, \"https://cognates.ru/words/e\"]\n",+    "alphabet['yo'] = [1, \"https://cognates.ru/words/yo\"]\n",+    "alphabet['zh'] = [7, \"https://cognates.ru/words/zh\"]\n",+    "alphabet['z'] = [37, \"https://cognates.ru/words/z\"]\n",+    "alphabet['i'] = [21, \"https://cognates.ru/words/i\"]\n",+    "alphabet['yi'] = [1, \"https://cognates.ru/words/yi\"]\n",+    "alphabet['k'] = [57, \"https://cognates.ru/words/k\"]\n",+    "alphabet['l'] = [18, \"https://cognates.ru/words/l\"]\n",+    "alphabet['m'] = [36, \"https://cognates.ru/words/m\"]\n",+    "alphabet['n'] = [47, \"https://cognates.ru/words/n\"]\n",+    "alphabet['o'] = [60, \"https://cognates.ru/words/o\"]\n",+    "alphabet['p'] = [142, \"https://cognates.ru/words/p\"]\n",+    "alphabet['r'] = [42, \"https://cognates.ru/words/r\"]\n",+    "alphabet['s'] = [78, \"https://cognates.ru/words/s\"]\n",+    "alphabet['t'] = [30, \"https://cognates.ru/words/t\"]\n",+    "alphabet['u'] = [22, \"https://cognates.ru/words/u\"]\n",+    "alphabet['f'] = [15, \"https://cognates.ru/words/f\"]\n",+    "alphabet['h'] = [10, \"https://cognates.ru/words/h\"]\n",+    "alphabet['cz'] = [5, \"https://cognates.ru/words/cz\"]\n",+    "alphabet['ch'] = [10, \"https://cognates.ru/words/ch\"]\n",+    "alphabet['sh'] = [12, \"https://cognates.ru/words/sh\"]\n",+    "alphabet['sc'] = [2, \"https://cognates.ru/words/sc\"]\n",+    "alphabet['iy'] = [1, \"https://cognates.ru/words/iy\"]\n",+    "alphabet['ye'] = [12, \"https://cognates.ru/words/ye\"]\n",+    "alphabet['yu'] = [2, \"https://cognates.ru/words/yu\"]\n",+    "alphabet['ya'] = [4, \"https://cognates.ru/words/ya\"]"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 2,+   "metadata": {},+   "outputs": [],+   "source": [+    "from urllib.request import urlopen\n",+    "from bs4 import BeautifulSoup\n",+    "\n",+    "def get_children(link_str):\n",+    "    page = urlopen(link_str)\n",+    "    soup = BeautifulSoup(page)\n",+    "\n",+    "    links = soup.find_all(attrs={\"class\":\"list\"})\n",+    "    if len(links):\n",+    "        arr = str(links[0])\n",+    "        arr = arr.replace(\"</a>\", \"\")\n",+    "        arr = arr.replace(\"</p>\", \"\")\n",+    "        arr = arr.replace('<p class=\"list\">', \"\")\n",+    "        arr = arr.replace(\"<a href=\", \"\")\n",+    "        arr = arr.replace(\">\", \" \")\n",+    "        curr_list = arr.split()\n",+    "\n",+    "        children = []\n",+    "        for i in range(len(curr_list) // 2):\n",+    "            children.append([curr_list[2 * i].replace('\"', ''), curr_list[2 * i + 1]])\n",+    "        return children\n",+    "    return []"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 5,+   "metadata": {},+   "outputs": [+    {+     "name": "stdout",+     "output_type": "stream",+     "text": [+      "Writing complete\n"+     ]+    }+   ],+   "source": [+    "import csv\n",+    "\n",+    "MAXN = 10\n",+    "\n",+    "file = open('cognates_full.csv', 'w')\n",+    "writer = csv.writer(file)\n",+    "writer.writerows([['first_word', 'second_word']])\n",+    "\n",+    "with file:\n",+    "    first_word = list()\n",+    "    second_word = list()\n",+    "    for key in alphabet:\n",+    "        for i in range(alphabet[key][0]):\n",+    "            curr_link = alphabet[key][1]\n",+    "            if i != 0:\n",+    "                curr_link += \"/pn\"\n",+    "                curr_link += str(i + 1)\n",+    "            word_list = get_children(curr_link)\n",+    "            for elem in word_list:\n",+    "                child_page = \"https://cognates.ru\" + elem[0]\n",+    "                cognates = get_children(child_page)\n",+    "                for i in range(min(MAXN, len(cognates))):\n",+    "                    cognate = cognates[i]\n",+    "                    first_word.append(elem[1])\n",+    "                    second_word.append(cognate[1])\n",+    "                    writer = csv.writer(file)\n",+    "                    writer.writerows([[elem[1], cognate[1]]])\n",+    "print(\"Writing complete\")"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 6,+   "metadata": {},+   "outputs": [+    {+     "data": {+      "text/html": [+       "<div>\n",+       "<style scoped>\n",+       "    .dataframe tbody tr th:only-of-type {\n",+       "        vertical-align: middle;\n",+       "    }\n",+       "\n",+       "    .dataframe tbody tr th {\n",+       "        vertical-align: top;\n",+       "    }\n",+       "\n",+       "    .dataframe thead th {\n",+       "        text-align: right;\n",+       "    }\n",+       "</style>\n",+       "<table border=\"1\" class=\"dataframe\">\n",+       "  <thead>\n",+       "    <tr style=\"text-align: right;\">\n",+       "      <th></th>\n",+       "      <th>first_word</th>\n",+       "      <th>second_word</th>\n",+       "    </tr>\n",+       "  </thead>\n",+       "  <tbody>\n",+       "    <tr>\n",+       "      <th>0</th>\n",+       "      <td>А</td>\n",+       "      <td>А-конто</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>1</th>\n",+       "      <td>А</td>\n",+       "      <td>Аканье</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>2</th>\n",+       "      <td>А</td>\n",

I suggest to except from training data those word pairs where:

  • one of words looks like a conjunction (а, но, и, с , то...), pronoun, preposition and other POS from stop-word category;
  • absolute difference between Levenshtein distance and LCS is too large (i.e. |a - b| >= 4);

The last condition we must apply very carefully due to alternating vowels in word's root :)

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+{+ "cells": [+  {+   "cell_type": "code",+   "execution_count": 1,+   "metadata": {},+   "outputs": [],+   "source": [+    "alphabet = dict() #for each letter save amount of pages and link to the first of these pages\n",+    "alphabet['a'] = [37, \"https://cognates.ru/words\"]\n",+    "alphabet['b'] = [42, \"https://cognates.ru/words/b\"]\n",+    "alphabet['v'] = [66, \"https://cognates.ru/words/v\"]\n",+    "alphabet['g'] = [23, \"https://cognates.ru/words/g\"]\n",+    "alphabet['d'] = [35, \"https://cognates.ru/words/d\"]\n",+    "alphabet['e'] = [3, \"https://cognates.ru/words/e\"]\n",+    "alphabet['yo'] = [1, \"https://cognates.ru/words/yo\"]\n",+    "alphabet['zh'] = [7, \"https://cognates.ru/words/zh\"]\n",+    "alphabet['z'] = [37, \"https://cognates.ru/words/z\"]\n",+    "alphabet['i'] = [21, \"https://cognates.ru/words/i\"]\n",+    "alphabet['yi'] = [1, \"https://cognates.ru/words/yi\"]\n",+    "alphabet['k'] = [57, \"https://cognates.ru/words/k\"]\n",+    "alphabet['l'] = [18, \"https://cognates.ru/words/l\"]\n",+    "alphabet['m'] = [36, \"https://cognates.ru/words/m\"]\n",+    "alphabet['n'] = [47, \"https://cognates.ru/words/n\"]\n",+    "alphabet['o'] = [60, \"https://cognates.ru/words/o\"]\n",+    "alphabet['p'] = [142, \"https://cognates.ru/words/p\"]\n",+    "alphabet['r'] = [42, \"https://cognates.ru/words/r\"]\n",+    "alphabet['s'] = [78, \"https://cognates.ru/words/s\"]\n",+    "alphabet['t'] = [30, \"https://cognates.ru/words/t\"]\n",+    "alphabet['u'] = [22, \"https://cognates.ru/words/u\"]\n",+    "alphabet['f'] = [15, \"https://cognates.ru/words/f\"]\n",+    "alphabet['h'] = [10, \"https://cognates.ru/words/h\"]\n",+    "alphabet['cz'] = [5, \"https://cognates.ru/words/cz\"]\n",+    "alphabet['ch'] = [10, \"https://cognates.ru/words/ch\"]\n",+    "alphabet['sh'] = [12, \"https://cognates.ru/words/sh\"]\n",+    "alphabet['sc'] = [2, \"https://cognates.ru/words/sc\"]\n",+    "alphabet['iy'] = [1, \"https://cognates.ru/words/iy\"]\n",+    "alphabet['ye'] = [12, \"https://cognates.ru/words/ye\"]\n",+    "alphabet['yu'] = [2, \"https://cognates.ru/words/yu\"]\n",+    "alphabet['ya'] = [4, \"https://cognates.ru/words/ya\"]"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 2,+   "metadata": {},+   "outputs": [],+   "source": [+    "from urllib.request import urlopen\n",+    "from bs4 import BeautifulSoup\n",+    "\n",+    "def get_children(link_str):\n",+    "    page = urlopen(link_str)\n",+    "    soup = BeautifulSoup(page)\n",+    "\n",+    "    links = soup.find_all(attrs={\"class\":\"list\"})\n",+    "    if len(links):\n",+    "        arr = str(links[0])\n",+    "        arr = arr.replace(\"</a>\", \"\")\n",+    "        arr = arr.replace(\"</p>\", \"\")\n",+    "        arr = arr.replace('<p class=\"list\">', \"\")\n",+    "        arr = arr.replace(\"<a href=\", \"\")\n",+    "        arr = arr.replace(\">\", \" \")\n",+    "        curr_list = arr.split()\n",+    "\n",+    "        children = []\n",+    "        for i in range(len(curr_list) // 2):\n",+    "            children.append([curr_list[2 * i].replace('\"', ''), curr_list[2 * i + 1]])\n",+    "        return children\n",+    "    return []"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 5,+   "metadata": {},+   "outputs": [+    {+     "name": "stdout",+     "output_type": "stream",+     "text": [+      "Writing complete\n"+     ]+    }+   ],+   "source": [+    "import csv\n",+    "\n",+    "MAXN = 10\n",+    "\n",+    "file = open('cognates_full.csv', 'w')\n",+    "writer = csv.writer(file)\n",+    "writer.writerows([['first_word', 'second_word']])\n",+    "\n",+    "with file:\n",+    "    first_word = list()\n",+    "    second_word = list()\n",+    "    for key in alphabet:\n",+    "        for i in range(alphabet[key][0]):\n",+    "            curr_link = alphabet[key][1]\n",+    "            if i != 0:\n",+    "                curr_link += \"/pn\"\n",+    "                curr_link += str(i + 1)\n",+    "            word_list = get_children(curr_link)\n",+    "            for elem in word_list:\n",+    "                child_page = \"https://cognates.ru\" + elem[0]\n",+    "                cognates = get_children(child_page)\n",+    "                for i in range(min(MAXN, len(cognates))):\n",+    "                    cognate = cognates[i]\n",+    "                    first_word.append(elem[1])\n",+    "                    second_word.append(cognate[1])\n",+    "                    writer = csv.writer(file)\n",+    "                    writer.writerows([[elem[1], cognate[1]]])\n",+    "print(\"Writing complete\")"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 6,+   "metadata": {},+   "outputs": [+    {+     "data": {+      "text/html": [+       "<div>\n",+       "<style scoped>\n",+       "    .dataframe tbody tr th:only-of-type {\n",+       "        vertical-align: middle;\n",+       "    }\n",+       "\n",+       "    .dataframe tbody tr th {\n",+       "        vertical-align: top;\n",+       "    }\n",+       "\n",+       "    .dataframe thead th {\n",+       "        text-align: right;\n",+       "    }\n",+       "</style>\n",+       "<table border=\"1\" class=\"dataframe\">\n",+       "  <thead>\n",+       "    <tr style=\"text-align: right;\">\n",+       "      <th></th>\n",+       "      <th>first_word</th>\n",+       "      <th>second_word</th>\n",+       "    </tr>\n",+       "  </thead>\n",+       "  <tbody>\n",+       "    <tr>\n",+       "      <th>0</th>\n",+       "      <td>А</td>\n",+       "      <td>А-конто</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>1</th>\n",+       "      <td>А</td>\n",+       "      <td>Аканье</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>2</th>\n",+       "      <td>А</td>\n",+       "      <td>Акать</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>3</th>\n",+       "      <td>А</td>\n",+       "      <td>Акающий</td>\n",+       "    </tr>\n",+       "    <tr>\n",+       "      <th>4</th>\n",+       "      <td>А</td>\n",+       "      <td>Ашка</td>\n",+       "    </tr>\n",+       "  </tbody>\n",+       "</table>\n",+       "</div>"+      ],+      "text/plain": [+       "  first_word second_word\n",+       "0          А     А-конто\n",+       "1          А      Аканье\n",+       "2          А       Акать\n",+       "3          А     Акающий\n",+       "4          А        Ашка"+      ]+     },+     "execution_count": 6,+     "metadata": {},+     "output_type": "execute_result"+    }+   ],+   "source": [+    "import pandas as pd\n",+    "\n",+    "data = pd.read_csv('cognates_full.csv', encoding='utf_8')\n",+    "data.head()"+   ]+  },+  {+   "cell_type": "code",+   "execution_count": 7,+   "metadata": {},+   "outputs": [],+   "source": [+    "def dist_Levenshtein(s1, s2):\n",+    "    d = [[0] * (len(s2) + 1) for i in range(len(s1) + 1)]\n",

In list comprehension we can use _ instead of i :)

As an alternative two-dimension array initialization: d = [[0] * (len(s2) + 1)] * (len(s2) + 1).

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+import logging
+
+import telebot
+from telebot import types
+
+import src.bot.settings as config
+from config import Config
+
+bot = telebot.TeleBot(Config.TOKEN)
+empty_keyboard_hider = types.ReplyKeyboardRemove()
+
+logger = telebot.logger
+telebot.logger.setLevel(logging.INFO)
+
+from src.bot import utils as db_utils
+
+
+@bot.message_handler(commands=['start'])
+def start_message(message):
+    word = config.get_random_word()
+    msg = bot.send_message(
+        message.chat.id,
+        'Я загадал слово на букву %s.' % word[0],
+        reply_markup=empty_keyboard_hider
+    )
+    db_utils.set_user_data(message.chat.id,
+                           data={
+                               'gold': word,
+                               'index': 1,
+                               'state': int(config.States.S_ENTER_DEFINITION),
+                               'exceptions': []
+                           })
+
+
+# модель угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Да',
+    content_types=['text'])
+def enter_yes(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    check_word(message, user_data, guessed=True)
+
+
+# модель не угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Нет',
+    content_types=['text'])
+def enter_no(message):
+    send = bot.send_message(message.chat.id, "Я не смог угадать слово. Введи загаданное слово.")
+    db_utils.set_user_state(message.chat.id, state=config.States.S_ENTER_WORD.value)
+
+
+# ввод корректного слова
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_WORD.value,
+    content_types=['text'])
+def enter_word(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    user_data['word'] = message.text
+    check_word(message, user_data, guessed=False)
+
+
+# ввод определения
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_DEFINITION.value,
+    content_types=['text'])
+def enter_definition(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    definition = message.text
+    gold = user_data['gold']
+    index = user_data['index']
+
+    word = config.convert_question_to_word(definition, gold[:index])
+    user_data['definition'] = definition
+    user_data['word'] = word
+
+    if word:
+        markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
+        markup.add('Да', 'Нет')  # Имена кнопок
+        msg = bot.send_message(message.chat.id, 'Это слово "%s"?' % word, reply_markup=markup)
+        user_data['state'] = config.States.S_CHECK_WORD.value
+    else:
+        msg = bot.send_message(
+            message.chat.id,
+            "Я не знаю этого слова. Введи загаданное слово."
+        )
+        user_data['state'] = config.States.S_ENTER_WORD.value
+
+    db_utils.set_user_data(message.chat.id, data=user_data)
+
+
+# по дефолту
+@bot.message_handler(func=lambda message: True, content_types=['text'])
+def default(message):
+    bot.send_message(
+        message.chat.id,
+        """Чтобы начать игру, нажмите /start ,
+чтобы получить информацию об игре, нажмите /info"""
+    )
+
+
+# проверка ответа
+def check_word(message, user_data, guessed):
+    word = user_data['word']
+    gold = user_data['gold']
+    index = user_data['index']
+    
+    if word not in user_data['exceptions']:
+        db_utils.add_definition(word, user_data['definition'], guessed)
+
+    if gold == word:
+        msg = bot.send_message(
+            message.chat.id,
+            'Поздравляем, ты угадал слово! Чтобы начать игру нажми /start'
+        )
+        db_utils.finish_user_game(message.chat.id)
+    elif gold[:index] == word[:index]:
+        if word in user_data['exceptions']:
+            send = bot.send_message(message.chat.id,
+                                    "Ты уже называл это слово! Введи что-нибудь новенькое, пожалуйста:)")
+        else:
+            send = bot.send_message(message.chat.id, "Следующая буква: %s" % gold[index])
+            user_data['index'] = index + 1
+            user_data['exceptions'].append(word)
+        user_data['state'] = config.States.S_ENTER_DEFINITION.value
+        db_utils.set_user_data(message.chat.id, data=user_data)
+    else:
+        if word not in used_data['exceptions']:
+            user_data['exceptions'].append(word)
+        msg = bot.send_message(message.chat.id, '''Слово должно начинаться на %s.
+Попробуйте ввести определение слова сначала''' % gold[:index])

Instead of message break, let's write each argument of send_message (...) method at the new line :)

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+import logging
+
+import telebot
+from telebot import types
+
+import src.bot.settings as config
+from config import Config
+
+bot = telebot.TeleBot(Config.TOKEN)
+empty_keyboard_hider = types.ReplyKeyboardRemove()
+
+logger = telebot.logger
+telebot.logger.setLevel(logging.INFO)
+
+from src.bot import utils as db_utils
+
+
+@bot.message_handler(commands=['start'])
+def start_message(message):
+    word = config.get_random_word()
+    msg = bot.send_message(
+        message.chat.id,
+        'Я загадал слово на букву %s.' % word[0],
+        reply_markup=empty_keyboard_hider
+    )
+    db_utils.set_user_data(message.chat.id,
+                           data={
+                               'gold': word,
+                               'index': 1,
+                               'state': int(config.States.S_ENTER_DEFINITION),
+                               'exceptions': []
+                           })
+
+
+# модель угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Да',
+    content_types=['text'])
+def enter_yes(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    check_word(message, user_data, guessed=True)
+
+
+# модель не угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Нет',
+    content_types=['text'])
+def enter_no(message):
+    send = bot.send_message(message.chat.id, "Я не смог угадать слово. Введи загаданное слово.")
+    db_utils.set_user_state(message.chat.id, state=config.States.S_ENTER_WORD.value)
+
+
+# ввод корректного слова
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_WORD.value,
+    content_types=['text'])
+def enter_word(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    user_data['word'] = message.text
+    check_word(message, user_data, guessed=False)
+
+
+# ввод определения
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_DEFINITION.value,
+    content_types=['text'])
+def enter_definition(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    definition = message.text
+    gold = user_data['gold']
+    index = user_data['index']
+
+    word = config.convert_question_to_word(definition, gold[:index])
+    user_data['definition'] = definition
+    user_data['word'] = word
+
+    if word:
+        markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
+        markup.add('Да', 'Нет')  # Имена кнопок
+        msg = bot.send_message(message.chat.id, 'Это слово "%s"?' % word, reply_markup=markup)
+        user_data['state'] = config.States.S_CHECK_WORD.value
+    else:
+        msg = bot.send_message(
+            message.chat.id,
+            "Я не знаю этого слова. Введи загаданное слово."
+        )
+        user_data['state'] = config.States.S_ENTER_WORD.value
+
+    db_utils.set_user_data(message.chat.id, data=user_data)
+
+
+# по дефолту
+@bot.message_handler(func=lambda message: True, content_types=['text'])
+def default(message):
+    bot.send_message(
+        message.chat.id,
+        """Чтобы начать игру, нажмите /start ,
+чтобы получить информацию об игре, нажмите /info"""
+    )
+
+
+# проверка ответа
+def check_word(message, user_data, guessed):
+    word = user_data['word']
+    gold = user_data['gold']
+    index = user_data['index']
+    
+    if word not in user_data['exceptions']:
+        db_utils.add_definition(word, user_data['definition'], guessed)
+
+    if gold == word:
+        msg = bot.send_message(
+            message.chat.id,
+            'Поздравляем, ты угадал слово! Чтобы начать игру нажми /start'
+        )
+        db_utils.finish_user_game(message.chat.id)
+    elif gold[:index] == word[:index]:
+        if word in user_data['exceptions']:
+            send = bot.send_message(message.chat.id,
+                                    "Ты уже называл это слово! Введи что-нибудь новенькое, пожалуйста:)")
+        else:
+            send = bot.send_message(message.chat.id, "Следующая буква: %s" % gold[index])
+            user_data['index'] = index + 1
+            user_data['exceptions'].append(word)
+        user_data['state'] = config.States.S_ENTER_DEFINITION.value
+        db_utils.set_user_data(message.chat.id, data=user_data)
+    else:
+        if word not in used_data['exceptions']:
+            user_data['exceptions'].append(word)
+        msg = bot.send_message(message.chat.id, '''Слово должно начинаться на %s.
+Попробуйте ввести определение слова сначала''' % gold[:index])
+        db_utils.set_user_state(message.chat.id, state=config.States.S_ENTER_DEFINITION.value)

Let's add a new empty line at the end of our code. it's a good practice by PEP8 instruction. :)

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+import logging
+
+import telebot
+from telebot import types
+
+import src.bot.settings as config
+from config import Config
+
+bot = telebot.TeleBot(Config.TOKEN)
+empty_keyboard_hider = types.ReplyKeyboardRemove()
+
+logger = telebot.logger
+telebot.logger.setLevel(logging.INFO)
+
+from src.bot import utils as db_utils
+
+
+@bot.message_handler(commands=['start'])
+def start_message(message):
+    word = config.get_random_word()
+    msg = bot.send_message(
+        message.chat.id,
+        'Я загадал слово на букву %s.' % word[0],
+        reply_markup=empty_keyboard_hider
+    )
+    db_utils.set_user_data(message.chat.id,
+                           data={
+                               'gold': word,
+                               'index': 1,
+                               'state': int(config.States.S_ENTER_DEFINITION),
+                               'exceptions': []
+                           })
+
+
+# модель угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Да',
+    content_types=['text'])
+def enter_yes(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    check_word(message, user_data, guessed=True)
+
+
+# модель не угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Нет',
+    content_types=['text'])
+def enter_no(message):
+    send = bot.send_message(message.chat.id, "Я не смог угадать слово. Введи загаданное слово.")
+    db_utils.set_user_state(message.chat.id, state=config.States.S_ENTER_WORD.value)
+
+
+# ввод корректного слова
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_WORD.value,
+    content_types=['text'])
+def enter_word(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    user_data['word'] = message.text
+    check_word(message, user_data, guessed=False)
+
+
+# ввод определения
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_DEFINITION.value,
+    content_types=['text'])
+def enter_definition(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    definition = message.text
+    gold = user_data['gold']
+    index = user_data['index']
+
+    word = config.convert_question_to_word(definition, gold[:index])
+    user_data['definition'] = definition
+    user_data['word'] = word
+
+    if word:
+        markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
+        markup.add('Да', 'Нет')  # Имена кнопок
+        msg = bot.send_message(message.chat.id, 'Это слово "%s"?' % word, reply_markup=markup)
+        user_data['state'] = config.States.S_CHECK_WORD.value
+    else:
+        msg = bot.send_message(
+            message.chat.id,
+            "Я не знаю этого слова. Введи загаданное слово."
+        )
+        user_data['state'] = config.States.S_ENTER_WORD.value
+
+    db_utils.set_user_data(message.chat.id, data=user_data)
+
+
+# по дефолту
+@bot.message_handler(func=lambda message: True, content_types=['text'])
+def default(message):
+    bot.send_message(
+        message.chat.id,
+        """Чтобы начать игру, нажмите /start ,
+чтобы получить информацию об игре, нажмите /info"""
+    )
+
+
+# проверка ответа
+def check_word(message, user_data, guessed):
+    word = user_data['word']
+    gold = user_data['gold']
+    index = user_data['index']
+    
+    if word not in user_data['exceptions']:
+        db_utils.add_definition(word, user_data['definition'], guessed)
+
+    if gold == word:
+        msg = bot.send_message(
+            message.chat.id,
+            'Поздравляем, ты угадал слово! Чтобы начать игру нажми /start'
+        )
+        db_utils.finish_user_game(message.chat.id)
+    elif gold[:index] == word[:index]:
+        if word in user_data['exceptions']:
+            send = bot.send_message(message.chat.id,
+                                    "Ты уже называл это слово! Введи что-нибудь новенькое, пожалуйста:)")
+        else:
+            send = bot.send_message(message.chat.id, "Следующая буква: %s" % gold[index])
+            user_data['index'] = index + 1
+            user_data['exceptions'].append(word)
+        user_data['state'] = config.States.S_ENTER_DEFINITION.value
+        db_utils.set_user_data(message.chat.id, data=user_data)
+    else:
+        if word not in used_data['exceptions']:

Is used_data variable really exists? Or you meant user_data?.. ;)

PredelinaAsya

comment created time in 2 months

Pull request review commentAlioth6/contact_game_bot

Analysis of datasets and time, new dataset of cognates, change in game logic

+import logging
+
+import telebot
+from telebot import types
+
+import src.bot.settings as config
+from config import Config
+
+bot = telebot.TeleBot(Config.TOKEN)
+empty_keyboard_hider = types.ReplyKeyboardRemove()
+
+logger = telebot.logger
+telebot.logger.setLevel(logging.INFO)
+
+from src.bot import utils as db_utils
+
+
+@bot.message_handler(commands=['start'])
+def start_message(message):
+    word = config.get_random_word()
+    msg = bot.send_message(
+        message.chat.id,
+        'Я загадал слово на букву %s.' % word[0],
+        reply_markup=empty_keyboard_hider
+    )
+    db_utils.set_user_data(message.chat.id,
+                           data={
+                               'gold': word,
+                               'index': 1,
+                               'state': int(config.States.S_ENTER_DEFINITION),
+                               'exceptions': []
+                           })
+
+
+# модель угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Да',
+    content_types=['text'])
+def enter_yes(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    check_word(message, user_data, guessed=True)
+
+
+# модель не угадала слово
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_CHECK_WORD.value \
+                         and message.text == 'Нет',
+    content_types=['text'])
+def enter_no(message):
+    send = bot.send_message(message.chat.id, "Я не смог угадать слово. Введи загаданное слово.")
+    db_utils.set_user_state(message.chat.id, state=config.States.S_ENTER_WORD.value)
+
+
+# ввод корректного слова
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_WORD.value,
+    content_types=['text'])
+def enter_word(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    user_data['word'] = message.text
+    check_word(message, user_data, guessed=False)
+
+
+# ввод определения
+@bot.message_handler(
+    func=lambda message: db_utils.get_user_state(message.chat.id) == config.States.S_ENTER_DEFINITION.value,
+    content_types=['text'])
+def enter_definition(message):
+    user_data = db_utils.get_user_data(message.chat.id)
+    definition = message.text
+    gold = user_data['gold']
+    index = user_data['index']
+
+    word = config.convert_question_to_word(definition, gold[:index])
+    user_data['definition'] = definition
+    user_data['word'] = word
+
+    if word:
+        markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
+        markup.add('Да', 'Нет')  # Имена кнопок
+        msg = bot.send_message(message.chat.id, 'Это слово "%s"?' % word, reply_markup=markup)
+        user_data['state'] = config.States.S_CHECK_WORD.value
+    else:
+        msg = bot.send_message(
+            message.chat.id,
+            "Я не знаю этого слова. Введи загаданное слово."
+        )
+        user_data['state'] = config.States.S_ENTER_WORD.value
+
+    db_utils.set_user_data(message.chat.id, data=user_data)
+
+
+# по дефолту
+@bot.message_handler(func=lambda message: True, content_types=['text'])
+def default(message):
+    bot.send_message(
+        message.chat.id,
+        """Чтобы начать игру, нажмите /start ,
+чтобы получить информацию об игре, нажмите /info"""
+    )
+
+
+# проверка ответа
+def check_word(message, user_data, guessed):
+    word = user_data['word']
+    gold = user_data['gold']
+    index = user_data['index']
+    
+    if word not in user_data['exceptions']:
+        db_utils.add_definition(word, user_data['definition'], guessed)
+
+    if gold == word:
+        msg = bot.send_message(
+            message.chat.id,
+            'Поздравляем, ты угадал слово! Чтобы начать игру нажми /start'
+        )
+        db_utils.finish_user_game(message.chat.id)
+    elif gold[:index] == word[:index]:
+        if word in user_data['exceptions']:
+            send = bot.send_message(message.chat.id,
+                                    "Ты уже называл это слово! Введи что-нибудь новенькое, пожалуйста:)")
+        else:
+            send = bot.send_message(message.chat.id, "Следующая буква: %s" % gold[index])
+            user_data['index'] = index + 1
+            user_data['exceptions'].append(word)
+        user_data['state'] = config.States.S_ENTER_DEFINITION.value
+        db_utils.set_user_data(message.chat.id, data=user_data)
+    else:
+        if word not in used_data['exceptions']:
+            user_data['exceptions'].append(word)
+        msg = bot.send_message(message.chat.id, '''Слово должно начинаться на %s.

It seems that we never use msg/send variable.. So we may not assign a result if send_message(...) method :)

PredelinaAsya

comment created time in 2 months

startedNVIDIA/FasterTransformer

started time in 2 months

startedRangiLyu/nanodet

started time in 3 months

startedcgtuebingen/robust-vmm-guiding

started time in 3 months

startedtwangnh/Distilling-Object-Detectors

started time in 3 months