从php调用wordnet(Wordnet类或PHP API) [英] Calling wordnet from php (Wordnet class or API for PHP)

查看:120
本文介绍了从php调用wordnet(Wordnet类或PHP API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个程序来查找两个文档之间的相似性,并且由于即时消息仅使用英语,所以我决定使用wordnet,但是我无法找到将wordnet与php链接的方法,因此无法找到任何wordnet api php.

I am trying to write a program to find similarity between two documents, and since im using only english, I decided to use wordnet, but I cannot find a way to link the wordnet with php, I cannot find any wordnet api from php.

我在论坛上看到有人说(Spudley)他从php调用了wordnet(使用shell_exec()函数), 用于PHP的同义词库类或API

I saw in the forum some one said (Spudley) he called wordnet from php (using shell_exec() function), Thesaurus class or API for PHP [edited]

我真的很想知道所使用的方法或一些示例代码,或者是一个教程,可能会开始在php中使用wordnet.

I would really like to know a method used or some example code, a tutorial perhaps to start using the wordnet with php.

非常感谢

推荐答案

从WordNet站点链接到的PHP扩展非常旧且过时-它声称可以与PHP4一起使用,所以我认为已经有好几年了.

The PHP extension which is linked to from the WordNet site is very old and out of date -- it claims to work with PHP4, so I don't think it's been looked at in years.

WordNet-> PHP没有其他可用的API,因此我推出了自己的解决方案.

There aren't any other APIs available for WordNet->PHP, so I rolled my own solution.

WordNet可以从命令行运行,因此PHP的shell_exec()函数可以读取输出.

WordNet can be run from the command-line, so PHP's shell_exec() function can read the output.

如果从命令行(从CD到Wordnet的目录,然后只是wn)运行WordNet,而没有任何参数,它将显示Wordnet支持的可能功能列表.

If you run WordNet from the command-line (cd to Wordnet's directory, then just wn) without any parameters, it will show you a list of possible functions that Wordnet supports.

仍然在命令行中,如果您尝试其中一个/某些功能,您将看到Wordnet如何输出其结果.例如,如果您想要单词'star'的同义词,则可以尝试-synsn函数:

Still in the command-line, if you then try one/some of those functions, you'll see how Wordnet outputs its results. For example, if you want synonyms for the word 'star', you could try the -synsn function:

wn star -synsn

这将产生看起来像这样的输出:

This will produce output that looks a bit like this:

名词星的同义词/双音(按估计的频率排序)

Synonyms/Hypernyms (Ordered by Estimated Frequency) of noun star

8种星星感

感知1星 =>天体,天体

Sense 1 star => celestial body, heavenly body

Sense 2 ace,熟练,冠军,感觉,maven,mavin,virtuoso,天才,热门,明星,巨星,whiz,whizz,巫师,wiz =>专家

Sense 2 ace, adept, champion, sensation, maven, mavin, virtuoso, genius, hotshot, star, superstar, whiz, whizz, wizard, wiz => expert

Sense 3星 =>天体,天体

Sense 3 star => celestial body, heavenly body

Sense 4星 =>平面图,二维图

Sense 4 star => plane figure, two-dimensional figure

感官5星,负责人,领导 =>演员,历史学家,玩家,剧情片,角色扮演者

Sense 5 star, principal, lead => actor, histrion, player, thespian, role player

Sense 6顶篷,星形 =>表演者,表演艺术家

Sense 6 headliner, star => performer, performing artist

Sense 7星号,星号 =>字符,字素,图形符号

Sense 7 asterisk, star => character, grapheme, graphic symbol

Sense 8星拓扑,星型 =>拓扑,网络拓扑

Sense 8 star topology, star => topology, network topology

在PHP中,您可以使用shell_exec()函数读取相同的输出.

In PHP, you can read this same output using the shell_exec() function.

$result = shell_exec('/path/to/wn '.$word.' -synsn');

现在$result应该包含上面引用的文本块.

Now $result should contain the block of text quoted above.

这时,您必须进行一些适当的编码.您需要获取该文本块并将其解析为所需的数据.

At this point, you have to do some proper coding. You'll need to take that block of text and parse it for the data you want.

这是棘手的地方.由于数据是以旨在供人类而非程序读取的格式呈现的,因此准确地解析是很棘手的.

This is where it gets tricky. Because the data is presented in a format designed to be read by a human rather than by a program, it is tricky to parse accurately.

重要的是要注意,不同的搜索选项显示的输出略有不同.而且,返回的某些结果可能有些神秘.我最终编写了一个加权系统来对结果进行评分,但是它非常符合我的需求,因此您需要尝试使用它来设计自己的系统.

It is important to note that different search options present their output slightly differently. And, some of the results that are returned can be somewhat esoteric. I ended up writing a weighting system to score the results, but it was fairly specific to my needs, so you'll need to experiment with it to come up with your own system.

我希望这对您有足够的帮助. :)

I hope that's enough help for you. :)

这篇关于从php调用wordnet(Wordnet类或PHP API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆