Mecabで取り扱う名詞と接尾語を連結させる

<?php  
    $mecab = new MeCab_Tagger();  
    $last_posid = false;

    for ($node = $mecab->parseToNode($str); $node; $node = $node->getNext()) {

        if (($last_posid == 46 || $last_posid == 47) && ($node->posid == 46 || $node->posid == 47)) {  
          // 前後が地名同士ならば連結させる  
          $tokens[count($tokens) - 1]["surface"] .= $node->getSurface();  
        }  
        elseif ($node->posid == 56) {  
          // 接尾語だった場合は、前の名詞に連結させる  
          $tokens[count($tokens) - 1]["surface"] .= $node->getSurface();  
        }  
        else {  
          $tokens[] = array(  
            "id"      => $node->getId(),  
            "surface" => $node->getSurface(),  
            "posid"   => $node->posid,  
            "stat"    => $node->getStat(),  
            "length"  => $node->getLength(),  
            "feature" => split(",", $node->getFeature()),  
          );

          $last_posid = $node->posid;  
        }  
    }