2012-06-22 17 views
-4

我不是很熟悉NLTk和蟒蛇,我必須執行以下任務的程序:發現卦使用NLTK

  1. 記號化和小寫輸入的text1
  2. 記號化輸入文本2
  3. 找到所有輸入的text1

任何人都可以幫我嗎?

+3

沒有顯示你自己的努力「任何人都可以幫助」聽起來像「任何人都可以爲我做這件事」。答案可能不是。 – georg

+4

這聽起來像是功課似的... – aab

回答

0

text1text2的一部分nltk的例子?然後看看它們,你會發現標記化並不像你想象的那麼多:-)

對於小型化,請看任何介紹性的python教程。對於卦,請查看nltk書。

-1

的情況下,如果你沒有爲 要找到所有卦的例子中,你應該首先記號化它

>>> import nltk 
>>> from nltk import word_tokenize 
>>> from nltk.util import ngrams 
>>> text1 = "Hi How are you? i am fine and you" 
>>> token=nltk.word_tokenize(text1) #tokenize your text 
>>> tttt=nltk.word_tokenize(text.lower()) #tokenize your text and make it lowercase in onestep 
>>> tttt 
['hi', 'how', 'are', 'you', '?', 'i', 'am', 'fine', 'and', 'you'] 

>>> trigrams=ngrams(token,3)   # find all the trigram in text1 
>>> trigrams 
[('Hi', 'How', 'are'), ('How', 'are', 'you'), ('are', 'you', '?'), ('you', '?', 'i'), ('?', 'i', 'am'), ('i', 'am', 'fine'), ('am', 'fine', 'and'), ('fine', 'and', 'you')] 

有關使您的text2你只需要應用標記化的步驟