Calling wordnet from php (Wordnet class or API for PHP)

I am trying to write a program to find the similarities between the two documents, and since I used only English, I decided to use wordnet, but can not find a way to associate wordnet with php, I can not find any wordnet api from PHP.

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

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

thank you very much

+4
source share
1 answer

The PHP extension that is associated with the WordNet site is very outdated and outdated - it claims to work with PHP4, so I don't think it has been viewed for years.

There are no other APIs for WordNet-> PHP, so I implemented my own solution.

WordNet can be run from the command line, so the PHP function shell_exec() can read the result.

If you start WordNet from the command line (cd into the Wordnet directory, and then just wn ) without any parameters, it will show you a list of possible functions that Wordnet supports.

On the command line, if you then try one or some of these functions, you will see how Wordnet displays its results. For example, if you want to use synonyms for the word "star", you can try the -synsn function:

 wn star -synsn 

This will produce a result that looks something like this:

Synonyms / Hypermin (ranked by estimated frequency) of a noun

8 senses of the star

Feeling 1 star => heavenly body, heavenly body

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

Feeling 3 stars => heavenly body, heavenly body

Feeling 4 stars => planar figure, two-dimensional figure

The feeling of 5 stars, most importantly, leadership => actor, histrion, player, thespian, role player

Sense 6 headliner, star => performer, performer

Feeling 7 asterisk, star => symbol, grapheme, graphic symbol

Sensitivity 8-star topology, star => topology, network topology

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

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

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

At this point you need to do the right coding. You will need to take this block of text and analyze it for the required data.

That's where it gets complicated. Since the data is presented in a format intended for human reading, and not a program, it is difficult to accurately analyze.

It is important to note that different search options present their conclusion in a slightly different way. And some results that return may be somewhat esoteric. I ended up writing a weighing system to score the results, but it was quite specific to my needs, so you need to experiment with it to create your own system.

I hope you have enough help. :)

+9
source

All Articles