Search in sources :

Example 1 with CompositeFilterImpl

use of org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl in project cytoscape-impl by cytoscape.

the class CompositeFilterTest method testCompositeFilterEmpty.

@Test
public void testCompositeFilterEmpty() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("s", String.class, false);
    CyNode n1 = network.addNode();
    network.getRow(n1).set("s", "abc");
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    composite.setType(Type.ANY);
    assertTrue(composite.accepts(network, n1));
    composite.setType(Type.ALL);
    assertTrue(composite.accepts(network, n1));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Example 2 with CompositeFilterImpl

use of org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl in project cytoscape-impl by cytoscape.

the class CompositeFilterTest method testCompositeFilterString.

@Test
public void testCompositeFilterString() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("s", String.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    CyNode n4 = network.addNode();
    network.getRow(n1).set("s", "abc");
    network.getRow(n2).set("s", "def");
    network.getRow(n3).set("s", "aa");
    ColumnFilter filterForA = new ColumnFilter("s", Predicate.CONTAINS, "a");
    ColumnFilter filterForB = new ColumnFilter("s", Predicate.CONTAINS, "b");
    ColumnFilter filterForC = new ColumnFilter("s", Predicate.CONTAINS, "c");
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    composite.append(filterForA);
    composite.append(filterForB);
    composite.append(filterForC);
    composite.setType(Type.ANY);
    assertTrue(composite.accepts(network, n1));
    assertFalse(composite.accepts(network, n2));
    assertTrue(composite.accepts(network, n3));
    assertFalse(composite.accepts(network, n4));
    composite.setType(Type.ALL);
    assertTrue(composite.accepts(network, n1));
    assertFalse(composite.accepts(network, n2));
    assertFalse(composite.accepts(network, n3));
    assertFalse(composite.accepts(network, n4));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Example 3 with CompositeFilterImpl

use of org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl in project cytoscape-impl by cytoscape.

the class CompositeFilterTest method testCompositeFilterAlwaysFalse.

@Test
public void testCompositeFilterAlwaysFalse() {
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    ColumnFilter filterForA = new ColumnFilter();
    ColumnFilter filterForB = new ColumnFilter();
    ColumnFilter filterForC = new ColumnFilter();
    composite.append(filterForA);
    composite.append(filterForB);
    composite.append(filterForC);
    assertTrue(filterForA.isAlwaysFalse());
    assertTrue(filterForB.isAlwaysFalse());
    assertTrue(filterForC.isAlwaysFalse());
    composite.setType(Type.ALL);
    assertTrue(composite.isAlwaysFalse());
    composite.setType(Type.ANY);
    assertTrue(composite.isAlwaysFalse());
    filterForA.setColumnName("s");
    filterForA.setPredicateAndCriterion(Predicate.CONTAINS, "a");
    assertFalse(filterForA.isAlwaysFalse());
    composite.setType(Type.ALL);
    assertTrue(composite.isAlwaysFalse());
    composite.setType(Type.ANY);
    assertFalse(composite.isAlwaysFalse());
    filterForB.setColumnName("s");
    filterForB.setPredicateAndCriterion(Predicate.CONTAINS, "a");
    filterForC.setColumnName("s");
    filterForC.setPredicateAndCriterion(Predicate.CONTAINS, "a");
    composite.setType(Type.ALL);
    assertFalse(composite.isAlwaysFalse());
    composite.setType(Type.ANY);
    assertFalse(composite.isAlwaysFalse());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Example 4 with CompositeFilterImpl

use of org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl in project cytoscape-impl by cytoscape.

the class FilterIOTest method testNestedFilterRoundTrip.

@SuppressWarnings("rawtypes")
@Test
public void testNestedFilterRoundTrip() throws Exception {
    DegreeFilter degreeFilter = new DegreeFilter();
    degreeFilter.setCriterion(new Double[] { 0.2, 5.5 });
    degreeFilter.setEdgeType(CyEdge.Type.ANY);
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class);
    composite.setType(Type.ANY);
    composite.append(degreeFilter);
    CyTransformerWriter writer = new CyTransformerWriterImpl();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    writer.write(stream, FilterIO.createNamedTransformer("filter1", composite));
    String serialized = stream.toString("utf-8");
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerFilterFactory(new DegreeFilterFactory(), properties);
    transformerManager.registerFilterFactory(new CompositeFilterFactory<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class), properties);
    CyTransformerReaderImpl reader = new CyTransformerReaderImpl();
    reader.registerTransformerManager(transformerManager, null);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
    NamedTransformer<?, ?>[] transformers = reader.read(inputStream);
    Assert.assertNotNull(transformers);
    Assert.assertEquals(1, transformers.length);
    NamedTransformer<?, ?> namedTransformer = transformers[0];
    Assert.assertNotNull(namedTransformer);
    Assert.assertEquals("filter1", namedTransformer.getName());
    List children = namedTransformer.getTransformers();
    Assert.assertEquals(1, children.size());
    Transformer child = (Transformer) children.get(0);
    Assert.assertNotNull(child);
    Assert.assertTrue(child instanceof CompositeFilter);
    CompositeFilter composite2 = (CompositeFilter) child;
    Assert.assertEquals(composite.getType(), composite2.getType());
    Assert.assertEquals(composite.getLength(), composite2.getLength());
    Filter filter = composite2.get(0);
    Assert.assertTrue(filter instanceof DegreeFilter);
    DegreeFilter degreeFilter2 = (DegreeFilter) filter;
    Assert.assertArrayEquals((Number[]) degreeFilter.getCriterion(), (Number[]) degreeFilter2.getCriterion());
    Assert.assertEquals(degreeFilter.getEdgeType(), degreeFilter2.getEdgeType());
}
Also used : CyTransformerReaderImpl(org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl) CompositeFilter(org.cytoscape.filter.model.CompositeFilter) Transformer(org.cytoscape.filter.model.Transformer) AdjacencyTransformer(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) AbstractTransformer(org.cytoscape.filter.model.AbstractTransformer) CyNetwork(org.cytoscape.model.CyNetwork) CyTransformerWriter(org.cytoscape.io.write.CyTransformerWriter) CyTransformerWriterImpl(org.cytoscape.io.internal.write.transformer.CyTransformerWriterImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) DegreeFilterFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory) DegreeFilter(org.cytoscape.filter.internal.filters.degree.DegreeFilter) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) ByteArrayInputStream(java.io.ByteArrayInputStream) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) TopologyFilter(org.cytoscape.filter.internal.filters.topology.TopologyFilter) DegreeFilter(org.cytoscape.filter.internal.filters.degree.DegreeFilter) Filter(org.cytoscape.filter.model.Filter) CompositeFilter(org.cytoscape.filter.model.CompositeFilter) List(java.util.List) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Aggregations

CompositeFilterImpl (org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)4 CyNetwork (org.cytoscape.model.CyNetwork)4 Test (org.junit.Test)4 ColumnFilter (org.cytoscape.filter.internal.filters.column.ColumnFilter)3 CyNode (org.cytoscape.model.CyNode)2 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 List (java.util.List)1 DegreeFilter (org.cytoscape.filter.internal.filters.degree.DegreeFilter)1 DegreeFilterFactory (org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory)1 TopologyFilter (org.cytoscape.filter.internal.filters.topology.TopologyFilter)1 AdjacencyTransformer (org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer)1 TransformerManagerImpl (org.cytoscape.filter.internal.work.TransformerManagerImpl)1 AbstractTransformer (org.cytoscape.filter.model.AbstractTransformer)1 CompositeFilter (org.cytoscape.filter.model.CompositeFilter)1 Filter (org.cytoscape.filter.model.Filter)1 NamedTransformer (org.cytoscape.filter.model.NamedTransformer)1 Transformer (org.cytoscape.filter.model.Transformer)1