本文整理匯總了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;
}