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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器