// continue (orthologous statement intersects the proto network)
// - find object parameter's uuid in a proto network term, if found
// continue (orthologous statement intersects the proto network)
// 1. Map parameter UUIDs to containing term ids in the proto network
final TermTable tt = pn.getTermTable();
final TermParameterMapTable tpmt = pn.getTermParameterMapTable();
final ParameterTable pt = pn.getParameterTable();
final Map<Integer, Integer> pglob = pt.getGlobalIndex();
final Map<Integer, SkinnyUUID> puuid = pt.getGlobalUUIDs();
final Set<Integer> tidset = tt.getIndexedTerms().keySet();
final Map<SkinnyUUID, Set<Integer>> uuidterms = sizedHashMap(puuid
.size());
final Set<Term> pnterms = new HashSet<Term>(tt.getVisitedTerms().keySet());
// for each term
for (final Integer tid : tidset) {
// get its parameters
final List<Integer> pids = tpmt.getParameterIndexes(tid);
for (final Integer pid : pids) {
// find global parameter index for pid
Integer globalpid = pglob.get(pid);
// find UUID for global parameter index
final SkinnyUUID pu = puuid.get(globalpid);
// save this term to this UUID
Set<Integer> terms = uuidterms.get(pu);
if (terms == null) {
terms = new HashSet<Integer>();
uuidterms.put(pu, terms);
}
terms.add(tid);
}
}
// get all statement in orthology document
final List<Statement> orthoStmts = d.getAllStatements();
// map them to statement groups for efficient pruning
Map<StatementGroup, Set<Statement>> orthomap = d.mapStatements();
// set up pruning result
int total = orthoStmts.size();
int pruned = 0;
// establish cache to skinny uuids to avoid superfluous jdbm lookups
final Map<Parameter, SkinnyUUID> paramcache = sizedHashMap(total * 2);
// iterate all statements in the orthology document
ORTHO_STATEMENT: for (final Statement orthoStmt : orthoStmts) {
// rule out invalid or non-orthologous statements
if (validOrthologousStatement(orthoStmt)) {
// break down subject
final Term sub = orthoStmt.getSubject();
final FunctionEnum subf = sub.getFunctionEnum();
final List<Parameter> subp = sub.getParameters();
final Parameter subjectParam = subp.get(0);
// break down object
final Term obj = orthoStmt.getObject().getTerm();
final FunctionEnum objf = obj.getFunctionEnum();
final List<Parameter> objp = obj.getParameters();
final Parameter objectParam = objp.get(0);
// lookup exact match of subject term
if (pnterms.contains(sub)) {
pnterms.add(obj);
continue;
}
// find UUID for subject parameter
SkinnyUUID uuid = paramcache.get(subjectParam);
if (uuid == null) {
final Namespace ns = subjectParam.getNamespace();
final JDBMEquivalenceLookup lookup = lookups.get(ns
.getResourceLocation());
if (lookup == null) {
continue;
}
uuid = lookup.lookup(subjectParam.getValue());
paramcache.put(subjectParam, uuid);
}
// if there is a proto network term with this UUID contained, then
// this orthologous statement intersects the proto network, continue
if (uuid != null) {
Set<Integer> tids = uuidterms.get(uuid);
if (hasItems(tids)) {
for (final Integer tid : tids) {
final Term t = tt.getIndexedTerms().get(tid);
if (t.getFunctionEnum() == subf) {
pnterms.add(sub);
pnterms.add(t);
pnterms.add(obj);
continue ORTHO_STATEMENT;
}
}
}
}
// lookup exact match of object term
if (pnterms.contains(obj)) {
pnterms.add(sub);
continue;
}
// find UUID for object parameter
uuid = paramcache.get(objectParam);
if (uuid == null) {
final Namespace ns = objectParam.getNamespace();
final JDBMEquivalenceLookup lookup = lookups.get(ns
.getResourceLocation());
if (lookup == null) {
continue;
}
uuid = lookup.lookup(objectParam.getValue());
paramcache.put(objectParam, uuid);
}
// if there is a proto network term with this UUID contained, then
// this orthologous statement intersects the proto network, continue
if (uuid != null) {
Set<Integer> tids = uuidterms.get(uuid);
if (hasItems(tids)) {
for (final Integer tid : tids) {
final Term t = tt.getIndexedTerms().get(tid);
if (t.getFunctionEnum() == objf) {
pnterms.add(obj);
pnterms.add(t);
pnterms.add(sub);