1 | import json, nltk, os |
||
2 | |||
3 | from flask import Flask, jsonify, request |
||
4 | from nltk.stem.lancaster import LancasterStemmer |
||
5 | from skf.api.security import log, val_num, val_alpha_num, val_alpha_num_special |
||
6 | from skf.api.chatbot.scripts import intent_classifier |
||
7 | from skf.api.chatbot.scripts import entity_classifier1 |
||
8 | from skf.api.chatbot.scripts import entity_classifier2 |
||
9 | from skf.api.chatbot.scripts import code_classify |
||
10 | |||
11 | app = Flask(__name__) |
||
12 | |||
13 | def des_sol(question,intent): |
||
14 | entity=entity_classifier1.entity_recognizer(question.lower()) |
||
15 | if entity is None: |
||
16 | entity=entity_classifier2.entity(question) |
||
17 | intent=intent |
||
18 | read_file = open(os.path.join(app.root_path, "datasets/desc_sol.json"), 'r') |
||
19 | data = json.load(read_file) |
||
20 | ite=data['items'] |
||
21 | if type(entity)==str: |
||
22 | for d in ite: |
||
23 | if entity.lower()==d['title'].lower(): |
||
24 | if intent=="Description": |
||
25 | desc="Description for "+d['title']+" is : "+ d[intent] |
||
26 | intent="NULL" |
||
27 | return desc |
||
28 | break |
||
29 | else: |
||
30 | sol="Solution for "+d['title']+" is : "+ d[intent] |
||
31 | intent="NULL" |
||
32 | return sol |
||
33 | break |
||
34 | else: |
||
35 | if len(entity)>0: |
||
36 | for i in entity: |
||
37 | entity[i]=intent+" "+entity[i] |
||
38 | |||
39 | return entity |
||
40 | else: |
||
41 | msg="Please be more specific" |
||
42 | return msg |
||
43 | |||
44 | def code(question,intent,language): |
||
45 | code_entity=code_classify.entity(question) |
||
46 | read_file = open(os.path.join(app.root_path, "datasets/code_data.json"), 'r') |
||
47 | code_data = json.load(read_file) |
||
48 | code_ite=code_data['items'] |
||
49 | code_languages=[] |
||
50 | count=0 |
||
51 | if len(code_entity)==2 and type(code_entity[0])==str: |
||
52 | entity=str(code_entity[0].strip("\n").lower()) |
||
53 | if language is None: |
||
54 | language=str(code_entity[-1].strip("\n").lower()) |
||
55 | else: |
||
56 | language=language |
||
57 | for d in code_ite: |
||
58 | if entity==d['title'].lower(): |
||
59 | code_languages.append(d['code_lang']) |
||
60 | for d in code_ite: |
||
61 | if entity==d['title'].lower() and language in code_languages: |
||
62 | if language==d['code_lang'].lower(): |
||
63 | code_a="Code for "+ d['content']+"\n Code language is " + d['code_lang'] |
||
64 | count=count+1 |
||
65 | return code_a,language |
||
66 | if count==0: |
||
67 | code_l={} |
||
68 | entity=intent+" "+str(code_entity[0].strip("\n").lower()) |
||
69 | for i in range(len(code_languages)): |
||
70 | code_l[i+1]=code_languages[i] |
||
71 | return entity,code_l |
||
72 | #print("The language you typed is not availabe. Select from the following:") |
||
73 | #for i in code_l: |
||
74 | # print(str(i)+":"+code_l[i]) |
||
75 | #TO_BE_CHANGEDn=int(input("Enter your choice: ")) |
||
76 | #lang=language |
||
77 | for d in code_ite: |
||
78 | if entity==d['title'].lower() and lang in code_languages: |
||
79 | if lang==d['code_lang'].lower(): |
||
80 | return d['content'] |
||
81 | #print("\n Code language is " + d['code_lang']) |
||
82 | count=count+1 |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
83 | #TO_BE_CHANGEDques=input("\n Do you have more Questions Y/N ") |
||
84 | else: |
||
85 | if language is None: |
||
86 | language=str(code_entity[-1].strip("\n").lower()) |
||
87 | else: |
||
88 | language=language |
||
89 | code_list={} |
||
90 | for i in code_entity[0]: |
||
91 | code_list[i]=intent+" "+code_entity[0][i] |
||
92 | return code_list,language |
||
93 | |||
94 |