Skip to content

Commit 0bb811f

Browse files
committed
simplifying unify call
1 parent 37c6f77 commit 0bb811f

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/ai/susi/mind/SusiArgument.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public SusiThought applyAction(final SusiAction action) throws ReactionException
294294
// this prepares reflection elements to be instantiated before the reflection is called
295295
unificationSuccess = false;
296296
if (expression.indexOf('$') >= 0) {
297-
String unification = this.unify(expression, false, Integer.MAX_VALUE);
297+
String unification = this.unify(expression);
298298
if (unification == null) throw new ReactionException("expression '" + expression + "' cannot be unified with thoughts");
299299
unificationSuccess = true;
300300
expression = unification;
@@ -347,22 +347,22 @@ public SusiThought applyAction(final SusiAction action) throws ReactionException
347347
}
348348
}
349349
if (action.getRenderType() == RenderType.websearch && action.hasAttr("query")) {
350-
action.setStringAttr("query", this.unify(action.getStringAttr("query"), false, Integer.MAX_VALUE));
350+
action.setStringAttr("query", this.unify(action.getStringAttr("query")));
351351
}
352352
if (action.getRenderType() == RenderType.anchor && action.hasAttr("link") && action.hasAttr("text")) {
353-
action.setStringAttr("link", this.unify(action.getStringAttr("link"), false, Integer.MAX_VALUE));
354-
action.setStringAttr("text", this.unify(action.getStringAttr("text"), false, Integer.MAX_VALUE));
353+
action.setStringAttr("link", this.unify(action.getStringAttr("link")));
354+
action.setStringAttr("text", this.unify(action.getStringAttr("text")));
355355
}
356356
if (action.getRenderType() == RenderType.map && action.hasAttr("latitude") && action.hasAttr("longitude") && action.hasAttr("zoom")) {
357-
action.setStringAttr("latitude", this.unify(action.getStringAttr("latitude"), false, Integer.MAX_VALUE));
358-
action.setStringAttr("longitude", this.unify(action.getStringAttr("longitude"), false, Integer.MAX_VALUE));
359-
action.setStringAttr("zoom", this.unify(action.getStringAttr("zoom"), false, Integer.MAX_VALUE));
357+
action.setStringAttr("latitude", this.unify(action.getStringAttr("latitude")));
358+
action.setStringAttr("longitude", this.unify(action.getStringAttr("longitude")));
359+
action.setStringAttr("zoom", this.unify(action.getStringAttr("zoom")));
360360
}
361361
if ((action.getRenderType() == RenderType.video_play || action.getRenderType() == RenderType.audio_play) && action.hasAttr("identifier")) {
362-
action.setStringAttr("identifier", this.unify(action.getStringAttr("identifier"), false, Integer.MAX_VALUE));
362+
action.setStringAttr("identifier", this.unify(action.getStringAttr("identifier")));
363363
}
364364
if ((action.getRenderType() == RenderType.audio_volume) && action.hasAttr("volume")) {
365-
String volume = this.unify(action.getStringAttr("volume"), false, Integer.MAX_VALUE);
365+
String volume = this.unify(action.getStringAttr("volume"));
366366
int p = volume.indexOf(' ');
367367
if (p >= 0) volume = volume.substring(0, p).trim();
368368
int v = 50;

src/ai/susi/mind/SusiInference.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,25 @@ public JSONObject getDefinition() {
181181
return queued;
182182
});
183183
memoryProcedures.put(Pattern.compile("SET\\h+?([^=]*?)\\h+?=\\h+?([^=]*)\\h*?"), (flow, matcher) -> {
184-
String remember = flow.unify(matcher.group(1), false, Integer.MAX_VALUE), matching = flow.unify(matcher.group(2), false, Integer.MAX_VALUE);
184+
String remember = flow.unify(matcher.group(1)), matching = flow.unify(matcher.group(2));
185185
return see(flow, "%1% AS " + remember, matching, Pattern.compile("(.*)"));
186186
});
187187
memoryProcedures.put(Pattern.compile("SET\\h+?([^=]*?)\\h+?=\\h+?([^=]*?)\\h+?MATCHING\\h+?(.*)\\h*?"), (flow, matcher) -> {
188-
String remember = flow.unify(matcher.group(1), false, Integer.MAX_VALUE), matching = flow.unify(matcher.group(2), false, Integer.MAX_VALUE), pattern = flow.unify(matcher.group(3), false, Integer.MAX_VALUE);
188+
String remember = flow.unify(matcher.group(1)), matching = flow.unify(matcher.group(2)), pattern = flow.unify(matcher.group(3));
189189
return see(flow, remember, matching, Pattern.compile(pattern));
190190
});
191191
memoryProcedures.put(Pattern.compile("CLEAR\\h+?(.*)\\h*?"), (flow, matcher) -> {
192192
String clear = matcher.group(1);
193-
return see(flow, "%1% AS " + flow.unify(clear, false, Integer.MAX_VALUE), "", Pattern.compile("(.*)"));
193+
return see(flow, "%1% AS " + flow.unify(clear), "", Pattern.compile("(.*)"));
194194
});
195195
memoryProcedures.put(Pattern.compile("IF\\h+?([^=]*)\\h*?"), (flow, matcher) -> {
196-
String expect = flow.unify(matcher.group(1), false, Integer.MAX_VALUE);
196+
String expect = flow.unify(matcher.group(1));
197197
if (expect == null || expect.length() == 0) return new SusiThought(); // empty thought -> fail
198198
return new SusiThought().addObservation("EXPECTED", matcher.group(1));
199199
});
200200
memoryProcedures.put(Pattern.compile("IF\\h+?([^=]*?)\\h*=\\h*([^=]*)\\h*?"), (flow, matcher) -> {
201-
String expect = matcher.group(1), matching = flow.unify(matcher.group(2), false, Integer.MAX_VALUE);
202-
SusiThought t = see(flow, "%1% AS EXPECTED", flow.unify(expect, false, Integer.MAX_VALUE), Pattern.compile(matching));
201+
String expect = matcher.group(1), matching = flow.unify(matcher.group(2));
202+
SusiThought t = see(flow, "%1% AS EXPECTED", flow.unify(expect), Pattern.compile(matching));
203203
if (t.isFailed() || t.hasEmptyObservation("EXPECTED")) return new SusiThought(); // empty thought -> fail
204204
return t;
205205
});
@@ -209,20 +209,20 @@ public JSONObject getDefinition() {
209209
return new SusiThought().addObservation("REJECTED", "");
210210
});
211211
memoryProcedures.put(Pattern.compile("NOT\\h+?([^=]*)\\h*?"), (flow, matcher) -> {
212-
String reject = flow.unify(matcher.group(1), false, Integer.MAX_VALUE);
212+
String reject = flow.unify(matcher.group(1));
213213
if (reject == null || reject.length() == 0) return new SusiThought().addObservation("REJECTED", matcher.group(1));
214214
return new SusiThought(); // empty thought -> fail
215215
});
216216
memoryProcedures.put(Pattern.compile("NOT\\h+?([^=]*?)\\h*=\\h*([^=]*)\\h*?"), (flow, matcher) -> {
217217
// This is a not of an assignment. This must fail if the assigned value is non-empty
218-
String reject = matcher.group(1), matching = flow.unify(matcher.group(2), false, Integer.MAX_VALUE);
219-
SusiThought t = see(flow, "%1% AS EXPECTED", flow.unify(reject, false, Integer.MAX_VALUE), Pattern.compile(matching));
218+
String reject = matcher.group(1), matching = flow.unify(matcher.group(2));
219+
SusiThought t = see(flow, "%1% AS EXPECTED", flow.unify(reject), Pattern.compile(matching));
220220
if (t.isFailed() || t.hasEmptyObservation("EXPECTED")) return new SusiThought().addObservation("REJECTED(" + matcher.group(2) + ")", matcher.group(1));
221221
return new SusiThought(); // empty thought -> fail
222222
});
223223
javascriptProcedures.put(Pattern.compile("(?s:(.*))"), (flow, matcher) -> {
224224
String term = matcher.group(1);
225-
term = flow.unify(term, false, Integer.MAX_VALUE);
225+
term = flow.unify(term);
226226
while (term.indexOf('`') >= 0) try {
227227
Reflection reflection = new Reflection(term, flow, false);
228228
term = reflection.expression;
@@ -249,7 +249,7 @@ public JSONObject getDefinition() {
249249
}
250250
});
251251
prologProcedures.put(Pattern.compile("(?s:(.*))"), (flow, matcher) -> {
252-
String term = flow.unify(matcher.group(1), false, Integer.MAX_VALUE);
252+
String term = flow.unify(matcher.group(1));
253253
try {
254254
Prolog engine = new Prolog();
255255
try {
@@ -297,7 +297,7 @@ private static final SusiThought see(SusiArgument flow, String transferExpr, Str
297297
// example: see $1$ as idea from ""
298298
SusiThought nextThought = new SusiThought();
299299
try {
300-
Matcher m = pattern.matcher(flow.unify(expr, false, Integer.MAX_VALUE));
300+
Matcher m = pattern.matcher(flow.unify(expr));
301301
int gc = -1;
302302
if (new TimeoutMatcher(m).matches()) {
303303
SusiTransfer transfer = new SusiTransfer(transferExpr);
@@ -360,7 +360,7 @@ public SusiThought applyProcedures(SusiArgument flow) {
360360
SusiArgument.Reflection reflection = new SusiArgument.Reflection(url, flow, true);
361361
url = reflection.expression;
362362
}} catch (ReactionException e) {}
363-
String path = definition.has("path") ? flow.unify(definition.getString("path"), false, Integer.MAX_VALUE) : null;
363+
String path = definition.has("path") ? flow.unify(definition.getString("path")) : null;
364364

365365
// make a custom request header
366366
Map<String, String> request_header = new HashMap<>();

src/ai/susi/server/api/susi/ConsoleService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static void addGenericConsole(String serviceName, String serviceURL, Stri
8383
byte[] b = new byte[0];
8484
String bs = "";
8585
try {
86-
String testquery = flow.unify(matcher.group(2), false, Integer.MAX_VALUE);
86+
String testquery = flow.unify(matcher.group(2));
8787
Map<String, String> request_header = new HashMap<>();
8888
request_header.put("Accept","application/json");
8989
b = loadDataWithQuery(serviceURL, request_header, testquery);

0 commit comments

Comments
 (0)