public string predictAccentsWithMultiMatches(string sentence, int nResults, bool getWeight = true) { LinkedHashMap <string, double> output = new LinkedHashMap <string, double>(); string @in = Utils.normaliseString(sentence); string lowercaseIn = @in.ToLower(); string[] words = ("0 " + lowercaseIn + " 0").Split(' '); Graph graph = new VariableGraph(); Dictionary <int, string> idxWordMap = new Dictionary <int, string>(); int index = 0; int[] numberP = new int[words.Length]; string[,] possibleChange = new string[words.Length, maxp]; int[,] indices = new int[words.Length, maxp]; int nVertex = 0; index = buildGraph(words, graph, idxWordMap, index, numberP, possibleChange, indices, nVertex); //Yen Algorithm for kShortestPaths YenTopKShortestPathsAlg yenAlg = new YenTopKShortestPathsAlg(graph); List <Accent.KShortestPaths.Model.Path> shortest_paths_list = yenAlg.get_shortest_paths(graph.get_vertex(0), graph.get_vertex(index - 1), nResults); foreach (Accent.KShortestPaths.Model.Path path in shortest_paths_list) { List <BaseVertex> pathVertex = path.get_vertices(); string text = ""; for (int i = 1; i < pathVertex.Count - 1; i++) { BaseVertex vertext = pathVertex[i]; text += idxWordMap[vertext.get_id()] + " "; if (text.Contains("đầm dáng")) { text.Replace("đầm dáng", "đảm đang"); } if (text.Contains("chào bán")) { text = Regex.Replace(text, "chào bán", "chào bạn"); } if (text.Contains("bị đầu tay")) { text = Regex.Replace(text, "bị đầu tay", "bị đau tay"); } if (text.Contains("tay tôi bị đầu")) { text = Regex.Replace(text, "tay tôi bị đầu", "tay tôi bị đau"); } } output.Add(processOutput(@in, text.Trim()), path.get_weight()); } // Không lấy trọng số đo lường cho các trường hợp thêm dấu. if (!getWeight) { return(output.ToString2()); } return(output.ToString()); }
public virtual void TestSortInDescendingOrder() { BlockStoragePolicySuite bsps = BlockStoragePolicySuite.CreateDefaultSuite(); StoragePolicySummary sts = new StoragePolicySummary(bsps.GetAllPolicies()); BlockStoragePolicy hot = bsps.GetPolicy("HOT"); BlockStoragePolicy warm = bsps.GetPolicy("WARM"); BlockStoragePolicy cold = bsps.GetPolicy("COLD"); //DISK:3 sts.Add(new StorageType[] { StorageType.Disk, StorageType.Disk, StorageType.Disk } , hot); sts.Add(new StorageType[] { StorageType.Disk, StorageType.Disk, StorageType.Disk } , hot); //DISK:1,ARCHIVE:2 sts.Add(new StorageType[] { StorageType.Disk, StorageType.Archive, StorageType.Archive }, warm); sts.Add(new StorageType[] { StorageType.Archive, StorageType.Disk, StorageType.Archive }, warm); sts.Add(new StorageType[] { StorageType.Archive, StorageType.Archive, StorageType .Disk }, warm); //ARCHIVE:3 sts.Add(new StorageType[] { StorageType.Archive, StorageType.Archive, StorageType .Archive }, cold); sts.Add(new StorageType[] { StorageType.Archive, StorageType.Archive, StorageType .Archive }, cold); sts.Add(new StorageType[] { StorageType.Archive, StorageType.Archive, StorageType .Archive }, cold); sts.Add(new StorageType[] { StorageType.Archive, StorageType.Archive, StorageType .Archive }, cold); IDictionary <string, long> actualOutput = ConvertToStringMap(sts); NUnit.Framework.Assert.AreEqual(3, actualOutput.Count); IDictionary <string, long> expectedOutput = new LinkedHashMap <string, long>(); expectedOutput["COLD|ARCHIVE:3(COLD)"] = 4l; expectedOutput["WARM|DISK:1,ARCHIVE:2(WARM)"] = 3l; expectedOutput["HOT|DISK:3(HOT)"] = 2l; NUnit.Framework.Assert.AreEqual(expectedOutput.ToString(), actualOutput.ToString( )); }