public string GetForm(WordCase aCase, WordAmount amount) { WordToken token = new WordToken(null, aCase, amount); foreach (WordToken tok in irregulars) { if (tok.Is(token)) { return(tok.Text); } } return(null); }
public void UpdateIrregular(WordToken aToken) { // find and update existing one foreach (WordToken token in this.irregulars) { if (token.WordAmount == aToken.WordAmount && token.WordCase == aToken.WordCase) { token.Text = aToken.Text; return; } } // not found - add new this.irregulars.Add(aToken); }
public bool AnalyzeLine(string line) { this.irregulars.Clear(); this.categories.Clear(); this.singularPostfixSelector.Clear(); this.pluralPostfixSelector.Clear(); if (!string.IsNullOrEmpty(line)) { string[] elements = line.Split('|'); this.root = elements[0]; // always will be at last one element in nonempty string if (elements.Length > 1) { for (int i = 1; i < elements.Length; i++) { string str = elements[i]; if (string.IsNullOrEmpty(str)) { continue; } switch (str[0]) { #region Nondeclinative item case '#': { this.IsConstant = true; break; } #endregion #region Main Data case '!': { if (str.Length > 1) { this.genre = EnumHelper.GetWordGenre(str[1]); // TODO: read more details if (str.Length > 3) { this.declinationType = str.Substring(2, 2); } } else { // err return(false); } break; } case '*': { if (str.Length > 1) { this.IrregularGenre = EnumHelper.GetWordGenre(str[1]); // TODO: read more details this.HasIrregularGenre = this.irrGenre != WordGenre._Unknown; } else { // err return(false); } break; } case '@': { if (str.Length > 1) { // take root for other cases then Nominative this.rootOther = str.Substring(1); } else { // err return(false); } break; } case '+': { if (str.Length > 2) { // Specifies other than first index is used WordAmount amount = EnumHelper.GetWordAmount(str[1]); WordCase aCase = EnumHelper.GetWordCase(str[2]); int postFixIndex = int.Parse(str.Substring(3)); switch (amount) { case WordAmount.Singular: { if (!singularPostfixSelector.ContainsKey(aCase)) { singularPostfixSelector.Add(aCase, postFixIndex); } else { singularPostfixSelector[aCase] = postFixIndex; } break; } case WordAmount.Plural: { if (!pluralPostfixSelector.ContainsKey(aCase)) { pluralPostfixSelector.Add(aCase, postFixIndex); } else { pluralPostfixSelector[aCase] = postFixIndex; } break; } } } else { // err return(false); } break; } #endregion #region Exception Cases case '%': { if (str.Length > 3) { this.IsException = true; WordCase aCase = EnumHelper.GetWordCase(str[1]); WordAmount amount = EnumHelper.GetWordAmount(str[2]); string txt = str.Substring(3); WordToken token = new WordToken(txt, aCase, amount); this.irregulars.Add(token); } else { // err return(false); } break; } case '^': { if (str.Length == 2) { // only singular/plural word - no sense meaning or grammar WordAmount amount = EnumHelper.GetWordAmount(str[1]); if (amount == WordAmount.Plural) { this.canBePlural = false; } else if (amount == WordAmount.Singular) { this.canBeSingular = false; } } else { // err return(false); } break; } #endregion #region Categories case '$': { string cats = str.Substring(1); categories.Clear(); if (!string.IsNullOrEmpty(cats)) { string[] arr = cats.Split(','); foreach (string catId in arr) { int id = int.Parse(catId); if (!categories.Contains(id)) { categories.Add(id); } } } break; } #endregion } } } // check all data is specified if (this.genre == WordGenre._Unknown) { return(false); } return(true); } return(false); }
public bool AnalyzeLine(string line) { this.irregulars.Clear(); this.categories.Clear(); this.singularPostfixSelector.Clear(); this.pluralPostfixSelector.Clear(); if (!string.IsNullOrEmpty(line)) { string[] elements = line.Split('|'); this.root = elements[0]; // always will be at last one element in nonempty string if (elements.Length > 1) { for (int i = 1; i < elements.Length; i++) { string str = elements[i]; if (string.IsNullOrEmpty(str)) continue; switch (str[0]) { #region Nondeclinative item case '#': { this.IsConstant = true; break; } #endregion #region Main Data case '!': { if (str.Length > 1) { this.genre = EnumHelper.GetWordGenre(str[1]); // TODO: read more details if (str.Length > 3) { this.declinationType = str.Substring(2, 2); } } else { // err return false; } break; } case '*': { if (str.Length > 1) { this.IrregularGenre = EnumHelper.GetWordGenre(str[1]); // TODO: read more details this.HasIrregularGenre = this.irrGenre != WordGenre._Unknown; } else { // err return false; } break; } case '@': { if (str.Length > 1) { // take root for other cases then Nominative this.rootOther = str.Substring(1); } else { // err return false; } break; } case '+': { if (str.Length > 2) { // Specifies other than first index is used WordAmount amount = EnumHelper.GetWordAmount(str[1]); WordCase aCase = EnumHelper.GetWordCase(str[2]); int postFixIndex = int.Parse(str.Substring(3)); switch (amount) { case WordAmount.Singular: { if (!singularPostfixSelector.ContainsKey(aCase)) singularPostfixSelector.Add(aCase, postFixIndex); else singularPostfixSelector[aCase] = postFixIndex; break; } case WordAmount.Plural: { if (!pluralPostfixSelector.ContainsKey(aCase)) pluralPostfixSelector.Add(aCase, postFixIndex); else pluralPostfixSelector[aCase] = postFixIndex; break; } } } else { // err return false; } break; } #endregion #region Exception Cases case '%': { if (str.Length > 3) { this.IsException = true; WordCase aCase = EnumHelper.GetWordCase(str[1]); WordAmount amount = EnumHelper.GetWordAmount(str[2]); string txt = str.Substring(3); WordToken token = new WordToken(txt, aCase, amount); this.irregulars.Add(token); } else { // err return false; } break; } case '^': { if (str.Length == 2) { // only singular/plural word - no sense meaning or grammar WordAmount amount = EnumHelper.GetWordAmount(str[1]); if (amount == WordAmount.Plural) this.canBePlural = false; else if (amount == WordAmount.Singular) this.canBeSingular = false; } else { // err return false; } break; } #endregion #region Categories case '$': { string cats = str.Substring(1); categories.Clear(); if (!string.IsNullOrEmpty(cats)) { string[] arr = cats.Split(','); foreach (string catId in arr) { int id = int.Parse(catId); if (!categories.Contains(id)) categories.Add(id); } } break; } #endregion } } } // check all data is specified if (this.genre == WordGenre._Unknown) return false; return true; } return false; }
public void UpdateIrregular(WordToken aToken) { // find and update existing one foreach (WordToken token in this.irregulars) if (token.WordAmount == aToken.WordAmount && token.WordCase == aToken.WordCase) { token.Text = aToken.Text; return; } // not found - add new this.irregulars.Add(aToken); }
public string GetForm(WordCase aCase, WordAmount amount) { WordToken token = new WordToken(null, aCase, amount); foreach (WordToken tok in irregulars) if (tok.Is(token)) return tok.Text; return null; }
public virtual bool Is(WordToken token2) { return(this.amount == token2.amount && this.inflectionCase == token2.inflectionCase); }
public virtual bool Is(WordToken token2) { return (this.amount == token2.amount && this.inflectionCase == token2.inflectionCase); }