1 | /* |
---|
2 | * To change this template, choose Tools | Templates |
---|
3 | * and open the template in the editor. |
---|
4 | */ |
---|
5 | package org.biohackathon.SPARQLBuilder.OWL; |
---|
6 | |
---|
7 | /** |
---|
8 | * |
---|
9 | * @author atsuko |
---|
10 | */ |
---|
11 | import java.util.*; |
---|
12 | |
---|
13 | |
---|
14 | public class LabeledMultiDigraph { |
---|
15 | List<List<LabeledEdge>> adjlist; |
---|
16 | List<String> labels; |
---|
17 | HashMap<String,Integer> labelednodes; |
---|
18 | List<Map<Integer,List<LabeledEdge>>> gadjlist; // grouped adj list: node, node-edge list |
---|
19 | |
---|
20 | public class LabeledEdge{ |
---|
21 | Integer node; |
---|
22 | Object label; |
---|
23 | |
---|
24 | public LabeledEdge(Integer node, Object label){ |
---|
25 | this.node = node; |
---|
26 | this.label = label; |
---|
27 | } |
---|
28 | |
---|
29 | public Object getLabel(){ |
---|
30 | return label; |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | public LabeledMultiDigraph(){ |
---|
35 | adjlist = new ArrayList<List<LabeledEdge>>(); |
---|
36 | labels = new LinkedList<String>(); |
---|
37 | labelednodes = new HashMap<String, Integer>(); |
---|
38 | gadjlist = new ArrayList<Map<Integer,List<LabeledEdge>>>(); |
---|
39 | } |
---|
40 | |
---|
41 | public void addNode(String label){ |
---|
42 | labelednodes.put(label, labels.size()); |
---|
43 | labels.add(label); |
---|
44 | adjlist.add(new LinkedList<LabeledEdge>()); |
---|
45 | gadjlist.add(new HashMap<Integer, List<LabeledEdge>>()); |
---|
46 | } |
---|
47 | |
---|
48 | public void addEdge(Integer node1, Integer node2, Object elabel){ |
---|
49 | if ( labels.size() < node1 || labels.size() < node2 ){ |
---|
50 | System.err.println("Error for Edge Addition: No Node for the Edge"); |
---|
51 | return; |
---|
52 | } |
---|
53 | LabeledEdge edge = new LabeledEdge(node2, elabel); |
---|
54 | adjlist.get(node1).add(edge); |
---|
55 | |
---|
56 | Map<Integer, List<LabeledEdge>> edges = gadjlist.get(node1); |
---|
57 | List<LabeledEdge> sedge = edges.get(node2); |
---|
58 | if ( sedge == null ){ |
---|
59 | sedge = new LinkedList<LabeledEdge>(); |
---|
60 | edges.put(node2, sedge); |
---|
61 | } |
---|
62 | sedge.add(edge); |
---|
63 | } |
---|
64 | } |
---|