Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def add_to_corpus_index(corpus_index,word,next_word):
  2.     for el in corpus_index:
  3.         if el[0]==word:
  4.             el[1].append(next_word)
  5.             return
  6.         corpus_index.append([word,[next_word]])
  7. def add_all_to_corpus_index(corpus_index,corpus):
  8.     splitted_text=corpus.split()
  9.     for i in range(len(splitted_text)-1):
  10.         current_word,next_word=splitted_text[i],splitted_text[i+1]
  11.         add_to_corpus_index(corpus_index,current_word,next_word)
  12. corpus="Today is Sunday. I stay at home and keep coding. Today is Monday. I stay at office and keep cleaning. Today I stay awake."
  13. corpus_index=[]
  14. add_all_to_corpus_index(corpus_index, corpus)
  15. print(corpus_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement