如何制作像Wolfram | Alpha这样的小型引擎?

5 parsing ruby-on-rails prediction wolframalpha

比方说,我有三个型号/表:operating_systems,words,和programming_languages:

# operating_systems
name:string created_by:string family:string
Windows     Microsoft         MS-DOS
Mac OS X    Apple             UNIX
Linux       Linus Torvalds    UNIX
UNIX        AT&T              UNIX

# words
word:string defenitions:string
window      (serialized hash of defenitions)
hello       (serialized hash of defenitions)
UNIX        (serialized hash of defenitions)

# programming_languages
name:string created_by:string example_code:text
C++         Bjarne Stroustrup #include <iostream> etc...
HelloWorld  Jeff Skeet        h
AnotherOne  Jon Atwood        imports 'SORULEZ.cs' etc...
Run Code Online (Sandbox Code Playgroud)

当用户搜索时hello,系统会显示"你好"的防御.这相对容易实现.但是,当用户搜索时UNIX,引擎必须选择:wordoperating_system.此外,当用户搜索windows(小写字母'w')时,引擎会选择word,但也应该显示Assuming 'windows' is a word. Use as an <a href="etc..">operating system</a> instead.

任何人都可以通过解析和选择搜索查询的主题来指出我正确的方向吗?谢谢.


注意:它不需要能够像WA那样执行计算.

Mat*_*yer 2

有一个名为 的新索引表terms,其中包含每个有效术语的标记化版本。这样,您只需搜索一张表。

# terms
Id Name     Type               Priority
1  window   word               false
2  Windows  operating_system   true
Run Code Online (Sandbox Code Playgroud)

然后您可以看到用户搜索词的匹配程度。即“Windows”将与 - 100% 匹配2,因此假设,但也接近匹配1,因此建议将其作为替代方案。您必须编写自己的规则引擎来决定单词匹配的程度(即“windows”与“Windows”的假设是什么?)Priority如果规则引擎无法决定,则该字段可能是最终决定者,并且可以理论上是由用户活动驱动的,因此它可以了解用户更有可能参考的内容。