forked from kaushal2161/Mathaware-Q-A-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetidentifiers.py
68 lines (50 loc) · 1.53 KB
/
getidentifiers.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
import json
from flask import jsonify
from sympy.core.sympify import sympify
from sympy import Number, NumberSymbol, Symbol
def evalformula(formula):
#f=process_sympy(formula)
a=sympify(formula)
symbol=a.atoms(Symbol)
return symbol
def value(formula):
#f=process_sympy(formula)
a=sympify(formula)
symbol=a.atoms(Symbol)
return symbol
def equality(formula,ext):
global lhs
global rhs
lhs,rhs=formula.split(ext,1)
value=evalformula(rhs)
return value
def formuladivision(formula):
k = ['=', '\leq', '\req', '\\approx']
if '=' in formula:
ext = '='
return ext
if '\leq' in formula:
ext = '\leq'
return ext
if '\req' in formula:
ext = '\req'
return ext
if '\\approx' in formula:
ext = '\\approx'
return ext
if not any(ext in formula for ext in k):
return None
class Getidentifiers:
def __init__(self, request):
self.request = request
def answer(self):
formula=self.request
global seprator
self.seprator= formuladivision(formula)
if self.seprator is not None:
symbol=equality(formula,self.seprator)
else:
symbol=value(formula)
listsymbol=list(symbol)
#string=''.join(str(listsymbol))
return listsymbol