【发布时间】:2017-05-14 01:33:23
【问题描述】:
我有一个由一个函数组成的 python 文件,machineLearning(issue)。
在我的 PHP 代码中,要运行 python 脚本,我有以下内容:
'category' => exec("python C:/xampp/htdocs/ci/assets/machineLearning.py $temp 2>&1"),
它按预期运行机器学习功能。但是,我需要包含另一个名为updateTrain 的函数,它接受参数issue, category。这是当前的python文件:
from textblob import TextBlob;
from textblob.classifiers import NaiveBayesClassifier;
import sys;
train = [
('I cannot enter or exit the building','idCard'),
('Enter or exit', 'idCard'),
('Card needs replacing','idCard'),
('ID card not working','idCard'),
('Printing', 'printer'),
("My ID Card doesn't sign me into the printers", "printer"),
('Mono', "printer"),
('Colour Printing',"printer"),
('I cannot connect my phone to the wifi', 'byod'),
('I do not get emails on my phone, tablet, or laptop', 'byod'),
('Cannot send emails','email'),
('Do not recieve emails','email'),
('Cannot sign in to moodle', 'email'),
('Cannot sign in to computer','desktop_pc'),
("Software isn't working",'desktop_pc'),
('Scratch disks are full', 'desktop_pc'),
('I have forgotten my password for the computers', 'desktop_pc'),
('forgotten password','forgotten_password'),
('My password does not work','forgotten_password'),
('Applications fail to launch and I get an error', 'desktop_pc'),
('My ID card does not allow me to print. I go to scan my card on the printer, and it comes up with a message saying that I need to associate my card every day I want to print. Other peoples cards work fine?','idCard'),
("I am having trouble connecting my android phone to my emails. I open the gmail app and select exchange account. I then enter my email and password and click okay on the message that asks if its alright to use the autoconfigure.xml. It then gives me all the server details, I click okay and then it tells me that I cannot connect to the server.", 'byod'),
('I cannot find my work', 'lost_work'),
('My work has been corrupted', 'lost_work'),
('My work has been lost', 'lost_work'),
('Coursework gone missing', 'lost_work'),
('my id card isnt working','idCard'),
('I cannot print in colour', 'printer')
]
cl = NaiveBayesClassifier(train);
def updateTrain(issue, category):
new_data = [(issue,category)];
cl.update(new_data);
def machineLearning(issue):
test = [
("My id card does not allow me to go through the gates, the light flashes orange and then goes red. The gate doesn't open", "idCard"),
('My id card has snapped', 'idCard'),
('When printing, swiping my ID card does not automatically sign me in, I have to manually register my card', 'printer'),
('I am getting errors when trying to sign into my email account on the website', 'email'),
('Microsoft applications were not working','desktop_pc'),
('Software is missing','desktop_pc'),
('software keeps crashing','desktop_pc'),
('my phone refuses to connect to the internet','byod'),
('I cannot sign in to the computers, moodle or emails because I have forgotten my password','desktop_pc'),
('I cannot get my emails on my device I bought from home','byod'),
('My ID card does not allow me to print. I go to scan my card on the printer, and it comes up with a message saying that I need to associate my card every day I want to print. Other peoples cards work fine?','idCard'),
('My password does not allow me to sign in to the computers, laptops, moodle or emails','forgotten_password'),
('I have forgotten my password','forgotten_poassword'),
('My work has been corrupted', 'lost_work'),
('My work has been lost', 'lost_work'),
('Coursework gone missing', 'lost_work'),
('I cannot print in colour', 'printer'),
];
print(cl.classify(issue));
if __name__ == "__main__":
machineLearning(sys.argv[1]);
由于updateTrain(issue, category) 需要2 个参数,我该如何更改上述exec 命令以使其忽略更新列车?
同样,我如何调用updateTrain,而忽略machineLearning 函数?
【问题讨论】:
标签: php python codeigniter python-3.x php-7