public void Classify() { Dictionary <Product, ProductClass> setClass = new Dictionary <Product, ProductClass>(); ProductClassRepository productClassRepository = new ProductClassRepository(); ProductRepository productRepository = new ProductRepository(); List <ProductClass> productClasses = productClassRepository.GetAllProductClasses(); List <Product> products = productRepository.GetAllProducts(); foreach (var product in products) { float similarity = 0.0F; Dictionary <ProductClass, float> res = new Dictionary <ProductClass, float>(); foreach (var cl in productClasses) { string tagStr = ""; foreach (var tag in cl.ClassTags) { tagStr += tag.Tag.TagName + " "; } MatchsMaker match = new MatchsMaker(ReplaceBadStrings(product.Name), tagStr); res.Add(cl, match.Score); //if (similarity < match.Score) //{ // similarity = match.Score; // if (setClass.ContainsKey(product)) // { // setClass.Remove(product); // } // setClass.Add(product, cl); // string output = "Product: " + product.Name + " is " + cl.Name + "(" + tagStr + ") with " + similarity * 100.0 + "% confidence."; // Console.WriteLine(output); // if (!File.Exists(filePath)) // { // File.WriteAllText(filePath, output + Environment.NewLine); // } // else // { // File.AppendAllText(filePath, output + Environment.NewLine); // } //} } var result = res.ToList(); result.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value)); Console.WriteLine("Лучшие 3 совпадения для " + product.Name + ":"); if (!File.Exists(filePath)) { File.WriteAllText(filePath, "Лучшие 3 совпадения для " + product.Name + ":" + Environment.NewLine); } else { File.AppendAllText(filePath, "Лучшие 3 совпадения для " + product.Name + ":" + Environment.NewLine); } for (int i = 0; i < 3; i++) { string output = "Product: " + product.Name + " is " + result.ElementAt(i).Key.Name + " with " + result.ElementAt(i).Value * 100.0 + "% confidence."; Console.WriteLine(output); File.AppendAllText(filePath, output + Environment.NewLine); } } }
public void ClassifyV3() { Dictionary <Product, ProductClass> setClass = new Dictionary <Product, ProductClass>(); ProductClassRepository productClassRepository = new ProductClassRepository(); ProductRepository productRepository = new ProductRepository(); List <ProductClass> productClasses = productClassRepository.GetAllProductClasses(); List <Product> products = productRepository.GetAllProducts(); foreach (var product in products) { float similarity = 0.0F; Dictionary <ProductClass, float> res = new Dictionary <ProductClass, float>(); foreach (var cl in productClasses) { MatchsMaker match = new MatchsMaker(ReplaceBadStrings(product.Name), ReplaceBadStrings(cl.Name)); res.Add(cl, match.Score); } var result = res.ToList(); result.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value)); Console.WriteLine("Лучшие 3 совпадения для " + product.Name + ":"); if (!File.Exists(filePath)) { File.WriteAllText(filePath, "Лучшие 3 совпадения для " + product.Name + ":" + Environment.NewLine); } else { File.AppendAllText(filePath, "Лучшие 3 совпадения для " + product.Name + ":" + Environment.NewLine); } for (int i = 0; i < 3; i++) { string output = "Product: " + product.Name + " is " + result.ElementAt(i).Key.Name + " with " + result.ElementAt(i).Value * 100.0 + "% confidence."; Console.WriteLine(output); File.AppendAllText(filePath, output + Environment.NewLine); } } }