File: DAG.java

package info (click to toggle)
metastudent 2.0.1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 95,644 kB
  • sloc: java: 3,287; perl: 2,089; python: 1,421; ruby: 242; sh: 39; makefile: 19
file content (105 lines) | stat: -rwxr-xr-x 2,381 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package pp2.go;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

import pp2.prediction.knn.DAGNode;

public class DAG {

	String[] nodes = new String[0];
	HashMap<String,String[]> ancestors;
	String[] leaves = new String[0];
	HashMap<String,DAGNode> DAGNodes;
	
	/**
	 * 
	 * @author Mark Heron
	 *
	 */
	public DAG(Relations rel, String[] goterms) {
		
		//filter goterms
		String[] goterms_f = new String[0];
		HashSet<String> tmp = new HashSet<String>();
		tmp.addAll(Arrays.asList(goterms));
		goterms_f = tmp.toArray(goterms_f);
		tmp = new HashSet<String>();
		for (String goterm : goterms_f) {
			if(rel.getType(goterm).length() > 0 && rel.isTypeofInterst(goterm)) {
				tmp.add(goterm);
			}
		}
		goterms_f = new String[0];
		goterms_f = tmp.toArray(goterms_f);
		
		
		// make nodes
		HashSet<String> nodes_tmp = new HashSet<String>();
		nodes_tmp.addAll(Arrays.asList(goterms_f));
		for (String goterm : goterms_f) {
			nodes_tmp.addAll(Arrays.asList(rel.getAncestors(goterm)));
		}
		nodes = nodes_tmp.toArray(nodes);
		
		// make ancestors
		ancestors = new HashMap<String, String[]>();
		for (String goterm : nodes) {
			ancestors.put(goterm, rel.getAncestors(goterm));
		}
		
		// make leaves
		HashSet<String> leaves_tmp = new HashSet<String>();
		for (String goterm : goterms_f) {
			boolean leaf = true;
			for (String goterm2 : goterms_f) {
				if(goterm != goterm2) {
					for (String ancestor : rel.getAncestors(goterm2)) {
						if(goterm.equals(ancestor)) {
							leaf = false;
						}
					}
				}
			}
			if(leaf) {
				leaves_tmp.add(goterm);
			}
		}
		leaves = leaves_tmp.toArray(leaves);
		
		// make initial scores
		DAGNodes = new HashMap<String, DAGNode>();
		for (String node : nodes) {
			DAGNodes.put(node, new DAGNode());
			
			// also add scores for the ancestors
			for (String anc : ancestors.get(node)) {
				DAGNodes.put(anc, new DAGNode());
			}
		}
		
	}
	
	
	public String[] getNodes() {
		return nodes;
	}
	
	public String[] getAncestors(String goterm) {
		return ancestors.get(goterm);
	}
	
	public String[] getLeaves() {
		return leaves;
	}
	
	public DAGNode getDAGNode(String goterm) {
		return DAGNodes.get(goterm);
	}
	
	public HashMap<String, DAGNode> getDAGNodes()
	{
		return DAGNodes;
	}
}