You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-07-12 22:50:22 +02:00
remove useless inheritance from command
bugfix
This commit is contained in:
@ -4,7 +4,7 @@ class ACString(ACObject):
|
|||||||
value: str
|
value: str
|
||||||
|
|
||||||
def __init__(self, value: str):
|
def __init__(self, value: str):
|
||||||
self.value = string
|
self.value = value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, fromString: str):
|
def parse(cls, fromString: str):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from typing import Type, Optional
|
from typing import Type, Optional
|
||||||
from .Command import Command
|
from .Command import Command
|
||||||
from ..ACObjects import ACObject
|
from ..ACObjects import *
|
||||||
from .RThread import RThread, Event
|
from .RThread import RThread, Event
|
||||||
|
|
||||||
class SearchResult:
|
class SearchResult:
|
||||||
@ -13,6 +13,7 @@ class SearchResult:
|
|||||||
|
|
||||||
class CommandsManager:
|
class CommandsManager:
|
||||||
allCommands: list[Command] = []
|
allCommands: list[Command] = []
|
||||||
|
QA: Command
|
||||||
|
|
||||||
def __new__(cls): # Singleton
|
def __new__(cls): # Singleton
|
||||||
if not hasattr(cls, 'instance'):
|
if not hasattr(cls, 'instance'):
|
||||||
@ -39,7 +40,7 @@ class CommandsManager:
|
|||||||
results.append(SearchResult(command, parameters))
|
results.append(SearchResult(command, parameters))
|
||||||
|
|
||||||
if results: return results
|
if results: return results
|
||||||
else: return [SearchResult(Command.QA, {'string': acstring,}),]
|
else: return [SearchResult(self.QA, {'string': acstring,}),]
|
||||||
|
|
||||||
def append(self, command):
|
def append(self, command):
|
||||||
if hasattr(self, command.name):
|
if hasattr(self, command.name):
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from ..Control import Control
|
from ..Control import Control
|
||||||
|
|
||||||
class Django(Control):
|
class Django(Control):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
#TODO: run manage.py
|
#TODO: run manage.py
|
||||||
pass
|
pass
|
||||||
|
@ -10,6 +10,9 @@ class RemoteControl(Control):
|
|||||||
url = 'http://t97316v1.beget.tech/read'
|
url = 'http://t97316v1.beget.tech/read'
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -16,6 +16,9 @@ class TelegramBot(Control):
|
|||||||
voice = Text2Speech.Engine()
|
voice = Text2Speech.Engine()
|
||||||
bot = MyTeleBot(config.telebot)
|
bot = MyTeleBot(config.telebot)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def reply(self, id, response):
|
def reply(self, id, response):
|
||||||
if response.text:
|
if response.text:
|
||||||
self.bot.send_message(id, response.text)
|
self.bot.send_message(id, response.text)
|
||||||
|
@ -17,6 +17,9 @@ class VoiceAssistant(Control):
|
|||||||
lastClapTime = 0
|
lastClapTime = 0
|
||||||
doubleClap = False
|
doubleClap = False
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.listener.listen_noise()
|
self.listener.listen_noise()
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
@ -47,7 +50,7 @@ class VoiceAssistant(Control):
|
|||||||
self.reply(response)
|
self.reply(response)
|
||||||
self.check_threads()
|
self.check_threads()
|
||||||
self.report()
|
self.report()
|
||||||
|
|
||||||
if response.callback:
|
if response.callback:
|
||||||
speech = recognize(response.callback, {})
|
speech = recognize(response.callback, {})
|
||||||
else:
|
else:
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
from bs4 import BeautifulSoup as BS
|
from bs4 import BeautifulSoup as BS
|
||||||
from ArchieCore import Command, Response
|
from ArchieCore import CommandsManager, Command, Response
|
||||||
import wikipedia as wiki
|
import wikipedia as wiki
|
||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class QA(Command):
|
class QAHelper():
|
||||||
def confirm(self, string): return True
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def googleDictionary(self, word):
|
def googleDictionary(self, word):
|
||||||
responce = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/ru/{word}')
|
responce = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/ru/{word}')
|
||||||
if responce.status_code == 200:
|
if responce.status_code == 200:
|
||||||
@ -41,34 +41,37 @@ class QA(Command):
|
|||||||
}
|
}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def wikipedia(self, word):
|
def wikipedia(self, word):
|
||||||
wiki.set_lang("ru")
|
wiki.set_lang("ru")
|
||||||
article = wiki.summary(word, sentences=5)
|
article = wiki.summary(word, sentences=5)
|
||||||
try: return article[:article.find('\n\n')][:600]
|
try: return article[:article.find('\n\n')][:600]
|
||||||
except: return ''
|
except: return ''
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def googleSearch(self, word):
|
def googleSearch(self, word):
|
||||||
responce = requests.get(f'https://www.google.ru/search?&q={word}&lr=lang_ru&lang=ru')
|
responce = requests.get(f'https://www.google.ru/search?&q={word}&lr=lang_ru&lang=ru')
|
||||||
page = BS(responce.content, 'html.parser')
|
page = BS(responce.content, 'html.parser')
|
||||||
info = page.select('div.BNeawe>div>div.BNeawe')
|
info = page.select('div.BNeawe>div>div.BNeawe')
|
||||||
return info[0].get_text() if info else ''
|
return info[0].get_text() if info else ''
|
||||||
|
|
||||||
def start(self, params):
|
@Command.new()
|
||||||
query = params['string']
|
def qa_start(params):
|
||||||
if 'вики' in query:
|
query = params['string']
|
||||||
query = query.replace('википедия', '').replace('вики', '').strip()
|
if 'вики' in query:
|
||||||
try: search = self.googleSearch(query)
|
query = query.replace('википедия', '').replace('вики', '').strip()
|
||||||
except: search = ''
|
try: search = QAHelper.googleSearch(query)
|
||||||
try: wiki = self.wikipedia(query) if not 'Википедия' in search else ''
|
except: search = ''
|
||||||
except: wiki = ''
|
try: wiki = QAHelper.wikipedia(query) if not 'Википедия' in search else ''
|
||||||
try: gdict = self.googleDictionary(query)
|
except: wiki = ''
|
||||||
except: gdict = []
|
try: gdict = QAHelper.googleDictionary(query)
|
||||||
voice = search or (gdict['short'] if gdict else '') or wiki
|
except: gdict = []
|
||||||
text = (f'Google Search:\n\t{search}' if search else '') + (f'\n\nWikipedia:\n\t{wiki}' if wiki else '') + ('\n\nDictionary:'+gdict['text'] if gdict else '')
|
voice = search or (gdict['short'] if gdict else '') or wiki
|
||||||
else:
|
text = (f'Google Search:\n\t{search}' if search else '') + (f'\n\nWikipedia:\n\t{wiki}' if wiki else '') + ('\n\nDictionary:'+gdict['text'] if gdict else '')
|
||||||
try: search = self.googleSearch(query)
|
else:
|
||||||
except: search = ''
|
try: search = QAHelper.googleSearch(query)
|
||||||
voice = text = search or random.choice(['Не совсем понимаю, о чём вы.', 'Вот эта последняя фраза мне не ясна.', 'А вот это не совсем понятно.', 'Можете сказать то же самое другими словами?', 'Вот сейчас я совсем вас не понимаю.', 'Попробуйте выразить свою мысль по-другому',])
|
except: search = ''
|
||||||
return Response(text = text, voice = voice)
|
voice = text = search or random.choice(['Не совсем понимаю, о чём вы.', 'Вот эта последняя фраза мне не ясна.', 'А вот это не совсем понятно.', 'Можете сказать то же самое другими словами?', 'Вот сейчас я совсем вас не понимаю.', 'Попробуйте выразить свою мысль по-другому',])
|
||||||
|
return Response(text = text, voice = voice)
|
||||||
|
|
||||||
Command.QA = QA('QA', [])
|
CommandsManager.QA = qa_start
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# from .Media import Media
|
# from .Media import Media
|
||||||
from .QA.QA import QA
|
|
||||||
from .SmallTalk import SmallTalk
|
from .SmallTalk import SmallTalk
|
||||||
from .Raspi import Raspi
|
from .Raspi import Raspi
|
||||||
from .Zieit import Zieit
|
from .Zieit import Zieit
|
||||||
|
101
General/StringProcesser/NumeralsParser.py
Normal file
101
General/StringProcesser/NumeralsParser.py
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
def is_number(x):
|
||||||
|
if type(x) == str:
|
||||||
|
x = x.replace(',', '')
|
||||||
|
try:
|
||||||
|
float(x)
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def text2int (textnum, numwords={}):
|
||||||
|
units = [
|
||||||
|
'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
|
||||||
|
'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
|
||||||
|
'sixteen', 'seventeen', 'eighteen', 'nineteen',
|
||||||
|
]
|
||||||
|
tens = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
|
||||||
|
scales = ['hundred', 'thousand', 'million', 'billion', 'trillion']
|
||||||
|
ordinal_words = {'first':1, 'second':2, 'third':3, 'fifth':5, 'eighth':8, 'ninth':9, 'twelfth':12}
|
||||||
|
ordinal_endings = [('ieth', 'y'), ('th', '')]
|
||||||
|
|
||||||
|
if not numwords:
|
||||||
|
numwords['and'] = (1, 0)
|
||||||
|
for idx, word in enumerate(units): numwords[word] = (1, idx)
|
||||||
|
for idx, word in enumerate(tens): numwords[word] = (1, idx * 10)
|
||||||
|
for idx, word in enumerate(scales): numwords[word] = (10 ** (idx * 3 or 2), 0)
|
||||||
|
|
||||||
|
textnum = textnum.replace('-', ' ')
|
||||||
|
|
||||||
|
current = result = 0
|
||||||
|
curstring = ''
|
||||||
|
onnumber = False
|
||||||
|
lastunit = False
|
||||||
|
lastscale = False
|
||||||
|
|
||||||
|
def is_numword(x):
|
||||||
|
if is_number(x):
|
||||||
|
return True
|
||||||
|
if word in numwords:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def from_numword(x):
|
||||||
|
if is_number(x):
|
||||||
|
scale = 0
|
||||||
|
increment = int(x.replace(',', ''))
|
||||||
|
return scale, increment
|
||||||
|
return numwords[x]
|
||||||
|
|
||||||
|
for word in textnum.split():
|
||||||
|
if word in ordinal_words:
|
||||||
|
scale, increment = (1, ordinal_words[word])
|
||||||
|
current = current * scale + increment
|
||||||
|
if scale > 100:
|
||||||
|
result += current
|
||||||
|
current = 0
|
||||||
|
onnumber = True
|
||||||
|
lastunit = False
|
||||||
|
lastscale = False
|
||||||
|
else:
|
||||||
|
for ending, replacement in ordinal_endings:
|
||||||
|
if word.endswith(ending):
|
||||||
|
word = "%s%s" % (word[:-len(ending)], replacement)
|
||||||
|
|
||||||
|
if (not is_numword(word)) or (word == 'and' and not lastscale):
|
||||||
|
if onnumber:
|
||||||
|
# Flush the current number we are building
|
||||||
|
curstring += repr(result + current) + " "
|
||||||
|
curstring += word + " "
|
||||||
|
result = current = 0
|
||||||
|
onnumber = False
|
||||||
|
lastunit = False
|
||||||
|
lastscale = False
|
||||||
|
else:
|
||||||
|
scale, increment = from_numword(word)
|
||||||
|
onnumber = True
|
||||||
|
|
||||||
|
if lastunit and (word not in scales):
|
||||||
|
# Assume this is part of a string of individual numbers to
|
||||||
|
# be flushed, such as a zipcode "one two three four five"
|
||||||
|
curstring += repr(result + current)
|
||||||
|
result = current = 0
|
||||||
|
|
||||||
|
if scale > 1:
|
||||||
|
current = max(1, current)
|
||||||
|
|
||||||
|
current = current * scale + increment
|
||||||
|
if scale > 100:
|
||||||
|
result += current
|
||||||
|
current = 0
|
||||||
|
|
||||||
|
lastscale = False
|
||||||
|
lastunit = False
|
||||||
|
if word in scales:
|
||||||
|
lastscale = True
|
||||||
|
elif word in units:
|
||||||
|
lastunit = True
|
||||||
|
|
||||||
|
if onnumber:
|
||||||
|
curstring += repr(result + current)
|
||||||
|
|
||||||
|
return curstring
|
1
General/StringProcesser/__init__.py
Normal file
1
General/StringProcesser/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .NumeralsParser import *
|
@ -1,5 +1,5 @@
|
|||||||
Python 3.10
|
Python 3.10
|
||||||
pip install speech_recognition
|
pip install SpeechRecognition
|
||||||
pip install google-cloud-texttospeech
|
pip install google-cloud-texttospeech
|
||||||
pip install pygame
|
pip install pygame
|
||||||
pip install bs4
|
pip install bs4
|
||||||
|
Reference in New Issue
Block a user