【问题标题】:Summarize from a variable instead of ob_get_content从变量而不是 ob_get_content 进行汇总
【发布时间】:2015-04-06 11:57:36
【问题描述】:

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

【问题讨论】:

    标签: php summarization


    【解决方案1】:

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

    【讨论】:

    • 好的,谢谢,但是运行时摘要长度也是 0 对吗?
    • 是的。但我不知道这样的“摘要”是什么,因此我无法判断这是否正确。无论如何,这超出了这个问题的范围,不是吗?
    猜你喜欢
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    相关资源
    最近更新 更多