@@ -81,16 +81,16 @@ public HashMap<String, String> modelAnalysis() throws IOException, InterruptedEx |
81 | 81 |
|
82 | 82 | for (AbstractGraph g : graphs.values()) { |
83 | 83 |
|
84 | | - if (g.isCyclic(true)){ |
| 84 | + if (g.isCyclic(true)) { |
85 | 85 | total_directed_cyclic++; |
86 | 86 | } |
87 | | - if (g.isCyclic(false)){ |
| 87 | + if (g.isCyclic(false)) { |
88 | 88 | total_undirected_cyclic++; |
89 | 89 | } |
90 | | - if ((boolean) g.isPlanar().get("planar")){ |
| 90 | + if ((boolean) g.isPlanar().get("planar")) { |
91 | 91 | total_planar++; |
92 | 92 | } |
93 | | - if (!g.connectedBFS(g.getNodes().values().iterator().next().getId())){ |
| 93 | + if (!g.connectedBFS(g.getNodes().values().iterator().next().getId())) { |
94 | 94 | total_not_connected++; |
95 | 95 |
|
96 | 96 | } |
@@ -102,73 +102,79 @@ public HashMap<String, String> modelAnalysis() throws IOException, InterruptedEx |
102 | 102 | } |
103 | 103 |
|
104 | 104 | AnalysisInfo.put("Total Number of Graphs", graphs.values().size() + ""); |
105 | | - AnalysisInfo.put("Total Number of Nodes",Math.round(total_nodes)+""); |
106 | | - AnalysisInfo.put("Total Number of Edges",Math.round(total_edges)+""); |
107 | | - AnalysisInfo.put("Total Number of Tokens",Math.round(total_tokens)+""); |
108 | | - AnalysisInfo.put("Average Span of Node",Precision.round(total_spans/graphs.values().size(),2)+""); |
109 | | - AnalysisInfo.put("Average Number of Nodes",Precision.round(total_nodes/graphs.values().size(),2)+""); |
110 | | - AnalysisInfo.put("Average Number of Edges",Precision.round(total_edges/graphs.values().size(),2)+""); |
111 | | - AnalysisInfo.put("Average Number of Tokens",Precision.round(total_tokens/graphs.values().size(),2)+""); |
112 | | - AnalysisInfo.put("Percentage of Directed Cyclic Graphs",Precision.round((total_directed_cyclic/graphs.values().size())*100,2)+""); |
113 | | - AnalysisInfo.put("Percentage of Undirected Cyclic Graphs",Precision.round((total_undirected_cyclic/graphs.values().size())*100,2)+""); |
114 | | - AnalysisInfo.put("Percentage of Disconnected Graphs",Precision.round((total_not_connected/graphs.values().size())*100,2)+""); |
115 | | - AnalysisInfo.put("Percentage of Planar Graphs",Precision.round((total_planar/graphs.values().size())*100,2)+""); |
| 105 | + AnalysisInfo.put("Total Number of Nodes", Math.round(total_nodes) + ""); |
| 106 | + AnalysisInfo.put("Total Number of Edges", Math.round(total_edges) + ""); |
| 107 | + AnalysisInfo.put("Total Number of Tokens", Math.round(total_tokens) + ""); |
| 108 | + AnalysisInfo.put("Average Span of Node", Precision.round(total_spans / graphs.values().size(), 2) + ""); |
| 109 | + AnalysisInfo.put("Average Number of Nodes", Precision.round(total_nodes / graphs.values().size(), 2) + ""); |
| 110 | + AnalysisInfo.put("Average Number of Edges", Precision.round(total_edges / graphs.values().size(), 2) + ""); |
| 111 | + AnalysisInfo.put("Average Number of Tokens", Precision.round(total_tokens / graphs.values().size(), 2) + ""); |
| 112 | + AnalysisInfo.put("Percentage of Directed Cyclic Graphs", Precision.round((total_directed_cyclic / graphs.values().size()) * 100, 2) + ""); |
| 113 | + AnalysisInfo.put("Percentage of Undirected Cyclic Graphs", Precision.round((total_undirected_cyclic / graphs.values().size()) * 100, 2) + ""); |
| 114 | + AnalysisInfo.put("Percentage of Disconnected Graphs", Precision.round((total_not_connected / graphs.values().size()) * 100, 2) + ""); |
| 115 | + AnalysisInfo.put("Percentage of Planar Graphs", Precision.round((total_planar / graphs.values().size()) * 100, 2) + ""); |
116 | 116 | return AnalysisInfo; |
117 | 117 | } |
118 | 118 |
|
119 | 119 | public void parseAlltokens() { |
120 | 120 | Properties props = new Properties(); |
121 | 121 | props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner"); |
122 | 122 | StanfordCoreNLP pipeline = new StanfordCoreNLP(props); |
123 | | - for (AbstractGraph g : this.graphs.values()) { |
124 | | - try { |
| 123 | + for (AbstractGraph g : this.graphs.values()) { |
| 124 | + try { |
125 | 125 |
|
126 | | - ArrayList<Token> tokenlist = new ArrayList<>(); |
| 126 | + ArrayList<Token> tokenlist = new ArrayList<>(); |
127 | 127 |
|
128 | | - CoreDocument document = new CoreDocument(g.getInput()); |
129 | | - pipeline.annotate(document); |
| 128 | + CoreDocument document = new CoreDocument(g.getInput()); |
| 129 | + pipeline.annotate(document); |
130 | 130 |
|
131 | | - int index = 0; |
132 | | - List<String> posTags = new ArrayList<>(); |
133 | | - List<String> nerTags = new ArrayList<>(); |
134 | | - for (int j = 0; j < document.sentences().size(); j++) { |
135 | | - CoreSentence sentence = document.sentences().get(j); |
136 | | - posTags.addAll(sentence.posTags()); |
137 | | - nerTags.addAll(sentence.nerTags()); |
138 | | - } |
139 | 131 |
|
140 | | - List<CoreLabel> tokens = document.tokens(); |
| 132 | + List<String> posTags = new ArrayList<>(); |
| 133 | + List<String> nerTags = new ArrayList<>(); |
| 134 | + for (int j = 0; j < document.sentences().size(); j++) { |
| 135 | + CoreSentence sentence = document.sentences().get(j); |
| 136 | + posTags.addAll(sentence.posTags()); |
| 137 | + nerTags.addAll(sentence.nerTags()); |
| 138 | + } |
141 | 139 |
|
142 | | - for (int i = 0; i < tokens.size(); i++) { |
143 | | - tokenlist.add(new Token(i, tokens.get(i).originalText(), tokens.get(i).lemma(), null)); |
144 | | - if (posTags.size() > 0) { |
145 | | - tokenlist.get(i).getExtraInformation().put("POS", posTags.get(i)); |
146 | | - } |
147 | | - if (nerTags.size() > 0) { |
148 | | - tokenlist.get(i).getExtraInformation().put("NER", nerTags.get(i)); |
149 | | - } |
| 140 | + List<CoreLabel> tokens = document.tokens(); |
| 141 | + |
| 142 | + for (int i = 0; i < tokens.size(); i++) { |
| 143 | + tokenlist.add(new Token(i, tokens.get(i).originalText(), tokens.get(i).lemma(), null)); |
| 144 | + if (posTags.size() > 0) { |
| 145 | + tokenlist.get(i).getExtraInformation().put("POS", posTags.get(i)); |
| 146 | + } |
| 147 | + if (nerTags.size() > 0) { |
| 148 | + tokenlist.get(i).getExtraInformation().put("NER", nerTags.get(i)); |
150 | 149 | } |
| 150 | + } |
| 151 | + int index = 0; |
| 152 | + for (CoreLabel label : tokens) { |
| 153 | + for (Node n : g.getNodes().values()) { |
| 154 | + if (n.getCharacterSpans() == null) { |
| 155 | + continue; |
| 156 | + } |
| 157 | + for (int i = 0; i < n.getCharacterSpans().size(); i++) { |
| 158 | + |
| 159 | + if (n.getCharacterSpans().get(i).getFrom() == label.beginPosition()) { |
151 | 160 |
|
152 | | - for (CoreLabel label : tokens) { |
153 | | - for (Node n : g.getNodes().values()) { |
154 | | - if (n.getAnchors() == null) { |
155 | | - continue; |
| 161 | + n.getAnchors().get(i).setFrom(index); |
156 | 162 | } |
157 | | - for (Anchors a : n.getAnchors()) { |
158 | | - if (a.getFrom() == label.beginPosition()) { |
159 | | - a.setFrom(index); |
160 | | - } |
161 | | - if (a.getEnd() == label.endPosition()) { |
162 | | - a.setEnd(index); |
163 | | - } |
| 163 | + if (n.getCharacterSpans().get(i).getEnd() == label.endPosition()) { |
| 164 | + n.getAnchors().get(i).setEnd(index); |
164 | 165 | } |
| 166 | + |
165 | 167 | } |
166 | 168 |
|
167 | | - index++; |
168 | 169 | } |
169 | | - g.setTokens(tokenlist); |
170 | | - }catch (Exception e){continue;} |
| 170 | + |
| 171 | + index++; |
| 172 | + } |
| 173 | + g.setTokens(tokenlist); |
| 174 | + } catch (Exception e) { |
| 175 | + continue; |
171 | 176 | } |
| 177 | + } |
172 | 178 |
|
173 | 179 | } |
174 | 180 |
|
@@ -250,19 +256,19 @@ public AbstractGraph CreateSubsetDescendent(AbstractGraph parent, String headNod |
250 | 256 | parent.setNodeNeighbours(); |
251 | 257 |
|
252 | 258 | HashMap<String, Node> DescendentNodes = new HashMap<String, Node>(); |
253 | | - HashMap<String,Boolean> visited = new HashMap<>(); |
| 259 | + HashMap<String, Boolean> visited = new HashMap<>(); |
254 | 260 | ArrayList<Edge> DescendentEdges = new ArrayList<>(); |
255 | 261 | ArrayList<Token> SubsetTokens = new ArrayList<>(); |
256 | 262 |
|
257 | | - for (Node n:parent.getNodes().values()) { |
258 | | - visited.put(n.getId(),false); |
| 263 | + for (Node n : parent.getNodes().values()) { |
| 264 | + visited.put(n.getId(), false); |
259 | 265 | } |
260 | 266 |
|
261 | 267 | Node n = parent.getNodes().get(headNodeID); |
262 | 268 |
|
263 | 269 | //Add the head Node to the descendent nodes hashmap |
264 | 270 | DescendentNodes.put(n.getId(), new Node(n)); |
265 | | - visited.put(n.getId(),true); |
| 271 | + visited.put(n.getId(), true); |
266 | 272 | for (Edge e : n.getDirectedEdgeNeighbours()) { |
267 | 273 | DescendentEdges.add(new Edge(e)); |
268 | 274 | } |
@@ -587,14 +593,16 @@ public HashMap<String, Object> compareTwoGraphs(String graphID1, String graphID2 |
587 | 593 | } else { |
588 | 594 | String phrase1 = ""; |
589 | 595 | String phrase2 = ""; |
590 | | - if (n1.getAnchors()!=null){ |
591 | | - for (Anchors a : n1.getAnchors()) { |
592 | | - phrase1 += g1.getTokenInput(g1.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase(); |
593 | | - }} |
594 | | - if (n2.getAnchors()!=null){ |
595 | | - for (Anchors a : n2.getAnchors()) { |
596 | | - phrase2 += g2.getTokenInput(g2.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase(); |
597 | | - }} |
| 596 | + if (n1.getAnchors() != null) { |
| 597 | + for (Anchors a : n1.getAnchors()) { |
| 598 | + phrase1 += g1.getTokenInput(g1.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase(); |
| 599 | + } |
| 600 | + } |
| 601 | + if (n2.getAnchors() != null) { |
| 602 | + for (Anchors a : n2.getAnchors()) { |
| 603 | + phrase2 += g2.getTokenInput(g2.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase(); |
| 604 | + } |
| 605 | + } |
598 | 606 |
|
599 | 607 | if (n1.getLabel().equals(n2.getLabel()) && phrase1.equals(phrase2)) { |
600 | 608 | //if they are equal then it adds the respective IDs to the individual similar nodes lists for the graphs |
@@ -617,12 +625,12 @@ public HashMap<String, Object> compareTwoGraphs(String graphID1, String graphID2 |
617 | 625 | phrase1 = ""; |
618 | 626 | phrase2 = ""; |
619 | 627 |
|
620 | | - if (nn1.getAnchors()!=null) { |
| 628 | + if (nn1.getAnchors() != null) { |
621 | 629 | for (Anchors a : nn1.getAnchors()) { |
622 | 630 | phrase1 += g1.getTokenInput(g1.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase(); |
623 | 631 | } |
624 | 632 | } |
625 | | - if (nn2.getAnchors()!=null) { |
| 633 | + if (nn2.getAnchors() != null) { |
626 | 634 | for (Anchors a : nn2.getAnchors()) { |
627 | 635 | phrase2 += g2.getTokenInput(g2.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase(); |
628 | 636 | } |
|