Search in sources :

Example 1 with EquationCompilerImpl

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

the class SourceIDTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new SourceID(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=SOURCEID(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 2 with EquationCompilerImpl

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

the class InterpreterTest method init.

@Before
public void init() {
    eventHelper = new DummyCyEventHelper();
    serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    parser = new EquationParserImpl(serviceRegistrar);
    compiler = new EquationCompilerImpl(parser);
    interpreter = new InterpreterImpl();
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Before(org.junit.Before)

Example 3 with EquationCompilerImpl

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

the class CySubNetworkCyTableManagerTest method setUp.

@Before
public void setUp() {
    final CyEventHelper eh = new DummyCyEventHelper();
    final CyNetworkNaming namingUtil = mock(CyNetworkNaming.class);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    final EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    final Interpreter interpreter = new InterpreterImpl();
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eh);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    networkTableMgr = new CyNetworkTableManagerImpl();
    networkManager = new CyNetworkManagerImpl(serviceRegistrar);
    mgr = new CyTableManagerImpl(networkTableMgr, networkManager, serviceRegistrar);
    CyTableFactoryImpl tableFactory = new CyTableFactoryImpl(eh, serviceRegistrar);
    CyRootNetworkImpl baseNet = new CyRootNetworkImpl(eh, (CyTableManagerImpl) mgr, networkTableMgr, tableFactory, serviceRegistrar, true, SavePolicy.DO_NOT_SAVE);
    // This is a different subnetwork and not "baseNetwork" in ArrayGraph.
    goodNetwork = baseNet.addSubNetwork();
    globalTable = tableFactory.createTable("test table", CyIdentifiable.SUID, Long.class, true, true);
    networkManager.addNetwork(goodNetwork);
    assertNotNull(globalTable);
    assertNotNull(goodNetwork);
    assertEquals(1, networkManager.getNetworkSet().size());
}
Also used : DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) CyEventHelper(org.cytoscape.event.CyEventHelper) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) CyTableFactoryImpl(org.cytoscape.model.internal.CyTableFactoryImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) CyRootNetworkImpl(org.cytoscape.model.internal.CyRootNetworkImpl) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) EquationCompiler(org.cytoscape.equations.EquationCompiler) Before(org.junit.Before)

Example 4 with EquationCompilerImpl

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

the class CyTableTest method setUp.

@Before
public void setUp() {
    eventHelper = new DummyCyEventHelper();
    compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    final Interpreter interpreter = new InterpreterImpl();
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    table = new CyTableImpl("homer", CyIdentifiable.SUID, Long.class, false, true, SavePolicy.SESSION_FILE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 1000);
    attrs = table.getRow(1L);
    table2 = new CyTableImpl("marge", CyIdentifiable.SUID, Long.class, false, true, SavePolicy.SESSION_FILE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 1000);
    CyTableManagerImpl tblMgr = new CyTableManagerImpl(new CyNetworkTableManagerImpl(), new CyNetworkManagerImpl(serviceRegistrar), serviceRegistrar);
    tblMgr.addTable(table);
    ((CyTableImpl) table).handleEvent(new TableAddedEvent(tblMgr, table));
    tblMgr.addTable(table2);
    ((CyTableImpl) table2).handleEvent(new TableAddedEvent(tblMgr, table2));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) TableAddedEvent(org.cytoscape.model.events.TableAddedEvent) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) CyTableImpl(org.cytoscape.model.internal.CyTableImpl) Before(org.junit.Before)

Example 5 with EquationCompilerImpl

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

the class EquationTest method parseEquation.

Equation parseEquation(String equation, CyTable context) {
    Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
    for (CyColumn column : context.getColumns()) {
        Class<?> type = column.getType();
        if (type == Integer.class)
            type = Long.class;
        typeMap.put(column.getName(), type);
    }
    EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    assertTrue(compiler.compile(equation, typeMap));
    return compiler.getEquation();
}
Also used : EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) HashMap(java.util.HashMap)

Aggregations

EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)12 EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)11 Interpreter (org.cytoscape.equations.Interpreter)9 InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)9 HashMap (java.util.HashMap)6 Equation (org.cytoscape.equations.Equation)5 IdentDescriptor (org.cytoscape.equations.IdentDescriptor)5 Before (org.junit.Before)5 Test (org.junit.Test)5 EquationCompiler (org.cytoscape.equations.EquationCompiler)4 DummyCyEventHelper (org.cytoscape.event.DummyCyEventHelper)4 CyNetworkManagerImpl (org.cytoscape.model.internal.CyNetworkManagerImpl)4 CyNetworkTableManagerImpl (org.cytoscape.model.internal.CyNetworkTableManagerImpl)4 CyTableManagerImpl (org.cytoscape.model.internal.CyTableManagerImpl)4 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)3 TableAddedEvent (org.cytoscape.model.events.TableAddedEvent)2 CyTableFactoryImpl (org.cytoscape.model.internal.CyTableFactoryImpl)2 CyTableImpl (org.cytoscape.model.internal.CyTableImpl)2 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)2 CyEventHelper (org.cytoscape.event.CyEventHelper)1