Skip to content

Instantly share code, notes, and snippets.

@hkparker
Created December 8, 2014 23:23
Show Gist options
  • Save hkparker/c7419b6a7e0dde6b9d78 to your computer and use it in GitHub Desktop.
Save hkparker/c7419b6a7e0dde6b9d78 to your computer and use it in GitHub Desktop.
Ruby script to determine part of speech of a word
#!/usr/bin/env ruby
require 'httpclient'
require 'nokogiri'
def part_of_speech(word)
parts_of_speech = []
client = HTTPClient.new
body = client.get("http://dictionary.reference.com/browse/#{word}?s=t").body
structure = Nokogiri::HTML(body)
structure.xpath("//div[contains(@class,'def-list')]").search(".dbox-pg").each do |part|
text = part.text
if !parts_of_speech.include? text
parts_of_speech << text
end
end
return parts_of_speech
end
puts part_of_speech(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment