public void Without_any_excluded_facts_and_multiple_variants_then_all_possible_opening_facts_are_generated() { //Given var openingsFactsGenerator = new OpeningsFactsGenerator(); var chessGame = new ChessGame(); chessGame.White = "tailuge"; chessGame.Black = "sydeman"; chessGame.Result = "1-0"; chessGame.Opening = "King's Gambit, Polerio Gambit, something here, Accepted"; //When var result = openingsFactsGenerator.Generate(new List <IFact <ChessGame> >(), chessGame); //Then var kingsGambitFact = new OpeningFact("King's Gambit"); var kingsGambitPolerioGambitFact = new OpeningFact("King's Gambit, Polerio Gambit"); var kingsGambitPolerioGambitSomethingHereFact = new OpeningFact("King's Gambit, Polerio Gambit, something here"); var kingsGambitPolerioGambitAcceptedFact = new OpeningFact("King's Gambit, Polerio Gambit, something here, Accepted"); var gambit = new OpeningFact("Gambit"); Assert.Equal(5, result.Count); Assert.Contains(kingsGambitFact, result); Assert.Contains(kingsGambitPolerioGambitFact, result); Assert.Contains(kingsGambitPolerioGambitAcceptedFact, result); Assert.Contains(kingsGambitPolerioGambitSomethingHereFact, result); Assert.Contains(gambit, result); }
public void When_implies_is_called_with_openings_without_any_words_in_common_and_no_implication_exists() { //Given var thisFact = new OpeningFact("King's Gambit"); var impliedFact = new OpeningFact("Indian Game"); //When Assert.False(thisFact.Implies(impliedFact)); // <-- Then }
public void When_implies_is_called_with_gambit_opening_and_an_implication_exists() { //Given var thisFact = new OpeningFact("King's Gambit"); var impliedFact = new OpeningFact("Gambit"); //When Assert.True(thisFact.Implies(impliedFact)); // <-- Then }
public void When_implies_is_called_with_openings_with_words_in_common_and_no_implication_exists() { //Given var thisFact = new OpeningFact("King's Gambit, Modern Defense"); var impliedFact = new OpeningFact("Modern Defense"); //When Assert.False(thisFact.Implies(impliedFact)); // <-- Then Assert.False(impliedFact.Implies(thisFact)); }
public void When_IsTrue_is_called_without_satisying_opening_return_false() { //Given var thisFact = new OpeningFact("Indian Game"); var game = new ChessGame(); game.Opening = "King's Gambit, Accepted"; //When Assert.False(thisFact.IsTrue(game)); // <-- Then }
public void When_IsTrue_is_called_on_GambitOpeningFact_with_satisying_opening_return_true() { //Given var thisFact = new OpeningFact("Gambit"); var game = new ChessGame(); game.Opening = "King's Gambit, Accepted"; //When Assert.True(thisFact.IsTrue(game)); // <-- Then }
public void When_IsTrue_is_called_with_non_satisying_opening_with_words_in_common_return_false() { //Given var thisFact = new OpeningFact("King's Gambit, Accepted, Modern Defense"); var game = new ChessGame(); game.Opening = "Modern Defense"; //When Assert.False(thisFact.IsTrue(game)); // <-- Then //Given thisFact = new OpeningFact("Modern Defense"); game.Opening = "King's Gambit, Accepted, Modern Defense"; //When Assert.False(thisFact.IsTrue(game)); // <-- Then }
public void Without_any_excluded_facts_and_with_an_opening_without_any_variants_then_no_variant_openings_are_generated(string opening) { //Given var openingsFactsGenerator = new OpeningsFactsGenerator(); var chessGame = new ChessGame(); chessGame.White = "tailuge"; chessGame.Black = "sydeman"; chessGame.Result = "1-0"; chessGame.Opening = opening; //When var result = openingsFactsGenerator.Generate(new List <IFact <ChessGame> >(), chessGame); //Then var openingFact = new OpeningFact(opening); Assert.Equal(1, result.Count); Assert.Contains(openingFact, result); }
public void With_excluded_facts_then_opening_facts_are_generated_that_are_not_in_the_exclusion_list() { //Given var openingsFactsGenerator = new OpeningsFactsGenerator(); var chessGame = new ChessGame(); chessGame.White = "tailuge"; chessGame.Black = "sydeman"; chessGame.Result = "1-0"; chessGame.Opening = "King's Gambit, Accepted"; //When var kingsGambitAcceptedFact = new OpeningFact("King's Gambit, Accepted"); var result = openingsFactsGenerator.Generate(new List <IFact <ChessGame> >() { kingsGambitAcceptedFact }, chessGame); //Then Assert.Equal(0, result.Count); }
static void Main(string[] args) { List <ChessGame> result; var serializer = new JsonSerializer(); using (var re = File.OpenText("rated.json")) using (var reader = new JsonTextReader(re)) { result = serializer.Deserialize <List <ChessGame> >(reader); } var database = new Database <ChessGame>(result); var projectedFact1 = new OpeningFact("Gambit"); //var projectedFact2 = new SimpleFact("White", "tailuge"); var projectedFacts = new List <IFact <ChessGame> >() { projectedFact1 }; var targetFact = new SimpleFact("Result", "1-0"); var targetFacts = new List <IFact <ChessGame> >() { targetFact }; //Fact Generators var openingFactsGenerator = new OpeningsFactsGenerator(); var simpleFactsGenerator = new SimpleFactsGenerator(); var timeControlFactsGenerator = new TimeControlFactsGenerator(new TimeControlCategoriser()); var takesFirstFactGenerator = new TakesFirstFactGenerator(); var candidateGenerator = new SelfJoinAndPruneGenerator <ChessGame>(); var factGenerators = new List <IFactsGenerator <ChessGame> >() { simpleFactsGenerator, openingFactsGenerator, timeControlFactsGenerator, takesFirstFactGenerator }; var apriori = new Apriori <ChessGame>(candidateGenerator, factGenerators); var filterer = new ThresholdFilterer <ChessGame>(); var candidateRuleGenerator = new CandidateRuleGenerator <ChessGame>(); var ruleGenerator = new AssociationRuleGenerator <ChessGame>(database, apriori, candidateRuleGenerator, filterer); //When var minsup = 0.01; var minconf = 0.1; var rules = ruleGenerator.Generate(minsup, minconf, projectedFacts, targetFacts); var i = 1; using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\tferguson\Documents\Visual Studio 2013\Projects\PatternDiscoveryInDataMining\Week1\chessAssociationRules.txt")) { file.WriteLine("Minsup: " + minsup + ", " + "Minconf: " + minconf); file.WriteLine("For games where " + projectedFacts[0] + ", "); file.WriteLine("there are " + rules.Count + " strong association rules \n"); foreach (var rule in rules) { file.Write(i + ". "); file.WriteLine(rule); i++; } } System.Console.WriteLine("Done!"); System.Console.ReadLine(); }