EC2 に GUI を使わないで コマンドラインだけで Jython をインストールする ヘッドレス メモ

jython-installer-2.7.0.jar を下記から ダウンロード
http://www.jython.org/downloads.html

$ sudo su -
# java -jar /tmp/jython-installer-2.7.0.jar -c
Welcome to Jython !
You are about to install Jython version 2.7.0
(at any time, answer c to cancel the installation)
For the installation process, the following languages are available: English, German
Please select your language [E/g] >>>
Do you want to read the license agreement now ? [y/N] >>>
Do you accept the license agreement ? [Y/n] >>>
The following installation types are available:
  1. All (everything, including sources)
  2. Standard (core, library modules, demos and examples, documentation)
  3. Minimum (core)
  9. Standalone (a single, executable .jar)
Please select the installation type [ 1 /2/3/9] >>> 2
Do you want to install additional parts ? [y/N] >>>
Do you want to exclude parts from the installation ? [y/N] >>>
Please enter the target directory >>> /usr/local/jython
Directory /usr/local/jython is not empty - ok to overwrite contents ? [y/N] >>> y
Contents of directory /usr/local/jython will be deleted now! Are you sure to proceed ? [Y/n] >>>
Your java version to start Jython is: Oracle Corporation / 1.8.0_31
Your operating system version is: Linux / 3.10.35-43.137.amzn1.x86_64
Summary:
  - mod: true
  - demo: true
  - doc: true
  - src: false
  - ensurepip: true
  - JRE: /usr/java/jdk1.8.0_31/jre
Please confirm copying of files to directory /usr/local/jython [Y/n] >>>
 10 %
 20 %
 30 %
 40 %
 50 %
 60 %
 70 %
Generating start scripts ...
Installing pip and setuptools
 90 %
Ignoring indexes: https://pypi.python.org/simple/
Downloading/unpacking setuptools
Downloading/unpacking pip
Installing collected packages: setuptools, pip
Successfully installed setuptools pip
Cleaning up...
 100 %
Do you want to show the contents of README ? [y/N] >>>
Congratulations! You successfully installed Jython 2.7.0 to directory /usr/local/jython.

Jython から Kuromoji を使って形態素解析する メモ

kuromoji-0.7.7.jar に CLASSPATH を通しておく


hoge.jy

#!/usr/local/jython/bin/jython
# -*- coding: utf-8 -*-

from org.atilika.kuromoji import Tokenizer

if __name__ == "__main__":

 parseWord = u"すもももももももものうち"
 builder = Tokenizer.builder();

 # ノーマルモード
 normal = builder.build();
 TokensNormal = normal.tokenize(parseWord);

 for token in TokensNormal:
  print token.getSurfaceForm() + "\t" + token.getAllFeatures()
$ hoge.jy
すもも	名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も	助詞,係助詞,*,*,*,*,も,モ,モ
もも	名詞,一般,*,*,*,*,もも,モモ,モモ
も	助詞,係助詞,*,*,*,*,も,モ,モ
もも	名詞,一般,*,*,*,*,もも,モモ,モモ
の	助詞,連体化,*,*,*,*,の,ノ,ノ
うち	名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ