Skip to main content
. 2021 Aug 23;21(16):5666. doi: 10.3390/s21165666
Algorithm 1. Rating prediction based on sentiment for user ua and item ij.
1. Function sentiment_ratingPred (user ua, item ij) {
2. //This function is used to obtain thepr_sentajterm of Equation (1)
3.  //Step 1:
4.  FOR each item ik in the training set:
5.   IF user ua already rated item ik AND review score matches rating THEN
6.    Add ik to list of items I;
7. //The result of this step is a set of m items  I={i1,i2,im}
8. //Step 2:
9.  FOR each user ub in the training set:
10.   FOR each item ik in the set of items I:
11.    IF user ub already rated item ij AND user ub already rated item ik
      AND their review scores match ratings
12.     Add user ub to list of users U;
13. //The results of this step is a set of n users  U={u1,u2,un}
14. //Step 3:
15.  IF length(U)>0 THEN
16.   FOR each user ui in the set of user U:
17.    Compute sa,i= sim (user ua, user ui) by applying cosine metric;
18.    Add sa,i to S;
19.   //The result is a set of n similarity values  S={sa,i}
20.   Set the K value to select the K nearest neighbors using S;
21.   Compute the predicted rating praj by applying the Equation (2);
22.    pr_sentaj=praj
23.   Return pr_sentaj;
24.  ELSE
25.   Return 0;
26. }