-
Notifications
You must be signed in to change notification settings - Fork 0
/
kric_2.0.py
138 lines (105 loc) · 3.39 KB
/
kric_2.0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 22 01:42:32 2021
@author: Aromal Pradeep
"""
'''
KRIC - Kric is a Random Intellegent Calculator
==============================================
# Project for Mec Labs
'''
# The GUI interface
# Basic
# Imports
import time
#import random as r
#import re
from word2number import w2n
from simpleeval import simple_eval
# NLTK
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
from nltk.tokenize import word_tokenize
# Spell Checker
#from spellchecker import SpellChecker
#spell = SpellChecker()
# Kivy
import kivy
from kivy.app import App
from kivy.config import Config
from kivy.core.window import Window
# UIX
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.pagelayout import PageLayout
from kivy.clock import Clock
# Date and Time
def today():
return time.strftime("%d.%m.%y.%A.%H.%M").split('.')
# Base
class base(GridLayout):
'''def __init__(self):
pass'''
def kill(self):
pass
def Minus_app_button(self):
App.get_running_app().root_window.minimize()
def MaxiMin_app_button(self):
if Window.fullscreen:
Window.fullscreen = False
else:
Window.fullscreen = True
def close_app_button(self):
kricApp.stop()
def Time(self):
return time.strftime('[b]%H[/b]:%M:%S')
# Think - The main code
def think(self,i):
# User input
#i = entry.text
#i = self.root.ids.entry.text
if i.lower() in ['break','end','quit']:
exit()
else:
try:
#case 0 : a Number entered
try:
o = (w2n.word_to_num(i))
except:
try:
#case 1 : Normal calculations (basic calculator)
'''Easy way was to use eval, but using eval has great risks as it could be used to potentially crack your system'''
o = simple_eval(i)
except:
try:
# clean sentence
i = i.lower()
words = [k for k in word_tokenize(i) if k not in stop_words]
o = words
except:
#raise Exception()
pass
except: # if in case of errors
o = 'x_Random error occured_x'
# Output
self.ids.output.text = str(o)
self.ids.entry.text = ''
class KricApp(App):
def build(self):
# Layout dimensions
#Config.set('graphics', 'resizable', False)
#Config.set('graphics', 'borderless', 'True')
#Config.set('graphics', 'width', '400')
#Config.set('graphics', 'height', '300')
Window.size = (300,300)
Window.borderless = True
return base()
# Run the App
if __name__ == "__main__":
kricApp = KricApp()
kricApp.run()