doufei0933 2011-12-01 22:36
浏览 92
已采纳

短语查询扩展的最快方法

I'm using a list of synonyms to direct a process of query expansion. The format looks like this:

fu=foo
ba=bar
etc=etcetera
werd=word

I'm using a straightforward binary search algorithm to run each of the user input words against this list. The problem is, when it comes to using phrases.

    quick brown fox=alphabet
    out of this world=space
    why hello there=hello

Typical input: why hello there, where can I get an out of this world hopper?

And the desired output is: hello, where can I get an space hopper?

I don't want to run each word pair or tripple through the search too, and I want to avoid a linear search of the thesaurus list against the input as this is inefficient (although the list should be quite small so this an option).

Therefore I'm looking for ways to run binary search on phrases, or to construct the thesaurus in such a way as to compensate for phrases.

I'm using PHP for this. Any suggestions most welcome.

  • 写回答

3条回答 默认 最新

  • dongwo5940 2011-12-01 22:52
    关注

    The simple approach would be using str_replace. I don't know about the performance though.

    $list = array('out of this world' => 'space');
    $str = 'why hello there, where can I get an out of this world hopper?';
    
    foreach ($list as $old => $new) {
        $str = str_replace($old, $new, $str);
    }
    

    Edit: I've often noticed that it's more efficient to use built-in functions instead of writing your own because the built-ins are already compiled but your optimized algorithm needs to be interpreted which is a huge slowdown.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集