0

I've installed this library from github:

https://github.com/robholmes/term-extractor

I placed the files under public/term-extractor.

I tried creating a route to test the results of the library, but I keep getting the error Class 'TermExtractor' not found.

Here is the route:

Route::get('/test', function()
{
    require public_path() . '/term-extractor/src/TermExtractor/TermExtractor.php';

    $text = 'Inevitably, then, corporations do not restrict themselves merely to the arena of economics. Rather, as John Dewey observed, "politics is the shadow cast on society by big business". Over decades, corporations have worked together to ensure that the choices offered by \'representative democracy\' all represent their greed for maximised profits. This is a sensitive task. We do not live in a totalitarian society - the public potentially has enormous power to interfere. The goal, then, is to persuade the public that corporate-sponsored political choice is meaningful, that it makes a difference. The task of politicians at all points of the supposed \'spectrum\' is to appear passionately principled while participating in what is essentially a charade.';

    $extractor = new TermExtractor();
    $terms = $extractor->extract($text);
    // We're outputting results in plain text...
    header('Content-Type: text/plain; charset=UTF-8');
    // Loop through extracted terms and print each term on a new line
    foreach ($terms as $term_info) {
        // index 0: term
        // index 1: number of occurrences in text
        // index 2: word count
        list($term, $occurrence, $word_count) = $term_info;
        echo "$term\n";
    }
});

What's wrong?

1 Answers1

0

First you should put in your composer.json dependecy for that TermExtractor

"require": {
"robholmes/term-extractor" : "3.*"
}

Inside file app.php you need to do 2 things (something like this, dunno the proper name of alias and provider (be sure to do composer update before doing it)

First add provider

'providers' => [
term-extractor/TermExtractorProvider::class
]

Second add alias

'aliases' => [
'TermExtractor' => term-extractor\TermExtractor\Facades\TermExtractor::class,
]

That should give you alias TermExtractor which u can use in whole app without each time do require public_path() . '/term-extractor/src/TermExtractor/TermExtractor.php';

Hope it helps

KuKeC
  • 4,392
  • 5
  • 31
  • 60
  • Then remove it from composer.json and add it manually with help of [this](http://blog.jambura.com/2014/04/26/add-your-own-github-library-in-laravel-using-composer/) – KuKeC Jul 13 '16 at 07:15
  • How do I find the name of the alias and provider? – user6525541 Jul 13 '16 at 07:30
  • That i was looking too in guthub, but was unable to find it. I think you will have to do yours alias and provider. To get some more help about, check [this](http://stackoverflow.com/a/19811029/5139222) – KuKeC Jul 13 '16 at 07:34