问题
I am trying to get POS tags using nltk, i think it should take less then or around 1 sencond for processing small text. But 2-3 sentence it takes 20-25 second.
import nltk,re, time
def findPos( text):
start_time = time.time()
try:
tokens = nltk.word_tokenize(text)
pos_tags = nltk.pos_tag(tokens)
print [ x[0] for x in pos_tags if x[1] == "NN" or "NNP"]
except Exception:
import traceback
traceback.format_exc()
print("--- %s seconds ---" % (time.time() - start_time))
findPos(raw_input())
Any suggestion how to reduce time ere?
来源:https://stackoverflow.com/questions/33558836/pos-tagging-using-nltk-takes-time