Source code: org/alicebot/server/core/Bot.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4
5 package org.alicebot.server.core;
6
7 import java.io.File;
8 import java.util.*;
9 import org.alicebot.server.core.logging.XMLLog;
10 import org.alicebot.server.core.node.Nodemapper;
11 import org.alicebot.server.core.util.DeveloperError;
12 import org.alicebot.server.core.util.InputNormalizer;
13 import org.alicebot.server.core.util.Substituter;
14 import org.alicebot.server.core.util.XMLResourceSpec;
15
16 // Referenced classes of package org.alicebot.server.core:
17 // PredicateInfo, Globals
18
19 public class Bot
20 {
21
22 public Bot(String s)
23 {
24 loadedFiles = new HashMap();
25 properties = new HashMap();
26 predicatesInfo = new HashMap();
27 inputSubstitutions = new HashMap();
28 personSubstitutions = new HashMap();
29 person2Substitutions = new HashMap();
30 genderSubstitutions = new HashMap();
31 sentenceSplitters = new ArrayList();
32 predicateCache = Collections.synchronizedMap(new HashMap());
33 PREDICATE_EMPTY_DEFAULT = Globals.getPredicateEmptyDefault();
34 id = s;
35 chatlogSpec = XMLLog.getChatlogSpecClone();
36 chatlogSpec.path = Globals.getProperty("programd.logging.xml.chat.log-directory", "./logs") + File.separator + s + File.separator + "chat.xml";
37 }
38
39 public String getID()
40 {
41 return id;
42 }
43
44 public HashMap getLoadedFilesMap()
45 {
46 return loadedFiles;
47 }
48
49 public void addToFilenameMap(String s, Nodemapper nodemapper)
50 {
51 HashSet hashset = (HashSet)loadedFiles.get(s);
52 if(hashset != null)
53 hashset.add(nodemapper);
54 }
55
56 public String getPropertyValue(String s)
57 {
58 if(s.equals(""))
59 return PREDICATE_EMPTY_DEFAULT;
60 String s1 = (String)properties.get(s);
61 if(s1 != null)
62 return s1;
63 else
64 return PREDICATE_EMPTY_DEFAULT;
65 }
66
67 public void setPropertyValue(String s, String s1)
68 {
69 if(s.equals(""))
70 {
71 return;
72 } else
73 {
74 properties.put(s, new String(s1));
75 return;
76 }
77 }
78
79 public void addPredicateInfo(String s, String s1, boolean flag)
80 {
81 PredicateInfo predicateinfo = new PredicateInfo();
82 predicateinfo.name = s;
83 predicateinfo.defaultValue = s1;
84 predicateinfo.returnNameWhenSet = flag;
85 predicatesInfo.put(s, predicateinfo);
86 }
87
88 public HashMap getPredicatesInfo()
89 {
90 return predicatesInfo;
91 }
92
93 public Map getPredicateCache()
94 {
95 return predicateCache;
96 }
97
98 public Map predicatesFor(String s)
99 {
100 Map map;
101 if(!predicateCache.containsKey(s))
102 {
103 map = Collections.synchronizedMap(new HashMap());
104 predicateCache.put(s, map);
105 } else
106 {
107 map = (Map)predicateCache.get(s);
108 if(map == null)
109 throw new DeveloperError("userPredicates is null.");
110 }
111 return map;
112 }
113
114 public void addInputSubstitution(String s, String s1)
115 {
116 addSubstitution(inputSubstitutions, s, s1);
117 }
118
119 public void addGenderSubstitution(String s, String s1)
120 {
121 addSubstitution(genderSubstitutions, s, s1);
122 }
123
124 public void addPersonSubstitution(String s, String s1)
125 {
126 addSubstitution(personSubstitutions, s, s1);
127 }
128
129 public void addPerson2Substitution(String s, String s1)
130 {
131 addSubstitution(person2Substitutions, s, s1);
132 }
133
134 private void addSubstitution(HashMap hashmap, String s, String s1)
135 {
136 if(s != null && s1 != null)
137 hashmap.put(s.toUpperCase(), s1);
138 }
139
140 public void addSentenceSplitter(String s)
141 {
142 if(s != null)
143 sentenceSplitters.add(s);
144 }
145
146 public HashMap getInputSubstitutionsMap()
147 {
148 return inputSubstitutions;
149 }
150
151 public HashMap getGenderSubstitutionsMap()
152 {
153 return genderSubstitutions;
154 }
155
156 public HashMap getPersonSubstitutionsMap()
157 {
158 return personSubstitutions;
159 }
160
161 public HashMap getPerson2SubstitutionsMap()
162 {
163 return person2Substitutions;
164 }
165
166 public ArrayList getSentenceSplitters()
167 {
168 return sentenceSplitters;
169 }
170
171 public ArrayList sentenceSplit(String s)
172 {
173 return InputNormalizer.sentenceSplit(sentenceSplitters, s);
174 }
175
176 public String applyInputSubstitutions(String s)
177 {
178 return Substituter.applySubstitutions(inputSubstitutions, s);
179 }
180
181 public XMLResourceSpec getChatlogSpec()
182 {
183 return chatlogSpec;
184 }
185
186 private String id;
187 private HashMap loadedFiles;
188 private HashMap properties;
189 private HashMap predicatesInfo;
190 private HashMap inputSubstitutions;
191 private HashMap personSubstitutions;
192 private HashMap person2Substitutions;
193 private HashMap genderSubstitutions;
194 private ArrayList sentenceSplitters;
195 private Map predicateCache;
196 protected String PREDICATE_EMPTY_DEFAULT;
197 private static final String EMPTY_STRING = "";
198 protected XMLResourceSpec chatlogSpec;
199 }