当前位置: 首页>>代码示例>>Java>>正文


Java PythonInterpreter.close方法代码示例

本文整理汇总了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());
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:21,代码来源:TextBlobAnalyser.java

示例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;
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:69,代码来源:TextBlobAnalyser.java


注:本文中的org.python.util.PythonInterpreter.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。