private function findSurpriseValue( Node $pNode, $pSubstring ) {
        $length = $pNode->end - $pNode->start;
        $text   = implode('', $this->text);
        if ( ($pNode->start != -1 && $pNode->end != -1 ) ) { 
            // node is not the root node
            if ( substr( $text , $pNode->start, $length ) === $pSubstring ) { 
                // found substring
                return $pNode->surpriseValue;
            } elseif ( strlen( $pSubstring ) < $length && strlen( $pSubstring ) > 0 ) {
                // string is only substring of string represented by pNode
                $substringLength = strlen($pSubstring);
                for ( $i=0; $i < strlen($text) - $substringLength; $i++ ) { 
                    if ( substr( $text, $pNode->start + $i, $substringLength ) === $pSubstring) {
                        return $pNode->surpriseValue;
                    }
                }
            }

            // shorten
            $pSubstring = substr($pSubstring, $length, strlen($pSubstring));
        }

        // else check childnodes for substring of pSubstring
        // substring is pSubstring without the letters represented by pNode
        $ret = $this->upperBound;
        foreach ( $pNode->next as $childKey => $childValue ) {
            if ($ret != $this->upperBound) {
                // we found the substring in another path already
                return $ret;
            }
            // check begin of substring with begin 
            // of string represented by this node
            if ($childKey !== $pSubstring[0]) {
                // substring does not start with 
                // the same letter -> check other paths
                continue;
            }
            // found a child starting with the same letter -> check child
            $childNode          = $this->nodes[$childValue];
            $childNodeLength    = $childNode->end - $childNode->start;

            $ret = $this->findSurpriseValue( $childNode,  $pSubstring );
        }

        return $ret;

    }
private function findSurpriseValue( Node $pNode, $pSubstring ) {
        $length = $pNode->end - $pNode->start;
        $text   = implode('', $this->text);
        if ( ($pNode->start != -1 && $pNode->end != -1 ) ) { 
            // node is not the root node
            if ( substr( $text , $pNode->start, $length ) === $pSubstring ) { 
                // found substring
                return $pNode->surpriseValue;
            } elseif ( strlen( $pSubstring ) < $length && strlen( $pSubstring ) > 0 ) {
                // string is only substring of string represented by pNode
                $substringLength = strlen($pSubstring);
                for ( $i=0; $i < strlen($text) - $substringLength; $i++ ) { 
                    if ( substr( $text, $pNode->start + $i, $substringLength ) === $pSubstring) {
                        return $pNode->surpriseValue;
                    }
                }
            }

            // shorten
            $pSubstring = substr($pSubstring, $length, strlen($pSubstring));
        }

        // else check childnodes for substring of pSubstring
        // substring is pSubstring without the letters represented by pNode
        $ret = $this->upperBound;
        foreach ( $pNode->next as $childKey => $childValue ) {
            if ($ret != $this->upperBound) {
                // we found the substring in another path already
                return $ret;
            }
            // check begin of substring with begin 
            // of string represented by this node
            if ($childKey !== $pSubstring[0]) {
                // substring does not start with 
                // the same letter -> check other paths
                continue;
            }
            // found a child starting with the same letter -> check child
            $childNode          = $this->nodes[$childValue];
            $childNodeLength    = $childNode->end - $childNode->start;

            $ret = $this->findSurpriseValue( $childNode,  $pSubstring );
        }

        return $ret;

    }
private function findSurpriseValue ( Node $ pNode , $ pSubstring ) { $ length = $ pNode -> end - $ pNode -> start ; $ text = implode ( '' , $ this -> text ) ; if ( ( $ pNode -> start != - 1 && $ pNode -> end != - 1 ) ) { // node is not the root node if ( substr ( $ text , $ pNode -> start , $ length ) === $ pSubstring ) { // found substring return $ pNode -> surpriseValue ; } elseif ( strlen ( $ pSubstring ) < $ length && strlen ( $ pSubstring ) > 0 ) { // string is only substring of string represented by pNode $ substringLength = strlen ( $ pSubstring ) ; for ( $ i = 0 ; $ i < strlen ( $ text ) - $ substringLength ; $ i ++ ) { if ( substr ( $ text , $ pNode -> start + $ i , $ substringLength ) === $ pSubstring ) { return $ pNode -> surpriseValue ; } } } // shorten $ pSubstring = substr ( $ pSubstring , $ length , strlen ( $ pSubstring ) ) ; } // else check childnodes for substring of pSubstring // substring is pSubstring without the letters represented by pNode $ ret = $ this -> upperBound ; foreach ( $ pNode -> next as $ childKey => $ childValue ) { if ( $ ret != $ this -> upperBound ) { // we found the substring in another path already return $ ret ; } // check begin of substring with begin  // of string represented by this node if ( $ childKey !== $ pSubstring [ 0 ] ) { // substring does not start with  // the same letter -> check other paths continue ; } // found a child starting with the same letter -> check child $ childNode = $ this -> nodes [ $ childValue ] ; $ childNodeLength = $ childNode -> end - $ childNode -> start ; $ ret = $ this -> findSurpriseValue ( $ childNode , $ pSubstring ) ; } return $ ret ; }
Tries to find the surprise value of the given substring in the given node.
If not successfull for the given string and a child node starts with
the first letter of the given string, it will try its corresponding child.
Used in a recursive manner with given node representing the root node
at the begin

@param  Node   $pNode      Node on which to try to find the given substring
@param  string $pSubstring String to get occurences of
@return integer            Amount of surprise for the given substring
Tries to find the surprise value of the given substring in the given node . If not successfull for the given string and a child node starts with the first letter of the given string it will try its corresponding child . Used in a recursive manner with given node representing the root node at the begin