如何调用类的实例?

时间:2016-08-10 07:52:11

标签: php neo4j recommendation-engine

我正在使用设置,我从github下载并设置了包含以下链接:

https://github.com/graphaware/reco4php

我还安装了php7和neo7j,它们在localhost(ubuntu16.04)上正常运行。

我在浏览器中收到错误:

Fatal error: Uncaught Error: Class 'GraphAware\Reco4PHP\Demo\Github\RecommendationEngine' not found in /var/www/html/recommendation_2/example.php:9 Stack trace: #0 {main} thrown in /var/www/html/recommendation_2/example.php on line 9

当点击example.php表单下面的browser.example.php文件代码时:

<?php
// example.php file

require_once __DIR__.'/vendor/autoload.php';

use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;

$rs = RecommenderService::create("http://neo4j:idealindore@localhost:7474");
$rs->registerRecommendationEngine(new RecommendationEngine());

$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();

$input = $rs->findInputBy('User', 'login', 'jakzal');

$engine = $rs->getRecommender("github_who_to_follow");

$stopwatch->start('reco');
$recommendations = $engine->recommend($input);
$e = $stopwatch->stop('reco');

//echo $recommendations->size() . ' found in ' . $e->getDuration() .  'ms' .PHP_EOL;

foreach ($recommendations->getItems(10) as $reco) {
    echo $reco->item()->get('login') . PHP_EOL;
    echo $reco->totalScore() . PHP_EOL;
    foreach ($reco->getScores() as $name => $score) {
        echo "\t" . $name . ':' . $score->score() . PHP_EOL;
    }
}

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

由于没有使用正确的类路径,因此出现此错误。

更改此:

use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;

这些文件的实际存储位置。

  • RecommendationEngine.php
  • RecommenderService.php

此外,您还需要使用以下类:

use GraphAware\Common\Cypher\Statement;
use GraphAware\Common\Type\Node;
use GraphAware\Reco4PHP\Context\Context;
use GraphAware\Reco4PHP\Engine\SingleDiscoveryEngine;

请参见This Link,并按照教程逐步学习如何使用Neo4J构建图基推荐系统。

如果您对本教程有任何疑问,也请检查This Post