当前位置: 首页>>代码示例>>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;未经允许,请勿转载。