Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import nltk
  2. from nltk.tokenize.moses import MosesDetokenizer
  3.  
  4. my_dict = {'abc': 'aBc'}  # put your special dict here
  5.  
  6. # split the sentence in words
  7. words = nltk.word_tokenize(raw_sentence)
  8.  
  9. # replace those that map in the dict
  10. new_words = [my_dict.get(word.lower(), word) for word in words]
  11.  
  12. # now we construct it back to sentence
  13. detokenizer = MosesDetokenizer()
  14. detokenizer.detokenize(new_words, return_str=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement