public void match ( SAXSymbol theDigram , SAXSymbol matchingDigram ) { SAXRule rule ; SAXSymbol first , second ; // System.out.println("[sequitur debug] *match* newDigram [" + newDigram.value + "," // + newDigram.n.value + "], old matching one [" + matchingDigram.value + "," // + matchingDigram.n.value + "]"); // if previous of matching digram is a guard if ( matchingDigram . p . isGuard ( ) && matchingDigram . n . n . isGuard ( ) ) { // reuse an existing rule rule = ( ( SAXGuard ) matchingDigram . p ) . r ; theDigram . substitute ( rule ) ; } else { // well, here we create a new rule because there are two matching digrams rule = new SAXRule ( ) ; try { // tie the digram's links together within the new rule // this uses copies of objects, so they do not get cut out of S first = ( SAXSymbol ) theDigram . clone ( ) ; second = ( SAXSymbol ) theDigram . n . clone ( ) ; rule . theGuard . n = first ; first . p = rule . theGuard ; first . n = second ; second . p = first ; second . n = rule . theGuard ; rule . theGuard . p = second ; // System.out.println("[sequitur debug] *newRule...* \n" + rule.getRules()); // put this digram into the hash // this effectively erases the OLD MATCHING digram with the new DIGRAM (symbol is wrapped // into Guard) theDigrams . put ( first , first ) ; // substitute the matching (old) digram with this rule in S // System.out.println("[sequitur debug] *newRule...* substitute OLD digram first."); matchingDigram . substitute ( rule ) ; // substitute the new digram with this rule in S // System.out.println("[sequitur debug] *newRule...* substitute NEW digram last."); theDigram . substitute ( rule ) ; // rule.assignLevel(); // System.out.println(" *** Digrams now: " + makeDigramsTable()); } catch ( CloneNotSupportedException c ) { c . printStackTrace ( ) ; } } // Check for an underused rule. if ( rule . first ( ) . isNonTerminal ( ) && ( ( ( SAXNonTerminal ) rule . first ( ) ) . r . count == 1 ) ) ( ( SAXNonTerminal ) rule . first ( ) ) . expand ( ) ; rule . assignLevel ( ) ; }
Deals with a matching digram .