Skip to content
Browse files

add more paths and finish the reindex function

  • Loading branch information...
1 parent 78f78be commit 17a8daa97f78f80d03b13e6bfba1b9e130402ae9 @Ykid Ykid committed
Showing with 14 additions and 3 deletions.
  1. +14 −3 utils/neighborhood
17 utils/neighborhood
@@ -3,20 +3,22 @@
#The TrainFile is in format of "uid \t mid \t rating"
#The PredFile is in format of "uid \t mid \t rating"
#The MovieTagFile is in format of "mid \t tag1,tag2,......."
+#The CVFile is in format of "uid \t mid \t rating"
#For output
#The TrainFileReindex is in formate of "uid \t mid \t rating", with reindexed
#The PredFileReindex is in format of "uid \t mid \t rating",with reindexed
#The MovieTagFileReindex is in format of "mid \t tag1,tag2,.......", with reindexed
-def reIndex(fin,gin,hin,fout,gout,hout):
+#The CVFileReindex is in format of "uid \t mid \t rating",with reindexed
+def reIndex(fin,gin,hin,CVfin,fout,gout,hout,CVfout):
TrainFile =open(fin,'r')
MovieTagFile =open(gin,'r')
PredFile =open(hin,'r')
+ CVFile =open(CVin,'r')
TrainFileReindex =open(fout,'w')
MovieTagFileReindex =open(gout,'w')
PredFileReindex =open(hout,'w')
+ CVFileReindex =open(CVfout,'w')
uidDic={} #Key is original uid. Corresponding value is reindexed uid
midDic={} #Key is original mid. Corresponding value is reindexed mid
@@ -45,6 +47,13 @@ def reIndex(fin,gin,hin,fout,gout,hout):
TrainFileReindex.write('%d\t%d\t%d\n' %(uidDic[uid],midDic[mid],rating))
+#this part is for reindexing CVfile
+ for line in CVFile:
+ arr=line.split()
+ uid=int(arr[0].strip())
+ mid=int(arr[1].strip())
+ rating=int(float(arr[2].strip()))
+ CVFileReindex.write('%d\t%d\t%d\n' %(uidDic[uid],midDic[mid],rating))
#this part is for reindexing movie-tag file
for line in MovieTagFile:
@@ -85,9 +94,11 @@ def reIndex(fin,gin,hin,fout,gout,hout):
+ CVFileReindex.close()
+ CVFile.close()
#This function is going to use movie_tag_new.txt to get movie pairs which have certain number of tags in common

0 comments on commit 17a8daa

Please sign in to comment.
Something went wrong with that request. Please try again.