GeezerVison is showing github.com — Add docs and remove console logs · RepGraph/RepGraph@0222180
File treeExpand file treeCollapse file tree Open diff view settings javascript/repgraphfrontend/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/AMRGraph.java +15-73Lines changed: 15 additions & 73 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | import java.util.Stack; | 16 | 16 |
| 17 | 17 | /** | 18 | | - * The Graph class represents a single sentence which comprises of nodes, edges and tokens. | | 18 | + * The AMR Graph class represents a graph following the AMR Framework | 19 | 19 | */ | 20 | 20 | public class AMRGraph extends AbstractGraph { | 21 | 21 |
| @@ -47,6 +47,9 @@ public AMRGraph(@JsonProperty("id") String id, @JsonProperty("source") String so | 47 | 47 | } | 48 | 48 |
| 49 | 49 |
| | 50 | + /** | | 51 | + * Utility function used in the process of aligning nodes to tokens using the JAMR aligner | | 52 | + */ | 50 | 53 | public void alignUtil(String NodeID, HashMap<String, Node> nodes, HashMap<String, Boolean> visited, int layer, StringWriter writer) throws IOException { | 51 | 54 | // Mark the current node as visited and print it | 52 | 55 | visited.put(NodeID, true); | @@ -71,6 +74,11 @@ public void alignUtil(String NodeID, HashMap<String, Node> nodes, HashMap<String | 71 | 74 |
| 72 | 75 | } | 73 | 76 |
| | 77 | + /** | | 78 | + * Aligns nodes to tokens | | 79 | + * @throws IOException | | 80 | + * @throws InterruptedException | | 81 | + */ | 74 | 82 | public void alignNodes() throws IOException, InterruptedException { | 75 | 83 | setNodeNeighbours(); | 76 | 84 |
| @@ -158,78 +166,12 @@ public void alignNodes() throws IOException, InterruptedException { | 158 | 166 |
| 159 | 167 | } | 160 | 168 |
| 161 | | - public void fillInSpans(HashMap<String, Node> nodes) { | 162 | | - ArrayList<ArrayList<String>> order = getPaths(nodes); | 163 | | - | 164 | | - for (ArrayList<String> path : order) { | 165 | | - if (nodes.get(path.get(0)).getAnchors() != null) { | 166 | | - continue; | 167 | | - } | 168 | | - int min = Integer.MAX_VALUE; | 169 | | - for (int i = 1; i < path.size(); i++) { | 170 | | - if (nodes.get(path.get(i)).getAnchors() != null) { | 171 | | - min = Math.min(min, nodes.get(path.get(i)).getAnchors().get(0).getFrom()); | 172 | | - } | 173 | | - } | 174 | | - if (min == Integer.MAX_VALUE) { | 175 | | - for (Node n : nodes.get(path.get(0)).getUndirectedNeighbours()) { | 176 | | - if (n.getAnchors() != null) { | 177 | | - min = Math.min(min, n.getAnchors().get(0).getFrom()); | 178 | | - } | 179 | | - } | 180 | | - } | 181 | | - if (min != Integer.MAX_VALUE) { | 182 | | - ArrayList<Anchors> arr = new ArrayList<>(); | 183 | | - Anchors a = new Anchors(min, min); | 184 | | - arr.add(a); | 185 | | - nodes.get(path.get(0)).setAnchors(arr); | 186 | | - } | 187 | | - } | 188 | | - | 189 | | - } | 190 | | - | 191 | | - private void topologicalSort(String nodeID, HashMap<String, Node> nodes, HashMap<String, Boolean> visited, | 192 | | - Stack<String> stack) { | 193 | | - | 194 | | - visited.put(nodeID, true); | 195 | | - Iterator<Node> it = nodes.get(nodeID).getDirectedNeighbours().iterator(); | 196 | | - | 197 | | - String i; | 198 | | - while (it.hasNext()) { | 199 | | - i = it.next().getId(); | 200 | | - if (!visited.get(i)) | 201 | | - topologicalSort(i, nodes, visited, stack); | 202 | | - } | 203 | | - | 204 | | - stack.push((nodeID)); | 205 | | - } | 206 | | - | 207 | | - private ArrayList<ArrayList<String>> getPaths(HashMap<String, Node> nodes) { | 208 | | - | 209 | | - Stack<String> stack = new Stack<String>(); | 210 | | - | 211 | | - HashMap<String, Boolean> visited = new HashMap<>(); | 212 | | - | 213 | | - ArrayList<ArrayList<String>> searches = new ArrayList<>(); | 214 | | - for (Node n : nodes.values()) { | 215 | | - for (String i : nodes.keySet()) { | 216 | | - visited.put(i, false); | 217 | | - } | 218 | | - if (!visited.get(n.getId())) { | 219 | | - topologicalSort(n.getId(), nodes, visited, stack); | 220 | | - } | 221 | | - | 222 | | - ArrayList<String> order = new ArrayList<>(); | 223 | | - while (!stack.empty()) { | 224 | | - order.add(stack.pop()); | 225 | | - } | 226 | | - searches.add(order); | 227 | | - | 228 | | - } | 229 | | - | 230 | | - return searches; | 231 | | - } | 232 | | - | | 169 | + /** | | 170 | + * Overrided method to align nodes before calling planar method | | 171 | + * @return planar data | | 172 | + * @throws IOException | | 173 | + * @throws InterruptedException | | 174 | + */ | 233 | 175 | @JsonIgnore | 234 | 176 | public HashMap<String,Object> isPlanar() throws IOException, InterruptedException { | 235 | 177 | this.alignNodes(); | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/AMRModel.java +22-1Lines changed: 22 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | import java.io.IOException; | 6 | 6 | import java.util.*; | 7 | 7 |
| | 8 | + | 8 | 9 | /** | 9 | | - * The RepGraphModel class is used to store all the system's graphs and run analysis functions on graphs. | | 10 | + * Model class for AMR graphs - contains AMR specific functions | 10 | 11 | */ | 11 | 12 | public class AMRModel extends AbstractModel { | 12 | 13 |
| 13 | 14 |
| | 15 | + /** | | 16 | + * AMR model constructor - simply calls super | | 17 | + */ | 14 | 18 | public AMRModel() { | 15 | 19 | super(); | 16 | 20 | } | 17 | 21 |
| | 22 | + /** | | 23 | + * @param graphID A Graph's ID. | | 24 | + * @return the graph requested. | | 25 | + * @throws IOException | | 26 | + * @throws InterruptedException | | 27 | + */ | | 28 | + @Override | 18 | 29 | public AMRGraph getGraph(String graphID) throws IOException, InterruptedException { | 19 | 30 | AMRGraph g = (AMRGraph)graphs.get(graphID); | 20 | 31 | g.alignNodes(); | 21 | 32 | return g; | 22 | 33 | } | 23 | 34 |
| | 35 | + /** | | 36 | + * Runs all graphs in the model through the aligner | | 37 | + * @throws IOException | | 38 | + * @throws InterruptedException | | 39 | + */ | 24 | 40 | public void alignAllGraphs() throws IOException, InterruptedException { | 25 | 41 | for (AbstractGraph t:graphs.values()) { | 26 | 42 | AMRGraph g = (AMRGraph)t; | @@ -29,6 +45,11 @@ public void alignAllGraphs() throws IOException, InterruptedException { | 29 | 45 | } | 30 | 46 | } | 31 | 47 |
| | 48 | + /** | | 49 | + * @return statistics about the graphs in the dataset - AMR model analysis does not include planarity or edge length | | 50 | + * @throws IOException | | 51 | + * @throws InterruptedException | | 52 | + */ | 32 | 53 | @Override | 33 | 54 | public HashMap<String, String> modelAnalysis() throws IOException, InterruptedException { | 34 | 55 | HashMap<String, String> AnalysisInfo = new HashMap<>(); | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/AbstractModel.java +35-2Lines changed: 35 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,11 @@ public AbstractGraph getGraph(String graphID) throws IOException, InterruptedExc | 37 | 37 | return graphs.get(graphID); | 38 | 38 | } | 39 | 39 |
| | 40 | + | | 41 | + /** | | 42 | + * get hashmap of all graphs in model | | 43 | + * @return all graphs in model | | 44 | + */ | 40 | 45 | public HashMap<String, AbstractGraph> getAllGraphs() { | 41 | 46 | return graphs; | 42 | 47 | } | @@ -67,6 +72,12 @@ public void clearGraphs() { | 67 | 72 | graphs.clear(); | 68 | 73 | } | 69 | 74 |
| | 75 | + /** | | 76 | + * Collects statistics about the dataset the model represents | | 77 | + * @return model statistics | | 78 | + * @throws IOException | | 79 | + * @throws InterruptedException | | 80 | + */ | 70 | 81 | public HashMap<String, String> modelAnalysis() throws IOException, InterruptedException { | 71 | 82 | HashMap<String, String> AnalysisInfo = new HashMap<>(); | 72 | 83 |
| @@ -119,6 +130,9 @@ public HashMap<String, String> modelAnalysis() throws IOException, InterruptedEx | 119 | 130 | return AnalysisInfo; | 120 | 131 | } | 121 | 132 |
| | 133 | + /** | | 134 | + * Runs graphs through Core NLP NER model and assigns NER to tokens | | 135 | + */ | 122 | 136 | public void parseAlltokens() { | 123 | 137 | Properties props = new Properties(); | 124 | 138 | props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner"); | @@ -157,6 +171,12 @@ public void parseAlltokens() { | 157 | 171 |
| 158 | 172 | } | 159 | 173 |
| | 174 | + /** | | 175 | + * Creates a subgraph from adjacent nodes | | 176 | + * @param parent Graph that the subgraph is created from | | 177 | + * @param headNodeID Node ID that the subgraph is created from | | 178 | + * @return Subgraph | | 179 | + */ | 160 | 180 | public AbstractGraph CreateSubsetAdjacent(AbstractGraph parent, String headNodeID) { | 161 | 181 |
| 162 | 182 |
| @@ -229,6 +249,12 @@ public AbstractGraph CreateSubsetAdjacent(AbstractGraph parent, String headNodeI | 229 | 249 | return subset; | 230 | 250 | } | 231 | 251 |
| | 252 | + /** | | 253 | + * Creates a subgraph from descendent nodes | | 254 | + * @param parent Graph that the subgraph is created from | | 255 | + * @param headNodeID Node ID that the subgraph is created from | | 256 | + * @return Subgraph | | 257 | + */ | 232 | 258 | public AbstractGraph CreateSubsetDescendent(AbstractGraph parent, String headNodeID) { | 233 | 259 |
| 234 | 260 | AbstractGraph subset = new AbstractGraph(); | @@ -348,6 +374,11 @@ public HashMap<String, Object> searchSubgraphPattern(String graphID, String[] No | 348 | 374 |
| 349 | 375 | } | 350 | 376 |
| | 377 | + /** | | 378 | + * Search through model to find graphs containing the subgraph pattern given | | 379 | + * @param Asubgraph subgraph pattern | | 380 | + * @return hashmap of inputs and ids as well as a response - keys : "data" and "response" | | 381 | + */ | 351 | 382 | public HashMap<String, Object> searchSubgraphPattern(AbstractGraph Asubgraph) { | 352 | 383 |
| 353 | 384 | AbstractGraph subgraph = (AbstractGraph) Asubgraph; | @@ -505,6 +536,9 @@ public HashMap<String, Object> searchSubgraphNodeSet(ArrayList<String> labels) { | 505 | 536 | * | 506 | 537 | * @param graphID1 AbstractGraph ID of the first AbstractGraph. | 507 | 538 | * @param graphID2 AbstractGraph ID of the second AbstractGraph. | | 539 | + * @param strict Boolean for strict comparison | | 540 | + * @param noSurface Boolean to not check surface nodes | | 541 | + * @param noAbstract Boolean to not check abstract nodes | 508 | 542 | * @return HashMap<String, Object> The differences and similarities of the two graphs i.e | 509 | 543 | * the "SimilarNodes1" key gives the Node ids of the similar nodes in graph1. | 510 | 544 | * the "SimilarNodes2" key gives the Node ids of the similar nodes in graph2. | @@ -657,8 +691,7 @@ public HashMap<String, Object> compareTwoGraphs(String graphID1, String graphID2 | 657 | 691 | * @param longestPathUndirected Boolean to decide if to find the longest undirected path. | 658 | 692 | * @param connected Boolean to decide if to test for if the AbstractGraph is connected. | 659 | 693 | * @return HashMap<String, Object> Results of the tests i.e | 660 | | - * the "Planar" key returns a boolean of whether or not the AbstractGraph is planar | 661 | | - * the "PlanarVis" key returns the visualisation data | | 694 | + * the "Planar" key returns a HashMap of Planar data - the result and the graph construction | 662 | 695 | * the "LongestPathDirected" key returns an ArrayList of an Arraylist of integers defining the multiple longest directed paths in the graphs | 663 | 696 | * the "LongestPathUndirected" key returns an ArrayList of an Arraylist of integers defining the multiple longest undirected paths in the graphs | 664 | 697 | * the "Connected" returns a boolean of whether or not the AbstractGraph is connected. | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/EDSGraph.java +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | import java.util.*; | 12 | 12 |
| 13 | 13 | /** | 14 | | - * The Graph class represents a single sentence which comprises of nodes, edges and tokens. | | 14 | + * The EDS Graph class represents a graph following the EDS Framework | 15 | 15 | */ | 16 | 16 | public class EDSGraph extends AbstractGraph { | 17 | 17 |
| 18 | 18 |
| 19 | 19 | /** | 20 | | - * Default constructor for the Graph class. | | 20 | + * Default constructor for the EDS Graph class. | 21 | 21 | */ | 22 | 22 | public EDSGraph() { | 23 | 23 | super(); | @@ -28,6 +28,10 @@ public EDSGraph(String id, String source, String input, HashMap<String, Node> no | 28 | 28 |
| 29 | 29 | } | 30 | 30 |
| | 31 | + /** | | 32 | + * Set the hashmap of nodes from an array of nodes - uses EDS specific rules | | 33 | + * @param nodelist Array of Node objects | | 34 | + */ | 31 | 35 | @JsonSetter("nodes") | 32 | 36 | public void setNodes(ArrayList<Node> nodelist) { | 33 | 37 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/EDSModel.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import java.util.*; | 4 | 4 |
| 5 | 5 | /** | 6 | | - * The RepGraphModel class is used to store all the system's graphs and run analysis functions on graphs. | | 6 | + * Model class for EDS graphs - contains EDS specific functions | 7 | 7 | */ | 8 | 8 | public class EDSModel extends AbstractModel { | 9 | 9 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/Node.java +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 | import java.util.LinkedHashMap; | 18 | 18 | import java.util.Map; | 19 | 19 |
| | 20 | +/** | | 21 | + * Node object - contains node information | | 22 | + */ | 20 | 23 | @JsonIgnoreProperties(ignoreUnknown = true) | 21 | 24 | public class Node { | 22 | 25 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/PTGGraph.java +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | import java.util.HashMap; | 7 | 7 |
| 8 | 8 | /** | 9 | | - * The Graph class represents a single sentence which comprises of nodes, edges and tokens. | | 9 | + * The PTG Graph class represents a graph following the PTG Framework | 10 | 10 | */ | 11 | 11 | public class PTGGraph extends AbstractGraph { | 12 | 12 |
| 13 | 13 |
| 14 | | - /** | 15 | | - * Default constructor for the Graph class. | 16 | | - */ | | 14 | + | 17 | 15 | public PTGGraph() { | 18 | 16 | super(); | 19 | 17 | } | @@ -23,6 +21,10 @@ public PTGGraph(String id, String source, String input, HashMap<String, Node> no | 23 | 21 |
| 24 | 22 | } | 25 | 23 |
| | 24 | + /** | | 25 | + * Sets the nodes hashmap from an array of node objects - uses PTG specific rules | | 26 | + * @param nodelist Array of Node objects | | 27 | + */ | 26 | 28 | @JsonSetter("nodes") | 27 | 29 | public void setNodes(ArrayList<Node> nodelist) { | 28 | 30 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/PTGModel.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import java.util.*; | 4 | 4 |
| 5 | 5 | /** | 6 | | - * The RepGraphModel class is used to store all the system's graphs and run analysis functions on graphs. | | 6 | + * Model class for PTG graphs - contains PTG specific functions | 7 | 7 | */ | 8 | 8 | public class PTGModel extends AbstractModel { | 9 | 9 |
| |
|