public int RankOf(string Token) { ITokenStats stats = this[Token]; if (stats != null) return stats.Rank; return -1; }
public int PositionOf(string Token) { ITokenStats stats = this[Token]; if (stats != null) return stats.Position; return -1; }
/// <summary> /// Access a single TokenStats by its token /// </summary> /// <param name="token">the token to look for</param> /// <returns>the found ITokenStats or null if not found</returns> public ITokenStats this[string token] { get { ITokenStats result = null; this.m_InnerDict.TryGetValue(token, out result); return result; } }
private void cbTables_SelectedIndexChanged(object sender, EventArgs e) { string lang = ((CultureInfo)cbTables.SelectedItem).TwoLetterISOLanguageName; ITokenTable table = this.m_Model[lang] as TokenTable; int maxRank = 0; int maxWordRank = 0; int maxCharRank = 0; lvNGrams.BeginUpdate(); lvNGrams.Items.Clear(); lvWords.BeginUpdate(); lvWords.Items.Clear(); listView3.BeginUpdate(); listView3.Items.Clear(); lvCharset.BeginUpdate(); lvCharset.Items.Clear(); foreach (string key in table.Keys) { ITokenStats stats = table[key]; maxRank = System.Math.Max(maxRank, stats.Rank); ListViewItem item = new ListViewItem(stats.Position.ToString()); item.SubItems.Add(stats.Token); item.SubItems.Add(stats.Rank.ToString()); item.SubItems.Add(stats.Occurences.ToString()); StringBuilder sbHex = new StringBuilder(); foreach (char c in stats.Token) { int Val = (int)c; if (c > 255) { sbHex.AppendFormat("{0}{1} ", Convert.ToString((byte)((c & 0xff00) >> 8), 16), Convert.ToString((byte)c, 16)); } else { sbHex.AppendFormat("{0} ", Convert.ToString((byte)c, 16)); } } item.SubItems.Add(sbHex.ToString().Trim()); lvNGrams.Items.Add(item); } ITokenTable wordTable = table.WordTable; foreach (string key in wordTable.Keys) { ITokenStats stats = wordTable[key]; maxWordRank = System.Math.Max(maxWordRank, stats.Rank); ListViewItem item = new ListViewItem(stats.Position.ToString()); item.SubItems.Add(stats.Token); item.SubItems.Add(stats.Rank.ToString()); item.SubItems.Add(stats.Occurences.ToString()); lvWords.Items.Add(item); } ITokenTable charsetTable = table.CharsetTable; foreach (string key in charsetTable.Keys) { ITokenStats stats = charsetTable[key]; maxCharRank = System.Math.Max(maxCharRank, stats.Rank); ListViewItem item = new ListViewItem(stats.Position.ToString()); item.SubItems.Add(stats.Token); item.SubItems.Add(stats.Rank.ToString()); item.SubItems.Add(stats.Occurences.ToString()); lvCharset.Items.Add(item); } this.tbTokenRanks.Text = maxRank.ToString(); this.tbWordRanks.Text = maxWordRank.ToString(); this.tbCharRanks.Text = maxCharRank.ToString(); double maxScore = 0; List <TableVoter> tables = new List <TableVoter>(); foreach (string key in this.m_Model.Keys) { TableVoter tableVoter = new TableVoter(key, table.ComparisonScore(this.m_Model[key], 0)); maxScore = Math.Max(maxScore, tableVoter.Score); tables.Add(tableVoter); } tables.Sort(); foreach (TableVoter voter in tables) { if (voter.Language != lang) { voter.Score /= maxScore; // voter.Score = 100 - voter.Score *200; voter.Score = Math.Max(0, 100 - (voter.Score * 150)); // from 90 on there is not enough similarity to be wrongly detected if (voter.Score > 90) { continue; } ListViewItem item = new ListViewItem(voter.Language); item.SubItems.Add(GetLanguageCulture(voter.Language).DisplayName.ToString()); item.SubItems.Add(voter.Score.ToString("0.00")); listView3.Items.Add(item); } } lvNGrams.EndUpdate(); lvWords.EndUpdate(); listView3.EndUpdate(); lvCharset.EndUpdate(); }
//�Public�Methods�(11)� public void Add(string key, ITokenStats stats) { this.m_InnerDict.Add(key, stats); }