GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add character spans to nodes · RepGraph/RepGraph@b45a3b7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/com/RepGraph
    • AbstractGraph.java
    • AbstractModel.java
    • Anchors.java
    • EDSGraph.java
    • Node.java
    • PTGGraph.java
    • UCCAGraph.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/com/RepGraph/AbstractGraph.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/AbstractGraph.java
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ public void setNodes(ArrayList<Node> nodelist) {
231231

232232
for (Node n : nodelist) {
233233
this.nodes.put(n.getId(), n);
234+
ArrayList<Anchors> characterSpans = null;
235+
if (n.getAnchors()!=null){
236+
characterSpans = new ArrayList<>();
237+
for (Anchors a:this.nodes.get(n.getId()).getAnchors()) {
238+
Anchors AnchChar = new Anchors(a.getFrom(),a.getEnd());
239+
characterSpans.add(AnchChar);
240+
}}
241+
242+
this.nodes.get(n.getId()).setCharacterSpans(characterSpans);
234243
if (this.nodes.get(n.getId()).getLabel().startsWith("_")){
235244
this.nodes.get(n.getId()).setSurface(true);
236245
}
@@ -958,7 +967,7 @@ public int compare(Node o1, Node o2) {
958967

959968
}
960969
}
961-
// MIN 9
970+
962971

963972
for (int i = 0; i < ordered.size() - 1; i++) {
964973
if (!(ordered.get(i).getAnchors().get(0).getFrom() == ordered.get(i + 1).getAnchors().get(0).getFrom() && ordered.get(i).getAnchors().get(0).getEnd() == ordered.get(i + 1).getAnchors().get(0).getEnd())) {
Collapse file

‎src/main/java/com/RepGraph/AbstractModel.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/AbstractModel.java
+73-65Lines changed: 73 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ public HashMap<String, String> modelAnalysis() throws IOException, InterruptedEx
8181

8282
for (AbstractGraph g : graphs.values()) {
8383

84-
if (g.isCyclic(true)){
84+
if (g.isCyclic(true)) {
8585
total_directed_cyclic++;
8686
}
87-
if (g.isCyclic(false)){
87+
if (g.isCyclic(false)) {
8888
total_undirected_cyclic++;
8989
}
90-
if ((boolean) g.isPlanar().get("planar")){
90+
if ((boolean) g.isPlanar().get("planar")) {
9191
total_planar++;
9292
}
93-
if (!g.connectedBFS(g.getNodes().values().iterator().next().getId())){
93+
if (!g.connectedBFS(g.getNodes().values().iterator().next().getId())) {
9494
total_not_connected++;
9595

9696
}
@@ -102,73 +102,79 @@ public HashMap<String, String> modelAnalysis() throws IOException, InterruptedEx
102102
}
103103

104104
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) + "");
116116
return AnalysisInfo;
117117
}
118118

119119
public void parseAlltokens() {
120120
Properties props = new Properties();
121121
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner");
122122
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
123-
for (AbstractGraph g : this.graphs.values()) {
124-
try {
123+
for (AbstractGraph g : this.graphs.values()) {
124+
try {
125125

126-
ArrayList<Token> tokenlist = new ArrayList<>();
126+
ArrayList<Token> tokenlist = new ArrayList<>();
127127

128-
CoreDocument document = new CoreDocument(g.getInput());
129-
pipeline.annotate(document);
128+
CoreDocument document = new CoreDocument(g.getInput());
129+
pipeline.annotate(document);
130130

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-
}
139131

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+
}
141139

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));
150149
}
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()) {
151160

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);
156162
}
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);
164165
}
166+
165167
}
166168

167-
index++;
168169
}
169-
g.setTokens(tokenlist);
170-
}catch (Exception e){continue;}
170+
171+
index++;
172+
}
173+
g.setTokens(tokenlist);
174+
} catch (Exception e) {
175+
continue;
171176
}
177+
}
172178

173179
}
174180

@@ -250,19 +256,19 @@ public AbstractGraph CreateSubsetDescendent(AbstractGraph parent, String headNod
250256
parent.setNodeNeighbours();
251257

252258
HashMap<String, Node> DescendentNodes = new HashMap<String, Node>();
253-
HashMap<String,Boolean> visited = new HashMap<>();
259+
HashMap<String, Boolean> visited = new HashMap<>();
254260
ArrayList<Edge> DescendentEdges = new ArrayList<>();
255261
ArrayList<Token> SubsetTokens = new ArrayList<>();
256262

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);
259265
}
260266

261267
Node n = parent.getNodes().get(headNodeID);
262268

263269
//Add the head Node to the descendent nodes hashmap
264270
DescendentNodes.put(n.getId(), new Node(n));
265-
visited.put(n.getId(),true);
271+
visited.put(n.getId(), true);
266272
for (Edge e : n.getDirectedEdgeNeighbours()) {
267273
DescendentEdges.add(new Edge(e));
268274
}
@@ -587,14 +593,16 @@ public HashMap<String, Object> compareTwoGraphs(String graphID1, String graphID2
587593
} else {
588594
String phrase1 = "";
589595
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+
}
598606

599607
if (n1.getLabel().equals(n2.getLabel()) && phrase1.equals(phrase2)) {
600608
//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
617625
phrase1 = "";
618626
phrase2 = "";
619627

620-
if (nn1.getAnchors()!=null) {
628+
if (nn1.getAnchors() != null) {
621629
for (Anchors a : nn1.getAnchors()) {
622630
phrase1 += g1.getTokenInput(g1.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase();
623631
}
624632
}
625-
if (nn2.getAnchors()!=null) {
633+
if (nn2.getAnchors() != null) {
626634
for (Anchors a : nn2.getAnchors()) {
627635
phrase2 += g2.getTokenInput(g2.getTokenSpan(a.getFrom(), a.getEnd())).toLowerCase();
628636
}
Collapse file

‎src/main/java/com/RepGraph/Anchors.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/Anchors.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public class Anchors {
1919
*/
2020
public Anchors() {}
2121

22-
22+
public Anchors(Anchors a) {
23+
this.from = a.from;
24+
this.end = a.end;
25+
}
2326

2427
/**
2528
* This is the parameterised constructor
Collapse file

‎src/main/java/com/RepGraph/EDSGraph.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/EDSGraph.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public void setNodes(ArrayList<Node> nodelist) {
3333

3434
//Dont understand the CARG property thing
3535
for (Node n : nodelist) {
36+
ArrayList<Anchors> characterSpans = null;
37+
if (n.getAnchors()!=null){
38+
characterSpans = new ArrayList<>();
39+
for (Anchors a:n.getAnchors()) {
40+
Anchors AnchChar = new Anchors(a.getFrom(),a.getEnd());
41+
characterSpans.add(AnchChar);
42+
}}
43+
n.setCharacterSpans(characterSpans);
44+
3645
if (n.getLabel().startsWith("_") || (n.getProperties()!=null && n.getProperties().contains("CARG")) ){n.setSurface(true);}else{n.setSurface(false);}
3746
this.nodes.put(n.getId(), n);
3847
}
Collapse file

‎src/main/java/com/RepGraph/Node.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/Node.java
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ public class Node {
2424
@JsonProperty("id")
2525
private String id;
2626

27-
2827
@JsonProperty("label")
2928
private String label;
3029

31-
3230
@JsonProperty("anchors")
3331
private ArrayList<Anchors> anchors;
3432

@@ -41,6 +39,9 @@ public class Node {
4139
@JsonProperty("surface")
4240
private boolean surface;
4341

42+
@JsonIgnore
43+
private ArrayList<Anchors> characterSpans;
44+
4445
@JsonIgnore
4546
private ArrayList<Node> directedNeighbours;
4647

@@ -120,7 +121,13 @@ public void setId(String id) {
120121
}
121122

122123

124+
public void setCharacterSpans(ArrayList<Anchors> characterSpans) {
125+
this.characterSpans = characterSpans;
126+
}
123127

128+
public ArrayList<Anchors> getCharacterSpans() {
129+
return characterSpans;
130+
}
124131

125132
public String getLabel() {
126133
return label;
Collapse file

‎src/main/java/com/RepGraph/PTGGraph.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/PTGGraph.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public PTGGraph(String id, String source, String input, HashMap<String, Node> no
2727
public void setNodes(ArrayList<Node> nodelist) {
2828

2929
for (Node n : nodelist) {
30+
ArrayList<Anchors> characterSpans = null;
31+
if (n.getAnchors()!=null){
32+
characterSpans = new ArrayList<>();
33+
for (Anchors a:n.getAnchors()) {
34+
Anchors AnchChar = new Anchors(a.getFrom(),a.getEnd());
35+
characterSpans.add(AnchChar);
36+
}}
37+
n.setCharacterSpans(characterSpans);
38+
3039
if (n.getLabel()!=null){
3140
if (n.getLabel().startsWith("#")){
3241
n.setSurface(false);
Collapse file

‎src/main/java/com/RepGraph/UCCAGraph.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/RepGraph/UCCAGraph.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public UCCAGraph(@JsonProperty("id") String id, @JsonProperty("source") String s
2828
this.input = input;
2929
this.edges = edges;
3030
for (Node n : nodes) {
31+
ArrayList<Anchors> characterSpans = null;
32+
if (n.getAnchors()!=null){
33+
characterSpans = new ArrayList<>();
34+
for (Anchors a:n.getAnchors()) {
35+
Anchors AnchChar = new Anchors(a.getFrom(),a.getEnd());
36+
characterSpans.add(AnchChar);
37+
}}
38+
n.setCharacterSpans(characterSpans);
3139
this.nodes.put(n.getId(), n);
3240
}
3341
this.setNodeNeighbours();

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.