【问题标题】:How to call the instance of class?如何调用类的实例?
【发布时间】:2016-08-10 07:52:10
【问题描述】:

我正在使用设置,我从 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;
    }
}

谁能帮我解决这个问题?

【问题讨论】:

  • 是的,我也设置了 reco4j 并得到了同样的错误,如果有人帮助解决这个问题,它将对我有所帮助。提前致谢。
  • 是的,我也在寻找解决方案,我也在尝试运行设置,如果我得到解决方案,我会在这里发布。如果您有任何解决方案,请告知。

标签: php neo4j recommendation-engine


【解决方案1】:

您收到此错误是因为您没有使用正确的类路径。

改变这个:

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

【讨论】:

    猜你喜欢
    • 2014-11-21
    • 2014-07-30
    • 2014-08-06
    • 2017-12-10
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    相关资源
    最近更新 更多