Saturday, November 12, 2005

Ruby/Link Grammar Binding

This blog entry is out of date. Please visit 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.

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

require 'linkgrammar'

dict ="4.0.dict", nil, nil, nil)
sent ='I love you.', dict)
opts =
linkage =, sent, opts)
words = linkage.get_words
print "w = #{w}\n"
cnode = linkage.constituent_tree
print "Root node label = #{cnode.label}\n"

The result:

w = I.p
w = love.v
w = you.[?].n
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 :-)


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:

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

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 .

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 = _p_[?].v
w = minimalist[?].a
w = programmer.n
w = _p_[?].n
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 ='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 (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...

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 of warcraft leveling Yes, because I love you,world of warcraft leveling I hope you will be power leveling happy forever.

Anonymous said...

buy wow goldbuy wow gold[url=]buy wow gold[/url]
[url=]buy wow gold [/url]

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