Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion fca/src/main/java/org/nmdp/ngs/fca/CompleteLattice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<E extends PartiallyOrdered> implements java.util.Iterator<E> {
private final java.util.Iterator<Vertex> vertices;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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() /
Expand Down
4 changes: 4 additions & 0 deletions fca/src/main/java/org/nmdp/ngs/fca/ConceptLattice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions fca/src/main/java/org/nmdp/ngs/fca/IntervalLattice.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
package org.nmdp.ngs.fca;

import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;

public class IntervalLattice<C extends Comparable<?>> extends CompleteLattice<Interval<C>> {

public IntervalLattice(final Graph graph) {
super(graph, Interval.MAGIC);
}

public IntervalLattice() {
super(new TinkerGraph(), Interval.MAGIC);
}

public Interval<C> insert(final Interval<C> interval) {
return super.addIntent(interval, top).getProperty(LABEL);
Expand Down
2 changes: 2 additions & 0 deletions fca/src/test/java/org/nmdp/ngs/fca/ConceptLatticeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down