Monday, November 14, 2005

The client of the English parser service

According to the English parsing service over POX and HTTP that was mentioned in this blog. It seems to miss an important example that is example of client wriiting. So it will be shown here.




require 'net/http'
require 'uri'

res = Net::HTTP.post_form(URI.parse('http://127.0.0.1:8030/parse/'),
{'txt'=>'I love you.'})
print res.body




We can just use standard HTTP lib of any languages. Then the parsing result in XML can be obtained, as shown below.




<result>
<constituent label="S" >
....
....
....
</constituent>
</result>




Easy, isn't it?

English parsing service over POX and HTTP

The Link grammar parser from CMU is freely available and very robust. It has to be used over C API or the command line interface. In order to integrate tools from heterogeneous platforms, most of my tools communicate each others by Plain Old XML ( POX ) and the Hypertext Transfer Protocol ( HTTP ). Hence I write POX and HTTP wrapper for the Link grammar parser by using the Link grammar parser, its Ruby binding and the WEBrick. Moreover the Link grammar parser from Abiword CVS has been adopted because it provides the script for the GNU Building tools and the pkg-config are convenient.



In order to show the way this service work, HTML script below is written.



form1



The script above will generate HTML page, as shown in figure 1 and it send plain text to parsing service. Then parsing service will return parsing result in XML, which is illustrated in figure 2. For real usage, a web browser is replaced by a program with a xml parser and a http client framework.




web1

Figure 1




web2

Figure 2




Now I have a parser service, which is easy (?) to use. So I will step to look at pdf2text. :-)

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