Skip to content

Instantly share code, notes, and snippets.

@dalyons
Created January 13, 2012 09:30
Show Gist options
  • Save dalyons/1605271 to your computer and use it in GitHub Desktop.
Save dalyons/1605271 to your computer and use it in GitHub Desktop.
bootstrapping the Stanford NLP from JRuby
require 'java'
include Java
require 'lib/stanford-parser/stanford-parser.jar'
include_class 'java.io.StringReader'
include_class 'edu.stanford.nlp.parser.lexparser.LexicalizedParser'
include_class 'edu.stanford.nlp.trees.PennTreebankLanguagePack'
module NLP
PARSER = LexicalizedParser.new('lib/stanford-parser/englishPCFG.ser.gz')
PTLP = PennTreebankLanguagePack.new
def NLP.parse(sentence)
toke = PTLP.getTokenizerFactory().getTokenizer(StringReader.new(sentence))
wordlist = toke.tokenize()
PARSER.parse(wordlist) ? PARSER.getBestParse() : nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment