本文整理汇总了Java中org.python.util.PythonInterpreter.close方法的典型用法代码示例。如果您正苦于以下问题:Java PythonInterpreter.close方法的具体用法?Java PythonInterpreter.close怎么用?Java PythonInterpreter.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.util.PythonInterpreter
的用法示例。
在下文中一共展示了PythonInterpreter.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
String text = "Hallo wie gehts es dir? Du bist echt böse.";
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.set("text", text);
interpreter.execfile("AnSoMiaPy/analyser/test1.py");
PyObject translated_text = interpreter.get("translated_text");
//PyObject sentiment = interpreter.get("sentiment");
interpreter.close();
System.out.println("translated_text: " + translated_text.toString());
}
示例2: analyseText
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
/**
* Analyse text.
*
* @param news the news
* @return true, if successful
*/
public boolean analyseText(News news) {
try{
/*String prg = "import sys\nprint int(sys.argv[1])+int(sys.argv[2])\n";
BufferedWriter out = new BufferedWriter(new FileWriter("test1.py"));
out.write(prg);
out.close();*/
/*String argv1 = "This is a test argument 1";
//ProcessBuilder pb = new ProcessBuilder("python","test1.py",""+number1,""+number2);
ProcessBuilder pb = new ProcessBuilder("python","AnSoMiaPy/analyser/test1.py", argv1);
Process p = pb.start();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = in.readLine()) != null) {
System.out.println(line);
}*/
@SuppressWarnings("unused")
String text = "The titular threat of The Blob has always struck me as the ultimate movie monster: an insatiably hungry, amoeba-like mass able to penetrate virtually any safeguard, capable of--as a doomed doctor chillingly describes it assimilating flesh on contact. Snide comparisons to gelatin be damned, it's a concept with the most devastating of potential consequences, not unlike the grey goo scenario proposed by technological theorists fearful of artificial intelligence run rampant.";
PythonInterpreter interpreter = new PythonInterpreter();
//interpreter.set("text", text);
interpreter.execfile("AnSoMiaPy/analyser/test1.py");
//interpreter.exec("import sys");
//interpreter.exec("from textblob import TextBlob");
//interpreter.set("text", text);
//interpreter.exec("blob = TextBlob(text)");
//interpreter.exec("print blob.noun_phrases");
//interpreter.exec("for sentence in blob.sentences:\n\tprint sentence.sentiment.polarity");
//interpreter.exec("translated_text = blob.translate(to=\"de\")");
PyObject translated_text = interpreter.get("translated_text");
//PyObject sentiment = interpreter.get("sentiment");
interpreter.close();
System.out.println("translated_text: " + translated_text.toString());
//System.out.println("sentiment: " + sentiment);
// execute a function that takes a string and returns a string
/*PyObject someFunc = interpreter.get("funcName");
PyObject result = someFunc.__call__(new PyString("Test!"));
String realResult = (String) result.__tojava__(String.class);*/
}catch(Exception e) {
System.out.println(e);
return false;
}
return true;
}