从变量而不是ob_get_content进行汇总


Summarize from a variable instead of ob_get_content

我有一个变量,它包含一个文本字符串和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();

好吧,如果你做了演示显示的事情,但事情不起作用,那么我建议你在他们的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. 需要类脚本

当php脚本出现问题时,应始终执行的第一步是查看错误日志文件。这就是显示错误的地方。当你所要做的只是读取错误是什么时,尝试猜测错误是什么是没有意义的。