Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import os
  2.  
  3.  
  4. separator = "+++$+++"
  5.  
  6. def main():
  7. movie_lines_file = "data/movie_lines.txt"
  8. movie_conversations_file = "data/movie_conversations.txt"
  9.  
  10. line_idxs = {}
  11.  
  12. with open(movie_lines_file, "r") as movie_lines:
  13. line = movie_lines.readline()
  14. while line:
  15. line = line.split(separator)
  16. line_idxs[line[0].strip()] = line[4].strip()
  17. line = movie_lines.readline()
  18.  
  19. with open(movie_conversations_file, "r") as movie_conversations:
  20. line = movie_conversations.readline()
  21. counter = 0
  22. while line:
  23. line = line.split(separator)
  24. convo = line[3].strip()
  25. convo = convo.strip('[')
  26. convo = convo.strip(']')
  27. convo = convo.replace('\'', "")
  28. convo = convo.split(", ")
  29. with open("data/cornell_lines/{0}.txt".format(counter), "a+") as f:
  30. f.write("\n".join([line_idxs[idx] for idx in convo]))
  31. counter += 1
  32. line = movie_conversations.readline()
  33.  
  34. if __name__=="__main__":
  35. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement