Skip to content
Browse files

Working on recommending items to a reviewer

  • Loading branch information...
1 parent 7a06753 commit 425010f29296f0aa0608d2ac8de0999b1f7d3bc6 @robertgreiner committed Nov 14, 2011
View
34 Recommender.Tests/Common/RecommendItemsTests.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using Recommender.Common;
+using Recommender.Data;
+using Recommender.Reviews;
+using Recommender.SimilarityScore;
+
+namespace Recommender.Tests.Common
+{
+ [TestFixture]
+ class RecommendItemsTests
+ {
+ private List<Reviewer> reviewers;
+ private Reviewer currentUser;
+ IOrderedEnumerable<KeyValuePair<Reviewer, double>> sortedReviewers;
+
+ [SetUp]
+ public void SetUp()
+ {
+ currentUser = ReviewerBuilder.BuildReviewerThatNeedsRecommendations();
+ reviewers = ReviewerBuilder.BuildReviewers();
+ }
+
+ [Test]
+ public void ShouldRecommendAnItem()
+ {
+ var r = new RecommendItems(currentUser, reviewers).Calculate();
+ Assert.AreEqual(4, r.Count);
+ }
+ }
+}
View
2 Recommender.Tests/Recommender.Tests.csproj
@@ -50,8 +50,10 @@
<Reference Include="System.Data" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Common\FindOppositeReviewsTests.cs" />
<Compile Include="Common\FindSimilarReviewsTests.cs" />
<Compile Include="Common\RankReviewersTests.cs" />
+ <Compile Include="Common\RecommendItemsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reviews\ReviewerTests.cs" />
<Compile Include="Instructions\SumProductsTests.cs" />
View
47 Recommender/Common/RecommendItems.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Recommender.Reviews;
+using Recommender.SimilarityScore;
+
+namespace Recommender.Common
+{
+ public class RecommendItems
+ {
+ private readonly Reviewer CurrentUser;
+ private readonly List<Reviewer> Reviewers;
+
+
+ public RecommendItems(Reviewer currentUser, List<Reviewer> reviewers)
+ {
+ CurrentUser = currentUser;
+ Reviewers = reviewers;
+ }
+
+ public List<string> Calculate()
+ {
+ var recommendations = new HashSet<string>();
+ foreach (var r in Reviewers)
+ {
+
+ var score = new EuclideanDistance(CurrentUser, r).Score();
+ if (score <= 0)
+ {
+ continue;
+ }
+ var oppositeItems = new FindOppositeReviews(CurrentUser.Reviews, r.Reviews).Calculate();
+
+ //TODO: Right now, this method recommends all items not reviewed by the current user.
+ //Next, I will calculate a weighted average for each item and order the recommended items accordingly.
+ //Calculated weighted score => r.Reviews[item] * score
+ foreach (var item in oppositeItems)
+ {
+ recommendations.Add(item);
+ }
+ }
+
+ return recommendations.ToList();
+ }
+ }
+}
View
8 Recommender/Data/ReviewerBuilder.cs
@@ -174,6 +174,14 @@ public static Reviewer BuildReviewerWithInvalidReviews()
reviewer.AddReview("C# in Depth", -2.0);
return reviewer;
}
+
+ public static Reviewer BuildReviewerThatNeedsRecommendations()
+ {
+ var reviewer = new Reviewer { Name = "JoeProgrammer" };
+ reviewer.AddReview("Code Complete", 3.0);
+ reviewer.AddReview("C# in Depth", 4.5);
+ return reviewer;
+ }
public static List<Reviewer> BuildReviewers()
{
View
2 Recommender/Recommender.csproj
@@ -43,8 +43,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Common\FindOppositeReviews.cs" />
<Compile Include="Common\FindSimilarReviews.cs" />
<Compile Include="Common\RankReviewers.cs" />
+ <Compile Include="Common\RecommendItems.cs" />
<Compile Include="Data\ReviewerBuilder.cs" />
<Compile Include="Reviews\Reviewer.cs" />
<Compile Include="SimilarityScoreRunner.cs" />

0 comments on commit 425010f

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