ruby and japanese

46
RUBY AND JAPANESE ルビーと日本語 Makoto Inoue LRUG December 2010

Upload: makoto-inoue

Post on 12-May-2015

6.467 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ruby and japanese

RUBY AND JAPANESEルビーと日本語

Makoto Inoue LRUG December 2010

Page 2: Ruby and japanese

WHO ARE WE(NORMAL)?

Page 3: Ruby and japanese

WHO ARE WE(TODAY)?

Page 5: Ruby and japanese

TOPIC

Basic Japanese

Object Oriented (OO)

Functional

Japanese Programming in Ruby

Page 6: Ruby and japanese

BASIC JAPANESE日本語の基礎

Step 1

Page 7: Ruby and japanese

WATASHI HA RUBY GA SUKI DESU私はルビーが好きです

Kanji  漢字  ( eg: 私,好 )

Katakanaカタカナ( eg: ルビー )

Hiraganaひらがな( eg:は ,が,きです)

Kanji Katakana Hiragana

Page 8: Ruby and japanese

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.

Page 9: Ruby and japanese

Kanji => Hiragana

Kanji

Hiragana

Page 10: Ruby and japanese

Kanji => KatakanaKanji

Katakana

Page 11: Ruby and japanese

Makoto makoto マコト まこと 真

Vivian bibiann ビビアン びびあん

Oliver  oriba- オリバー おりばー

Max makkusu マックス まっくす

WHAT’S YOUR NAME?お名前は?

Alphabet How Japanese interpret Katakana Hiragana Kanji

Page 12: Ruby and japanese

BUILD YOUR OWN

http://kanji-fandom.com/

Page 13: Ruby and japanese

WHY SO MANY WAYS?

Kanji = To import Chinese words

Hiragana = To suit for domestic use

Katakana = To adopt new words

Page 14: Ruby and japanese

WHY SO MANY WAYS?

To import OO & Functional

To suit for Scripting

To adopt New Concepts

Page 15: Ruby and japanese

OBJECT ORIENTEDオブジェクト指向

Step 2

Page 16: Ruby and japanese

JAPANESE & OO

http://satoshi.blogs.com/life/2004/09/post.html

Page 17: Ruby and japanese

ENGLISH (SVO)

I like Ruby

Subject Verb Object

Page 18: Ruby and japanese

日本語(SOV)

私はルビーが好きですWatashi ha Ruby ga Suki desu

Subject Object Verb

I Ruby Like

Page 19: Ruby and japanese

CUI(SVO)

Page 20: Ruby and japanese

GUI(SOV)http://satoshi.blogs.com/life/2004/09/post.html

Page 21: Ruby and japanese

RUBY

# Proceduralopen("box")open("car")

# OOBox.new.openCar.new.open

Page 22: Ruby and japanese

FUNCTIONAL関数型

Step 3

Page 23: Ruby and japanese

Japanese is a politician's language

日本語は政治家向けの言語である

Makoto Inoue (Me) - 2010

Page 24: Ruby and japanese

POLITICIAN....

does not commit to anything unless necessary

means different things depending on context

Page 25: Ruby and japanese

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

Page 26: Ruby and japanese

POSTPOSITIONS助詞

postposition |ˌpōstpəˈzi sh ən|noun Grammara word or morpheme placed after the word it governs, for example -ward in homeward.

Page 27: Ruby and japanese

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

Page 28: Ruby and japanese

ABUSING POSTPOSITIONS助詞の乱用

”もし 有権者の皆様が私に投票してくださり、な

おかつ必要な財源を期日内に確保することができ

ましたならば、みなさまのご期待に添う事が出来

るよう、政治生命を賭けて戦って行く所存でござ

います。”

Don’t Read !!

Confusing, vague, and long sentence without much point

(Could be powerful)

Page 29: Ruby and japanese

FUNCTIONAL

Lazy evaluation

high order function

Page 30: Ruby and japanese

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

Page 31: Ruby and japanese

JAPANESE PROGRAMMING IN RUBY

RUBYで日本語プログラミングhttps://github.com/makoto/japanize1.9 Step 4

Page 32: Ruby and japanese

DEMOデモ中

http://screenr.com/F9L

Page 33: Ruby and japanese

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

Page 34: Ruby and japanese

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

Page 35: Ruby and japanese

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

Page 36: Ruby and japanese

GOOGLE TRANSLATION

Page 37: Ruby and japanese

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

Page 38: Ruby and japanese

REVERSE POLISH NOTATION逆ポーランド記法

http://en.wikipedia.org/wiki/Reverse_Polish_notation

[1, 2, :+, 3 , :* , 1, :-, 2, :/]

Page 39: Ruby and japanese

RubiMaVM RUBY VM ON RUBY

http://jp.rubyist.net/magazine/?0007-YarvManiacs

Page 40: Ruby and japanese

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

Page 41: Ruby and japanese
Page 42: Ruby and japanese

SO WHAT?っで?

:-)

Page 43: Ruby and japanese

WHY SO MANY WAYS?

To import OO & Functional

To suit for Scripting

To adopt New Concepts

Page 44: Ruby and japanese

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

Page 46: Ruby and japanese

MERRY CHRISTMAS & HAVE A HAPPY NEW YEAR!!メリークリスマス&良いお年を!!

http://www.railsonwave.com/assets/2006/12/21/screensaver_1.jpg

hello 2011