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


Java PythonInterpreter类代码示例

本文整理汇总了Java中org.python.util.PythonInterpreter的典型用法代码示例。如果您正苦于以下问题:Java PythonInterpreter类的具体用法?Java PythonInterpreter怎么用?Java PythonInterpreter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PythonInterpreter类属于org.python.util包,在下文中一共展示了PythonInterpreter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.python.util.PythonInterpreter; //导入依赖的package包/类
/**
 * The main thread for this class invoked by Thread.run()
 *
 * @see java.lang.Thread#run()
 */
public void run() {
    PythonInterpreter p = new PythonInterpreter();
    for (String name : this.locals.keySet()) {
        p.set(name, this.locals.get(name));
    }

    URL jarUrl = JythonServer.class.getProtectionDomain().getCodeSource().getLocation();
    String jarPath = jarUrl.getPath();
    if (jarUrl.getProtocol().equals("file")) {
        // If URL is of type file, assume that we are in dev env and set path to python dir.
        // else use the jar file as is
        jarPath = jarPath + "../../src/main/python/";
    }

    p.exec("import sys");
    p.exec("sys.path.append('" + jarPath + "')");
    p.exec("from debugserver import run_server");
    if (this.host == null) {
    	p.exec("run_server(port=" + this.port + ", locals=locals())");
    } else {
    	p.exec("run_server(port=" + this.port + ", host='" + this.host + "', locals=locals())");
    }
}
 
开发者ID:hksoni,项目名称:SDN-Multicast,代码行数:29,代码来源:JythonServer.java

示例2: initializeInterperter

import org.python.util.PythonInterpreter; //导入依赖的package包/类
public void initializeInterperter(PythonInterpreter interpreter)
{
	boolean localsUninitialized = interpreter.getLocals() == initialLocals;
	if(localsUninitialized)
	{
		PyStringMap locals = new PyStringMap();
		interpreter.setLocals(locals);
		interpreter.exec(scripts.get(PythonTransformationHelper.getImportStatements()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getGetValueDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getIsEmptyDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getHasSelectedRowsStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getGetValueFromNestedColumnByIndexDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getRowIndexDefStatement()));
		interpreter.exec(scripts.get(PythonTransformationHelper.getVDefStatement()));
	}
	if(localsUninitialized ||(!libraryHasBeenLoaded || reloadLibrary))
	{
		importUserScripts(interpreter);
	}

}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:22,代码来源:PythonRepository.java

示例3: loadAvailableLexers

import org.python.util.PythonInterpreter; //导入依赖的package包/类
public List<LexerInfo> loadAvailableLexers(PyGateway gateway) {
    PythonInterpreter interpreter = gateway.getInterpreter();

    // Simple use Pygments as you would in Python
    interpreter.exec(""
            + "from pygments.lexers import get_all_lexers\n"
            + "result = get_all_lexers()");

    PyGenerator result = (PyGenerator) interpreter.get("result");
    ArrayList<LexerInfo> infos = Lists.newArrayList();
    for (Object o : result) {
        PyTuple tuple = (PyTuple) o;
        String name = (String) tuple.get(0);
        List<String> aliases = Lists.newArrayListWithCapacity(3);
        for (Object alias : (PyTuple) tuple.get(1)) {
            String str = (String) alias;
            aliases.add(str);
        }
        LexerInfo info = new LexerInfo(name, aliases);
        infos.add(info);
    }
    return infos;
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:24,代码来源:Lexers.java

示例4: SimulatorImpl

import org.python.util.PythonInterpreter; //导入依赖的package包/类
/**
 * Constructs a new instance.
 */
public SimulatorImpl() {
    // initialize Python interpreter
    Properties properties = new Properties();
    properties.setProperty("python.home", StaticConfiguration.JYTHON_HOME);
    properties.setProperty("python.path", StaticConfiguration.JYTHON_LIB);
    PythonInterpreter.initialize(System.getProperties(), properties, new String[] {""});

    // initialize the shutdown hook to terminate application properly
    Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());

    if (OS.getType() == OS.Type.WINDOWS) {
        // create hidden window to handle WM_CLOSE messages on Windows to react to taskkill
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.pack();
    }
}
 
开发者ID:qspin,项目名称:qtaste,代码行数:21,代码来源:SimulatorImpl.java

示例5: NifiClientFactory

import org.python.util.PythonInterpreter; //导入依赖的package包/类
public NifiClientFactory() {
    /*StringBuilder sb = new StringBuilder();
    sb.append(System.getProperty("java.class.path"));
    sb.append(":").append("~/workplace/echo/src/main/nifi");
    Properties props = new Properties();
    props.setProperty("python.path", sb.toString());
    props.setProperty("python.verbose", "error");

    PythonInterpreter.initialize(System.getProperties(), props, new String[0]);*/

    PythonInterpreter interpreter = new PythonInterpreter();
    //interpreter.exec("import os\nprint os.getcwd()");
    interpreter.exec("import sys\nif '' not in sys.path:\n    sys.path.append(\"\")");
    interpreter.exec("from modules.json2pojo.src.main.python.DefaultNifiClient import DefaultNifiClient");
    nifiClientClass = interpreter.get("DefaultNifiClient");
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:17,代码来源:NifiClientFactory.java

示例6: 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

示例7: 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

示例8: 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

示例9: getCompiledMethod

import org.python.util.PythonInterpreter; //导入依赖的package包/类
/**
 * Get a compiled version of the python call.
 * 
 * @param name
 * @param code
 * @param interp
 * @return
 */
private static synchronized PyObject getCompiledMethod(String name, String code, PythonInterpreter interp) {
	// TODO change this from a synchronized method to a few blocks to
	// improve concurrent performance
	if (objectCache.containsKey(name)) {
		return objectCache.get(name);
	}

	PyObject compiled = interp.compile(code);
	if (objectCache.size() > 25) {
		// keep the size to 6
		objectCache.remove(objectCache.keySet().iterator().next());
	}
	objectCache.put(name, compiled);
	return compiled;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:24,代码来源:Python.java

示例10: testPyJenkinsInterpreter

import org.python.util.PythonInterpreter; //导入依赖的package包/类
@Test
public void testPyJenkinsInterpreter() throws Exception {
    BuildContext context = newSimpleBuildContext();
    PythonInterpreter pyjenkins = PythonFactory.newPyJenkinsInterpreter(context, newSimpleBuildConfig());

    String script =
        "from pyjenkins import *\n" +
        "class Foo(PyJenkinsBuild):\n" +
        "  def run(self):\n" +
        "    return Result.NOT_BUILT\n" +
        "register_pybuild( Foo() )";
    pyjenkins.exec(script);

    PyJenkinsBuild pybuild = context.pybuild;
    assertNotNull("should have registered pybuild", pybuild);

    Result result = pybuild.run();
    assertEquals("should return the specified result", Result.NOT_BUILT, result);
}
 
开发者ID:tanium,项目名称:pyjenkins,代码行数:20,代码来源:PythonFactoryTest.java

示例11: testPyJenkinsBuildConfigFalse

import org.python.util.PythonInterpreter; //导入依赖的package包/类
@Test
public void testPyJenkinsBuildConfigFalse() throws Exception {
    BuildContext context = newSimpleBuildContext();
    BuildConfig config = new BuildConfig(false, false);
    PythonInterpreter pyjenkins = PythonFactory.newPyJenkinsInterpreter(context, config);

    String script =
        "from pyjenkins import *\n" +
        "class Foo(PyJenkinsBuild):\n" +
        "  def run(self):\n" +
        "    if is_pull_request_build() or is_release_build():\n" +
        "      return Result.FAILURE\n" +
        "    return Result.SUCCESS\n" +
        "register_pybuild( Foo() )";
    pyjenkins.exec(script);

    PyJenkinsBuild pybuild = context.pybuild;
    assertNotNull("should have registered pybuild", pybuild);

    Result result = pybuild.run();
    assertEquals("should return the specified result", Result.SUCCESS, result);
}
 
开发者ID:tanium,项目名称:pyjenkins,代码行数:23,代码来源:PythonFactoryTest.java

示例12: testPyJenkinsBuildConfigReviewBuild

import org.python.util.PythonInterpreter; //导入依赖的package包/类
@Test
public void testPyJenkinsBuildConfigReviewBuild() throws Exception {
    BuildContext context = newSimpleBuildContext();
    BuildConfig config = new BuildConfig(true, false);
    PythonInterpreter pyjenkins = PythonFactory.newPyJenkinsInterpreter(context, config);

    String script =
        "from pyjenkins import *\n" +
        "class Foo(PyJenkinsBuild):\n" +
        "  def run(self):\n" +
        "    if not is_pull_request_build() or is_release_build():\n" +
        "      return Result.FAILURE\n" +
        "    return Result.SUCCESS\n" +
        "register_pybuild( Foo() )";
    pyjenkins.exec(script);

    PyJenkinsBuild pybuild = context.pybuild;
    assertNotNull("should have registered pybuild", pybuild);

    Result result = pybuild.run();
    assertEquals("should return the specified result", Result.SUCCESS, result);
}
 
开发者ID:tanium,项目名称:pyjenkins,代码行数:23,代码来源:PythonFactoryTest.java

示例13: testPyJenkinsBuildConfigReleaseBuild

import org.python.util.PythonInterpreter; //导入依赖的package包/类
@Test
public void testPyJenkinsBuildConfigReleaseBuild() throws Exception {
    BuildContext context = newSimpleBuildContext();
    BuildConfig config = new BuildConfig(false, true);
    PythonInterpreter pyjenkins = PythonFactory.newPyJenkinsInterpreter(context, config);

    String script =
        "from pyjenkins import *\n" +
        "class Foo(PyJenkinsBuild):\n" +
        "  def run(self):\n" +
        "    if is_pull_request_build() or not is_release_build():\n" +
        "      return Result.FAILURE\n" +
        "    return Result.SUCCESS\n" +
        "register_pybuild( Foo() )";
    pyjenkins.exec(script);

    PyJenkinsBuild pybuild = context.pybuild;
    assertNotNull("should have registered pybuild", pybuild);

    Result result = pybuild.run();
    assertEquals("should return the specified result", Result.SUCCESS, result);
}
 
开发者ID:tanium,项目名称:pyjenkins,代码行数:23,代码来源:PythonFactoryTest.java

示例14: run

import org.python.util.PythonInterpreter; //导入依赖的package包/类
/**
 * The main thread for this class invoked by Thread.run()
 *
 * @see java.lang.Thread#run()
 */
public void run() {
    PythonInterpreter p = new PythonInterpreter();
    for (String name : this.locals.keySet()) {
        p.set(name, this.locals.get(name));
    }

    URL jarUrl = JythonServer.class.getProtectionDomain().getCodeSource().getLocation();
    String jarPath = jarUrl.getPath();
    if (jarUrl.getProtocol().equals("file")) {
        // If URL is of type file, assume that we are in dev env and set path to python dir.
        // else use the jar file as is
        jarPath = jarPath + "../../src/main/python/";
    }

    p.exec("import sys");
    p.exec("sys.path.append('" + jarPath + "')");
    p.exec("from debugserver import run_server");
    p.exec("run_server(" + this.port + ", '0.0.0.0', locals())");
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:25,代码来源:JythonServer.java

示例15: prepare

import org.python.util.PythonInterpreter; //导入依赖的package包/类
@Setup(Level.Trial)
public void prepare() {
  PythonInterpreter interpreter = new CodeLoader().jython("dispatch");
  dispatcher = (PyFunction) interpreter.get("dispatch");

  MonomorphicState monomorphicState = new MonomorphicState();
  monomorphicState.prepare();
  monomorphicArray = new PyArray(Object.class, monomorphicState.data);

  TriMorphicState triMorphicState = new TriMorphicState();
  triMorphicState.prepare();
  trimorphicArray = new PyArray(Object.class, triMorphicState.data);

  PolyMorphicState polyMorphicState = new PolyMorphicState();
  polyMorphicState.prepare();
  polymorphicArray = new PyArray(Object.class, polyMorphicState.data);
}
 
开发者ID:golo-lang,项目名称:golo-jmh-benchmarks,代码行数:18,代码来源:MethodDispatchMicroBenchmark.java


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