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<Map<Integer,List<LabeledEdge>>> labelededges; |
---|
17 | List<String> labels; |
---|
18 | HashMap<String,Integer> labelednodes; |
---|
19 | //List<Map<Integer,List<LabeledEdge>>> gadjlist; // grouped adj list: node, node-edge list |
---|
20 | |
---|
21 | public class LabeledEdge{ |
---|
22 | boolean direction; |
---|
23 | Object label; |
---|
24 | |
---|
25 | public LabeledEdge(boolean dir, Object label){ |
---|
26 | this.direction = dir; |
---|
27 | this.label = label; |
---|
28 | } |
---|
29 | |
---|
30 | public Object getLabel(){ |
---|
31 | return label; |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | public LabeledMultiDigraph(){ |
---|
36 | //adjlist = new ArrayList<List<LabeledEdge>>(); |
---|
37 | labelededges = new ArrayList<Map<Integer,List<LabeledEdge>>>(); |
---|
38 | labels = new LinkedList<String>(); |
---|
39 | labelednodes = new HashMap<String, Integer>(); |
---|
40 | //gadjlist = new ArrayList<Map<Integer,List<LabeledEdge>>>(); |
---|
41 | } |
---|
42 | |
---|
43 | public void addNode(String label){ |
---|
44 | labelednodes.put(label, labels.size()); |
---|
45 | labels.add(label); |
---|
46 | //adjlist.add(new LinkedList<LabeledEdge>()); |
---|
47 | //gadjlist.add(new HashMap<Integer, List<LabeledEdge>>()); |
---|
48 | labelededges.add(new HashMap<Integer, List<LabeledEdge>>()); |
---|
49 | } |
---|
50 | |
---|
51 | public void addEdge(Integer node1, Integer node2, Object elabel){ // node 1 -> node2 |
---|
52 | if ( labels.size() < node1 || labels.size() < node2 ){ |
---|
53 | System.err.println("Error for Edge Addition: No Node for the Edge"); |
---|
54 | return; |
---|
55 | } |
---|
56 | |
---|
57 | //LabeledEdge edge = new LabeledEdge(node2,elabel); |
---|
58 | //adjlist.get(node1).add(edge); |
---|
59 | List<LabeledEdge> edgesf = labelededges.get(node1).get(node2); |
---|
60 | if ( edgesf == null ){ |
---|
61 | edgesf = new LinkedList<LabeledEdge>(); |
---|
62 | labelededges.get(node1).put(node2, edgesf); |
---|
63 | } |
---|
64 | edgesf.add(new LabeledEdge(true, elabel)); |
---|
65 | |
---|
66 | List<LabeledEdge> edgesr = labelededges.get(node2).get(node1); |
---|
67 | if ( edgesr == null ){ |
---|
68 | edgesr = new LinkedList<LabeledEdge>(); |
---|
69 | labelededges.get(node2).put(node1, edgesr); |
---|
70 | } |
---|
71 | edgesr.add(new LabeledEdge(false, elabel)); |
---|
72 | } |
---|
73 | } |
---|