在浏览器中编译程序后,值为NULL

时间:2016-11-09 12:40:07

标签: php null stemming

我正在申请去除添加剂或通常称为Stemming confix剥离。我想制作一个循环来处理每个文本文件中的词干。进程阻止我把它们放在循环中。使这个过程的每个文件的内容也放在一个文本文件中。当我在浏览器中运行没有错误但只有注释NULL。什么是解决方案?我附上我的程序和程序结果`是代码

<?php
 require_once __DIR__ . '/vendor/autoload.php';
 $array_sentence = glob('../../ujicoba/simpantoken/*.txt');
 settype($array_sentence, "string");
 if(is_array($array_sentence) && is_object($array_sentence))
 {
   foreach ($array_sentence as $text) 
    {
        $textnormalizer = new src\Sastrawi\Stemmer\Filter\TextNormalizer();
        $stemmerFactory = new \Sastrawi\Stemmer\StemmerFactory();
        $stemmer  = $stemmerFactory->createStemmer();
        $content = file_get_contents($text);
        $stemmer  = $stemmerFactory->createStemmer();
        $output   = $stemmer->stem(array($content));
        echo $output . "\n";
    }           
    }
    var_dump($content);
     ?>
    <!DOCTYPE html>
   <html>
 <head>
  <title>Confix Stripping Stemmer</title>
   </head>
   <body>
   </body>
   </html>

my source code result in browser when running programenter code here

2 个答案:

答案 0 :(得分:0)

在l.4上,settype($array_sentence, "string");强制$array_sentence为字符串,这意味着is_array($array_sentence) && is_object($array_sentence)将返回false。

答案 1 :(得分:0)

以下代码适用于词干:

<?php
include('stopword.php');
$regexRules = array(
        '/^be(.*)lah$/',
        '/^be(.*)an$/',
        '/^me(.*)i$/',
        '/^di(.*)i$/',
        '/^pe(.*)i$/',
        '/^ter(.*)i$/',
        '/^di(.*)kan$/',
        '/^di(.*)nya$/',
        '/^di(.*)kannya$/',
        '/^mem(.*)pe$/',
        '/^meng(.*)g$/',
        '/^meng(.*)h$/',
        '/^meng(.*)q$/',
        '/^meng(.*)k$/',
        '/^mem(.*)kan$/',
        '/^diper(.*)i$/',
        '/^di(.*)i$/',
        '/^memper(.*)kan$/',
        '/^meny(.*)i$/',
        '/^meny(.*)kan$/',
        '/^men(.*)kan$/',
        '/^me(.*)kan$/',
        '/^meng(.*)nya$/',
        '/^memper(.*)i$/',
        '/^men(.*)i$/',
        '/^meng(.*)i$/',
        '/^ber(.*)nya$/',
        '/^ber(.*)an$/',
        '/^ke(.*)an$/',
        '/^ke(.*)annya$/',
        '/^peng(.*)an$/',
        '/^peny(.*)an$/',
        '/^per(.*)an$/',
        '/^pen(.*)an$/',
        '/^pe(.*)an$/',
        '/^ber(.*)$/',
        '/^di(.*)$/',
        '/^men(.*)$/',
        '/^meng(.*)$/',
        '/^meny(.*)$/',
        '/^mem(.*)$/',
        '/^pen(.*)$/',
        '/^peng(.*)$/',
        '/^ter(.*)$/',
        '/^mem(.*)$/',
        '/^(.*)nya$/',
        '/^(.*)lah$/',
        '/^(.*)pun$/',
        '/^(.*)kah$/',
        '/^(.*)mu$/',
        '/^(.*)an$/',
        '/^(.*)kan$/',
        '/^(.*)i$/',
        '/^(.*)ku$/',
);
global $regexRules;
$file_string = glob('yourfoldertoseavedata_text/*.txt');
$string = array('(.*)');
foreach ($file_string as $data)
{
    $string[] = file_get_contents($data);
    $stemming = str_ireplace($regexRules,"", $string);
    var_dump($stemming);
}
?>