3

私は、ドキュメントのコレクション内で辞書ベースのテキスト検索を行う小さなプロジェクトに取り組んでいます。私の辞書には肯定的な合図の単語(別名良い単語)がありますが、ドキュメントコレクションで単語を見つけただけでは、肯定的な結果が保証されません。たとえば、これらの肯定的な単語の近くに否定的な単語が存在する可能性があるためです(重要ではありません)。 。文書番号、正の単語、および負の単語への近接度が含まれるようにマトリックスを作成したいと思います。

誰かがそれを行う方法を提案できますか?私のプロジェクトは非常に初期の段階なので、私のテキストの基本的な例を示しています。

No significant drug interactions have been reported in studies of candesartan cilexetil given with other drugs such as glyburide, nifedipine, digoxin, warfarin, hydrochlorothiazide.   

これは、カンデサルタンシレキセチル、グリブリド、ニフェジピン、ジゴキシン、ワルファリン、ヒドロクロロチアジドが私の肯定的な言葉であり、重要ではないという私の否定的な言葉である私の例の文書です。ポジティブな単語とネバティブな単語の間で近接(単語ベース)マッピングを行いたい。

誰かがいくつかの役立つポインタを与えることができますか?

4

2 に答える 2

5

まず第一に、このタスクには R を使用しないことをお勧めします。R は多くの点で優れていますが、テキスト操作はその 1 つではありません。Python は良い代替手段になる可能性があります。

とはいえ、これを R で実装する場合、おそらく次のようにします (非常に大雑把ですが):

# You will probably read these from an external file or a database
goodWords <- c("candesartan cilexetil", "glyburide", "nifedipine", "digoxin", "blabla", "warfarin", "hydrochlorothiazide")
badWords <- c("no significant", "other drugs")

mytext <- "no significant drug interactions have been reported in studies of candesartan cilexetil given with other drugs such as glyburide, nifedipine, digoxin, warfarin, hydrochlorothiazide."
mytext <- tolower(mytext) # Let's make life a little bit easier...

goodPos <- NULL
badPos <- NULL

# First we find the good words
for (w in goodWords)
    {
    pos <- regexpr(w, mytext)
    if (pos != -1)
        {
        cat(paste(w, "found at position", pos, "\n"))
        }
    else    
        {
        pos <- NA
        cat(paste(w, "not found\n"))
        }

    goodPos <- c(goodPos, pos)
    }

# And then the bad words
for (w in badWords)
    {
    pos <- regexpr(w, mytext)
    if (pos != -1)
        {
        cat(paste(w, "found at position", pos, "\n"))
        }
    else    
        {
        pos <- NA
        cat(paste(w, "not found\n"))
        }

    badPos <- c(badPos, pos)
    }

# Note that we use -badPos so that when can calculate the distance with rowSums
comb <- expand.grid(goodPos, -badPos)
wordcomb <- expand.grid(goodWords, badWords)
dst <- cbind(wordcomb, abs(rowSums(comb)))

mn <- which.min(dst[,3])
cat(paste("The closest good-bad word pair is: ", dst[mn, 1],"-", dst[mn, 2],"\n"))
于 2010-06-21T15:15:53.230 に答える
3

どちらかを見ましたか

于 2010-06-21T15:18:08.200 に答える