Skip to content

Commit 34d8282

Browse files
committed
fixed missing unification for console rules
1 parent cd68f0c commit 34d8282

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

src/ai/susi/mind/SusiInference.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,11 @@ private static final SusiThought see(SusiArgument flow, String transferExpr, Str
328328
*/
329329
public SusiThought applyProcedures(SusiArgument flow) {
330330
Type type = this.getType();
331+
String expression = this.getExpression();
332+
if (expression != null && expression.length() > 0) {
333+
expression = flow.unify(expression, true, Integer.MAX_VALUE);
334+
}
331335
if (type == SusiInference.Type.console) {
332-
String expression = this.getExpression();
333336
// we have two ways to define a console rule:
334337
// with a "defintion" object which should have an "url" and "path" defined
335338
// with a "expression" object which has a susi db access string included
@@ -432,16 +435,16 @@ public SusiThought applyProcedures(SusiArgument flow) {
432435
}
433436
}
434437
if (type == SusiInference.Type.flow) {
435-
try {return flowProcedures.deduce(flow, this.getExpression());} catch (Exception e) {}
438+
try {return flowProcedures.deduce(flow, expression);} catch (Exception e) {}
436439
}
437440
if (type == SusiInference.Type.memory) {
438-
try {return memoryProcedures.deduce(flow, this.getExpression());} catch (Exception e) {}
441+
try {return memoryProcedures.deduce(flow, expression);} catch (Exception e) {}
439442
}
440443
if (type == SusiInference.Type.javascript) {
441-
try {return javascriptProcedures.deduce(flow, this.getExpression());} catch (Exception e) {}
444+
try {return javascriptProcedures.deduce(flow, expression);} catch (Exception e) {}
442445
}
443446
if (type == SusiInference.Type.prolog) {
444-
try {return prologProcedures.deduce(flow, this.getExpression());} catch (Exception e) {}
447+
try {return prologProcedures.deduce(flow, expression);} catch (Exception e) {}
445448
}
446449
// maybe the argument is not applicable, then an empty thought is produced (which means a 'fail')
447450
return new SusiThought();

src/ai/susi/mind/SusiIntent.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,9 @@ public Collection<SusiMatcher> matcher(String s) {
654654
* @param language this is the language the user is speaking
655655
* @return an intent score: the higher, the better; null if the expression cannot be matched
656656
*/
657-
public Score getScore(String expression, SusiLanguage language) {
657+
public Score getScore(SusiLanguage language) {
658658
if (this.score != null) return score;
659-
this.score = new Score(expression, language);
659+
this.score = new Score(language);
660660
if (this.score.score == Integer.MIN_VALUE) this.score = null;
661661
return this.score;
662662
}
@@ -680,7 +680,7 @@ public class Score {
680680
public long score;
681681
public String log;
682682

683-
public Score(String expression, SusiLanguage userLanguage) {
683+
public Score(SusiLanguage userLanguage) {
684684
if (SusiIntent.this.score != null) return;
685685

686686
/*
@@ -791,14 +791,24 @@ public Score(String expression, SusiLanguage userLanguage) {
791791
}
792792

793793
/**
794-
* If a intent is applied to an input stream, it must follow a specific process which is implemented
795-
* in this consideration method. It is called a consideration in the context of an AI process which
796-
* tries different procedures to get the optimum result, thus considering different intents.
797-
* @param query the user input
798-
* @param token the key from the user query which matched the intent tokens (also considering category matching)
794+
* Several intents can be candidates for answer computation. Each of such an intent is expressed as
795+
* an SusiIdea object. They are combined with a recall (data objects from past answer computations)
796+
* and tested by construction of an answer as the result of a causality chain that is described in the
797+
* idea. If the chain can be constructed by finding instances of variables, then this is a kind of
798+
* proof that the answer is correct. That answer is returned in the SusiArgument object.
799+
* @param idea the intent candidate
800+
* @param recall the data objects from past computations
801+
* @param identity the identity of the user
802+
* @param userLanguage the language of the user
803+
* @param minds the hierarchy of mind layers that may be used for reflection within the argument
799804
* @return the result of the application of the intent, a thought argument containing the thoughts which terminated into a final mindstate or NULL if the consideration should be rejected
800805
*/
801-
public SusiArgument consideration(final String query, SusiThought recall, SusiIdea idea, boolean debug, ClientIdentity identity, SusiLanguage userLanguage, SusiMind... minds) {
806+
public SusiArgument consideration(
807+
SusiIdea idea,
808+
SusiThought recall,
809+
ClientIdentity identity,
810+
SusiLanguage userLanguage,
811+
SusiMind... minds) {
802812

803813
SusiLinguistics.Token token = idea.getToken();
804814
HashSet<SusiThought> keynotes = new HashSet<>();
@@ -823,8 +833,9 @@ public SusiArgument consideration(final String query, SusiThought recall, SusiId
823833

824834
DAO.log("Susi has an idea: on " + keynote.toString() + " apply " + this.toJSON());
825835
// we start with the recall from previous interactions as new flow
826-
final SusiArgument flow = new SusiArgument(identity, userLanguage, minds).think(recall);
827-
flow.think(keynote);
836+
final SusiArgument flow = new SusiArgument(identity, userLanguage, minds) // empty flow
837+
.think(recall) // the past
838+
.think(keynote); // the now
828839

829840
// lets apply the intents that belong to this specific consideration
830841
for (SusiInference inference: this.getInferences()) {
@@ -835,7 +846,7 @@ public SusiArgument consideration(final String query, SusiThought recall, SusiId
835846
if (implication.isFailed() || flow.mindstate().equals(implication)) continue alternatives; // TODO: do this only if specific marker is in intent
836847

837848
// think
838-
flow.think(implication);
849+
flow.think(implication); // the future
839850
}
840851

841852
// add skill source

src/ai/susi/mind/SusiMind.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public List<SusiIdea> creativity(String query, SusiLanguage userLanguage, SusiTh
421421
AtomicLong count = new AtomicLong(0);
422422
ideas.forEach(idea -> {
423423
SusiIntent intent = idea.getIntent();
424-
Score score = intent.getScore(query, userLanguage);
424+
Score score = intent.getScore(userLanguage);
425425
assert score != null : "query = " + query;
426426
if (score != null) {
427427
long s = score.score;
@@ -451,7 +451,7 @@ public List<SusiIdea> creativity(String query, SusiLanguage userLanguage, SusiTh
451451
}
452452

453453
if (debug) for (SusiIdea idea: plausibleIdeas) {
454-
Score score = idea.getIntent().getScore(query, userLanguage);
454+
Score score = idea.getIntent().getScore(userLanguage);
455455
assert score != null;
456456
if (score == null) continue;
457457
DAO.log("creativity: skill=" + idea.getIntent().getSkillID());
@@ -516,7 +516,7 @@ public SusiThought react(String query, SusiLanguage userLanguage, ClientIdentity
516516
ideatest: for (SusiIdea idea: ideas) {
517517
// compute an argument: because one intent represents a horn clause, the argument is a deduction track, a "proof" of the result.
518518
long t5 = System.currentTimeMillis();
519-
SusiArgument argument = idea.getIntent().consideration(query, recall, idea, debug, identity, userLanguage, minds);
519+
SusiArgument argument = idea.getIntent().consideration(idea, recall, identity, userLanguage, minds);
520520
long t6 = System.currentTimeMillis();
521521
if (t6 - t5 > 100) DAO.log("=== Wasted " + (t6 - t5) + " milliseconds with intent " + idea.getIntent().toJSON());
522522

0 commit comments

Comments
 (0)