org.scijava.script.ScriptService Java Examples
The following examples show how to use
org.scijava.script.ScriptService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestScriptEngine.java From scijava-jupyter-kernel with Apache License 2.0 | 6 votes |
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(); }
Example #2
Source File: ReadmeExampleTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@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); }
Example #3
Source File: FrangiVesselnessTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override protected Context createContext() { return new Context(OpService.class, OpMatchingService.class, CacheService.class, ScriptService.class); }
Example #4
Source File: TestInstallKernel.java From scijava-jupyter-kernel with Apache License 2.0 | 3 votes |
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(); }