@@ -53,15 +53,17 @@ public class SusiSkill {
5353 private final static Pattern pathseparator = Pattern .compile ("/" );
5454 private final static Pattern commaseparator = Pattern .compile ("," );
5555 private final static Pattern pipeseparator = Pattern .compile ("\\ |" );
56-
56+
57+ private final static int INDENT_STEP = 4 ; // like in python
58+
5759 private String skillName , description , author , authorURL , authorEmail , image ;
5860 private String termsOfUse , kickoff , developerPrivacyPolicy ;
5961 private String [] on ;
6062 private Boolean protectedSkill , dynamicContent ;
6163 private Set <String > examples , tags ;
6264 private List <SusiIntent > skillIntents = new ArrayList <>();
6365 private SusiSkill .ID id ;
64-
66+
6567 public static class ID implements Comparable <ID > {
6668 private String skillpath ;
6769 private final String [] possible_path_prefixes = new String [] {
@@ -207,7 +209,6 @@ public SusiSkill(
207209 this .id = skillid ;
208210 // read the text file and turn it into a intent json; then learn that
209211 boolean prior = false , dynamicContent = false , protectedSkill = false ;
210- int indentStep = 4 ; // like in python
211212 intentloop : for (IntentBlock block : skillFile ) {
212213
213214 // we have intents without any model; these are 'single lines' and may contain configuration settings
@@ -283,8 +284,9 @@ public SusiSkill(
283284
284285 // parse model
285286 String bang_type = "" , bang_answers = "" ;
286- List <SusiIntent > fileIntents = new ArrayList <>();
287- fileIntents .add (new SusiIntent (utterances , prior , 0 , skillid ));
287+ List <SusiIntent > blockIntents = new ArrayList <>();
288+ SusiIntent initialintent = new SusiIntent (utterances , prior , 0 , skillid );
289+ blockIntents .add (initialintent );
288290 StringBuilder bang_bag = new StringBuilder ();
289291 int blockNr = 0 ;
290292 readloop : while (blockNr < block .model .size ()) {
@@ -297,7 +299,11 @@ public SusiSkill(
297299 for (int i = 0 ; i < line .length (); i ++) {
298300 if (line .charAt (i ) == ' ' ) sc ++; else break ;
299301 }
300- int indentLevel = sc % indentStep ;
302+ int indentLevel = sc % INDENT_STEP ;
303+ blockIntents .forEach (intent -> {
304+ intent .setDepth (indentLevel );
305+ //intent.addInference(new SusiInference("SET _node=" + block.getUtteranceFingerprint(), SusiInference.Type.memory, 0));
306+ });
301307 line = line .trim ();
302308
303309 // parse bang types and answer lines
@@ -310,19 +316,19 @@ public SusiSkill(
310316 if (paramspace >= 0 ) head = head .substring (0 , paramspace ).trim ();
311317 // test bang type
312318 if (head .equals ("example" )) {
313- fileIntents .forEach (intent -> intent .setExample (tail ));
319+ blockIntents .forEach (intent -> intent .setExample (tail ));
314320 } else if (head .equals ("expect" )) {
315- fileIntents .forEach (intent -> intent .setExpect (tail ));
321+ blockIntents .forEach (intent -> intent .setExpect (tail ));
316322 } else if (head .equals ("label" )) {
317- fileIntents .forEach (intent -> intent .setLabel (tail ));
323+ blockIntents .forEach (intent -> intent .setLabel (tail ));
318324 } else if (head .equals ("implication" )) {
319- fileIntents .forEach (intent -> intent .setImplication (tail ));
325+ blockIntents .forEach (intent -> intent .setImplication (tail ));
320326 } else if (head .equals ("first" )) {
321- fileIntents .forEach (intent -> intent .addInference (new SusiInference ("FIRST" , SusiInference .Type .flow , lineNumber )));
327+ blockIntents .forEach (intent -> intent .addInference (new SusiInference ("FIRST" , SusiInference .Type .flow , lineNumber )));
322328 } else if (head .equals ("rest" )) {
323- fileIntents .forEach (intent -> intent .addInference (new SusiInference ("REST" , SusiInference .Type .flow , lineNumber )));
329+ blockIntents .forEach (intent -> intent .addInference (new SusiInference ("REST" , SusiInference .Type .flow , lineNumber )));
324330 } else if (head .equals ("plan" )) {
325- fileIntents .forEach (intent -> intent .addInference (new SusiInference ("PLAN " + param + ":" + tail , SusiInference .Type .flow , lineNumber )));
331+ blockIntents .forEach (intent -> intent .addInference (new SusiInference ("PLAN " + param + ":" + tail , SusiInference .Type .flow , lineNumber )));
326332 } else {
327333 // start multi-line bang
328334 bang_type = head ;
@@ -350,7 +356,7 @@ public SusiSkill(
350356 // answers; must contain $!$
351357 SusiAction action = new SusiAction (SusiAction .answerAction (lineNumber , this .id .language (), pipeseparator .split (bang_answers )));
352358
353- fileIntents .forEach (intent -> {
359+ blockIntents .forEach (intent -> {
354360 intent .addInference (inference );
355361 intent .addAction (action );
356362 extendParentWithAnswer (this .skillIntents , intent );
@@ -369,15 +375,15 @@ public SusiSkill(
369375 } catch (JSONException e ) {
370376 throw new JSONException (e .getMessage () + " \" " + bang_bag .toString () + "\" " );
371377 }
372- fileIntents .forEach (intent -> intent .addInference (inference ));
378+ blockIntents .forEach (intent -> intent .addInference (inference ));
373379
374380 // actions; we may have several actions here
375381
376382 // verify actions
377383 if (definition .has ("actions" )) {
378384 JSONArray bo_actions = definition .getJSONArray ("actions" );
379385 bo_actions .forEach (action -> {
380- fileIntents .forEach (intent -> {
386+ blockIntents .forEach (intent -> {
381387 try {
382388 intent .addAction (new SusiAction ((JSONObject ) action ));
383389 } catch (SusiActionException e ) {
@@ -396,11 +402,11 @@ public SusiSkill(
396402 // answers; must contain names from the console result array
397403 if (bang_answers .length () > 0 ) try {
398404 SusiAction action = new SusiAction (SusiAction .answerAction (lineNumber , this .id .language (), pipeseparator .split (bang_answers )));
399- fileIntents .forEach (intent -> intent .addAction (action ));
405+ blockIntents .forEach (intent -> intent .addAction (action ));
400406 } catch (SusiActionException e ) {
401407 DAO .severe (e .getMessage ());
402408 }
403- fileIntents .forEach (intent -> {
409+ blockIntents .forEach (intent -> {
404410 extendParentWithAnswer (this .skillIntents , intent );
405411 this .skillIntents .add (intent );
406412 });
@@ -423,33 +429,33 @@ public SusiSkill(
423429 String ifsubstring = line .substring (thenpos + 1 ).trim ();
424430 if (ifsubstring .length () > 0 ) {
425431 String [] answers = pipeseparator .split (ifsubstring );
426- fileIntents .forEach (intent -> {
432+ blockIntents .forEach (intent -> {
427433 try {
428434 intent .addAction (new SusiAction (SusiAction .answerAction (lineNumber , skillid .language (), answers )));
429435 } catch (SusiActionException e ) {
430436 e .printStackTrace ();
431437 }
432438 });
433- fileIntents .forEach (intent -> intent .addInference (new SusiInference ("IF " + condition , SusiInference .Type .memory , lineNumber )));
439+ blockIntents .forEach (intent -> intent .addInference (new SusiInference ("IF " + condition , SusiInference .Type .memory , lineNumber )));
434440 continue readloop ;
435441 }
436442 } else {
437443 // here we must clone all current intents
438444 final List <SusiIntent > clonedIntents = new ArrayList <>();
439- fileIntents .forEach (intent -> clonedIntents .add ((SusiIntent ) intent .clone ()));
445+ blockIntents .forEach (intent -> clonedIntents .add ((SusiIntent ) intent .clone ()));
440446
441447 // "? if : then : else"
442448 String ifsubstring = line .substring (thenpos + 1 , elsepos ).trim ();
443449 if (ifsubstring .length () > 0 ) {
444450 String [] answers = pipeseparator .split (ifsubstring );
445- fileIntents .forEach (intent -> {
451+ blockIntents .forEach (intent -> {
446452 try {
447453 intent .addAction (new SusiAction (SusiAction .answerAction (lineNumber , skillid .language (), answers )));
448454 } catch (SusiActionException e ) {
449455 e .printStackTrace ();
450456 }
451457 });
452- fileIntents .forEach (intent -> intent .addInference (new SusiInference ("IF " + condition , SusiInference .Type .memory , lineNumber )));
458+ blockIntents .forEach (intent -> intent .addInference (new SusiInference ("IF " + condition , SusiInference .Type .memory , lineNumber )));
453459 }
454460 String elsesubstring = line .substring (elsepos + 1 ).trim ();
455461 if (elsesubstring .length () > 0 ) {
@@ -463,13 +469,13 @@ public SusiSkill(
463469 });
464470 clonedIntents .forEach (intent -> intent .addInference (new SusiInference ("NOT " + condition , SusiInference .Type .memory , lineNumber )));
465471 // attach the clones intents to the list of intents
466- clonedIntents .forEach (intent -> fileIntents .add (intent ));
472+ clonedIntents .forEach (intent -> blockIntents .add (intent ));
467473 }
468474 continue readloop ;
469475 }
470476 } else {
471477 String [] answers = pipeseparator .split (line );
472- fileIntents .forEach (intent -> {
478+ blockIntents .forEach (intent -> {
473479 try {
474480 intent .addAction (new SusiAction (SusiAction .answerAction (lineNumber , skillid .language (), answers )));
475481 } catch (SusiActionException e ) {
@@ -479,7 +485,7 @@ public SusiSkill(
479485 continue readloop ;
480486 }
481487 }
482- fileIntents .forEach (intent -> {
488+ blockIntents .forEach (intent -> {
483489 extendParentWithAnswer (this .skillIntents , intent );
484490 this .skillIntents .add (intent );
485491 });
@@ -529,7 +535,7 @@ private static void extendParentWithAnswer(List<SusiIntent> preceding_intents, S
529535 int parent_id = parent_intent .hashCode ();
530536
531537 // - set an invisible assignment in parent for linking variable to ID
532- parent_intent .addInferences (new SusiInference ("SET " , SusiInference .Type .memory , 0 ));
538+ parent_intent .addInferences (new SusiInference ("SET " , SusiInference .Type .memory , 0 )); // TODO: this SET is incomplete!
533539
534540 // - add a check rule in child so a child fires only if linking ID is set correctly
535541
0 commit comments