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

19 comments:

Michael Granger 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!

vee 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.

vee said...

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

nguma 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.

Nguma 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?

wtf 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?

veer 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?

veer said...

Did you try the example in SVN?

Graham said...

Ah! That's the trick. Thanks!

veer said...

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

uiyui said...

You said you will love me wow gold the whole life, but WoW Gold you marry her. You said you will wow power leveling,come to marry me, but this will not be carried out forever.WoW Gold I am trying my best to forget you and do not love you anymore. wow leveling But I failed and I still love you. Maybe wow leveling she needs you more compared wow leveling with me. So I tell you that world of warcraft power leveling you should love world of warcraft power leveling her and take good world of warcraft leveling care of her. You said I was so kind.world of warcraft leveling Yes, because I love you,world of warcraft leveling I hope you will be power leveling happy forever.

belrion 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]

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