/// <summary> /// Look at the top 10 programs learned from a single example for normalizing a phone number like in /// <see cref="LearnNormalizePhoneNumber" /> and show the behavior of them on a couple other phone nubmers. /// Demonstrates learning more than just the single top program, and shows the variation in outputs /// among the top-ranked programs on unseen input formats. /// </summary> /// <seealso cref="LearnTop10FormatName" /> private static void LearnTop10NormalizePhoneNumber() { IEnumerable <FlashFillExample> examples = new[] { new FlashFillExample("(425) 829 5512", "425-829-5512") }; // Request is for number of distinct rankings, not number of programs, // so more programs will be generated if there are ties. int numRankingsToGenerate = 10; IList <FlashFillProgram> programs = FlashFillProgram.LearnTopK(examples, k: numRankingsToGenerate).ToList(); if (!programs.Any()) { Console.Error.WriteLine("Error: failed to learn normalize phone number program."); } else { // More than numRankingsToGenerate programs may be generated if there are ties in the ranking. Console.WriteLine("Learned {0} programs.", programs.Count); // Run all of the programs to see how their output differs. for (int i = 0; i < programs.Count; i++) { foreach (var phoneNumber in new[] { "425 233 1234", "(425) 777 3333" }) { string normalized = programs[i].Run(phoneNumber); Console.WriteLine("Program {2}: \"{0}\" => \"{1}\"", phoneNumber, normalized, (i + 1)); } } } }
/// <summary> /// Look at the top 10 programs learned from a single example for formatting a name like in /// <see cref="LearnFormatName" /> and show the behavior of them on slightly differently formatted name. /// Demonstrates learning more than just the single top program, and shows the variation in outputs /// among the top-ranked programs on unseen input formats. /// </summary> /// <seealso cref="LearnTop10NormalizePhoneNumber" /> private static void LearnTop10FormatName() { var examples = new[] { new FlashFillExample("Greta Hermansson", "Hermansson, G.") }; IEnumerable <FlashFillProgram> programs = FlashFillProgram.LearnTopK(examples, k: 10); // This attempts running the top 10 programs on an input not directly similar to the example // to see if any of them work anyway. int i = 0; foreach (var program in programs) { var input = "Kettil hansson"; // Notice it's "hansson", not "Hansson". Console.WriteLine("Program {0}: \"{1}\" => \"{2}\"", ++i, input, program.Run(input)); } }