ruby and japanese
TRANSCRIPT
RUBY AND JAPANESEルビーと日本語
Makoto Inoue LRUG December 2010
WHO ARE WE(NORMAL)?
WHO ARE WE(TODAY)?
ME @ RUBYKAIGI
http://image.gihyo.co.jp/assets/images/news/report/01/rubykaigi2010/0003/thumb/TH400_IMG_1253.jpg
here
TOPIC
Basic Japanese
Object Oriented (OO)
Functional
Japanese Programming in Ruby
BASIC JAPANESE日本語の基礎
Step 1
WATASHI HA RUBY GA SUKI DESU私はルビーが好きです
Kanji 漢字 ( eg: 私,好 )
Katakanaカタカナ( eg: ルビー )
Hiraganaひらがな( eg:は ,が,きです)
Kanji Katakana Hiragana
Hiragana
Katakana
Each Japanese alphabet is a combination of vowels(a,i,u,e,o) and consonants(k,s,t,n,h,m,y,r,w). Total of Hiragana and Katakana are 46 each. The number of possible Kanji in use in Japan is around 50,000 , though around 2000 ~ 3000 are in common use.
Kanji => Hiragana
Kanji
Hiragana
Kanji => KatakanaKanji
Katakana
Makoto makoto マコト まこと 真
Vivian bibiann ビビアン びびあん
Oliver oriba- オリバー おりばー
Max makkusu マックス まっくす
WHAT’S YOUR NAME?お名前は?
Alphabet How Japanese interpret Katakana Hiragana Kanji
WHY SO MANY WAYS?
Kanji = To import Chinese words
Hiragana = To suit for domestic use
Katakana = To adopt new words
WHY SO MANY WAYS?
To import OO & Functional
To suit for Scripting
To adopt New Concepts
OBJECT ORIENTEDオブジェクト指向
Step 2
JAPANESE & OO
http://satoshi.blogs.com/life/2004/09/post.html
ENGLISH (SVO)
I like Ruby
Subject Verb Object
日本語(SOV)
私はルビーが好きですWatashi ha Ruby ga Suki desu
Subject Object Verb
I Ruby Like
CUI(SVO)
GUI(SOV)http://satoshi.blogs.com/life/2004/09/post.html
RUBY
# Proceduralopen("box")open("car")
# OOBox.new.openCar.new.open
FUNCTIONAL関数型
Step 3
Japanese is a politician's language
日本語は政治家向けの言語である
Makoto Inoue (Me) - 2010
POLITICIAN....
does not commit to anything unless necessary
means different things depending on context
PREPOSITIONS前置詞
preposition |ˌprepəˈzi sh ən|noun Grammara word governing, and usually preceding, a noun or pronoun and expressing a relation to another word or element in the clause, as in “the man on the platform,” “she arrived after dinner,” “what did you do it for you
POSTPOSITIONS助詞
postposition |ˌpōstpəˈzi sh ən|noun Grammara word or morpheme placed after the word it governs, for example -ward in homeward.
POSTPOSITIONS IN JAPANESE助詞(て に を は が)
私はルビーが好きですWatashi ha Ruby ga Suki desu(I Ruby Like)
ルビーが私は好きですRuby ga Watashi ha Suki desu(Ruby I Like)
ルビーが好きですRuby ga Suki desu(Ruby Like)
Postposition is used to decide the role of noun which it supports. This enables you to change the order of structure very flexibly, chain as many sentence as you like, and also let you to omit subject.
O
SO
S
O
ABUSING POSTPOSITIONS助詞の乱用
”もし 有権者の皆様が私に投票してくださり、な
おかつ必要な財源を期日内に確保することができ
ましたならば、みなさまのご期待に添う事が出来
るよう、政治生命を賭けて戦って行く所存でござ
います。”
Don’t Read !!
Confusing, vague, and long sentence without much point
(Could be powerful)
FUNCTIONAL
Lazy evaluation
high order function
RUBY
Enumerable
Arel
Block
User.order('users.id DESC').limit(20).includes(:items)
% 10000.times=> #<Enumerator: 10000:times>
File.open("/tmp.txt").each do |line| puts lineend
JAPANESE PROGRAMMING IN RUBY
RUBYで日本語プログラミングhttps://github.com/makoto/japanize1.9 Step 4
GRAMMAR
# -*- encoding: utf-8 -*-module Japanize module Grammar VERBS = { 'たす' => :+, # tasu 'ひく' => :-, # hiku 'かける' => :*, # kakeru 'わる' => :/, # waru } POSTPOSITIONAL_PARTICLES = ['て','に','を','は'] def 助詞; POSTPOSITIONAL_PARTICLES; end def 数字; NUMBERS; end def 動詞; VERBS; end
GRAMMAR
# -*- encoding: utf-8 -*- def parse @sequence.split('').map do |s| s.split(/#{助詞.join("|")}/) end.flatten.map do |s| if 動詞[s] 動詞[s] elsif 数字[s[0]] NumberConverter.convert(s) end end end
PARSER
# -*- encoding: utf-8 -*-describe Parser do it "must divide a phrase into words" do Parser.new("1に2をたして4を掛ける"). parse.must_equal [1, 2, :+, 4, :*] endend
GOOGLE TRANSLATION
EVALUATOR
describe Evaluator do it "must calculate all operands" do Evaluator.new([1, 2, :+, 3 , :* , 1, :-, 2, :/]). evaluate.must_equal ((((1+2) * 3) - 1 ) / 2) endend
REVERSE POLISH NOTATION逆ポーランド記法
http://en.wikipedia.org/wiki/Reverse_Polish_notation
[1, 2, :+, 3 , :* , 1, :-, 2, :/]
RubiMaVM RUBY VM ON RUBY
http://jp.rubyist.net/magazine/?0007-YarvManiacs
METHOD MISSING
# -*- encoding: utf-8 -*-def method_missing (*obj) if 数字[obj[0][0]] parsed = Parser.new(obj[0].to_s).parse Evaluator.new(parsed).evaluate else super endend
SO WHAT?っで?
:-)
WHY SO MANY WAYS?
To import OO & Functional
To suit for Scripting
To adopt New Concepts
MATZ @SAPPORO RUBY KAIGI
”In future, I want Ruby to keep being the light
which brings new concepts and ideas to people.
I also would like people to see such light, add their own, and spread it to other people.”
http://regional.rubykaigi.org/sapporo03
http://igarashikuniaki.net/tdiary/20101205.html
WHAT CAN YOU DO?http://www.igvita.com/2010/12/02/concurrency-with-actors-goroutines-ruby/
http://rubykaigi.org/2011/enhttp://www.rubyinside.com/ruby-refinements-an-overview-of-a-new-proposed-ruby-feature-3978.html
http://www.pragprog.com/titles/btlang/seven-languages-in-seven-weeks
MERRY CHRISTMAS & HAVE A HAPPY NEW YEAR!!メリークリスマス&良いお年を!!
http://www.railsonwave.com/assets/2006/12/21/screensaver_1.jpg
hello 2011