<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    First they ignore you
    then they ridicule you
    then they fight you
    then you win
        -- Mahatma Gandhi
    Chinese => English     英文 => 中文             
    隨筆-221  評論-1047  文章-0  trackbacks-0
    在搜索引擎,語音識別等領域常會統計單詞的出現頻率,下面給出Groovy實現,打印出現頻率最高的6個單詞以及相應的出現次數:

    def?content?? = ?
    ????
    """
    ????The?Java?Collections?API?is?the?basis?? for ??all?the?nice?support?that?Groovy?gives?you
    ????through?lists?and?maps.?In?fact,?Groovy?not?only?uses?the?same?abstractions,?it
    ????even?works?on?the?very?same?classes?that?make?up?the?Java?Collections?API.
    ????
    """
    ?
    def?words?
    = ?content.tokenize()

    def?wordFrequency?
    = ?[:]

    words.each?{
    ????wordFrequency[it]?
    = ?wordFrequency.get(it,? 0 )? + ? 1 ?
    }?

    def?wordList?
    = ?wordFrequency.keySet().toList()

    wordList.sort?{wordFrequency[it]}?

    def?result?
    = ? '' ?

    wordList[
    - 1 .. - 6 ].each?{
    ????result?
    += ?it.padLeft( 12 )? + ? " :? " ? + ?wordFrequency[it]? + ? " ?\n? " ?
    }?
    ?
    println?result?



    運行結果:

    ?????????? the:?5
    ?? Groovy:?2
    ????????? that:?2
    ?Collections:?2
    ??????? ?Java:?2
    ????????same:?2?

    ?


    如果所要處理的文本比較復雜,可以使用Regex進行處理,順便說一句,Groovy在語言級別支持Regex!

    posted on 2007-02-01 23:31 山風小子 閱讀(4353) 評論(6)  編輯  收藏 所屬分類: Groovy & Grails
    主站蜘蛛池模板: 超pen个人视频国产免费观看| 最近免费mv在线观看动漫| 在线人成精品免费视频| 久久亚洲精品中文字幕三区| 羞羞网站免费观看| 在线视频免费国产成人| 亚洲aⅴ无码专区在线观看| 免费无码又黄又爽又刺激| 亚洲字幕AV一区二区三区四区| 久久不见久久见免费视频7| 亚洲国产一区国产亚洲| 免费A级毛片无码A∨免费| 91嫩草亚洲精品| 成人片黄网站A毛片免费| 亚洲精品中文字幕| 国产亚洲福利一区二区免费看| 国产精品亚洲综合| 国产亚洲一区二区三区在线不卡 | 搡女人真爽免费视频大全| 亚洲а∨天堂久久精品9966| 韩国欧洲一级毛片免费| 黄色免费网址大全| 亚洲AV无码AV男人的天堂| 日韩精品人妻系列无码专区免费 | 毛片在线播放免费观看| 亚洲欧洲精品国产区| 日本高清免费不卡视频| 皇色在线免费视频| 亚洲福利电影一区二区?| 成年美女黄网站18禁免费| 丁香六月婷婷精品免费观看| 久久精品国产亚洲| 女人18毛片特级一级免费视频 | 成人免费毛片视频| 亚洲国产免费综合| 亚洲国产精品综合一区在线 | 久久久久亚洲?V成人无码| 久久99热精品免费观看动漫| 亚洲色成人网站WWW永久四虎| 久久精品国产亚洲AV不卡| 国产又大又粗又长免费视频|