/// <summary> /// Returns ID of the token specified /// </summary> /// <param name="str">The token</param> /// <returns></returns> public int GetTokenID(string str) { if (TokenID.ContainsKey(str)) { return TokenID[str]; } else { return AddToken(str); } }
/// <summary> /// Registers new token, returns assigned ID /// </summary> /// <param name="str">The string.</param> /// <returns></returns> public int AddToken(string str, Int32 frequency = 1) { if (!TokenID.ContainsKey(str)) { Tokens.Add(str); TokenID[str] = Tokens.Count - 1; TokenFrequency[str] = frequency; InvokeChanged(); return TokenID[str]; } return -1; }
/// <summary> /// Adds oscore point/s to the token frequency. If the token wasn't registered with the dictionary, it will register it automatically. /// </summary> /// <param name="token">The token - token in the dictionary</param> /// <param name="score">The score - points to be added.</param> public void CountToken(String token, Int32 score = 1) { if (!TokenID.ContainsKey(token)) { Tokens.Add(token); TokenID[token] = TokenID.Count; TokenFrequency[token] = 0; } TokenFrequency[token] = TokenFrequency[token] + score; InvokeChanged(); }
/// <summary> /// Returns list of IDs for given token list /// </summary> /// <param name="input">The input.</param> /// <returns></returns> public List<Int32> GetTokenIDs(IEnumerable<String> input) { List<Int32> output = new List<int>(); foreach (String tkn in input) { if (TokenID.ContainsKey(tkn)) { output.Add(TokenID[tkn]); } } return output; }
/// <summary> /// Gets the token by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> public List<Int32> GetIDsByTokens(IEnumerable<String> tkns) { List<Int32> output = new List<Int32>(); foreach (String i in tkns) { if (TokenID.ContainsKey(i)) { output.Add(TokenID[i]); } } return output; }
public Boolean Contains(String token) { return TokenID.ContainsKey(token); }