當前位置: 首頁>>代碼示例>>Java>>正文


Java PythonInterpreter.execfile方法代碼示例

本文整理匯總了Java中org.python.util.PythonInterpreter.execfile方法的典型用法代碼示例。如果您正苦於以下問題:Java PythonInterpreter.execfile方法的具體用法?Java PythonInterpreter.execfile怎麽用?Java PythonInterpreter.execfile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.python.util.PythonInterpreter的用法示例。


在下文中一共展示了PythonInterpreter.execfile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: CreateFromPython

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public void CreateFromPython()
	{
		PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState());

		PySystemState sys = Py.getSystemState();

		sys.path.append(new PyString(context.settings.GetModelPath()));

		if(context.settings.GetSysPath() != null)
			sys.path.append(new PyString(context.settings.GetSysPath()));

		/*
// some magic to pass context to all python modules
		interpreter.set("context", context);
		interpreter.set("model_service", model_service);
		interpreter.exec("import __builtin__");
		interpreter.exec("__builtin__.context = context");
		interpreter.exec("__builtin__.model_service = model_service");*/

		interpreter.execfile(context.settings.GetModelPath() + '/' + context.settings.GetModelMain());

		interpreter.cleanup();

		UpdateDefinedSensors();
	}
 
開發者ID:srcc-msu,項目名稱:octotron_core,代碼行數:26,代碼來源:ExecutionService.java

示例2: getCount

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public double getCount(int[] query) {
// convert the int[] query to PyList<PyInteger> pyQuery
// the input java query is like [0, 2, 1, -1], the converted python query is like [1, 3, 2]
List<PyInteger> pyQueryList = new ArrayList<PyInteger>();
for (int eachValue : query)
    if (eachValue != -1)
	pyQueryList.add(new PyInteger(eachValue+1));
PyList pyQuery = new PyList(pyQueryList);

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("/media/uraplutonium/Workstation/Workspace/teabag-ml/src/main/java/teabagml/adtree/PySparseADTree.py");
PyFunction getCountFunc = (PyFunction)interpreter.get("getCount", PyFunction.class);
PyInteger pyCount = (PyInteger)(getCountFunc.__call__(contab, pyQuery));
double count = (double)(pyCount.getValue());

/*
System.out.print("Query: ");
for (int eachValue : query) {
    System.out.print(eachValue + ' ');
}
System.out.println("\t Count: " + count);
*/
return count;
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:25,代碼來源:PyContingencyTable.java

示例3: PyDataset

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public PyDataset(String filePath, boolean symbolic, boolean labelled) {
// BEWEAR: symbolic and labelled are NOT used
this.symbolic = symbolic;
this.labelled = labelled;
PythonInterpreter interpreter = new PythonInterpreter();
       interpreter.execfile("/media/uraplutonium/Workstation/Workspace/teabag-ml/src/main/java/teabagml/adtree/PySparseADTree.py");
PyFunction loadFileFunc = (PyFunction)interpreter.get("loadFile", PyFunction.class);
fileTuple = (PyTuple)(loadFileFunc.__call__(new PyString(filePath)));
// todo extract dimension, dataSize, arity from fileTuple
PyInteger pyArityLength = (PyInteger)(fileTuple.pyget(1));
PyList pyArityList = (PyList)(fileTuple.pyget(2));
PyInteger pyRecordsLength = (PyInteger)(fileTuple.pyget(3));
this.dimension = pyArityLength.getValue();
this.dataSize = pyRecordsLength.getValue();
PyObject[] pyArityArray = pyArityList.getArray();
String[] arityNames = new String[dimension];
int[] arityArray = new int[dimension];
for (int i=0; i<dimension; i++) {
    arityArray[i] = ((PyInteger)(pyArityArray[i])).getValue();
    arityNames[i] = Integer.toString(arityArray[i]);
}
arity = new Arity(dimension, arityNames, arityArray);
System.out.println("file loaded.");
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:25,代碼來源:PyDataset.java

示例4: runTestOnce

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
private void runTestOnce(String testScript, PythonInterpreter interp, int invocationsSoFar)
{
    try
    {
        interp.execfile(testScript);
    }
    catch (PyException e)
    {
        if( e.type.toString().equals("<type 'exceptions.SystemExit'>") && e.value.toString().equals("0") )
        {
            // Build succeeded.
        }
        else
        {
            if (LOGGER.isLoggable(Level.FINE))
            {
                LOGGER.log(Level.FINE, "Jython interpreter failed. Test failures?", e);
            }

            // This unusual code is necessary because PyException toString() contains the useful Python traceback
            // and getMessage() is usually null
            fail("Caught PyException on invocation number " + invocationsSoFar + ": " + e.toString() + " with message: " + e.getMessage());
        }
    }
}
 
開發者ID:apache,項目名稱:qpid-proton-j,代碼行數:26,代碼來源:JythonTest.java

示例5: execute

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public void execute( ExecutionContext executionContext ) throws ParsingException, ExecutionException
{
	PythonInterpreter pythonInterpreter = adapter.getPythonInterpreter( executionContext, executable );

	try
	{
		PyCode pythonCode = this.pythonCode;
		if( pythonCode != null )
			pythonInterpreter.exec( pythonCode );
		else
			// We're using a stream because PythonInterpreter does not
			// expose a string-based method that also accepts a filename.
			pythonInterpreter.execfile( new ByteArrayInputStream( sourceCode.getBytes() ), executable.getDocumentName() );
	}
	catch( Exception x )
	{
		throw JythonAdapter.createExecutionException( executable.getDocumentName(), startLineNumber, x );
	}
	finally
	{
		JythonAdapter.flush( pythonInterpreter, executionContext );
	}
}
 
開發者ID:tliron,項目名稱:scripturian,代碼行數:24,代碼來源:JythonProgram.java

示例6: importUserScripts

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public void importUserScripts(PythonInterpreter interpreter) {
	String dirpathString = ServletContextParameterMap
			.getParameterValue(ContextParameter.USER_PYTHON_SCRIPTS_DIRECTORY);

	if (dirpathString != null && dirpathString.compareTo("") != 0) {
		File f = new File(dirpathString);
		String[] scripts = f.list(new FilenameFilter(){

			@Override
			public boolean accept(File dir, String name) {
				return name.endsWith(".py");
			}});
		for(String script : scripts)
		{
			interpreter.execfile(dirpathString  + File.separator + script);
		}
	}
}
 
開發者ID:therelaxist,項目名稱:spring-usc,代碼行數:19,代碼來源:PythonTransformationHelper.java

示例7: PythonExecutor

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public PythonExecutor(Object extension) throws PythonWrapperError {
    String scriptPath = getScriptPath(extension);
    pinterp = new PythonInterpreter();
    pinterp.exec("import sys");
    String modulePath = new File(scriptPath).getParent();
    modulePath = modulePath.replace("\\", "\\\\");
    modulePath = modulePath.replace("'", "\\'");
    String cmdPath = "sys.path.append('" + modulePath + "')";
    pinterp.exec(cmdPath);
    pinterp.execfile(scriptPath);
    pinterp.set("extension", extension);
    callId = 0;
    this.extension = extension;
    if (hasFunction("init_plugin", 0)) {
        pinterp.exec("init_plugin()");
    }
}
 
開發者ID:conyx,項目名稱:jenkins.py,代碼行數:18,代碼來源:PythonExecutor.java

示例8: hiveColumnParserTest

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
@Test
public void hiveColumnParserTest() {

  LaunchJython l = new LaunchJython();
  PythonInterpreter interpreter = l.setUp();

  ClassLoader classLoader = getClass().getClassLoader();
  InputStream inputStream = classLoader.getResourceAsStream("jython-test/HiveColumnParserTest.py");
  interpreter.execfile(inputStream);

}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:12,代碼來源:HiveColumnParserTest.java

示例9: avroTest

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
@Test
public void avroTest() {

  LaunchJython l = new LaunchJython();
  PythonInterpreter interpreter = l.setUp();

  ClassLoader classLoader = getClass().getClassLoader();
  InputStream inputStream = classLoader.getResourceAsStream("jython-test/AvroColumnParserTest.py");
  interpreter.execfile(inputStream);

}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:12,代碼來源:AvroColumnParserTest.java

示例10: onReceive

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
@Override
public void onReceive(Object o) throws Exception {
  if (o instanceof String) {
    Properties whProps = EtlJobPropertyDao.getWherehowsProperties();
    PyDictionary config = new PyDictionary();
    for (String key : whProps.stringPropertyNames()) {
      String value = whProps.getProperty(key);
      config.put(new PyString(key), new PyString(value));
    }
    sys = new PySystemState();
    sys.argv.append(config);
    interpreter = new PythonInterpreter(null, sys);
    String msg = (String) o;
    Logger.info("Start build {} tree", msg);
    InputStream in = null;
    switch (msg) {
      case "dataset":
        in = EtlJob.class.getClassLoader().getResourceAsStream("jython/DatasetTreeBuilder.py");
        break;
      case "flow":
        //in = EtlJob.class.getClassLoader().getResourceAsStream("jython/FlowTreeBuilder.py");
        break;
      default:
        Logger.error("unknown message : {}", msg);
    }
    if (in != null) {
      interpreter.execfile(in);
      in.close();
      Logger.info("Finish build {} tree", msg);
    } else {
      Logger.error("can not find jython script");
    }
  } else {
    throw new Exception("message type is not supported!");
  }
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:37,代碼來源:TreeBuilderActor.java

示例11: PySparseADTree

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public PySparseADTree(String dataPath) {
PythonInterpreter interpreter = new PythonInterpreter();
       interpreter.execfile("/media/uraplutonium/Workstation/Workspace/teabag-ml/src/main/java/teabagml/adtree/PySparseADTree.py");
PyFunction makeSparseADTreeFunc = (PyFunction)interpreter.get("makeSparseADTree", PyFunction.class);
adtree = makeSparseADTreeFunc.__call__(new PyString(dataPath));
System.out.println("sparse adtree constructed.");
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:8,代碼來源:PySparseADTree.java

示例12: PyContingencyTable

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public PyContingencyTable(PySparseADTree pyADTree, int[] attrList) {
// convert the int[] attrList to PyList<PyInteger> pyAttrList
PyInteger[] pyAttrArray = new PyInteger[attrList.length];
for (int i=0; i<attrList.length; i++)
    pyAttrArray[i] = new PyInteger(attrList[i]);
PyList pyAttrList = new PyList(pyAttrArray);

PythonInterpreter interpreter = new PythonInterpreter();
       interpreter.execfile("/media/uraplutonium/Workstation/Workspace/teabag-ml/src/main/java/teabagml/adtree/PySparseADTree.py");
PyFunction makeContabFunc = (PyFunction)interpreter.get("makeContab", PyFunction.class);
contab = makeContabFunc.__call__(pyADTree.getPyADTree(), pyAttrList);
System.out.println("contingency table constructed.");
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:14,代碼來源:PyContingencyTable.java

示例13: PyADTreeDataset

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public PyADTreeDataset(String filePath, boolean symbolic, boolean labelled) {
// BEWEAR: symbolic and labelled are NOT used
if (pyADTree == null) {
    long startTime = System.currentTimeMillis();
    //DataCollector.startEvent("adtree", startTime);
    
    this.symbolic = symbolic;
    this.labelled = labelled;
    PythonInterpreter interpreter = new PythonInterpreter();
    interpreter.execfile("/media/uraplutonium/Workstation/Workspace/teabag-ml/src/main/java/teabagml/adtree/PySparseADTree.py");
    PyFunction makeSparseADTreeFunc = (PyFunction)interpreter.get("makeSparseADTree", PyFunction.class);
    adtreeTuple = (PyTuple)(makeSparseADTreeFunc.__call__(new PyString(filePath)));

    // todo extract dimension, dataSize, arity from adtreeTuple
    PyADTreeDataset.pyADTree = (PyObject)(adtreeTuple.pyget(0));
    PyInteger pyArityLength = (PyInteger)(adtreeTuple.pyget(1));
    PyList pyArityList = (PyList)(adtreeTuple.pyget(2));
    PyInteger pyRecordsLength = (PyInteger)(adtreeTuple.pyget(3));
    this.dimension = pyArityLength.getValue();
    this.dataSize = pyRecordsLength.getValue();
    PyObject[] pyArityArray = pyArityList.getArray();
    String[] arityNames = new String[dimension];
    int[] arityArray = new int[dimension];
    for (int i=0; i<dimension; i++) {
	arityArray[i] = ((PyInteger)(pyArityArray[i])).getValue();
	arityNames[i] = Integer.toString(arityArray[i]);
    }
    arity = new Arity(dimension, arityNames, arityArray);
    System.out.println("sparse adtree constructed.");
    
    //DataCollector.endEvent("adtree", startTime);
} else {
    System.out.println("sparse adtree already built.");
}

// initialise the contabMap
contabMap = new HashMap<String, PyObject>();
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:39,代碼來源:PyADTreeDataset.java

示例14: getContab

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
/**
    * 
    */
   private PyObject getContab(int[] attrList) {
String attrStr = "";
for (int eachAttr : attrList) {
    attrStr = attrStr + Integer.toString(eachAttr) + ",";
}

if (contabMap.containsKey(attrStr)) {
    // contab already built
    System.out.println("contingency table already exists.");
    return contabMap.get(attrStr);
} else {
    // build new contab and add it to contabMap
    // convert the int[] attrList to PyList<PyInteger> pyAttrList
    PyInteger[] pyAttrArray = new PyInteger[attrList.length];
    for (int i=0; i<attrList.length; i++)
	pyAttrArray[i] = new PyInteger(attrList[i]);
    PyList pyAttrList = new PyList(pyAttrArray);

    PythonInterpreter interpreter = new PythonInterpreter();
    interpreter.execfile("/media/uraplutonium/Workstation/Workspace/teabag-ml/src/main/java/teabagml/adtree/PySparseADTree.py");
    PyFunction makeContabFunc = (PyFunction)interpreter.get("makeContab", PyFunction.class);
    PyObject contab = makeContabFunc.__call__(PyADTreeDataset.pyADTree, pyAttrList);
    contabMap.put(attrStr, contab);
    System.out.println("contingency table constructed.");
    return contab;
}
   }
 
開發者ID:uraplutonium,項目名稱:teabag-ml,代碼行數:31,代碼來源:PyADTreeDataset.java

示例15: getTokens

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
/**
 * Return list of token for command.
 * @param command The command
 * @return Token list
 * @throws java.io.UnsupportedEncodingException
 */
public PyList getTokens(String command) throws UnsupportedEncodingException {
    StringBuilder sb = new StringBuilder();
    sb.append("import cStringIO");
    sb.append("\n");
    sb.append("import tokenize");
    sb.append("\n");
    sb.append("command = str('");
    sb.append(command);
    sb.append("')");
    sb.append("\n");
    sb.append("f = cStringIO.StringIO(command)");
    sb.append("\n");
    sb.append("tokens = []");
    sb.append("\n");
    sb.append("def eater(*args):");
    sb.append("\n");
    sb.append("    tokens.append(args)");
    sb.append("\n");
    sb.append("tokenize.tokenize_loop(f.readline, eater)");
    sb.append("\n");
    String code = sb.toString();
    String encoding = "utf-8";
    PythonInterpreter pi = new PythonInterpreter();
    try {
        pi.execfile(new ByteArrayInputStream(code.getBytes(encoding)));
        PyList tokens = (PyList)pi.get("tokens");            
        return tokens;
    } catch (Exception e){
        return null;
    }
}
 
開發者ID:meteoinfo,項目名稱:MeteoInfoMap,代碼行數:38,代碼來源:JIntrospect.java


注:本文中的org.python.util.PythonInterpreter.execfile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。