动态语言很好,很强大!

前几天看了徐老师写的[url=http://hi.baidu.com/xuqingyang/blog/item/665b9601b70b7e031d9583a8.html]谈谈学习动态脚本语言对搞web mining研究的必要性[/url],想起上次英语课话剧,使用ruby一行代码完成任务的事,深刻体会到动态语言的简洁强大之处,对处理文本的方便之处。开始剧本中是为了更好的理解剧情,中英文混在一起的,后来剧情比较熟了,为了看台词方便,希望把英语提取出来,我们这组幸好有我是计算机出身的,否则得花一晚上手工完成了。
格式类似如下:
[quote]
在一旁看的七濑美雪以被打败的表情说话:「都是因为阿一你擅自在滑雪练习场之外的地方下来,所以才会变成这样啊。」 That's all because you had to go beyond the training grounds to ski.
还说咧!下大雪使得升降椅停止运转,如果照那样直直下去,根本就到不了山庄。同一座山,只要斜斜地穿越过去,应该就可以回到国民旅馆。」 Stop talking please,If the cable cars stop we won't be able to get back to the hotel. This way!
阿一边说边把鼻子上的雪块擦掉。
「我却不那麽认为。」 I don't think so
美雪愈来愈听不下去:「——通常都是先滑到山下,然後搭计程车回国民旅馆。你从小就喜欢和别人唱反调,而且顽固得要命…」 We always go to the bottom of the hill,and take a cab back to the hotel. you are always so stubborn.
「真是罗哩八嗦,每次只要和你出来旅行,总是会遇到灾难、或是被卷入奇怪的事件」
Oh you’re so troublesome we get into trouble every time we travel,or get involved in some weird situation.
「阿一,你说什麽!这句话应该是我说的才对吧:以前就没有发生过这种事吗?你提议要去陌生的地力滑雪,不仅差一点遇难,最後躲进小木尾里,结果在那里面发生杀人事件」
I think I shooud say that! You are the the one who wanted to go skiing in a unknown place,the last time this happened we got involved in a murder!
「喂,美雪!我们太幸运了!」 Hey May, we're so lucky!
「阿一,你有在听我说话吗?」 Are you listening?
「别说了,你看那栋房子!」 Oh look, there's a house!
阿一用滑雪杖指着斜面下方一栋有红色屋顶的房子。
「咦?可是刚才我们看到的别墅,里面都没有住人啊。这一带的别墅,一到了冬季,几乎都没有人使用…」 But we saw a house a while before, most of the houses in the area are empty during the winter.
阿一笑着对不抱希望的美雪说:「没问题的啦。你看冰柱就知道了嘛。」 That’s no problem, look at the icicles.
「冰柱?」 Icicles?
「我们之前所见到的无人别墅,屋檐下的冰柱并没有像现在这栋这样巨大吧?」 The empty house we saw, didn't have icicles this size, did it?
「这麽说来…不过,那又怎样?」 Yes, but what if they didn't?
「冰柱这玩意的形成是靠屋顶上的积雪融化滴下来,再因为天气冷而结冻所形成的。有巨大的冰柱表示说,这栋房子因为有热气,所以屋顶的积雪才会融化而形成冰柱。」
Icicles are made fro the melting snow,only a house with enough heat would have icicles this size.
「哦、原来如此」 Oh, I get it.
「我们走吧!那里面一定有暖气。」 Lets go,it must be warm inside.
「嗯。」 OK!
...
[/quote]
一行ruby代码就可以搞定了:

File.read('script.txt').scan(/[\s\?\.,'!]*\w+[\s\?\.,'!]*/m).each{|w| print w }

结果:
[quote]
That's all because you had to go beyond the training grounds to ski.
Stop talking please,If the cable cars stop we won't be able to get back to the hotel. This way!
I don't think so
We always go to the bottom of the hill,and take a cab back to the hotel. you are always so stubborn.

Oh youre so troublesome we get into trouble every time we travel,or get involved in some weird situation.

I think I shooud say that! You are the the one who wanted to go skiing in a unknown place,the last time this happened we got involved in a murder!
Hey May, we're so lucky!
Are you listening?
Oh look, there's a house!
But we saw a house a while before, most of the houses in the area are empty during the winter.
Thats no problem, look at the icicles.
Icicles?
The empty house we saw, didn't have icicles this size, did it?
Yes, but what if they didn't?

Icicles are made fro the melting snow,only a house with enough heat would have icicles this size.
Oh, I get it.
Lets go,it must be warm inside.
OK!
[/quote]
再稍加排版就可以了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值