Skip to content

Commit

Permalink
Merge a9041df into b4b832f
Browse files Browse the repository at this point in the history
  • Loading branch information
jnguyenx authored Mar 4, 2017
2 parents b4b832f + a9041df commit fc0dfe4
Show file tree
Hide file tree
Showing 38 changed files with 2,596 additions and 2,731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.monarchinitiative.owlsim.kb.BMKnowledgeBase;
import org.monarchinitiative.owlsim.kb.LabelMapper;
Expand All @@ -20,65 +17,57 @@
*/
public class ClassMatcher {

BMKnowledgeBase kb;


@Inject
public ClassMatcher(BMKnowledgeBase kb) {
super();
this.kb = kb;
}
BMKnowledgeBase kb;

public ClassMatcher(BMKnowledgeBase kb) {
super();
this.kb = kb;
}

/**
* Find best match for every class in ont1, where the best match is in ont2
*
* @param qOnt
* @param tOnt
* @return list of matches
*/
public List<SimpleClassMatch> matchOntologies(String qOnt, String tOnt) {
Set<String> qids = kb.getClassIdsByOntology(qOnt);
Set<String> tids = kb.getClassIdsByOntology(tOnt);
return matchClassSets(qids, tids);
}

public List<SimpleClassMatch> matchClassSets(Set<String> qids, Set<String> tids) {
ArrayList<SimpleClassMatch> matches = new ArrayList<>();
for (String q : qids) {
matches.add(getBestMatch(q, tids));
}
return matches;
}

/**
* Find best match for every class in ont1, where the best
* match is in ont2
*
* @param qOnt
* @param tOnt
* @return list of matches
*/
public List<SimpleClassMatch> matchOntologies(String qOnt, String tOnt) {
Set<String> qids = kb.getClassIdsByOntology(qOnt);
Set<String> tids = kb.getClassIdsByOntology(tOnt);
return matchClassSets(qids, tids);
}
private SimpleClassMatch getBestMatch(String q, Set<String> tids) {
EWAHCompressedBitmap qbm = kb.getSuperClassesBM(q);
double bestEqScore = 0.0;
String best = null;
for (String t : tids) {
EWAHCompressedBitmap tbm = kb.getSuperClassesBM(t);
int numInQueryAndInTarget = qbm.andCardinality(tbm);
int numInQueryOrInTarget = qbm.orCardinality(tbm);
double eqScore = numInQueryAndInTarget / (double) numInQueryOrInTarget;
if (eqScore > bestEqScore) {
bestEqScore = eqScore;
best = t;
}
}

public List<SimpleClassMatch> matchClassSets(Set<String> qids,
Set<String> tids) {
ArrayList<SimpleClassMatch> matches = new ArrayList<>();
for (String q : qids) {
matches.add(getBestMatch(q, tids));
}
return matches;
}
EWAHCompressedBitmap tbm = kb.getSuperClassesBM(best);
int numInQueryAndInTarget = qbm.andCardinality(tbm);
double subClassScore = numInQueryAndInTarget / (double) qbm.cardinality();
double superClassScore = numInQueryAndInTarget / (double) tbm.cardinality();

private SimpleClassMatch getBestMatch(String q, Set<String> tids) {
EWAHCompressedBitmap qbm = kb.getSuperClassesBM(q);
double bestEqScore = 0.0;
String best = null;
for (String t : tids) {
EWAHCompressedBitmap tbm = kb.getSuperClassesBM(t);
int numInQueryAndInTarget = qbm.andCardinality(tbm);
int numInQueryOrInTarget = qbm.orCardinality(tbm);
double eqScore = numInQueryAndInTarget / (double) numInQueryOrInTarget;
if (eqScore > bestEqScore) {
bestEqScore = eqScore;
best = t;
}
}

EWAHCompressedBitmap tbm = kb.getSuperClassesBM(best);
int numInQueryAndInTarget = qbm.andCardinality(tbm);
double subClassScore = numInQueryAndInTarget / (double) qbm.cardinality();
double superClassScore = numInQueryAndInTarget / (double) tbm.cardinality();

LabelMapper lm = kb.getLabelMapper();
return new SimpleClassMatch(q, best,
lm.getArbitraryLabel(q),
lm.getArbitraryLabel(best),
bestEqScore,
subClassScore,
superClassScore);
}
LabelMapper lm = kb.getLabelMapper();
return new SimpleClassMatch(q, best, lm.getArbitraryLabel(q), lm.getArbitraryLabel(best), bestEqScore,
subClassScore, superClassScore);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
/**
* @author cjm
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.monarchinitiative.owlsim.compute.cpt;

import java.util.Map;

import org.monarchinitiative.owlsim.kb.BMKnowledgeBase;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.monarchinitiative.owlsim.compute.enrich;

import javax.inject.Inject;

public class EnrichmentConfig {

public enum AnalysisType {OVER, UNDER, BOTH};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.apache.commons.math3.distribution.HypergeometricDistribution;
import org.apache.log4j.Logger;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentConfig;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentConfig.AnalysisType;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentEngine;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentQuery;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentResult;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentResultSet;
import org.monarchinitiative.owlsim.compute.enrich.EnrichmentConfig.AnalysisType;
import org.monarchinitiative.owlsim.kb.BMKnowledgeBase;
import org.monarchinitiative.owlsim.kb.ewah.EWAHUtils;
import org.monarchinitiative.owlsim.kb.filter.Filter;
Expand Down Expand Up @@ -44,7 +42,6 @@ public class HypergeometricEnrichmentEngine implements EnrichmentEngine {

protected EnrichmentConfig enrichmentConfig = new EnrichmentConfig();

@Inject
public HypergeometricEnrichmentEngine(BMKnowledgeBase kb) {
super();
this.kb = kb;
Expand Down
Loading

0 comments on commit fc0dfe4

Please sign in to comment.