Search in sources :

Example 11 with InterpreterImpl

use of org.cytoscape.equations.internal.interpreter.InterpreterImpl in project cytoscape-impl by cytoscape.

the class MapTableToNetworkTableTaskTest method testMappingTableToNetwork.

@Test
public void testMappingTableToNetwork() throws Exception {
    stm.addTunableHandlerFactory(syncTunableHandlerFactory, syncFactoryProp);
    net1 = support.getNetwork();
    node1 = net1.addNode();
    node2 = net1.addNode();
    net1.addEdge(node1, node2, true);
    net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyRootNetwork.SHARED_NAME, node1Name);
    net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyRootNetwork.SHARED_NAME, node2Name);
    netMgr.addNetwork(net1);
    table1 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), new InterpreterImpl(), 2);
    table1.createColumn("col1", String.class, false);
    CyRow row1 = table1.getRow(node1Name);
    row1.set("col1", "col1 row1");
    CyRow row2 = table1.getRow(node2Name);
    row2.set("col1", "col1 row2");
    mapping(table1, net1, false);
    assertNotNull(net1.getDefaultNodeTable().getColumn("col1"));
    assertEquals("col1 row1", net1.getRow(node1).get("col1", String.class));
}
Also used : InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) CyRow(org.cytoscape.model.CyRow) CyTableImpl(org.cytoscape.model.internal.CyTableImpl) Test(org.junit.Test)

Example 12 with InterpreterImpl

use of org.cytoscape.equations.internal.interpreter.InterpreterImpl in project cytoscape-impl by cytoscape.

the class InDegreeTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new InDegree(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=INDEGREE(101)", variableNameToTypeMap))
        fail(compiler.getLastErrorMsg());
    final Equation equation = compiler.getEquation();
    final Interpreter interpreter = new InterpreterImpl();
    final Map<String, IdentDescriptor> variableNameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    assertEquals("Equation evaluation returned an unexpected result!", 3L, interpreter.execute(equation, variableNameToDescriptorMap));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 13 with InterpreterImpl

use of org.cytoscape.equations.internal.interpreter.InterpreterImpl in project cytoscape-impl by cytoscape.

the class OutDegreeTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new OutDegree(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=OUTDEGREE(101)", variableNameToTypeMap))
        fail(compiler.getLastErrorMsg());
    final Equation equation = compiler.getEquation();
    final Interpreter interpreter = new InterpreterImpl();
    final Map<String, IdentDescriptor> variableNameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    assertEquals("Equation evaluation returned an unexpected result!", 3L, interpreter.execute(equation, variableNameToDescriptorMap));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 14 with InterpreterImpl

use of org.cytoscape.equations.internal.interpreter.InterpreterImpl in project cytoscape-impl by cytoscape.

the class TargetIDTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new TargetID(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=TARGETID(11)", variableNameToTypeMap))
        fail(compiler.getLastErrorMsg());
    final Equation equation = compiler.getEquation();
    final Interpreter interpreter = new InterpreterImpl();
    final Map<String, IdentDescriptor> variableNameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    assertEquals("Equation evaluation returned an unexpected result!", 101L, interpreter.execute(equation, variableNameToDescriptorMap));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 15 with InterpreterImpl

use of org.cytoscape.equations.internal.interpreter.InterpreterImpl in project cytoscape-impl by cytoscape.

the class CyActivator method start.

@Override
public void start(BundleContext bc) {
    final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
    InterpreterImpl interpreter = new InterpreterImpl();
    EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    registerService(bc, compiler, EquationCompiler.class, new Properties());
    registerService(bc, interpreter, Interpreter.class, new Properties());
    registerService(bc, parser, EquationParser.class, new Properties());
    // For dynamically add functions.
    registerServiceListener(bc, parser::registerFunctionService, parser::unregisterFunctionService, Function.class);
}
Also used : InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar)

Aggregations

InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)17 Interpreter (org.cytoscape.equations.Interpreter)14 EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)9 EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)9 HashMap (java.util.HashMap)7 IdentDescriptor (org.cytoscape.equations.IdentDescriptor)7 Test (org.junit.Test)7 Equation (org.cytoscape.equations.Equation)5 CyNetworkManagerImpl (org.cytoscape.model.internal.CyNetworkManagerImpl)5 CyNetworkTableManagerImpl (org.cytoscape.model.internal.CyNetworkTableManagerImpl)5 CyTableManagerImpl (org.cytoscape.model.internal.CyTableManagerImpl)5 Before (org.junit.Before)5 CyTableFactoryImpl (org.cytoscape.model.internal.CyTableFactoryImpl)4 CyTableImpl (org.cytoscape.model.internal.CyTableImpl)4 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)4 EquationCompiler (org.cytoscape.equations.EquationCompiler)3 DummyCyEventHelper (org.cytoscape.event.DummyCyEventHelper)3 CyRow (org.cytoscape.model.CyRow)2 CyNetworkFactoryImpl (org.cytoscape.model.internal.CyNetworkFactoryImpl)2 CyRootNetworkImpl (org.cytoscape.model.internal.CyRootNetworkImpl)2