Question: Given a simple python code,I try to write a same Java code to implement nested symbol table.Here is the given python code. def loadMovieLens(path='data'): #
Given a simple python code,I try to write a same Java code to implement nested symbol table.Here is the given python code.
def loadMovieLens(path='data'): # Get movie titles movies={} for line in open(path+'/u.item', encoding='latin-1'): (id,title)=line.split('|')[0:2] # 1|Toy Story movies[id]=title # Load data prefs={} for line in open(path+'/u.data', encoding='latin-1'): (user,movieid,rating,ts)=line.split('\t') prefs.setdefault(user,{}) prefs[user][movies[movieid]]=float(rating) return prefs print(" 10 critics for 85th person from Movielens Dataset") i = 0 for movie in prefs['85'].keys(): if i < 10: print(i, " ",movie, ": ", prefs['85'][movie]) i +=1 //Output
10 critics for 85th person from Movielens Dataset 0 To Kill a Mockingbird (1962) : 3.0 1 Streetcar Named Desire, A (1951) : 4.0 2 George of the Jungle (1997) : 2.0 3 Beauty and the Beast (1991) : 3.0 4 Legends of the Fall (1994) : 2.0 5 Koyaanisqatsi (1983) : 3.0 6 Star Trek: The Wrath of Khan (1982) : 3.0 7 Grifters, The (1990) : 4.0 8 Heathers (1989) : 3.0 9 Birdcage, The (1996) : 2.0
Where the data is in the link http://files.grouplens.org/datasets/movielens/ml-100k.zip
So I need to create nested dictionaries(using HashTable) and store them with the given data.Here is my Java code:
SeparateChainingHashST > a;
a = new SeparateChainingHashST<>();
for(int i=0;i
a.put(userList.get(i), new SeparateChainingHashST<>());
a.get(userList.get(i)).put(movieList.get(i), rankList.get(i));
}
where userList is the first column ,movieList is the second column and rankList is the third column of the u.data and they are ArrayList.
Just like the above python code when I write for example a.get(15) I want to know which movies does user 15 give ranking but it doesn't seem to work for this code.
Reminder,we have given SeparateChainingHashST class and it uses LinkedLists in collision situations, so I don't need to create class and it is not allowed to import Collections class.Just what I need to do is to read the data and populate the HashTable according to that data.
My question is to how to write proper Java code according the provided python code and data?Because given python code is the correct code for this project provided by our professor.
Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
