3

R を使用して、POS と実際の文字列を組み合わせて表現されたパターンをテキストから検索したいと考えています。(私はこの機能をPythonライブラリで見ました: http://www.clips.ua.ac.be/pages/pattern-search )。

たとえば、検索パターンは:'NOUNPHRASE be|is|was ADJECTIVE than NOUNPHRASE'であり、「猫は犬よりも速い」のような構造を含むすべての文字列を返す必要があります。

私は、パッケージが便利な POS タグ付けを好みopenNLP、提供していることを知っています。qdapこの種のパターン マッチングにその出力を使用している人はいますか?

4

1 に答える 1

2

手始めに、 and を使用koRpusTreeTaggerます。

library(koRpus) 
library(tm)
mytxt <- c("This is my house.", "A house is better than no house.", "A cat is faster than a dog.")
pattern <- "Noun, singular or mass.*?Adjective, comparative.*?Noun, singular or mass"

tagged.results <- treetag(file = mytxt, treetagger="C:/TreeTagger/bin/tag-english.bat", lang="en", format="obj", stopwords=stopwords("en")) 
tagged.results <- kRp.filter.wclass(tagged.results, "stopword")
taggedText(tagged.results)$id <- factor(head(cumsum(c(0, taggedText(tagged.results)$desc == "Sentence ending punctuation")) + 1, -1))

setNames(mytxt, grepl(pattern, aggregate(desc~id, taggedText(tagged.results), FUN = paste0)$desc))
#               FALSE                               TRUE                               TRUE 
# "This is my house." "A house is better than no house."      "A cat is faster than a dog."
于 2015-03-30T08:43:42.313 に答える