function count_noun2($array)
{
    $igo = new Igo("igo-php/ipadic", "UTF-8");
    $noun_count = array();
    foreach ($array as $sentence) {
        $result = $igo->parse($sentence);
        foreach ($result as $value) {
            $feature = explode(",", $value->feature);
            if ($feature[0] == "名詞") {
                $noun = $value->surface;
                if (isset($noun_count[$noun])) {
                    $noun_count[$noun]++;
                } else {
                    $noun_count[$noun] = 1;
                }
            }
        }
    }
    return $noun_count;
}
Example #2
0
if (isset($argc) && $argc > 1) {
    $dataDir = $argv[1];
    if (!is_dir($dataDir)) {
        die('dictionary not found.');
    }
    $text = $argv[2];
    if (is_file($text)) {
        $text = file_get_contents($text);
    }
    $enc = mb_detect_encoding($text, IGO_MB_DETECT_ORDER);
    mb_internal_encoding($enc);
    if ($e = getenv("IGO_OUTPUT_ENCODING")) {
        $enc = $e;
    }
    mb_http_output($enc);
    $igo = new Igo($dataDir, $enc);
    $result = $igo->parse($text);
    foreach ($result as $res) {
        $buf = "";
        $buf .= $res->surface;
        $buf .= "\t";
        $buf .= $res->feature;
        $buf .= ",";
        $buf .= $res->start;
        $buf .= PHP_EOL;
        echo $buf;
    }
}
class Igo
{
    private $tagger;