python - How to pick key words from a list, after appending a .csv file to that list? -
i need able pick keywords excel csv file, i've appended file list. program phone troubleshoot, , need input ("the screen won't turn on") have same output if inputted ("the display blank").
"troubleshooting program give user solution trouble they've     encountered based on inputted key words."  phoneprob=input("what problem having phone? ") prob=open("phone.csv","r") phone=prob.read() prob.close() eachprob=phone.split("\n")  print(eachprob) problist=[eachprob]  print (problist) 
are trying build keyword dictionary or retriving sentence problem ? in both case, need associate problem keywords.
a basic approch keywords split sentence in words (using s.split()) , update keyword list used of them... difflib can here.
since don't know given file schema, assume it's list of sentence , provided keyword/problems elsewhere (situation dict).
for example:
csv_ret = ["i can't turn on phone", "the screen won't turn on", "phone display blank"]  situations = {     "screen": ["turn on", "blank", "display", "screen"],     "battery": ["turn on", "phone"] }   def get_situation_from_sentence(sentence):     occurences = {}     word in sentence.split():         key, value in situations.items():             if word in value:                 if occurences.get(key) none:                     occurences[key] = [word]                 elif word not in occurences.get(key):                     occurences[key].append(word)     averages = {k: ((len(v) * 100) / len(situations[k])) k, v in occurences.items()}     return "{}, {}".format(averages, sentence)  sentence in csv_ret:     print(get_situation_from_sentence(sentence)) results:
{'battery': 50.0}, can't turn on phone
{'screen': 25.0}, screen won't turn on
{'screen': 50.0, 'battery': 50.0}, phone display blank
this code evaluate sentence problems , related keyword match in percent.
once again basic solution, , need more robust (lexer/parser, machine learning ...) sometime simpler better :)
Comments
Post a Comment