我正在使用Twitter進行項目,其中一部分是取出推文中的所有表情符號,以便它不會觸發解析器。我看了一下卡內基梅隆的方舟鳴叫NLP,它非常驚人,他們有這個非常好的Java正則表達式模式來檢測表情符號!將Java正則表達式運算符轉換爲Scala正則表達式
不過,我不完全熟悉Java的正則表達式語法(我熟悉基本的)
https://github.com/brendano/ark-tweet-nlp/blob/master/src/cmu/arktweetnlp/Twokenize.java
我需要轉換爲Scala的代碼看起來是這樣的:
public static String emoticon = OR(
// Standard version :) :(:] :D :P
"(?:>|>)?" + OR(normalEyes, wink) + OR(noseArea,"[Oo]") +
OR(tongue+"(?=\\W|$|RT|rt|Rt)", otherMouths+"(?=\\W|$|RT|rt|Rt)", sadMouths, happyMouths),
// reversed version (: D: use positive lookbehind to remove "(word):"
// because eyes on the right side is more ambiguous with the standard usage of : ;
"(?<=(?: |^))" + OR(sadMouths,happyMouths,otherMouths) + noseArea + OR(normalEyes, wink) + "(?:<|<)?",
//inspired by http://en.wikipedia.org/wiki/User:Scapler/emoticons#East_Asian_style
eastEmote.replaceFirst("2", "1"), basicface
// iOS 'emoji' characters (some smileys, some symbols) [\ue001-\uebbb]
// TODO should try a big precompiled lexicon from Wikipedia, Dan Ramage told me (BTO) he does this
);
運營商OR
有點混亂。
所以任何人都可以讓我知道如何做轉換?轉換之後,我所需要做的就是快速分割成單詞,並看到word.contains(emoticon)
對不對?謝謝!
看起來好像上面的問題是相當愚蠢的。然而,我還不知道最後一點任務:
我正在把那些表情帶出我的句子。如果我只是用空格將我的句子分成單詞,並且爲(word <- words if !word.contains(regexpattern))
做什麼,它會起作用嗎?
有沒有'或'運營商。這是Twokenize類中的靜態方法。 –
將'public static String emoticon'更改爲'val表情符號:String',這可能是Scala代碼。 Scala使用與Java相同的正則表達式引擎,也可以使用arktweetnlp庫。 – wingedsubmariner