0

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

1 回答 1

2

好吧,如果你做了演示显示的事情并且事情不起作用,那么我建议你在他们的错误跟踪器中创建一个问题。但是对我来说,脚本有效。也许您应该首先检查您实际遇到的错误。比如你不关闭第一条语句,;后面的内容就少了$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 脚本问题时,您应该始终做的第一步是查看错误日志文件。这就是显示错误的地方。当您所要做的就是阅读错误是什么时,试图猜测错误可能是什么是没有意义的。

于 2015-04-06T12:12:34.137 回答