本文整理汇总了Java中org.scijava.script.ScriptService类的典型用法代码示例。如果您正苦于以下问题:Java ScriptService类的具体用法?Java ScriptService怎么用?Java ScriptService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptService类属于org.scijava.script包,在下文中一共展示了ScriptService类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.scijava.script.ScriptService; //导入依赖的package包/类
public static void main(String[] args) throws ScriptException {
// Only for testing purpose
Context context = new Context();
ScriptService scriptService = context.getService(ScriptService.class);
ScriptLanguage scriptLanguage = scriptService.getLanguageByName("python");
ScriptEngine engine = scriptLanguage.getScriptEngine();
Object result = engine.eval("p=999\n555");
System.out.println(result);
scriptService = context.getService(ScriptService.class);
scriptLanguage = scriptService.getLanguageByName("python");
engine = scriptLanguage.getScriptEngine();
result = engine.eval("555");
System.out.println(result);
context.dispose();
}
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:21,代码来源:TestScriptEngine.java
示例2: testLocals
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testLocals() throws ScriptException {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final ScriptLanguage language = scriptService.getLanguageByExtension("kt");
final ScriptEngine engine = language.getScriptEngine();
assertTrue(engine.getFactory().getNames().contains("kotlin"));
engine.put("hello", 17);
assertEquals("17", engine.eval("bindings[\"hello\"]").toString());
assertEquals("17", engine.get("hello").toString());
engine.put("foo", "bar");
assertEquals("bar", engine.eval("bindings[\"foo\"]").toString());
assertEquals("bar", engine.get("foo").toString());
// FIXME: You cannot modify or insert a variable in the bindings!
// engine.eval("bindings[\"foo\"] = \"great\"");
// assertEquals("great", engine.eval("bindings[\"foo\"]").toString());
// assertEquals("great", engine.get("foo").toString());
final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.clear();
assertNull(engine.get("hello"));
}
开发者ID:scijava,项目名称:scripting-kotlin,代码行数:26,代码来源:KotlinTest.java
示例3: testLocals
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testLocals() throws ScriptException {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final ScriptLanguage language = scriptService.getLanguageByExtension("r");
final ScriptEngine engine = language.getScriptEngine();
assertEquals(RenjinScriptEngine.class, engine.getClass());
engine.put("hello", 17);
assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.eval("hello")));
assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.get("hello")));
final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.clear();
assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("hello")));
assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("polar_kraken")));
}
开发者ID:scijava,项目名称:scripting-renjin,代码行数:18,代码来源:RenjinTest.java
示例4: testParameters
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testParameters() throws InterruptedException, ExecutionException, IOException, ScriptException {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final String script = "" + //
"# @ScriptService ss\n" + //
"# @OUTPUT String name\n" + //
"language <- ss$getLanguageByName('Renjin')\n" + //
"name <- language$languageName\n";
final ScriptModule m = scriptService.run("hello.r", script, true).get();
final Object actual = m.getOutput("name");
final String expected = scriptService.getLanguageByName("Renjin").getLanguageName();
assertEquals(expected, actual);
}
开发者ID:scijava,项目名称:scripting-renjin,代码行数:17,代码来源:RenjinTest.java
示例5: testBasic
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testBasic() throws Exception {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final ScriptLanguage language =
scriptService.getLanguageByExtension("scala");
final ScriptEngine engine = language.getScriptEngine();
final SimpleScriptContext ssc = new SimpleScriptContext();
final StringWriter writer = new StringWriter();
ssc.setWriter(writer);
final String script = "print(\"3\");";
engine.eval(script, ssc);
assertEquals("3", writer.toString());
}
开发者ID:scijava,项目名称:scripting-scala,代码行数:18,代码来源:ScalaTest.java
示例6: testBasic
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testBasic() throws InterruptedException, ExecutionException,
IOException, ScriptException
{
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final String script = "1 + 2";
final ScriptModule m = scriptService.run("add.kt", script, true).get();
final Object result = m.getReturnValue();
assertEquals("3", result.toString());
}
开发者ID:scijava,项目名称:scripting-kotlin,代码行数:12,代码来源:KotlinTest.java
示例7: testReadmesExample
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testReadmesExample() throws Exception {
// extract the example script
final File readme = new File("README.md");
final String contents = new String(FileUtils.readFile(readme), "UTF-8");
final String telltale = String.format("```python%n");
final int begin = contents.indexOf(telltale) + telltale.length();
assertTrue(begin > telltale.length());
assertTrue(contents.indexOf(telltale, begin) < 0);
final int end = contents.indexOf(String.format("```%n"), begin);
assertTrue(end > 0);
final String snippet = contents.substring(begin, end);
assertTrue(snippet.startsWith("# @ImageJ ij"));
final Context context = new Context();
final ScriptService script = context.getService(ScriptService.class);
// create mock ImageJ gateway
script.addAlias("ImageJ", Mock.class);
final ScriptModule module =
script.run("op-example.py", snippet, true).get();
assertNotNull(module);
module.run();
final Mock ij = context.getService(Mock.class);
assertEquals(3, ij.images.size());
assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3);
assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3);
assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3);
}
开发者ID:imagej,项目名称:imagej-ops,代码行数:31,代码来源:ReadmeExampleTest.java
示例8: testBasic
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testBasic() throws InterruptedException, ExecutionException, IOException, ScriptException {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final String script = "as.integer(1) + as.integer(2)";
final ScriptModule m = scriptService.run("add.r", script, true).get();
final Object result = m.getReturnValue();
assertTrue(result instanceof IntArrayVector);
final IntArrayVector resultVector = (IntArrayVector) result;
assertEquals(1, resultVector.length());
assertEquals(3, resultVector.getElementAsInt(0));
}
开发者ID:scijava,项目名称:scripting-renjin,代码行数:13,代码来源:RenjinTest.java
示例9: testString
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testString() throws InterruptedException, ExecutionException, IOException, ScriptException {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final String script = "result = R.version$version.string\n";
final ScriptModule m = scriptService.run("version.r", script, true).get();
final Object result = m.getReturnValue();
assertTrue(result.toString().startsWith("Renjin version "));
}
开发者ID:scijava,项目名称:scripting-renjin,代码行数:10,代码来源:RenjinTest.java
示例10: testSciJava
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Test
public void testSciJava() throws InterruptedException, ExecutionException, IOException, ScriptException {
final Context context = new Context(ScriptService.class);
final ScriptService scriptService = context.getService(ScriptService.class);
final String langClass = RenjinScriptLanguage.class.getName();
final String script = "" + //
"# @OUTPUT " + langClass + " language\n" + //
"import(" + langClass + ")\n" + //
"language <<- RenjinScriptLanguage$new()\n" + //
"print(language$engineName)\n";
final ScriptModule m = scriptService.run("sjc.r", script, true).get();
final Object actual = m.getOutput("language");
assertEquals(scriptService.getLanguageByName("Renjin").getClass(), actual.getClass());
}
开发者ID:scijava,项目名称:scripting-renjin,代码行数:16,代码来源:RenjinTest.java
示例11: createContext
import org.scijava.script.ScriptService; //导入依赖的package包/类
@Override
protected Context createContext() {
return new Context(OpService.class, OpMatchingService.class,
CacheService.class, ScriptService.class);
}
开发者ID:imagej,项目名称:imagej-ops,代码行数:6,代码来源:FrangiVesselnessTest.java
示例12: main
import org.scijava.script.ScriptService; //导入依赖的package包/类
public static void main(String... args) {
String pythonBinaryPath = "/home/hadim/local/conda/bin/python";
Context context = new Context();
JupyterService jupyter = context.service(JupyterService.class);
ScriptService scriptService = context.service(ScriptService.class);
//jupyter.installKernel("groovy", "info", pythonBinaryPath);
System.out.println(scriptService.getLanguages());
context.dispose();
}
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:16,代码来源:TestInstallKernel.java
注:本文中的org.scijava.script.ScriptService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论