public static SAXRule runSequitur ( String inputString ) throws Exception { LOGGER . trace ( "digesting the string " + inputString ) ; // clear global collections // SAXRule . numRules = new AtomicInteger ( 0 ) ; SAXRule . theRules . clear ( ) ; SAXSymbol . theDigrams . clear ( ) ; SAXSymbol . theSubstituteTable . clear ( ) ; // init the top-level rule // SAXRule resRule = new SAXRule ( ) ; // tokenize the input string // StringTokenizer st = new StringTokenizer ( inputString , " " ) ; // while there are tokens int currentPosition = 0 ; while ( st . hasMoreTokens ( ) ) { String token = st . nextToken ( ) ; // System.out.println(" processing the token " + token); // extract next token SAXTerminal symbol = new SAXTerminal ( token , currentPosition ) ; // append to the end of the current sequitur string // ... As each new input symbol is observed, append it to rule S.... resRule . last ( ) . insertAfter ( symbol ) ; // once appended, check if the resulting digram is new or recurrent // // ... Each time a link is made between two symbols if the new digram is repeated elsewhere // and the repetitions do not overlap, if the other occurrence is a complete rule, // replace the new digram with the non-terminal symbol that heads the rule, // otherwise,form a new rule and replace both digrams with the new non-terminal symbol // otherwise, insert the digram into the index... resRule . last ( ) . p . check ( ) ; currentPosition ++ ; // LOGGER.debug("Current grammar:\n" + SAXRule.getRules()); } return resRule ; }
Digests a string of terminals separated by a space .