boolean findSimilarities ( MathNode refTree , MathNode comTree , List < Match > similarities , boolean holdRefTree , boolean onlyOperators ) { if ( isIdenticalTree ( refTree , comTree ) ) { // hit! comTree . setMarked ( ) ; similarities . add ( new Match ( refTree , comTree , type ) ) ; return true ; } // iterate the comparison tree over the current node from the ref tree for ( MathNode compChild : comTree . getChildren ( ) ) { // don't look at leafs if it is already marked // or we only want to compare branching nodes if ( compChild . isMarked ( ) || onlyOperators && compChild . isLeaf ( ) ) { continue ; } // go deeper in the comp. tree but hold the ref tree if ( findSimilarities ( refTree , compChild , similarities , true , onlyOperators ) ) { return true ; } } if ( ! holdRefTree ) { // go deeper in the reference tree for ( MathNode refChild : refTree . getChildren ( ) ) { if ( onlyOperators && refChild . isLeaf ( ) ) { continue ; } findSimilarities ( refChild , comTree , similarities , false , onlyOperators ) ; } } return false ; }
Recursive method that goes along every node of the reference tree and tries to find identical subtree with the comparison tree .