diff --git a/fca/src/main/java/org/nmdp/ngs/fca/CompleteLattice.java b/fca/src/main/java/org/nmdp/ngs/fca/CompleteLattice.java index a169bd5c..95987a98 100644 --- a/fca/src/main/java/org/nmdp/ngs/fca/CompleteLattice.java +++ b/fca/src/main/java/org/nmdp/ngs/fca/CompleteLattice.java @@ -68,6 +68,15 @@ protected CompleteLattice(final Graph graph, PartiallyOrdered top) { size = 1; } + /** + * Create a CompleteLattice with a TinkerGraph instance. This is an experiment + * meant to avoid a fatal error in JPype implementation. + * @param top + */ + protected CompleteLattice(PartiallyOrdered top) { + this(new TinkerGraph(), top); + } + public class Iterator implements java.util.Iterator { private final java.util.Iterator vertices; @@ -91,12 +100,24 @@ public void remove() { } } - protected boolean filter(final Vertex source, final Vertex target) { + public boolean filter(final Vertex source, final Vertex target) { E sourceConcept = source.getProperty(LABEL); E targetConcept = target.getProperty(LABEL); return filter(sourceConcept, targetConcept); } + public boolean up(final Vertex source, final Vertex target) { + E sourceLabel = source.getProperty(LABEL); + E targetLabel = target.getProperty(LABEL); + return sourceLabel.isLessOrEqualTo(targetLabel); + } + + public boolean down(final Vertex source, final Vertex target) { + E sourceLabel = source.getProperty(LABEL); + E targetLabel = target.getProperty(LABEL); + return sourceLabel.isGreaterOrEqualTo(targetLabel); + } + private boolean filter(final Vertex source, final E right) { if(source.getProperty(LABEL) == null) { return false; @@ -142,12 +163,28 @@ protected final Vertex supremum(final E proposed, Vertex generator) { } return generator; } + + public final Graph getGraph() { + return graph; + } + + public final int getColor() { + return color; + } + + public final void setColor(final int color) { + this.color = color; + } @Override public final E find(final E element) { return this.meet(element, this.top()); } + public final Vertex findVertex(final E element) { + return this.meetVertex(element, this.top()); + } + @Override public final boolean contains(final E element) { return this.find(element).equals(element); @@ -315,6 +352,10 @@ public final E bottom() { return bottom.getProperty(LABEL); } + public final Vertex bottomVertex() { + return bottom; + } + /** * Find the greatest element. * @return the greatest lattice element @@ -324,6 +365,10 @@ public final E top() { return top.getProperty(LABEL); } + public final Vertex topVertex() { + return top; + } + @Override public E join(final E left, final E right) { return supremum((E) left.union(right), top).getProperty(LABEL); @@ -334,6 +379,10 @@ public E meet(final E left, final E right) { return supremum((E) left.intersect(right), top).getProperty(LABEL); } + public Vertex meetVertex(final E left, final E right) { + return supremum((E) left.union(right), top); + } + @Override public double measure(final E left, final E right) { return (double) join(left, right).measure() / diff --git a/fca/src/main/java/org/nmdp/ngs/fca/ConceptLattice.java b/fca/src/main/java/org/nmdp/ngs/fca/ConceptLattice.java index 97784b92..0e033622 100644 --- a/fca/src/main/java/org/nmdp/ngs/fca/ConceptLattice.java +++ b/fca/src/main/java/org/nmdp/ngs/fca/ConceptLattice.java @@ -47,6 +47,10 @@ public ConceptLattice(final Graph graph, long numBits) { super(graph, new Concept(new MutableBitSet(), ones(numBits))); } + public ConceptLattice(long numBits) { + super(new Concept(new MutableBitSet(), ones(numBits))); + } + public Concept insert(final Concept concept) { Vertex added = super.addIntent(concept, top); diff --git a/fca/src/main/java/org/nmdp/ngs/fca/IntervalLattice.java b/fca/src/main/java/org/nmdp/ngs/fca/IntervalLattice.java index 11f19787..1eab60a4 100644 --- a/fca/src/main/java/org/nmdp/ngs/fca/IntervalLattice.java +++ b/fca/src/main/java/org/nmdp/ngs/fca/IntervalLattice.java @@ -23,12 +23,17 @@ package org.nmdp.ngs.fca; import com.tinkerpop.blueprints.Graph; +import com.tinkerpop.blueprints.impls.tg.TinkerGraph; public class IntervalLattice> extends CompleteLattice> { public IntervalLattice(final Graph graph) { super(graph, Interval.MAGIC); } + + public IntervalLattice() { + super(new TinkerGraph(), Interval.MAGIC); + } public Interval insert(final Interval interval) { return super.addIntent(interval, top).getProperty(LABEL); diff --git a/fca/src/test/java/org/nmdp/ngs/fca/ConceptLatticeTest.java b/fca/src/test/java/org/nmdp/ngs/fca/ConceptLatticeTest.java index 6c0ad3cb..ba77cfef 100644 --- a/fca/src/test/java/org/nmdp/ngs/fca/ConceptLatticeTest.java +++ b/fca/src/test/java/org/nmdp/ngs/fca/ConceptLatticeTest.java @@ -22,6 +22,7 @@ */ package org.nmdp.ngs.fca; +import com.google.common.collect.ImmutableList; import static org.junit.Assert.assertEquals; import static org.nmdp.ngs.fca.TestUtil.list; @@ -30,6 +31,7 @@ import java.util.List; import com.tinkerpop.blueprints.impls.tg.TinkerGraph; +import org.dishevelled.bitset.MutableBitSet; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;