-1

I'm making an application to remove additive or commonly called Stemming confix stripping. I wanted to make a loop to process stemming in each text file. process stemming I've put them in the loop. making the process the content of each document also I put in a text file. when I run in the browser no error but only the note NULL. what's the solution? I attach my program and program results`it is code

<?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

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107

2 Answers2

0

On l.4, settype($array_sentence, "string"); force $array_sentence as a string, which means is_array($array_sentence) && is_object($array_sentence) will return false.

tazorax
  • 51
  • 3
  • ok problem fix, i only mistake write array. so i must remove array on $output = $stemmer->stem(array($content));. so i write $output = $stemmer->stem($content); – user3718278 Nov 12 '16 at 08:15
0

The following code works for stemming:

<?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);
}
?>
Pang
  • 9,564
  • 146
  • 81
  • 122