|
22 | 22 |
|
23 | 23 | package com.rivescript; |
24 | 24 |
|
| 25 | +import static com.rivescript.regexp.Regexp.RE_ANY_TAG; |
| 26 | +import static com.rivescript.regexp.Regexp.RE_ARRAY; |
| 27 | +import static com.rivescript.regexp.Regexp.RE_BOT_VAR; |
| 28 | +import static com.rivescript.regexp.Regexp.RE_CALL; |
| 29 | +import static com.rivescript.regexp.Regexp.RE_CONDITION; |
| 30 | +import static com.rivescript.regexp.Regexp.RE_INHERITS; |
| 31 | +import static com.rivescript.regexp.Regexp.RE_META; |
| 32 | +import static com.rivescript.regexp.Regexp.RE_OPTIONAL; |
| 33 | +import static com.rivescript.regexp.Regexp.RE_PLACEHOLDER; |
| 34 | +import static com.rivescript.regexp.Regexp.RE_RANDOM; |
| 35 | +import static com.rivescript.regexp.Regexp.RE_REDIRECT; |
| 36 | +import static com.rivescript.regexp.Regexp.RE_SET; |
| 37 | +import static com.rivescript.regexp.Regexp.RE_SYMBOLS; |
| 38 | +import static com.rivescript.regexp.Regexp.RE_TOPIC; |
| 39 | +import static com.rivescript.regexp.Regexp.RE_USER_VAR; |
| 40 | +import static com.rivescript.regexp.Regexp.RE_WEIGHT; |
| 41 | +import static com.rivescript.regexp.Regexp.RE_ZERO_WITH_STAR; |
| 42 | +import static com.rivescript.session.SessionManager.HISTORY_SIZE; |
| 43 | +import static com.rivescript.util.StringUtils.countWords; |
| 44 | +import static com.rivescript.util.StringUtils.quoteMetacharacters; |
| 45 | +import static com.rivescript.util.StringUtils.stripNasties; |
| 46 | +import static java.util.Objects.requireNonNull; |
| 47 | + |
| 48 | +import java.io.BufferedReader; |
| 49 | +import java.io.File; |
| 50 | +import java.io.FileReader; |
| 51 | +import java.io.FilenameFilter; |
| 52 | +import java.io.IOException; |
| 53 | +import java.io.InputStream; |
| 54 | +import java.io.InputStreamReader; |
| 55 | +import java.io.Reader; |
| 56 | +import java.nio.charset.Charset; |
| 57 | +import java.nio.charset.StandardCharsets; |
| 58 | +import java.util.ArrayList; |
| 59 | +import java.util.Arrays; |
| 60 | +import java.util.Collections; |
| 61 | +import java.util.Comparator; |
| 62 | +import java.util.HashMap; |
| 63 | +import java.util.Iterator; |
| 64 | +import java.util.List; |
| 65 | +import java.util.Map; |
| 66 | +import java.util.Random; |
| 67 | +import java.util.regex.Matcher; |
| 68 | +import java.util.regex.Pattern; |
| 69 | + |
| 70 | +import org.slf4j.Logger; |
| 71 | +import org.slf4j.LoggerFactory; |
| 72 | + |
25 | 73 | import com.rivescript.ast.ObjectMacro; |
26 | 74 | import com.rivescript.ast.Root; |
27 | 75 | import com.rivescript.ast.Topic; |
|
45 | 93 | import com.rivescript.sorting.SortTrack; |
46 | 94 | import com.rivescript.sorting.SortedTriggerEntry; |
47 | 95 | import com.rivescript.util.StringUtils; |
48 | | -import org.slf4j.Logger; |
49 | | -import org.slf4j.LoggerFactory; |
50 | | - |
51 | | -import java.io.BufferedReader; |
52 | | -import java.io.File; |
53 | | -import java.io.FileReader; |
54 | | -import java.io.FilenameFilter; |
55 | | -import java.io.InputStream; |
56 | | -import java.io.InputStreamReader; |
57 | | -import java.io.IOException; |
58 | | -import java.io.Reader; |
59 | | -import java.nio.charset.Charset; |
60 | | -import java.nio.charset.StandardCharsets; |
61 | | -import java.util.ArrayList; |
62 | | -import java.util.Arrays; |
63 | | -import java.util.Collections; |
64 | | -import java.util.Comparator; |
65 | | -import java.util.HashMap; |
66 | | -import java.util.Iterator; |
67 | | -import java.util.List; |
68 | | -import java.util.Map; |
69 | | -import java.util.Random; |
70 | | -import java.util.regex.Matcher; |
71 | | -import java.util.regex.Pattern; |
72 | | - |
73 | | -import static com.rivescript.regexp.Regexp.RE_ANY_TAG; |
74 | | -import static com.rivescript.regexp.Regexp.RE_ARRAY; |
75 | | -import static com.rivescript.regexp.Regexp.RE_BOT_VAR; |
76 | | -import static com.rivescript.regexp.Regexp.RE_CALL; |
77 | | -import static com.rivescript.regexp.Regexp.RE_CONDITION; |
78 | | -import static com.rivescript.regexp.Regexp.RE_INHERITS; |
79 | | -import static com.rivescript.regexp.Regexp.RE_META; |
80 | | -import static com.rivescript.regexp.Regexp.RE_OPTIONAL; |
81 | | -import static com.rivescript.regexp.Regexp.RE_PLACEHOLDER; |
82 | | -import static com.rivescript.regexp.Regexp.RE_RANDOM; |
83 | | -import static com.rivescript.regexp.Regexp.RE_REDIRECT; |
84 | | -import static com.rivescript.regexp.Regexp.RE_SET; |
85 | | -import static com.rivescript.regexp.Regexp.RE_SYMBOLS; |
86 | | -import static com.rivescript.regexp.Regexp.RE_TOPIC; |
87 | | -import static com.rivescript.regexp.Regexp.RE_USER_VAR; |
88 | | -import static com.rivescript.regexp.Regexp.RE_WEIGHT; |
89 | | -import static com.rivescript.regexp.Regexp.RE_ZERO_WITH_STAR; |
90 | | -import static com.rivescript.session.SessionManager.HISTORY_SIZE; |
91 | | -import static com.rivescript.util.StringUtils.countWords; |
92 | | -import static com.rivescript.util.StringUtils.quoteMetacharacters; |
93 | | -import static com.rivescript.util.StringUtils.stripNasties; |
94 | | -import static java.util.Objects.requireNonNull; |
95 | 96 |
|
96 | 97 | /** |
97 | 98 | * A RiveScript interpreter written in Java. |
@@ -792,10 +793,12 @@ private void parse(String filename, String[] code) throws ParserException { |
792 | 793 | } |
793 | 794 | } |
794 | 795 | for (Map.Entry<String, List<String>> entry : ast.getBegin().getArray().entrySet()) { |
795 | | - if (entry.getValue().equals(UNDEF_TAG)) { |
796 | | - this.array.remove(entry.getKey()); |
797 | | - } else { |
798 | | - this.array.put(entry.getKey(), entry.getValue()); |
| 796 | + for(String value : entry.getValue()) { |
| 797 | + if (value.equals(UNDEF_TAG)) { |
| 798 | + this.array.remove(entry.getKey()); |
| 799 | + } else { |
| 800 | + this.array.put(entry.getKey(), entry.getValue()); |
| 801 | + } |
799 | 802 | } |
800 | 803 | } |
801 | 804 |
|
@@ -2359,7 +2362,7 @@ private String triggerRegexp(String username, String pattern) { |
2359 | 2362 | String inputPattern = "<input" + i + ">"; |
2360 | 2363 | String replyPattern = "<reply" + i + ">"; |
2361 | 2364 | History history = this.sessions.getHistory(username); |
2362 | | - if (history == null) { |
| 2365 | + if (history != null) { |
2363 | 2366 | pattern = pattern.replace(inputPattern, history.getInput(i - 1)); |
2364 | 2367 | pattern = pattern.replace(replyPattern, history.getReply(i - 1)); |
2365 | 2368 | } else { |
|
0 commit comments