public string GetForm(WordGenre genre, WordCase aCase, WordAmount amount, AdjectiveLevel level) { AdjectiveWordToken token = new AdjectiveWordToken(null, aCase, genre, amount, level); foreach (AdjectiveWordToken tok in irregulars) if (tok.Is(token)) return tok.Text; return null; }
public string GetForm(WordGenre genre, WordCase aCase, WordAmount amount, AdjectiveLevel level) { AdjectiveWordToken token = new AdjectiveWordToken(null, aCase, genre, amount, level); foreach (AdjectiveWordToken tok in irregulars) { if (tok.Is(token)) { return(tok.Text); } } return(null); }
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 bool AnalyzeLine(string line) { 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 Irregular levelling case '*': { if (str.Length > 1) { this.IsLevelledComplex = false; if (str[1] == '+') { this.LevelHighestForm = str.Substring(2); } else { this.LevelHigherForm = str.Substring(1); } } else { // err return(false); } break; } #endregion #region Nondeclinative item case '#': { this.IsConstant = true; break; } case '!': { this.canBeLevelled = false; break; } #endregion #region Exception Cases case '%': { if (str.Length > 5) { this.IsException = true; WordCase aCase = EnumHelper.GetWordCase(str[1]); WordAmount amount = EnumHelper.GetWordAmount(str[2]); WordGenre genre = EnumHelper.GetWordGenre(str[3]); AdjectiveLevel level = EnumHelper.GetAdjectiveLevel(str[4]); string txt = str.Substring(5); AdjectiveWordToken token = new AdjectiveWordToken(txt, aCase, genre, amount, level); this.Irregulars.Add(token); } 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 } } } else { // set defaults this.IsException = false; this.IsConstant = false; } //if (adj.IsException && adj.IsLevelledComplex) //{ // // not supported //} //else return(true); } return(false); }