Skip to content

Instantly share code, notes, and snippets.

@squarism
Created December 19, 2011 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarism/1498996 to your computer and use it in GitHub Desktop.
Save squarism/1498996 to your computer and use it in GitHub Desktop.
nlp_playtime_2
# Instructions for OSX likely to be brew install based, have not tried
# $ sudo apt-get install libtool
# $ sudo aptitude install liblink-grammar4-dev
# runs on regular ruby not jruby-1.6.5 (tested)
# $ gem install linkparser
# set putty or whatever to width of 128
dict = LinkParser::Dictionary.new( :screen_width => 128 )
sent = dict.parse( "People use your mom for all kinds of nifty things." )
puts sent.diagram
#
# +-----------------------------------Xp----------------------------------+
# | +-------MVp------+ |
# | +----Os----+ +-----Jp-----+ +------Jp-----+ |
# +----Wd---+--Sp--+ +--D-+ | +--Dmc-+--Mp-+ +----A---+ |
# | | | | | | | | | | | |
#LEFT-WALL people.p use.v your mom.f for.p all.a kinds.n of nifty.a things.n .
sent.words
# => ["LEFT-WALL", "People", "use", "your", "mom", "for", "all", "kinds",
# "of", "nifty", "things", ".", "RIGHT-WALL"]
sent.verb
# => "use"
sent.subject
# => "people"
sent.object
# => "mom.f"
# WTF!!! What is this .f crap?
# hey, pretty cool otherwise.
# $ gem install linguistics
require 'linguistics'
Linguistics::use( :en )
Linguistics::EN.has_link_parser?
# => true :)
Linguistics::EN.has_wordnet?
# => false :(
text = "Stimpy had a slice of bacon and soon he died of happiness."
text.en.sentence.linkages.collect {|l| l.verb}
# => ["had"]
text.en.sentence.linkages.collect {|l| l.nouns}.flatten
# => ["slice", "bacon", "happiness"]
text.en.sentence.linkages.collect {|l| l.verb}.first.en.infinitive
# => "have"
# or way easier:
text.en.sentence.nouns
=> ["slice", "bacon", "happiness"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment