从变量而不是ob_get_content汇总

时间:2015-04-06 11:57:37

标签: php summarization

我有一个包含一串text和p标签的变量,其中p标签表示不同的段落。我想从这个变量得到的是创建一个摘要。我找到了一个看起来很容易使用的库。但是我似乎无法使它与我的变量一起工作。它似乎只能使用ob_get_content?

库: https://github.com/freekrai/summarizer

到目前为止,我已经尝试了这个并且它似乎没有像在演示中那样返回摘要?

$full_text_strip = "<p>Counter-Strike: Global Offensive majors have a history of spurring serious roster overhauls. The moves following the results of ESL Katowice continue to reinforce tradition.</p><p>Penta Sports proved many doubters wrong by following up its first top-eight finish at a major at DreamHack Winter late last year with another top-eight finish at ESL Katowice. While the German squad did fall in the quarterfinal round to eventual champion Fnatic, the team proved without a doubt to be the best in Germany and among the best in Europe.</p>"

$st = new Summarizer();

$summary = $st->get_summary($full_text_strip);
echo $summary;
echo $st->how_we_did();

1 个答案:

答案 0 :(得分:2)

好吧,如果你做了演示显示的内容并且事情不起作用,那么我建议你在他们的bug跟踪器中创建一个问题。然而对我来说脚本是有效的。也许你应该先检查你实际得到的错误。例如,您没有关闭第一个语句,;的内容后缺少$full_text_strip ...

<?php

require 'summarizer.class.php';

$full_text_strip = "<p>Counter-Strike: Global Offensive majors have a history of spurring serious roster overhauls. The moves following the results of ESL Katowice continue to reinforce tradition.</p><p>Penta Sports proved many doubters wrong by following up its first top-eight finish at a major at DreamHack Winter late last year with another top-eight finish at ESL Katowice. While the German squad did fall in the quarterfinal round to eventual champion Fnatic, the team proved without a doubt to be the best in Germany and among the best in Europe.</p>";

$st = new Summarizer();

$summary = $st->get_summary($full_text_strip);
echo $summary;
echo $st->how_we_did();

以上对我的预期效果如上所述。针对您的版本的修改:

  1. 在字符串赋值后尾随分号(;),否则会出现语法错误并且
  2. 需要类脚本
  3. 当您遇到php脚本问题时,总是所做的第一步是查看错误日志文件。这就是显示错误的地方。尝试猜测错误可能时,没有任何意义,只需要阅读错误是什么。