我正在使用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