public void analyzeConditional(TextKeeper keeper, Int32 languageId) { Char symbolFirst, symbolSecond; Int32 indexFirst, indexSecond; Int64 currentTextLength = 0; foreach (String line in keeper.getText()) { for (int i = 0; i < line.Length; i++) { symbolFirst = line[i]; indexFirst = Helper.getCharIndex(symbolFirst, languageId); if (i != line.Length - 1) { symbolSecond = line[i + 1]; indexSecond = Helper.getCharIndex(symbolSecond, languageId); if (indexFirst != -1 && indexSecond != -1) { conditionalFrequencies[indexFirst, indexSecond] += 1; currentTextLength++; } } } } this.textLength = currentTextLength; }
public void countPerformance(TextKeeper keeper) { Double performance = 0; Int32 arraySize = conditionalFrequencies.GetLength(0); // Длина текста может быть разной: // Хранитель знает полную длину текста из всех символов // Анализатор знает длину текста значащих символов for (int i = 0; i < arraySize; i++) { int j = 0; foreach (KeyValuePair <String, Int32> pair in this.getAbsoluteFrequencies()) { Double p_j = ((Double)pair.Value / keeper.textLength); Double p_i_j = ((Double)conditionalFrequencies[i, j] / partialFrequencies[j]); if (p_i_j != 0) { performance += p_i_j * p_j * Math.Log(p_i_j, 2); } j++; } } performance *= -1; this.performance = performance; }
public void analyze(TextKeeper keeper) { foreach (String line in keeper.getText()) { foreach (Char sym in line.ToLower()) { if (absoluteFrequencies.ContainsKey(sym.ToString())) { absoluteFrequencies[sym.ToString()] += 1; } } } }
public void analyzePartial(TextKeeper keeper, Int32 languageId) { Int32 arrayLength = this.getConditionalFrequencies().GetLength(0); for (int i = 0; i < arrayLength; i++) { Int32 partialSize = 0; for (int j = 0; j < arrayLength; j++) { partialSize += conditionalFrequencies[j, i]; } this.partialFrequencies.Add(partialSize); } }
public void countEntropy(TextKeeper keeper) { Double entropy = 0; foreach (KeyValuePair <String, Int32> pair in this.getAbsoluteFrequencies()) { Double p_i = ((Double)pair.Value / keeper.textLength); if (p_i != 0) { entropy += p_i * Math.Log(p_i, 2); } } entropy *= -1; this.entropy = entropy; }
public MainForm() { InitializeComponent(); keeper = new TextKeeper(); analyzer = new Analyzer(); }