Say I have inserted a rule :
(defrule matching
(fever ?fever)
(headache ?headache)
(disease (fever ?fever) (disname ?disname1) (headache ?headache))
=>
(assert (dis ?disname1)))
Now I want to fetch the value of ?disname1 into a python variable so that I can display it on a webpage,
Flask code -
import clips
from flask import Flask , render_template ,request
app = Flask(__name__)
env = clips.Environment()
env.load("clips.clp")
env.reset()
@app.route('/')
def home():
return render_template('main.html')
@app.route('/result' , methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
if request.form.get('fever'):
env.assert_string("(fever true) ")
if request.form.get('headache'):
env.assert_string("(headache true)")
rule = """ (defrule matching
(fever ?fever) (headache ?headache)
(disease (fever ?fever) (disname ?disname1) (headache ?headache))
=>
(assert ( dis ?disname1 )) """
env.build(rule)
return render_template('next.html')
env.run()
if __name__ == '__main__':
app.run(debug= True)
So after the rule is build ( dis ?disname) is asserted as a fact into clips so now ,I want to retrieve the value of ?disname which will give me the illness a person is facing , into a python variable so that I can pass it to html template and display it.