Merge lp:~amebel/relex/rules into lp:~icog/relex/relex

Proposed by Amen Belayneh
Status: Merged
Merged at revision: 1454
Proposed branch: lp:~amebel/relex/rules
Merge into: lp:~icog/relex/relex
Diff against target: 305 lines (+126/-25) (has conflicts)
6 files modified
data/relex2logic-rules.txt (+17/-17)
src/java/relex/RelationExtractor.java (+1/-1)
src/java/relex/Server.java (+23/-2)
src/java/relex/logic/Criterium.java (+36/-0)
src/java/relex/logic/Rule.java (+6/-2)
src/java/relex/output/LogicProcessor.java (+43/-3)
Text conflict in src/java/relex/output/LogicProcessor.java
To merge this branch: bzr merge lp:~amebel/relex/rules
Reviewer Review Type Date Requested Status
Amen Belayneh Approve
Review via email: mp+199676@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Amen Belayneh (amebel) wrote :

working fine

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/relex2logic-rules.txt'
2--- data/relex2logic-rules.txt 2013-12-19 12:14:59 +0000
3+++ data/relex2logic-rules.txt 2013-12-19 15:38:25 +0000
4@@ -1,19 +1,19 @@
5-[SVO] {2} <SV, SVP> _subj($y, $x) & _obj($y, $z) => (SVO-rule $x (get_instance_name $x word_index sentence_index) $y (get_instance_name $y word_index sentence_index) $z (get_instance_name $z word_index sentence_index))
6-
7-[AMOD] {3} <> _amod($N, $A) => (amod-rule $N (get_instance_name $N word_index sentence_index) $A (get_instance_name $A word_index sentence_index))
8-
9-[ADVMOD] {4} <> _advmod($V, $ADV) => (advmod-rule $V (get_instance_name $V word_index sentence_index) $ADV (get_instance_name $ADV word_index sentence_index))
10-
11-[TENSEPOS] {5} <> tense($W, $Tense) & pos($W, verb) => (tense-rule $W (get_instance_name $W word_index sentence_index) $Tense)
12-
13-[DET] {6} <> _det($W, those) => (those-rule $W (get_instance_name $W word_index sentence_index) choose_var_name)
14-
15-[NEGFLAG] {7} <> NEGATIVE-FLAG($V, T) => (negative-rule $V (get_instance_name $V word_index sentence_index))
16-
17-[POSS1A] {8} <POSS1B, POSS2> _poss($N, $W) & pos($W, adj) => (possesive-rule $N (get_instance_name $N word_index sentence_index) $W (get_instance_name $W word_index sentence_index))
18-
19-[POSS1B] {8} <POSS1A, POSS2> _poss($N, $W) & pos($W, noun) & person-FLAG($W, T) => (possesive-rule $N (get_instance_name $N word_index sentence_index) $W (get_instance_name $W word_index sentence_index))
20-
21-[POSS2] {8} <POSS1A, POSS1B> _poss($N, $W) & pos($W, noun) => (possesive-rule $N (get_instance_name $V word_index sentence_index) $W (get_instance_name $W word_index sentence_index))
22+[SVO] {2} <SV, SVP> _subj($y, $x) & _obj($y, $z) => (SVO-rule $x (get-instance-name $x word_index sentence_index) $y (get-instance-name $y word_index sentence_index) $z (get-instance-name $z word_index sentence_index))
23+
24+[AMOD] {3} <> _amod($N, $A) => (amod-rule $N (get-instance-name $N word_index sentence_index) $A (get-instance-name $A word_index sentence_index))
25+
26+[ADVMOD] {4} <> _advmod($V, $ADV) => (advmod-rule $V (get-instance-name $V word_index sentence_index) $ADV (get-instance-name $ADV word_index sentence_index))
27+
28+[TENSEPOS] {5} <> tense($W, $Tense) & pos($W, verb) => (tense-rule $W (get-instance-name $W word_index sentence_index) $Tense)
29+
30+[DET] {6} <> _det($W, those) => (those-rule $W (get-instance-name $W word_index sentence_index) choose_var_name)
31+
32+[NEGFLAG] {7} <> NEGATIVE-FLAG($V, T) => (negative-rule $V (get-instance-name $V word_index sentence_index))
33+
34+[POSS1A] {8} <POSS1B, POSS2> _poss($N, $W) & pos($W, adj) => (possesive-rule $N (get-instance-name $N word_index sentence_index) $W (get-instance-name $W word_index sentence_index))
35+
36+[POSS1B] {8} <POSS1A, POSS2> _poss($N, $W) & pos($W, noun) & person-FLAG($W, T) => (possesive-rule $N (get-instance-name $N word_index sentence_index) $W (get-instance-name $W word_index sentence_index))
37+
38+[POSS2] {8} <POSS1A, POSS1B> _poss($N, $W) & pos($W, noun) => (possesive-rule $N (get-instance-name $V word_index sentence_index) $W (get-instance-name $W word_index sentence_index))
39
40 [maybe] {9} <> _advmod($v1, $r_maybe) => (maybe-rule $v1 (get_instance_name $v1 word_index sentence_index) $r_maybe )
41\ No newline at end of file
42
43=== modified file 'src/java/relex/RelationExtractor.java'
44--- src/java/relex/RelationExtractor.java 2013-12-06 20:33:26 +0000
45+++ src/java/relex/RelationExtractor.java 2013-12-19 15:38:25 +0000
46@@ -718,7 +718,7 @@
47
48 System.out.println("\n======\n");
49 System.out.println("Relex2Logic output:");
50- System.out.println(logicView.printRelationsNew(parse));
51+ System.out.println(logicView.printRelationsNew(parse).replaceAll("sentence_index", "(ParseNode " + parse.getIDString() + ")"));
52 System.out.println("\n======\n");
53 }
54
55
56=== modified file 'src/java/relex/Server.java'
57--- src/java/relex/Server.java 2013-12-10 19:43:22 +0000
58+++ src/java/relex/Server.java 2013-12-19 15:38:25 +0000
59@@ -29,6 +29,7 @@
60 import relex.corpus.DocSplitter;
61 import relex.corpus.DocSplitterFactory;
62 import relex.output.SimpleView;
63+import relex.output.LogicView;
64 import relex.output.OpenCogScheme;
65 import relex.Version;
66
67@@ -57,10 +58,11 @@
68 int listen_port = 4444;
69 int max_parses = 1;
70 boolean relex_on = false;
71+ boolean logic_on = false;
72 boolean link_on = false;
73 boolean anaphora_on = false;
74 boolean free_text = false;
75- boolean verbose = false;
76+ boolean verbose = false;
77 String lang = "en";
78 String host_name = null;
79 String usageString = "RelEx server (designed for OpenCog interaction).\n" +
80@@ -72,6 +74,7 @@
81 " --lang lang\t Set langauge (default: en)\n" +
82 " -n number \t Max number of parses to return (default: 1)\n" +
83 " --relex \t Output RelEx relations (default)\n" +
84+ " --logic \t Output of Relex2Logic scheme function calls and Relex relations" +
85 " --link \t Output Link Grammar Linkages\n" +
86 " --anaphora \t Output anaphore references\n" +
87 " --free-text\t Don't assume one sentence per line; look for !?. to end sentence.\n" +
88@@ -85,6 +88,7 @@
89 flags.add("--relex");
90 flags.add("--free-text");
91 flags.add("--verbose");
92+ flags.add("--logic");
93 HashSet<String> opts = new HashSet<String>();
94 opts.add("-n");
95 opts.add("-p");
96@@ -134,6 +138,11 @@
97 if (commandMap.get("--link") != null) link_on = true;
98 if (commandMap.get("--relex") != null) relex_on = true;
99 if (commandMap.get("--free-text") != null) free_text = true;
100+ if (commandMap.get("--logic") != null)
101+ {
102+ logic_on = true;
103+ relex_on = true;
104+ }
105
106 if (commandMap.get("--verbose") != null)
107 {
108@@ -167,6 +176,10 @@
109 System.err.println("Info: Link grammar output on.");
110 opencog.setShowLinkage(link_on);
111 }
112+ if (logic_on)
113+ {
114+ System.err.println("Info: Relex2Logic ouptut on");
115+ }
116 if (relex_on)
117 {
118 System.err.println("Info: RelEx output on.");
119@@ -344,8 +357,16 @@
120 }
121 opencog.setParse(parse);
122 out.println(opencog.toString());
123+
124+ if (logic_on)
125+ {
126+ LogicView logicView = new LogicView();
127+ logicView.loadRules();
128+// out.println("scm");
129+ out.println(logicView.printRelationsNew(parse).replaceAll("sentence_index", parse.getSentence().getID()));
130+ }
131 out.flush();
132- System.err.println("Info: sent parse " + pn + " of " + np);
133+ System.err.println("Info: sent parse " + (pn + 1) + " of " + np);
134 }
135
136 // Add a special tag to tell the cog server that it's
137
138=== modified file 'src/java/relex/logic/Criterium.java'
139--- src/java/relex/logic/Criterium.java 2013-11-08 21:50:45 +0000
140+++ src/java/relex/logic/Criterium.java 2013-12-19 15:38:25 +0000
141@@ -43,6 +43,10 @@
142 */
143 private HashMap<String, String> _variableValues = new HashMap<String, String>();
144 /**
145+ * Set to keep track of the UUID that criteria variables have been matched to.
146+ */
147+ private HashMap<String, String> _variableValueUUIDs = new HashMap<String, String>();
148+ /**
149 * The original criterium string
150 */
151 private String _criteriumString;
152@@ -181,4 +185,36 @@
153
154 return variableValue;
155 }
156+
157+ /**
158+ * Sets the UUID of a variable value, once it is found in the dependency graph.
159+ * @param variableName The name of the variable that will have its value's UUID set.
160+ * @param variableValueUUID The UUID of the variable value.
161+ */
162+ public void setVariableValueUUID(String variableName, String variableValueUUID)
163+ {
164+ if (_variableValueUUIDs.get(variableName) == null)
165+ {
166+ _variableValueUUIDs.put(variableName, variableValueUUID);
167+ }
168+ else
169+ {
170+ _variableValueUUIDs.put(variableName, variableValueUUID);
171+ }
172+ }
173+
174+ /**
175+ * Returns the value of a variable, used for retrieving variable values when writing the output of a rule.
176+ * @param variableName The name of the variable for which the value is to be retrieved.
177+ * @return
178+ */
179+ public String getVariableValueUUID(String variableName)
180+ {
181+ String variableValueUUID = "";
182+
183+ if (_variableValueUUIDs.containsKey(variableName))
184+ variableValueUUID = _variableValueUUIDs.get(variableName);
185+
186+ return variableValueUUID;
187+ }
188 }
189
190=== modified file 'src/java/relex/logic/Rule.java'
191--- src/java/relex/logic/Rule.java 2013-11-08 21:50:45 +0000
192+++ src/java/relex/logic/Rule.java 2013-12-19 15:38:25 +0000
193@@ -127,9 +127,13 @@
194 for (Criterium criterium : _criteria) {
195 for (String variableName : criterium.getVariables()) {
196 String variableValue = criterium.getVariableValue(variableName);
197-
198+ String variableValueUUID = criterium.getVariableValueUUID(variableName);
199+
200 schemeOutput = schemeOutput.replaceAll(
201- Pattern.quote(variableName), variableValue);
202+ Pattern.quote(variableName), variableValue);
203+ schemeOutput = schemeOutput.replaceAll(
204+ Pattern.quote("word_index"), variableValueUUID);
205+
206 }
207 }
208
209
210=== modified file 'src/java/relex/output/LogicProcessor.java'
211--- src/java/relex/output/LogicProcessor.java 2013-12-19 12:14:59 +0000
212+++ src/java/relex/output/LogicProcessor.java 2013-12-19 15:38:25 +0000
213@@ -132,25 +132,42 @@
214 }
215
216 String secondVariableName = ruleCriterium.getSecondVariableName();
217+<<<<<<< TREE
218 String secondVariableValue = foundNode.get("name").getValue();
219 if (bVerboseMode)
220 System.out.println("I just recorded the value of '" + secondVariableName + "' to be '" + secondVariableValue + "'");
221+=======
222+ String secondVariableValue = foundNode.get("name").getValue();
223+ String secondVariableUUID = getNameSourceUUIDValue(foundNode);
224+
225+ if (bVerboseMode)
226+ System.out.println(" I just recorded the value of '" + secondVariableName + "' to be '" + secondVariableValue + "'");
227+>>>>>>> MERGE-SOURCE
228
229 String firstVariableName = ruleCriterium.getFirstVariableName();
230+<<<<<<< TREE
231 String firstVariableValue = getHeadNameValue(rootNode);
232+=======
233+ String firstVariableValue = getHeadNameValue(rootNode);
234+ String firstVariableUUID = getNameSourceUUIDValue(rootNode.get("head"));
235+>>>>>>> MERGE-SOURCE
236
237 List<FeatureNode> suitableParents = findFeatureNodeByChildLinkName(rootNode, ruleCriterium.getCriteriumLabel(), null, null);
238
239 for (FeatureNode suitableParent : suitableParents)
240 {
241 firstVariableValue = suitableParent.get("name").getValue();
242+ firstVariableUUID = suitableParent.get("nameSource").get("uuid").getValue();
243+
244 }
245
246 if (bVerboseMode)
247 System.out.println("I just recorded the value of '" + firstVariableName + "' to be '" + firstVariableValue + "'");
248
249 ruleCriterium.setVariableValue(firstVariableName, firstVariableValue);
250+ ruleCriterium.setVariableValueUUID(firstVariableName, firstVariableUUID);
251 ruleCriterium.setVariableValue(secondVariableName, secondVariableValue);
252+ ruleCriterium.setVariableValueUUID(secondVariableName, secondVariableUUID);
253 }
254 }
255 else
256@@ -229,7 +246,7 @@
257
258 if (checkRuleApplicability(relexRule, rootNode, appliedRules))
259 {
260- applyRule(relexRule, schemeBuilder);
261+ applyRule(relexRule, schemeBuilder);
262
263 appliedRules.add(relexRule.getName());
264 }
265@@ -239,7 +256,7 @@
266 }
267
268 /**
269- * Retries the value of the name feature of the head.
270+ * Returns the value of the name feature of the head.
271 * @param rootNode The root of the dependency graph.
272 * @return
273 */
274@@ -262,7 +279,30 @@
275 return headNameValue;
276 }
277
278-
279+ /**
280+ * Returns the value of the uuid feature of the nameSource Node.
281+ * @param rootNode The root of the dependency graph.
282+ * @return the uuid value
283+ */
284+ private String getNameSourceUUIDValue(FeatureNode rootNode)
285+ {
286+ String uuidValue = "";
287+
288+ FeatureNode nameSourceNode = rootNode.get("nameSource");
289+
290+ if (nameSourceNode != null)
291+ {
292+ FeatureNode uuidNode = nameSourceNode.get("uuid");
293+
294+ if (uuidNode != null)
295+ {
296+ if (uuidNode.isValued())
297+ uuidValue = uuidNode.getValue();
298+ }
299+ }
300+ return uuidValue;
301+ }
302+
303 /**
304 * Finds a node based on it having a node within it's feature 'links' that matches childLinkName.
305 * @param nodeToSearchThrough The FeatureNode from which to begin the search.

Subscribers

People subscribed via source and target branches

to all changes: