Skip to content

Commit 48b8dd4

Browse files
AngledLuffaStanford NLP
authored andcommitted
Refactor the main method of UniversalEnhancer from the actual enhancements
1 parent 318c748 commit 48b8dd4

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/edu/stanford/nlp/trees/ud/UniversalEnhancer.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ public static void copyEmptyNodes(SemanticGraph source, SemanticGraph target) {
5050
}
5151
}
5252

53+
public static SemanticGraph enhanceGraph(SemanticGraph basic, SemanticGraph originalEnhanced,
54+
boolean keepEmptyNodes,
55+
Embedding embeddings,
56+
Pattern relativePronounsPattern) {
57+
58+
SemanticGraph enhanced = new SemanticGraph(basic.typedDependencies());
59+
60+
if (keepEmptyNodes) {
61+
copyEmptyNodes(originalEnhanced, enhanced);
62+
}
63+
64+
if (embeddings != null) {
65+
UniversalGappingEnhancer.addEnhancements(enhanced, embeddings);
66+
}
67+
UniversalGrammaticalStructure.addRef(enhanced, relativePronounsPattern);
68+
UniversalGrammaticalStructure.collapseReferent(enhanced);
69+
UniversalGrammaticalStructure.propagateConjuncts(enhanced);
70+
UniversalGrammaticalStructure.addExtraNSubj(enhanced);
71+
UniversalGrammaticalStructure.addCaseMarkerInformation(enhanced);
72+
UniversalGrammaticalStructure.addCaseMarkerForConjunctions(enhanced);
73+
UniversalGrammaticalStructure.addConjInformation(enhanced);
74+
return enhanced;
75+
}
5376

5477
public static void main(String[] args) {
5578
Properties props = StringUtils.argsToProperties(args);
@@ -62,7 +85,7 @@ public static void main(String[] args) {
6285

6386
boolean keepEmptyNodes = PropertiesUtils.getBool(props, "keepEmpty", false);
6487

65-
Pattern relativePronounPattern = Pattern.compile(relativePronounsPatternStr);
88+
Pattern relativePronounsPattern = Pattern.compile(relativePronounsPatternStr);
6689

6790
Iterator<Pair<SemanticGraph, SemanticGraph>> sgIterator; // = null;
6891

@@ -82,25 +105,9 @@ public static void main(String[] args) {
82105
while (sgIterator.hasNext()) {
83106
Pair<SemanticGraph, SemanticGraph> sgs = sgIterator.next();
84107
SemanticGraph basic = sgs.first();
85-
86108
SemanticGraph originalEnhanced = sgs.second();
87109

88-
SemanticGraph enhanced = new SemanticGraph(basic.typedDependencies());
89-
90-
if (keepEmptyNodes) {
91-
copyEmptyNodes(originalEnhanced, enhanced);
92-
}
93-
94-
if (embeddings != null) {
95-
UniversalGappingEnhancer.addEnhancements(enhanced, embeddings);
96-
}
97-
UniversalGrammaticalStructure.addRef(enhanced, relativePronounPattern);
98-
UniversalGrammaticalStructure.collapseReferent(enhanced);
99-
UniversalGrammaticalStructure.propagateConjuncts(enhanced);
100-
UniversalGrammaticalStructure.addExtraNSubj(enhanced);
101-
UniversalGrammaticalStructure.addCaseMarkerInformation(enhanced);
102-
UniversalGrammaticalStructure.addCaseMarkerForConjunctions(enhanced);
103-
UniversalGrammaticalStructure.addConjInformation(enhanced);
110+
SemanticGraph enhanced = enhanceGraph(basic, originalEnhanced, keepEmptyNodes, embeddings, relativePronounsPattern);
104111
System.out.print(writer.printSemanticGraph(basic, enhanced));
105112
}
106113

0 commit comments

Comments
 (0)