Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added algorithm to sum all of the similar reviews from a single user

  • Loading branch information...
commit 6e6e5930a253db623285982e1424c8de217d5edd 1 parent edea5cf
Robert Greiner authored November 07, 2011
1  Recommender.Tests/Recommender.Tests.csproj
@@ -53,6 +53,7 @@
53 53
     <Compile Include="Properties\AssemblyInfo.cs" />
54 54
     <Compile Include="Reviews\ReviewerTests.cs" />
55 55
     <Compile Include="Steps\SumDifferenceSquaresTests.cs" />
  56
+    <Compile Include="Steps\SumSimilarScoresTests.cs" />
56 57
   </ItemGroup>
57 58
   <ItemGroup>
58 59
     <None Include="packages.config" />
48  Recommender.Tests/Steps/SumSimilarScoresTests.cs
... ...
@@ -0,0 +1,48 @@
  1
+using System;
  2
+using System.Collections.Generic;
  3
+using System.Linq;
  4
+using System.Text;
  5
+using NUnit.Framework;
  6
+using Recommender.Common;
  7
+using Recommender.Data;
  8
+using Recommender.Reviews;
  9
+using Recommender.Steps;
  10
+
  11
+namespace Recommender.Tests.Steps
  12
+{
  13
+    [TestFixture]
  14
+    class SumSimilarScoresTests
  15
+    {
  16
+        private Reviewer r1;
  17
+        private Reviewer r2;
  18
+        private List<String> similarReviews;
  19
+
  20
+        [SetUp]
  21
+        public void SetUp()
  22
+        {
  23
+            r1 = ReviewerBuilder.BuildReviewer1();
  24
+            r2 = ReviewerBuilder.BuildReviewer2();
  25
+            similarReviews = new FindSimilarReviews(r1.Reviews, r2.Reviews).Calculate();
  26
+        }
  27
+
  28
+        [Test]
  29
+        public void SumASingleScoreFromOneUser()
  30
+        {
  31
+            r1 = ReviewerBuilder.BuildOneReviewMax();
  32
+            similarReviews = new List<string>(new String[] {"C# in Depth"});
  33
+            Assert.AreEqual(5.0, new SumSimilarScores(similarReviews, r1.Reviews).Calculate());
  34
+        }
  35
+
  36
+        [Test]
  37
+        public void ShouldSumAllOfTheScoresFromTheFirstUser()
  38
+        {
  39
+            Assert.AreEqual(18.0, new SumSimilarScores(similarReviews, r1.Reviews).Calculate());
  40
+        }
  41
+
  42
+        [Test]
  43
+        public void ShouldSumAllOfTheScoresFromTheSecondUser()
  44
+        {
  45
+            Assert.AreEqual(19.5, new SumSimilarScores(similarReviews, r2.Reviews).Calculate());
  46
+        }
  47
+    }
  48
+}
17  Recommender/PearsonCorrelation.cs
@@ -2,10 +2,25 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Text;
  5
+using Recommender.Reviews;
5 6
 
6 7
 namespace Recommender
7 8
 {
8  
-    class PearsonCorrelation
  9
+    class PearsonCorrelation : SimilarityScore
9 10
     {
  11
+        private readonly Reviewer R1;
  12
+        private readonly Reviewer R2;
  13
+        private List<string> SimilarReviews;
  14
+
  15
+        public PearsonCorrelation(Reviewer r1, Reviewer r2)
  16
+        {
  17
+            R1 = r1;
  18
+            R2 = r2;
  19
+        }
  20
+
  21
+        public double Score()
  22
+        {
  23
+            return 0.0;
  24
+        }
10 25
     }
11 26
 }
1  Recommender/Recommender.csproj
@@ -53,6 +53,7 @@
53 53
     <Compile Include="Properties\AssemblyInfo.cs" />
54 54
     <Compile Include="Steps\SimilarityScoreCommand.cs" />
55 55
     <Compile Include="Steps\SumDifferenceSquares.cs" />
  56
+    <Compile Include="Steps\SumSimilarScores.cs" />
56 57
   </ItemGroup>
57 58
   <ItemGroup />
58 59
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
24  Recommender/Steps/SumSimilarScores.cs
... ...
@@ -0,0 +1,24 @@
  1
+using System;
  2
+using System.Collections.Generic;
  3
+using System.Linq;
  4
+using System.Text;
  5
+
  6
+namespace Recommender.Steps
  7
+{
  8
+    public class SumSimilarScores : SimilarityScoreCommand
  9
+    {
  10
+        private readonly List<string> SimilarReviews;
  11
+        private readonly Dictionary<string, double> UserReviews;
  12
+
  13
+        public SumSimilarScores(List<string> similarReviews, Dictionary<string, double> userReviews)
  14
+        {
  15
+            SimilarReviews = similarReviews;
  16
+            UserReviews = userReviews;
  17
+        }
  18
+
  19
+        public double Calculate()
  20
+        {
  21
+            return SimilarReviews.Sum(title => UserReviews[title]);
  22
+        }
  23
+    }
  24
+}

0 notes on commit 6e6e593

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