| Algorithm 1. Rating prediction based on sentiment for user and item . | |
| 1. | Function sentiment_ratingPred (user , item ) { |
| 2. | //This function is used to obtain theterm of Equation (1) |
| 3. | //Step 1: |
| 4. | FOR each item in the training set: |
| 5. | IF user already rated item AND review score matches rating THEN |
| 6. | Add to list of items ; |
| 7. | //The result of this step is a set of m items |
| 8. | //Step 2: |
| 9. | FOR each user in the training set: |
| 10. | FOR each item in the set of items : |
| 11. | IF user already rated item AND user already rated item
AND their review scores match ratings |
| 12. | Add user to list of users ; |
| 13. | //The results of this step is a set of n users |
| 14. | //Step 3: |
| 15. | IF length(U)>0 THEN |
| 16. | FOR each user in the set of user : |
| 17. | Compute = sim (user , user ) by applying cosine metric; |
| 18. | Add to ; |
| 19. | //The result is a set of n similarity values |
| 20. | Set the K value to select the K nearest neighbors using S; |
| 21. | Compute the predicted rating by applying the Equation (2); |
| 22. | |
| 23. | Return ; |
| 24. | ELSE |
| 25. | Return 0; |
| 26. | } |