diff --git a/Python-bot/data/base.json b/Python-bot/data/base.json
index d3abb84..81dbe8d 100644
--- a/Python-bot/data/base.json
+++ b/Python-bot/data/base.json
@@ -1 +1 @@
-{"205589546": {"2020-01-29|13:39:28.778879": "a", "2020-01-29|13:39:35.527274": "aa", "2020-01-29|13:39:40.711174": "aaa"}}
\ No newline at end of file
+{"205589546": {"2020-01-29|13:39:28.778879": "a", "2020-01-29|13:39:35.527274": "aa", "2020-01-29|13:39:40.711174": "aaa"}, "109297779": {"2020-02-07|21:46:53.837151": "\u041d\u0435 \u043c\u043e\u0433\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443", "2020-02-07|21:47:25.329122": "\u041d\u0435 \u043c\u043e\u0433\u0443 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443", "null": "\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043a\u0438\u043d\u043e 08.02.2020", "null": "\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043a\u0438\u043d\u043e 08.02.2020"}}
\ No newline at end of file
diff --git a/Python-bot/parsing/PrettyOutput.html b/Python-bot/parsing/PrettyOutput.html
new file mode 100644
index 0000000..5e28eb8
--- /dev/null
+++ b/Python-bot/parsing/PrettyOutput.html
@@ -0,0 +1,51 @@
+
+Напомни
+
+ завтра
+
+ сходить
+
+ в
+
+ качалочку
+
+ напомни
+
+ погулять
+
+ напомни
+
+ напомни
+
+ иии
+
+ EOS
+
+
+| Text |
+Type |
+
+
+| напомни |
+TAuxDicArticle [Базовая грамматика] |
+
+
+| напомни |
+TAuxDicArticle [Базовая грамматика] |
+
+
+| напомни |
+TAuxDicArticle [Базовая грамматика] |
+
+
+| напомни |
+TAuxDicArticle [Базовая грамматика] |
+
+
+
diff --git a/Python-bot/parsing/config.proto b/Python-bot/parsing/config.proto
new file mode 100644
index 0000000..1200fed
--- /dev/null
+++ b/Python-bot/parsing/config.proto
@@ -0,0 +1,16 @@
+encoding "utf8"; // указываем кодировку, в которой написан конфигурационный файл
+
+TTextMinerConfig {
+ Dictionary = "mydic.gzt"; // путь к корневому словарю
+
+ PrettyOutput = "PrettyOutput.html"; // путь к файлу с отладочным выводом в удобном для чтения виде
+
+ Input = {
+ File = "test.txt"; // путь к входному файлу
+ }
+
+ Articles = [
+ { Name = "Базовая грамматика" } // название статьи в корневом словаре,
+ // которая содержит запускаемую грамматику
+ ]
+}
diff --git a/Python-bot/parsing/first.bin b/Python-bot/parsing/first.bin
new file mode 100644
index 0000000..0ead54f
Binary files /dev/null and b/Python-bot/parsing/first.bin differ
diff --git a/Python-bot/parsing/first.cxx b/Python-bot/parsing/first.cxx
new file mode 100644
index 0000000..28b5637
--- /dev/null
+++ b/Python-bot/parsing/first.cxx
@@ -0,0 +1,4 @@
+#encoding "utf-8" // сообщаем парсеру о том, в какой кодировке написана грамматика
+#GRAMMAR_ROOT Remind // указываем корневой нетерминал грамматики
+
+Remind -> Word;
diff --git a/Python-bot/parsing/mydic.gzt b/Python-bot/parsing/mydic.gzt
new file mode 100644
index 0000000..7a2471b
--- /dev/null
+++ b/Python-bot/parsing/mydic.gzt
@@ -0,0 +1,16 @@
+encoding "utf8"; // указываем кодировку, в которой написан этот файл
+
+import "base.proto"; // подключаем описания protobuf-типов (TAuxDicArticle и прочих)
+import "articles_base.proto"; // Файлы base.proto и articles_base.proto встроены в компилятор.
+ // Их необходимо включать в начало любого gzt-словаря.
+
+TAuxDicArticle "Напоминания"
+{
+ key = { "Напомни" | "напомни"}
+}
+
+TAuxDicArticle "Базовая грамматика"
+{
+ key = { "tomita:first.cxx" type=CUSTOM }
+}
+
diff --git a/Python-bot/parsing/mydic.gzt.bin b/Python-bot/parsing/mydic.gzt.bin
new file mode 100644
index 0000000..e0c8601
Binary files /dev/null and b/Python-bot/parsing/mydic.gzt.bin differ
diff --git a/Python-bot/parsing/test.txt b/Python-bot/parsing/test.txt
new file mode 100644
index 0000000..5f1c2ff
--- /dev/null
+++ b/Python-bot/parsing/test.txt
@@ -0,0 +1,4 @@
+Напомни завтра сходить в качалочку
+напомни погулять
+напомни
+напомни иии
diff --git a/Python-bot/server.py b/Python-bot/server.py
index ef2d086..f2f56f2 100644
--- a/Python-bot/server.py
+++ b/Python-bot/server.py
@@ -1,9 +1,11 @@
import requests
import json
-import random
import datetime
+import os
+import re
from user import UserList
+
class Server:
group_id = 191177272
access_token = 'access_token=f068c796542cba0f4dbdd0f6e39ba656a489731d36cfdcbdf7cee30de822ae000aa9e1aa8293bc61d77c7'
@@ -12,16 +14,18 @@ class Server:
data = UserList()
def __init__(self):
- Server.getLongPollServer(self)
+ self.server = str()
+ self.key = str()
+ self.ts = str()
+ self.get_long_poll_server()
- def getLongPollServer(self):
+ def get_long_poll_server(self):
method = 'groups.getLongPollServer?group_id=191177272'
reply = requests.get("&".join([Server.body + method, Server.v, Server.access_token]))
data = json.loads(reply.text)
self.server = data['response']['server']
self.key = data['response']['key']
self.ts = data['response']['ts']
- # print(self.server, self.key, self.ts)
def simple_request(self):
method = self.server + '?act=a_check&key=' + self.key + '&ts=' + self.ts + "&wait=25"
@@ -30,16 +34,26 @@ def simple_request(self):
def simple_loop(self):
reply = json.loads(self.simple_request().text)
self.ts = reply['ts']
- # print(json.dumps(reply, indent='\t'))
if reply['updates']:
message = reply['updates'][0]['object']['message']['text']
+ if 'Напомни' in message:
+ date = re.search('$d{2}-$d{2}-$d{4}', message)
+ if str(date) != '':
+ message = str(message).replace('Напомни ', '').replace(str(date), '')
+ else:
+ message = 'Не могу разобрать команду'
+ date = datetime.datetime.now().isoformat('|')
+ else:
+ message = 'Не могу разобрать команду'
+ date = datetime.datetime.now().isoformat('|')
user_id = reply['updates'][0]['object']['message']['from_id']
- self.data.add_rec(str(user_id), {datetime.datetime.now().isoformat('|'): message})
- random_id = random.randint(0, 100)
- method = 'messages.send?' + 'user_id=' + str(user_id) + '&random_id=' + str(random_id) \
- + '&message=' + message
- r = requests.get("&".join([Server.body + method, Server.v, Server.access_token]))
- print("&".join([Server.body + method, Server.v, Server.access_token]))
+ if message != 'Не могу разобрать команду':
+ catalog = os.system('pwd')
+ if str(catalog).endswith('/parsing'):
+ os.system('tomita-parser config.proto')
+ else:
+ os.system('cd parsing/ && tomita-parser config.proto')
+ self.data.add_rec(str(user_id), {date: message})
self.simple_loop()
diff --git a/parsing/config.proto b/parsing/config.proto
new file mode 100644
index 0000000..9bad2d6
--- /dev/null
+++ b/parsing/config.proto
@@ -0,0 +1,16 @@
+encoding "utf8"; // указываем кодировку, в которой написан конфигурационный файл
+
+TTextMinerConfig {
+ Dictionary = "mydic.gzt"; // путь к корневому словарю
+
+ PrettyOutput = "PrettyOutput.html"; // путь к файлу с отладочным выводом в удобном для чтения виде
+
+ Input = {
+ File = "test.txt"; // путь к входному файлу
+ }
+
+ Articles = [
+ { Name = "наша_первая_грамматика" } // название статьи в корневом словаре,
+ // которая содержит запускаемую грамматику
+ ]
+}
diff --git a/parsing/first.cxx b/parsing/first.cxx
new file mode 100644
index 0000000..a7104b1
--- /dev/null
+++ b/parsing/first.cxx
@@ -0,0 +1,4 @@
+#encoding "utf-8" // сообщаем парсеру о том, в какой кодировке написана грамматика
+#GRAMMAR_ROOT S // указываем корневой нетерминал грамматики
+
+Remind -> Noun
diff --git a/parsing/mydic.gzt b/parsing/mydic.gzt
new file mode 100644
index 0000000..db3cc81
--- /dev/null
+++ b/parsing/mydic.gzt
@@ -0,0 +1,15 @@
+encoding "utf8"; // указываем кодировку, в которой написан этот файл
+
+import "base.proto"; // подключаем описания protobuf-типов (TAuxDicArticle и прочих)
+import "articles_base.proto"; // Файлы base.proto и articles_base.proto встроены в компилятор.
+ // Их необходимо включать в начало любого gzt-словаря.
+
+TAuxDicArticle "Базовая грамматика"
+{
+ key = { "tomita:first.cxx" type=CUSTOM }
+}
+
+TAuxDicArticle "Напоминания"
+{
+ key = { "Напомни" | "напомни"}
+}
diff --git a/parsing/test.txt b/parsing/test.txt
new file mode 100644
index 0000000..dce37b9
--- /dev/null
+++ b/parsing/test.txt
@@ -0,0 +1 @@
+Тяжёлый труд облагораживает хорошего человека.
diff --git a/setup.py b/setup.py
index f5c36aa..fd7d0c8 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,8 @@
requirements = [
# TODO: put package requirements here
- 'requests'
+ 'requests',
+ 'datetime'
]
test_requirements = [