20
20
21
21
package org .loklak .susi ;
22
22
23
- import java .util .regex .Matcher ;
24
- import java .util .regex .Pattern ;
25
-
26
23
import org .json .JSONArray ;
27
24
import org .json .JSONObject ;
28
25
@@ -44,37 +41,6 @@ public SusiThought() {
44
41
this .data_name = "data" ;
45
42
}
46
43
47
- /**
48
- * create a clone of a json object as a SusiThought object
49
- * @param json the 'other' thought, probably an exported and re-imported thought
50
- */
51
- public SusiThought (JSONObject json ) {
52
- this ();
53
- if (json .has (this .metadata_name )) this .put (this .metadata_name , json .getJSONObject (this .metadata_name ));
54
- if (json .has (this .data_name )) this .setData (json .getJSONArray (this .data_name ));
55
- if (json .has ("actions" )) this .put ("actions" , json .getJSONArray ("actions" ));
56
- }
57
-
58
- /**
59
- * Create an initial thought using the matcher on an expression.
60
- * Such an expression is like the input from a text source which contains keywords
61
- * that are essential for the thought. The matcher extracts such information.
62
- * Matching informations are named using the order of the appearance of the information pieces.
63
- * The first information is named '1', the second '2' and so on. The whole information which contained
64
- * the matching information is named '0'.
65
- * @param matcher
66
- */
67
- public SusiThought (Matcher matcher ) {
68
- this ();
69
- this .setOffset (0 ).setHits (1 );
70
- JSONObject row = new JSONObject ();
71
- row .put ("0" , matcher .group (0 ));
72
- for (int i = 0 ; i < matcher .groupCount (); i ++) {
73
- row .put (Integer .toString (i + 1 ), matcher .group (i + 1 ));
74
- }
75
- this .setData (new JSONArray ().put (row ));
76
- }
77
-
78
44
@ Deprecated
79
45
public SusiThought (String metadata_name , String data_name ) {
80
46
super (true );
@@ -202,67 +168,5 @@ public JSONArray getData() {
202
168
this .put (data_name , a );
203
169
return a ;
204
170
}
205
-
206
- /**
207
- * Merging of data is required during an mind-meld.
208
- * To meld two thoughts, we combine their data arrays into one.
209
- * The resulting table has the maximum length of the source tables
210
- * @param table the information to be melted into our existing table.
211
- * @return the thought
212
- */
213
- public SusiThought mergeData (JSONArray table1 ) {
214
- JSONArray table0 = this .getData ();
215
- while (table0 .length () < table1 .length ()) table0 .put (new JSONObject ());
216
- for (int i = 0 ; i < table1 .length (); i ++) {
217
- table0 .getJSONObject (i ).putAll (table1 .getJSONObject (i ));
218
- }
219
- setData (table0 );
220
- return this ;
221
- }
222
-
223
- /**
224
- * If during thinking we observe something that we want to memorize, we can memorize this here
225
- * @param featureName the object key
226
- * @param observation the object value
227
- * @return the thought
228
- */
229
- public SusiThought addObservation (String featureName , String observation ) {
230
- JSONArray data = getData ();
231
- for (int i = 0 ; i < data .length (); i ++) {
232
- JSONObject spark = data .getJSONObject (i );
233
- if (!spark .has (featureName )) {
234
- spark .put (featureName , observation );
235
- return this ;
236
- }
237
- }
238
- data .put (new JSONObject ().put (featureName , observation ));
239
- return this ;
240
- }
241
-
242
- public static final Pattern variable_pattern = Pattern .compile ("\\ $.*?\\ $" );
243
-
244
- /**
245
- * Unification applies a piece of memory within the current argument to a statement
246
- * which creates an instantiated statement
247
- * @param statement
248
- * @return the instantiated statement with elements of the argument applied as much as possible
249
- */
250
- public String unify (String statement ) {
251
- JSONArray table = this .getData ();
252
- if (table != null && table .length () > 0 ) {
253
- JSONObject row = table .getJSONObject (0 );
254
- for (String key : row .keySet ()) {
255
- int i = statement .indexOf ("$" + key + "$" );
256
- if (i >= 0 ) {
257
- statement = statement .substring (0 , i ) + row .get (key ).toString () + statement .substring (i + key .length () + 2 );
258
- }
259
- }
260
- }
261
- return statement ;
262
- }
263
-
264
- public static void main (String [] args ) {
265
- SusiThought t = new SusiThought ().addObservation ("a" , "letter-a" );
266
- System .out .println (t .unify ("the letter $a$" ));
267
- }
171
+
268
172
}
0 commit comments