Created
September 16, 2014 03:40
-
-
Save mootoh/58a9f5dd9f9324ac6932 to your computer and use it in GitHub Desktop.
Collect nouns from HTTP POST data and get back as JSON array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'natto' | |
| require 'webrick' | |
| require 'json' | |
| def to_nouns(text) | |
| nm = Natto::MeCab.new | |
| results = [] | |
| nm.parse(text) do |n| | |
| type = n.feature.split(/,/).first | |
| next unless type == '名詞' | |
| results.push n.surface | |
| end | |
| results | |
| end | |
| server = WEBrick::HTTPServer.new :Port => 1978 | |
| server.mount_proc '/' do |req, res| | |
| nouns = to_nouns req.body | |
| res.body = nouns.to_json | |
| end | |
| server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment