Saturday, November 12, 2005

Ruby/Link Grammar Binding

This blog entry is out of date. Please visit http://rubyforge.org/projects/linkgrammar4r/ instead.

Since I want to use link grammar parser for some particular tasks and I'm using Ruby language. There is no existing Ruby binding for Link Grammar Parser. Hence I wrote one. It is incomplete but it may be useful for someone who want to make this binding but don't want to start from scratch.

http://www.geocities.com/veetai/ruby-linkgrammar-20051111.tar.gz

The example of using link grammar parsing in Ruby is as follow:

require 'linkgrammar'

dict = LinkGrammar::Dictionary.new("4.0.dict", nil, nil, nil)
sent = LinkGrammar::Sentence.new('I love you.', dict)
opts = LinkGrammar::ParseOptions.new
sent.parse(opts)
linkage = LinkGrammar::Linkage.new(0, sent, opts)
words = linkage.get_words
words.each{|w|
print "w = #{w}\n"
}
cnode = linkage.constituent_tree
print "Root node label = #{cnode.label}\n"



The result:

w = LEFT-WALL
w = I.p
w = love.v
w = you.[?].n
w = RIGHT-WALL
Root node label = S
Freeing dictionary 4.0.dict


P.S. I probably post the update later if I found that this binding is not enough for my tasks :-)

18 comments:

Anonymous said...

You say that there "is no existing binding". Where did you search for previous binding? I'm curious because yours is the third implementation of it for Ruby that I know of, and I'd like to figure out how to make the existing ones (including yours) more visible to people so we can stop re-implementing the same things over and over, or at least figure out what's missing from previous implementations.

I worked on the first implementation with a friend of mine, and gave up on using the C code because it had horrendous memory-leak issues. The way it was written (5 years ago, at least) precludes your from ever freeing links that you've parsed when the Ruby objects which wrap them are destroyed. I haven't looked at the code for quite some time -- have they fixed that bit?

Anyway, if you search for 'link grammar' on the RAA, you would find:

http://raa.ruby-lang.org/project/linkparser/

Searching for postings about it on ruby-talk, the english-language Ruby mailing list, you'd find this post, which is a different binding written some years later.

Anyway, I'm looking forward to trying out your code. Thanks for writing it!

veer said...

Michael Granger: Thank you for giving me information. I searched for the binding at RAA. So I found only http://raa.ruby-lang.org/project/linkparser/

I will add this implementation to RAA in order to make it visible to people as you suggested.

Anonymous said...

I've also been looking to play around with the link parser, and just started playing with ruby, so this binding is great news for me! Also, I tried the above mentioned implementations and had only limited success. The all-ruby implementations are either incomplete or just plain not working and this is the only recent binding written that I could find.

veer said...

The name of this implementation is LinkGrammar4R and the project is at http://rubyforge.org/projects/linkgrammar4r/ .

Anonymous said...

When i try running

ruby extconf.rb

i get this message:

Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

veer said...

Did you see something like "checking for pkg-config... no"? if yes, It may be this.

Anonymous said...

Works great.
I needed that for parsing noun phrases like 'italian composer', 'man of taste', 'cool cat'.

Parsing such phrases resulted in the following error:

Linkage index is out of range

So i added a pre a post tag so that it would parse correctly.

Now if i search for: "minimalist programmer" it would return:


w = LEFT-WALL
w = _p_[?].v
w = minimalist[?].a
w = programmer.n
w = _p_[?].n
w = RIGHT-WALL
Root node label = S


Unfortunately, doesn't seem to work in all cases. For instance, searching for 'painter from france' would result in the same Linkage index is out of range error...

Any idea?

Graham said...

It seems to install okay, but I get a segmentation fault on:

sent = LinkGrammar::Sentence.new('I love you.', dict)

I'm running ruby 1.8 on ubuntu 7.10 with LinkGrammar 4.3.

Any ideas?

veer said...

How did you install link-grammar? Which version of Ruby/Link Grammar do you use?

Graham said...

I installed link-grammar v.4.3.4 from source off the AbiWord site, and I'm using:

ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]

Graham said...

Btw, have you (or somebody else) developed a dictionary/grammar for Thai?

Anonymous said...

please use ruby-linkgrammar from http://rubyforge.org/projects/linkgrammar4r/ (svn-head must be better)

I haven't seen link grammar in Thai.

Graham said...

Tried the Rubyforge version, tried the svn-head. Same error. Anything else I could try?

Anonymous said...

Did you try the example in SVN?

Graham said...

Ah! That's the trick. Thanks!

Anonymous said...

you're welcome and sorry for an out-of-date entry

Anonymous said...

buy wow goldbuy wow gold[url=http://www.belrion.com]buy wow gold[/url]
[url=http://www.igamehub.com/wowgold/buy-wow-gold.htm]buy wow gold [/url]

Anonymous said...
This comment has been removed by a blog administrator.