Esempio n. 1
0
        public static int GetPostFixIndex(Noun noun, DecliantionNumber amount, InflectionCase aCase)
        {
            switch (amount)
            {
            case DecliantionNumber.Plural:
            {
                if (noun.PluralPostfixSelector.ContainsKey(aCase))
                {
                    return(noun.PluralPostfixSelector[aCase]);
                }
                break;
            }

            case DecliantionNumber.Singular:
            {
                if (noun.SingularPostfixSelector.ContainsKey(aCase))
                {
                    return(noun.SingularPostfixSelector[aCase]);
                }
                break;
            }
            }

            return(0);
        }
Esempio n. 2
0
        public string GetPostFix(GrammaticalGender genre, string decType, InflectionCase aCase, DecliantionNumber amount)
        {
            foreach (NounPostfixToken token in this.endings)
            {
                if (token.Declination == decType && token.Genre == genre &&
                    token.DecliantionNumber == amount && token.InflectionCase == aCase)
                {
                    if (token.Postfixes.Length > 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string postfix in token.Postfixes)
                        {
                            if (sb.Length > 0)
                            {
                                sb.Append(" ");
                            }
                            sb.Append(postfix);
                        }

                        return(sb.ToString());
                    }
                    else
                    if (token.Postfixes.Length == 1)
                    {
                        return(token.Postfixes[0]);
                    }
                }
            }

            return("");
        }
 public AdjectiveWordToken(string text, InflectionCase inflectionCase,
     GrammaticalGender grammaticalGender, DecliantionNumber decliantionNumber, AdjectiveLevel level)
     : base(text, inflectionCase, decliantionNumber)
 {
     this.level = level;
     this.genre = grammaticalGender;
 }
Esempio n. 4
0
        public static char GetWordCaseCode(InflectionCase aCase)
        {
            switch (aCase)
            {
            case InflectionCase.Nominative:
                return('N');

            case InflectionCase.Ablative:
                return('A');

            case InflectionCase.Accusative:
                return('C');

            case InflectionCase.Dative:
                return('D');

            case InflectionCase.Genitive:
                return('G');

            case InflectionCase.Locative:
                return('L');

            case InflectionCase.Vocative:
                return('V');
            }

            return('?');
        }
Esempio n. 5
0
        private string SelectPostfix(Noun word, InflectionCase aCase, DecliantionNumber amount,
                                     string root, params string[] postfixes)
        {
            foreach (NounPostfixToken token in this.endings)
            {
                if (token.Declination == word.DeclinationType &&
                    token.Genre == word.Genre && token.DecliantionNumber == amount &&
                    token.InflectionCase == aCase)
                {
                    if (token.Postfixes.Length > 1)
                    {
                        int indx = NounGrammar.GetPostFixIndex(word, amount, aCase);

                        if (indx < token.Postfixes.Length)
                        {
                            return(token.Postfixes[indx]);
                        }
                        else
                        {
                            return("");
                        }
                    }
                    else
                    {
                        return(token.Postfixes[0]);
                    }
                }
            }

            return("");           //postfixes[0];
        }
Esempio n. 6
0
 public AdjectiveWordToken(string text, InflectionCase inflectionCase,
                           GrammaticalGender grammaticalGender, DecliantionNumber decliantionNumber, AdjectiveLevel level)
     : base(text, inflectionCase, decliantionNumber)
 {
     this.level = level;
     this.genre = grammaticalGender;
 }
        public static string GetForm(Noun noun, InflectionCase aCase, DecliantionNumber amount)
        {
            WordToken token = new WordToken(null, aCase, amount);
            foreach (WordToken tok in noun.Irregulars)
                if (tok.Is(token))
                    return tok.Text;

            return null;
        }
Esempio n. 8
0
 public NounPostfixToken(GrammaticalGender grammaticalGender, InflectionCase inflectionCase, DecliantionNumber decliantionNumber,
                         string wordDeclination, params string[] wordPostfixes)
 {
     this.genre           = grammaticalGender;
     this.inflectionCase  = inflectionCase;
     this.amount          = decliantionNumber;
     this.nounDeclination = wordDeclination;
     this.postfixes       = wordPostfixes;
 }
Esempio n. 9
0
        public string GetForm(GrammaticalGender genre, InflectionCase aCase, DecliantionNumber 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 NounPostfixToken(GrammaticalGender grammaticalGender, InflectionCase inflectionCase, DecliantionNumber decliantionNumber,
            string wordDeclination, params string[] wordPostfixes)
        {
            this.genre = grammaticalGender;
            this.inflectionCase = inflectionCase;
            this.amount = decliantionNumber;
            this.nounDeclination = wordDeclination;
            this.postfixes = wordPostfixes;

        }
Esempio n. 11
0
        public void LoadPostfixes(string filePath)
        {
            this.endings.Clear();

            FileInfo   fi   = new FileInfo(filePath);
            TextReader tr   = new StreamReader(fi.FullName, Encoding.Default, true);
            string     line = null;

            try
            {
                while ((line = tr.ReadLine()) != null)
                {
#if DEBUG
                    if (line.Trim().StartsWith("EOF"))
                    {
                        break; // for testing purposes
                    }
#else
                    if (line.Trim().StartsWith("EOF"))
                    {
                        continue; // ignore
                    }
#endif
                    if (line.Trim().StartsWith(";"))
                    {
                        continue; // entry is commented out
                    }
                    string[] fields = line.Split('|');
                    if (fields.Length != 2)
                    {
                        return; // Error
                    }
                    if (fields[0].Length != 5)
                    {
                        return; // error
                    }
                    string            str        = fields[0];
                    GrammaticalGender genre      = EnumHelper.GetWordGenre(str[0]);
                    InflectionCase    aCase      = EnumHelper.GetWordCase(str[1]);
                    DecliantionNumber amount     = EnumHelper.GetWordAmount(str[2]);
                    string            declinType = str.Substring(3, 2);

                    string[] postfixes = fields[1].Split(' ');

                    NounPostfixToken token = new NounPostfixToken(genre, aCase, amount,
                                                                  declinType, postfixes);

                    this.endings.Add(token);
                }
            }
            finally
            {
                tr.Close();
            }
        }
Esempio n. 12
0
        public static string GetForm(Noun noun, InflectionCase aCase, DecliantionNumber amount)
        {
            WordToken token = new WordToken(null, aCase, amount);

            foreach (WordToken tok in noun.Irregulars)
            {
                if (tok.Is(token))
                {
                    return(tok.Text);
                }
            }

            return(null);
        }
Esempio n. 13
0
        public string GetForm(GrammaticalGender genre, InflectionCase aCase, DecliantionNumber amount, AdjectiveLevel level)
        {
            AdjectiveWordToken token = new AdjectiveWordToken(null, aCase, genre, amount, level);

            foreach (AdjectiveWordToken tok in this.Irregulars)
            {
                if (tok.Is(token))
                {
                    return(tok.Text);
                }
            }

            return(null);
        }
Esempio n. 14
0
        public static void SetPostIndex(Noun noun, InflectionCase aCase, DecliantionNumber amount, int postFixIndex)
        {
            switch (amount)
            {
            case DecliantionNumber.Plural:
            {
                if (postFixIndex > 0)
                {
                    if (noun.PluralPostfixSelector.ContainsKey(aCase))
                    {
                        noun.PluralPostfixSelector[aCase] = postFixIndex;
                    }
                    else
                    {
                        noun.PluralPostfixSelector.Add(aCase, postFixIndex);
                    }
                }
                else if (noun.PluralPostfixSelector.ContainsKey(aCase))
                {
                    noun.PluralPostfixSelector.Remove(aCase);
                }

                break;
            }

            case DecliantionNumber.Singular:
            {
                if (postFixIndex > 0)
                {
                    if (noun.SingularPostfixSelector.ContainsKey(aCase))
                    {
                        noun.SingularPostfixSelector[aCase] = postFixIndex;
                    }
                    else
                    {
                        noun.SingularPostfixSelector.Add(aCase, postFixIndex);
                    }
                }
                else if (noun.SingularPostfixSelector.ContainsKey(aCase))
                {
                    noun.SingularPostfixSelector.Remove(aCase);
                }

                break;
            }
            }
        }
Esempio n. 15
0
        public static int GetPostFixIndex(Noun noun, DecliantionNumber amount, InflectionCase aCase)
        {
            switch (amount)
            {
                case DecliantionNumber.Plural:
                {
                    if (noun.PluralPostfixSelector.ContainsKey(aCase))
                        return noun.PluralPostfixSelector[aCase];
                    break;
                }

                case DecliantionNumber.Singular:
                {
                    if (noun.SingularPostfixSelector.ContainsKey(aCase))
                        return noun.SingularPostfixSelector[aCase];
                    break;
                }
            }

            return 0;
        }
Esempio n. 16
0
        public static char GetWordCaseCode(InflectionCase aCase)
        {
            switch (aCase)
            {
                case InflectionCase.Nominative:
                    return 'N';
                case InflectionCase.Ablative:
                    return 'A';
                case InflectionCase.Accusative:
                    return 'C';
                case InflectionCase.Dative:
                    return 'D';
                case InflectionCase.Genitive:
                    return 'G';
                case InflectionCase.Locative:
                    return 'L';
                case InflectionCase.Vocative:
                    return 'V';
            }

            return '?';
        }
Esempio n. 17
0
        public static void SetPostIndex(Noun noun, InflectionCase aCase, DecliantionNumber amount, int postFixIndex)
        {
            switch (amount)
            {
                case DecliantionNumber.Plural:
                {
                    if (postFixIndex > 0)
                    {
                        if (noun.PluralPostfixSelector.ContainsKey(aCase))
                            noun.PluralPostfixSelector[aCase] = postFixIndex;
                        else
                            noun.PluralPostfixSelector.Add(aCase, postFixIndex);
                    }
                    else if (noun.PluralPostfixSelector.ContainsKey(aCase))
                        noun.PluralPostfixSelector.Remove(aCase);

                    break;
                }

                case DecliantionNumber.Singular:
                {
                    if (postFixIndex > 0)
                    {
                        if (noun.SingularPostfixSelector.ContainsKey(aCase))
                            noun.SingularPostfixSelector[aCase] = postFixIndex;
                        else
                            noun.SingularPostfixSelector.Add(aCase, postFixIndex);
                    }
                    else if (noun.SingularPostfixSelector.ContainsKey(aCase))
                        noun.SingularPostfixSelector.Remove(aCase);

                    break;
                }
            }

        }
Esempio n. 18
0
 public WordToken(string text, InflectionCase inflectionCase, DecliantionNumber decliantionNumber)
 {
     this.Text              = text;
     this.InflectionCase    = inflectionCase;
     this.DecliantionNumber = decliantionNumber;
 }
 public string TranslateWordCase(InflectionCase inflectionCase)
 {
     return translationsWordCase[inflectionCase.ToString()];
 }
Esempio n. 20
0
 public WordToken(string text, InflectionCase inflectionCase, DecliantionNumber decliantionNumber)
 {
     this.root = text;
     this.inflectionCase = inflectionCase;
     this.amount = decliantionNumber;
 }
Esempio n. 21
0
        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;
                                InflectionCase    aCase  = EnumHelper.GetWordCase(str[1]);
                                DecliantionNumber amount = EnumHelper.GetWordAmount(str[2]);
                                GrammaticalGender 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);
                            this.Categories.Clear();
                            if (!string.IsNullOrEmpty(cats))
                            {
                                string[] arr = cats.Split(',');
                                foreach (string catId in arr)
                                {
                                    int id = int.Parse(catId);

                                    if (!this.Categories.Contains(id))
                                    {
                                        this.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);
        }
Esempio n. 22
0
        private string Decode(string code)
        {
            if (!string.IsNullOrEmpty(code))
            {
                switch (code[0])
                {
                case 'A':       // Adjective (przymiotnik)
                {
                    if (code.Length == 5)
                    {
                        InflectionCase    aCase  = EnumHelper.GetWordCase(code[1]);
                        DecliantionNumber amount = EnumHelper.GetWordAmount(code[2]);
                        GrammaticalGender genre  = EnumHelper.GetWordGenre(code[3]);
                        AdjectiveLevel    level  = EnumHelper.GetAdjectiveLevel(code[4]);

                        Adjective adj = AdjectiveCollection.Collection.GetRandomAdjective();
                        if (adj == null)
                        {
                            return("{NO_VALID_ADJECTIVE}");
                        }

                        string form = AdjectiveDecliner.Decliner.MakeWord(adj, genre, aCase, amount, level);
                        if (form != null)
                        {
                            return(form);
                        }

                        int tries = 0;
                        // try randomizing little more...
                        // TODO: implement some shuffle algorithm
                        while (form == null && tries++ < 10)
                        {
                            adj  = AdjectiveCollection.Collection.GetRandomAdjective();
                            form = AdjectiveDecliner.Decliner.MakeWord(adj, genre, aCase, amount, level);
                        }
                        if (tries >= 10)
                        {
                            return("{NO_VALID_ADJECTIVE}");        // 10 tries - probably no valid word in dic
                        }
                        return(form);
                    }
                    break;
                }

                case 'N':     // Noun (rzeczownik)
                {
                    if (code.Length == 4)
                    {
                        InflectionCase    aCase  = EnumHelper.GetWordCase(code[1]);
                        DecliantionNumber amount = EnumHelper.GetWordAmount(code[2]);
                        GrammaticalGender genre  = EnumHelper.GetWordGenre(code[3]);

                        Noun noun = NounCollection.Collection.GetNoun(genre,
                                                                      null,
                                                                      (amount == DecliantionNumber.Singular) ? true : false,
                                                                      (amount == DecliantionNumber.Plural) ? true : false);
                        if (noun == null)
                        {
                            return("{NO_VALID_NOUN}");
                        }

                        /*if (amount == DecliantionNumber.Plural && !noun.CanBePlural)
                         *  amount = DecliantionNumber.Singular;
                         * else if (amount == DecliantionNumber.Singular && !noun.CanBeSingular)
                         *  amount = DecliantionNumber.Plural;*/// no longer needed

                        string form = NounDecliner.Decliner.MakeWord(noun, aCase, amount);
                        if (form != null)
                        {
                            return(form);
                        }

                        int tries = 0;
                        // try randomizing little more...
                        // TODO: implement some shuffle algorithm
                        while (form == null && tries++ < 10)
                        {
                            noun = NounCollection.Collection.GetNoun(genre,
                                                                     null,
                                                                     (amount == DecliantionNumber.Singular) ? true : false,
                                                                     (amount == DecliantionNumber.Plural) ? true : false);

                            form = NounDecliner.Decliner.MakeWord(noun, aCase, amount);
                        }
                        if (tries >= 10)
                        {
                            return("{NO_VALID_NOUN}");        // 10 tries - probably no valid word in dic
                        }
                        return(form);
                    }

                    break;
                }
                    //case 'C': // Counter (liczebnik)
                    //    {
                    //        break;
                    //    }
                    //case 'V': // Verb (czsownik)
                    //    {
                    //        break;
                    //    }
                }
            }

            return("{INVALID_FORMATTER}");
        }
 public string MakeWord(Adjective word, GrammaticalGender genre, InflectionCase aCase, DecliantionNumber amount)
 {
     return(this.MakeWord(word, genre, aCase, amount, AdjectiveLevel.Equal));
 }
Esempio n. 24
0
        public string MakeWord(Noun word, InflectionCase aCase, DecliantionNumber amount)
        {
            if (aCase == InflectionCase._Unknown || amount == DecliantionNumber._Unknown)
                return null;

            if ((amount == DecliantionNumber.Singular && !word.CanBeSingular) ||
                (amount == DecliantionNumber.Plural && !word.CanBePlural))
                return null;

            if (word.IsConstant)
                return word.Root;

            if (word.IsException)
            {
                string except = NounGrammar.GetForm(word, aCase, amount);
                if (except != null)
                    return except; // else - calculate own...
            }

            string prefix = "";
            string postfix = "";
            string root = ((aCase != InflectionCase.Nominative || amount != DecliantionNumber.Singular) &&
                !string.IsNullOrEmpty(word.RootOther))
                ? word.RootOther : word.Root;

            #region Switching

            postfix = SelectPostfix(word, aCase, amount, root);
            if (postfix == "*")
                postfix = "";

#if SW
            switch (word.Genre)
            {
            #region MasculineLife
                
                case GrammaticalGender.MasculineLife:
                    {                       
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }

                        break;
                    }

                #endregion

            #region MasculinePerson

                case GrammaticalGender.MasculinePerson:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            #region MasculineThing

                case GrammaticalGender.MasculineThing:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break; // Nothing
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                root = Soften(word, root);
                                                postfix = "y";
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                root = Soften(word, root);
                                                //postfix = SelectPostfix(word, root, "a", "u");
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                root = Soften(word, root);
                                                //postfix = SelectPostfix(word, root, "y", "ów");
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            #region Feminine

                case GrammaticalGender.Feminine:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            #region Neuter

                case GrammaticalGender.Neuter:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            }
#endif

            #endregion

            return string.Format("{0}{1}{2}", prefix, root, postfix);
        }
Esempio n. 25
0
        public bool Analyze()
        {
            this.results.Clear();

            // get noun...
            if (this.nounIndex < 0)
            {
                // cannot analyze groups without noun...
                return(false);
            }

            InflectionCase    naCase  = EnumHelper.GetWordCase(this.codes[this.nounIndex][1]);
            DecliantionNumber namount = EnumHelper.GetWordAmount(this.codes[this.nounIndex][2]);
            GrammaticalGender ngenre  = EnumHelper.GetWordGenre(this.codes[this.nounIndex][3]);

            // todo: categories

            if (naCase == InflectionCase._Unknown || namount == DecliantionNumber._Unknown ||
                ngenre == GrammaticalGender._Unknown)
            {
                this.results.Add(this.indexes[this.nounIndex], "{NOUN_DEFINITION_INCOMPLETE}");
                return(false);
            }

            Noun noun = NounCollection.Collection.GetRandomNoun(ngenre);

            if (noun == null)
            {
                this.results.Add(this.indexes[this.nounIndex], "{NO_VALID_NOUN}");
                // TODO: fill rest of the placeholders
                return(false);
            }
            else
            {
                if (namount == DecliantionNumber.Plural && !noun.CanBePlural)
                {
                    namount = DecliantionNumber.Singular;
                }
                else if (namount == DecliantionNumber.Singular && !noun.CanBeSingular)
                {
                    namount = DecliantionNumber.Plural;
                }

                string nounStr = NounDecliner.Decliner.MakeWord(noun, naCase, namount);
                if (!string.IsNullOrEmpty(nounStr))
                {
                    this.results.Add(this.indexes[this.nounIndex], nounStr);
                }
                else
                {
                    this.results.Add(this.indexes[this.nounIndex], "{CANT_DECLINE_NOUN}");
                }

                bool error = false;

                for (int codeIndex = 0; codeIndex < this.codes.Count; codeIndex++)
                {
                    if (codeIndex == this.nounIndex)
                    {
                        continue;
                    }

                    string code        = this.codes[codeIndex];
                    int    formatIndex = this.indexes[codeIndex];

                    switch (code[0])
                    {
                        #region Adjective
                    case 'A':       // Adjective (przymiotnik)
                    {
                        if (code.Length == 5)
                        {
                            InflectionCase    aCase  = EnumHelper.GetWordCase(code[1]);
                            DecliantionNumber amount = EnumHelper.GetWordAmount(code[2]);
                            GrammaticalGender genre  = EnumHelper.GetWordGenre(code[3]);
                            AdjectiveLevel    level  = EnumHelper.GetAdjectiveLevel(code[4]);

                            if (aCase == InflectionCase._Unknown)
                            {
                                aCase = naCase;
                            }

                            if (amount == DecliantionNumber._Unknown)
                            {
                                amount = namount;
                            }

                            if (genre == GrammaticalGender._Unknown)
                            {
                                genre = ngenre;
                            }

                            Adjective adj = AdjectiveCollection.Collection.GetRandomAdjective();
                            if (adj == null)
                            {
                                this.results.Add(formatIndex, "{NO_VALID_ADJECTIVE}");
                                error = true;
                                continue;
                            }

                            string form = AdjectiveDecliner.Decliner.MakeWord(adj, noun, aCase,
                                                                              amount, level);

                            if (form != null)
                            {
                                this.results.Add(formatIndex, form);
                                continue;
                            }

                            int tries = 0;
                            // try randomizing little more...
                            // TODO: implement some shuffle algorithm
                            while (form == null && tries++ < 10)
                            {
                                adj  = AdjectiveCollection.Collection.GetRandomAdjective();
                                form = AdjectiveDecliner.Decliner.MakeWord(adj, noun, aCase,
                                                                           amount, level);
                            }
                            if (tries >= 10)
                            {
                                this.results.Add(formatIndex, "{NO_VALID_ADJECTIVE}");
                                error = true;
                                continue;
                            }

                            this.results.Add(formatIndex, form);
                        }
                        break;
                    }
                        #endregion

                        // TODO: Verbs
                    }
                }

                return(!error);
            }

            return(true);
        }
        public string MakeWord(Adjective word, GrammaticalGender genre, InflectionCase aCase,
            DecliantionNumber amount, AdjectiveLevel level)
        {
            // check all arguments are provided...
            if (genre == GrammaticalGender._Unknown || aCase == InflectionCase._Unknown
                || amount == DecliantionNumber._Unknown || level == AdjectiveLevel._Unknown)
                return null;

            // constants
            if (word.IsConstant)
                return word.Root;

            // check word has exceptions
            if (word.IsException)
            {
                string except = word.GetForm(genre, aCase, amount, level);
                if (except != null)
                    return except; // alse - calculate own...
            }

            // now check if word has locked levels
            if (useNonLevellingRule && !word.CanBeLevelled &&
                (level == AdjectiveLevel.Higher || level == AdjectiveLevel.Highest))
                return null;

            string prefix = "";
            string postfix = "";
            string root = word.Root;

            // pick valid prefix for declination

            #region Levelling

            switch (level)
            {
                case AdjectiveLevel.Equal:
                    {
                        // nothing
                        break;
                    }
                case AdjectiveLevel.Higher:
                    {
                        if (!word.IsLevelledComplex && !string.IsNullOrEmpty(word.LevelHigherForm))
                            root = word.LevelHigherForm;
                        else
                            prefix = "bardziej ";
                        break;
                    }
                case AdjectiveLevel.Highest:
                    {
                        if (!word.IsLevelledComplex && !string.IsNullOrEmpty(word.LevelHighestForm))
                            root = word.LevelHighestForm;
                        else
                            prefix = "najbardziej ";
                        break;
                    }
            }

            #endregion

            // Chnage root / postfix depending of selected gender, number etc

            switch (amount)
            {
                #region DecliantionNumber.Singular

                case DecliantionNumber.Singular:
                    {
                        switch (genre)
                        {
                            case GrammaticalGender.MasculinePerson:
                            case GrammaticalGender.MasculineLife:
                                {
                                    switch (aCase)
                                    {
                                        case InflectionCase.Nominative:
                                        case InflectionCase.Vocative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                break;
                                            }
                                        case InflectionCase.Genitive:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "go";
                                                break;
                                            }
                                        case InflectionCase.Dative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "mu";
                                                break;
                                            }
                                        case InflectionCase.Accusative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "go";
                                                break;
                                            }
                                        case InflectionCase.Ablative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                        case InflectionCase.Locative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case GrammaticalGender.MasculineThing:
                                {
                                    switch (aCase)
                                    {
                                        case InflectionCase.Nominative:
                                        case InflectionCase.Vocative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                break;
                                            }
                                        case InflectionCase.Genitive:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "go";
                                                break;
                                            }
                                        case InflectionCase.Dative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "mu";
                                                break;
                                            }
                                        case InflectionCase.Accusative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                break;
                                            }
                                        case InflectionCase.Ablative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                        case InflectionCase.Locative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case GrammaticalGender.Feminine:
                                {
                                    switch (aCase)
                                    {
                                        case InflectionCase.Nominative:
                                        case InflectionCase.Vocative:
                                            {
                                                //postfix = MakePostfix(word, ref root, ending_A_IA);
                                                break;
                                            }
                                        case InflectionCase.Genitive:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "j";
                                                break;
                                            }
                                        case InflectionCase.Dative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "j";
                                                break;
                                            }
                                        case InflectionCase.Accusative:
                                            {
                                                postfix = MakePostfixBlue(word, ref root, ending_Aa_IAa);
                                                break;
                                            }
                                        case InflectionCase.Ablative:
                                            {
                                                postfix = MakePostfixBlue(word, ref root, ending_Aa_IAa);
                                                break;
                                            }
                                        case InflectionCase.Locative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "j";
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case GrammaticalGender.Neuter:
                                {
                                    switch (aCase)
                                    {
                                        case InflectionCase.Nominative:
                                        case InflectionCase.Vocative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                break;
                                            }
                                        case InflectionCase.Genitive:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "go";
                                                break;
                                            }
                                        case InflectionCase.Dative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                postfix += "mu";
                                                break;
                                            }
                                        case InflectionCase.Accusative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                break;
                                            }
                                        case InflectionCase.Ablative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                        case InflectionCase.Locative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

                #region DecliantionNumber.Plural

                case DecliantionNumber.Plural:
                    {
                        switch (genre)
                        {
                            case GrammaticalGender.MasculinePerson:
                                {
                                    switch (aCase)
                                    {
                                        case InflectionCase.Nominative:
                                        case InflectionCase.Vocative:
                                            {
                                                if (root.EndsWith("cona") || root.EndsWith("iona"))
                                                {
                                                    root = root.Substring(0, root.Length - 3);
                                                    postfix = "eni";
                                                }
                                                else
                                                {
                                                    root = this.MakeWord(word, genre, InflectionCase.Nominative, DecliantionNumber.Singular, level);
                                                    root = Soften(word, root);
                                                    //postfix = MakePostfix(word, ref root, ending_I_Y);
                                                    prefix = ""; // above launch of MakeWord will add prefix either
                                                }
                                                break;
                                            }
                                        case InflectionCase.Genitive:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "ch";
                                                break;
                                            }
                                        case InflectionCase.Dative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                        case InflectionCase.Accusative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "ch";
                                                break;
                                            }
                                        case InflectionCase.Ablative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "mi";
                                                break;
                                            }
                                        case InflectionCase.Locative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "ch";
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case GrammaticalGender.Feminine:
                            case GrammaticalGender.MasculineLife:
                            case GrammaticalGender.MasculineThing:
                            case GrammaticalGender.Neuter:
                                {
                                    switch (aCase)
                                    {
                                        case InflectionCase.Nominative:
                                        case InflectionCase.Vocative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                break;
                                            }
                                        case InflectionCase.Genitive:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "ch";
                                                break;
                                            }
                                        case InflectionCase.Dative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "m";
                                                break;
                                            }
                                        case InflectionCase.Accusative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_E_IE);
                                                break;
                                            }
                                        case InflectionCase.Ablative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "mi";
                                                break;
                                            }
                                        case InflectionCase.Locative:
                                            {
                                                postfix = MakePostfix(word, ref root, ending_I_Y);
                                                postfix += "ch";
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion
            }

            return string.Format("{0}{1}{2}", prefix, root, postfix);
        }
 public string MakeWord(Adjective word, GrammaticalGender genre, InflectionCase aCase, DecliantionNumber amount)
 {
     return MakeWord(word, genre, aCase, amount, AdjectiveLevel.Equal);
 }
 public string MakeWord(Adjective word, Noun noun, InflectionCase aCase, DecliantionNumber amount,
     AdjectiveLevel level)
 {
     return MakeWord(word, (noun.HasIrregularGenre) ? noun.IrregularGenre : noun.Genre,
         aCase, amount, level);
 }
Esempio n. 29
0
 public WordToken(string text, InflectionCase inflectionCase, DecliantionNumber decliantionNumber)
 {
     this.Text = text;
     this.InflectionCase = inflectionCase;
     this.DecliantionNumber = decliantionNumber;
 }
Esempio n. 30
0
        public string GetPostFix(GrammaticalGender genre, string decType, InflectionCase aCase, DecliantionNumber amount)
        {
            foreach (NounPostfixToken token in this.endings)
            {
                if (token.Declination == decType && token.Genre == genre &&
                    token.DecliantionNumber == amount && token.InflectionCase == aCase)
                {
                    if (token.Postfixes.Length > 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string postfix in token.Postfixes)
                        {
                            if (sb.Length > 0)
                                sb.Append(" ");
                            sb.Append(postfix);
                        }

                        return sb.ToString();
                    }
                    else
                        if (token.Postfixes.Length == 1)
                            return token.Postfixes[0];
                }
            }

            return "";
        }
 public string TranslateWordCase(InflectionCase inflectionCase)
 {
     return(this.translationsWordCase[inflectionCase.ToString()]);
 }
Esempio n. 32
0
        private string SelectPostfix(Noun word, InflectionCase aCase, DecliantionNumber amount,
    string root, params string[] postfixes)
        {
            foreach (NounPostfixToken token in this.endings)
            {
                if (token.Declination == word.DeclinationType &&
                    token.Genre == word.Genre && token.DecliantionNumber == amount
                    && token.InflectionCase == aCase)
                {
                    if (token.Postfixes.Length > 1)
                    {
                        int indx = NounGrammar.GetPostFixIndex(word, amount, aCase);

                        if (indx < token.Postfixes.Length)
                            return token.Postfixes[indx];
                        else
                            return "";
                    }
                    else
                    {
                        return token.Postfixes[0];
                    }
                }
            }

            return "";           //postfixes[0];
        }
Esempio n. 33
0
 public WordToken(string text, InflectionCase inflectionCase, DecliantionNumber decliantionNumber)
 {
     this.root           = text;
     this.inflectionCase = inflectionCase;
     this.amount         = decliantionNumber;
 }
 public string MakeWord(Adjective word, Noun noun, InflectionCase aCase, DecliantionNumber amount,
                        AdjectiveLevel level)
 {
     return(this.MakeWord(word, (noun.HasIrregularGenre) ? noun.IrregularGenre : noun.Genre,
                          aCase, amount, level));
 }
Esempio n. 35
0
        public Noun Load(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return(null);
            }

            Noun noun = new Noun();

            string[] elements = line.Split('|');
            noun.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 '#':
                    {
                        noun.IsConstant = true;
                        break;
                    }

                        #endregion

                        #region Main Data

                    case '!':
                    {
                        if (str.Length > 1)
                        {
                            noun.Genre = EnumHelper.GetWordGenre(str[1]);
                            // TODO: read more details
                            if (str.Length > 3)
                            {
                                noun.DeclinationType = str.Substring(2, 2);
                            }
                        }
                        else
                        {
                            // err
                            return(null);
                        }

                        break;
                    }

                    case '*':
                    {
                        if (str.Length > 1)
                        {
                            noun.IrregularGenre = EnumHelper.GetWordGenre(str[1]);
                            // TODO: read more details
                            noun.HasIrregularGenre = noun.IrregularGenre != GrammaticalGender._Unknown;
                        }
                        else
                        {
                            // err
                            return(null);
                        }

                        break;
                    }


                    case '@':
                    {
                        if (str.Length > 1)
                        {
                            // take root for other cases then Nominative
                            noun.RootOther = str.Substring(1);
                        }
                        else
                        {
                            // err
                            return(null);
                        }

                        break;
                    }

                    case '+':
                    {
                        if (str.Length > 2)
                        {
                            // Specifies other than first index is used
                            DecliantionNumber amount = EnumHelper.GetWordAmount(str[1]);
                            InflectionCase    aCase  = EnumHelper.GetWordCase(str[2]);
                            int postFixIndex         = int.Parse(str.Substring(3));

                            switch (amount)
                            {
                            case DecliantionNumber.Singular:
                            {
                                if (!noun.SingularPostfixSelector.ContainsKey(aCase))
                                {
                                    noun.SingularPostfixSelector.Add(aCase, postFixIndex);
                                }
                                else
                                {
                                    noun.SingularPostfixSelector[aCase] = postFixIndex;
                                }
                                break;
                            }

                            case DecliantionNumber.Plural:
                            {
                                if (!noun.PluralPostfixSelector.ContainsKey(aCase))
                                {
                                    noun.PluralPostfixSelector.Add(aCase, postFixIndex);
                                }
                                else
                                {
                                    noun.PluralPostfixSelector[aCase] = postFixIndex;
                                }
                                break;
                            }
                            }
                        }
                        else
                        {
                            // err
                            return(null);
                        }

                        break;
                    }

                        #endregion

                        #region Exception Cases

                    case '%':
                    {
                        if (str.Length > 3)
                        {
                            noun.IsException = true;
                            InflectionCase    aCase  = EnumHelper.GetWordCase(str[1]);
                            DecliantionNumber amount = EnumHelper.GetWordAmount(str[2]);
                            string            txt    = str.Substring(3);

                            WordToken token = new
                                              WordToken(txt, aCase, amount);
                            noun.Irregulars.Add(token);
                        }
                        else
                        {
                            // err
                            return(null);
                        }

                        break;
                    }

                    case '^':
                    {
                        if (str.Length == 2)
                        {
                            // only singular/plural word - no sense meaning or grammar
                            DecliantionNumber amount = EnumHelper.GetWordAmount(str[1]);
                            if (amount == DecliantionNumber.Plural)
                            {
                                noun.CanBePlural = false;
                            }
                            else if (amount == DecliantionNumber.Singular)
                            {
                                noun.CanBeSingular = false;
                            }
                        }
                        else
                        {
                            // err
                            return(null);
                        }

                        break;
                    }

                        #endregion

                        #region Categories

                    case '$':
                    {
                        string cats = str.Substring(1);
                        // noun.Categories.Clear();
                        if (!string.IsNullOrEmpty(cats))
                        {
                            string[] arr = cats.Split(',');
                            foreach (string catId in arr)
                            {
                                int id = int.Parse(catId);

                                if (!noun.Categories.Contains(id))
                                {
                                    noun.Categories.Add(id);
                                }
                            }
                        }

                        break;
                    }

                        #endregion
                    }
                }
            }

            // check all data is specified
            if (noun.Genre == GrammaticalGender._Unknown)
            {
                return(null);
            }

            return(noun);
        }
        public string MakeWord(Adjective word, GrammaticalGender genre, InflectionCase aCase,
                               DecliantionNumber amount, AdjectiveLevel level)
        {
            // check all arguments are provided...
            if (genre == GrammaticalGender._Unknown || aCase == InflectionCase._Unknown ||
                amount == DecliantionNumber._Unknown || level == AdjectiveLevel._Unknown)
            {
                return(null);
            }

            // constants
            if (word.IsConstant)
            {
                return(word.Root);
            }

            // check word has exceptions
            if (word.IsException)
            {
                string except = word.GetForm(genre, aCase, amount, level);
                if (except != null)
                {
                    return(except); // alse - calculate own...
                }
            }

            // now check if word has locked levels
            if (this.useNonLevellingRule && !word.CanBeLevelled &&
                (level == AdjectiveLevel.Higher || level == AdjectiveLevel.Highest))
            {
                return(null);
            }

            string prefix  = "";
            string postfix = "";
            string root    = word.Root;

            // pick valid prefix for declination

            #region Levelling

            switch (level)
            {
            case AdjectiveLevel.Equal:
            {
                // nothing
                break;
            }

            case AdjectiveLevel.Higher:
            {
                if (!word.IsLevelledComplex && !string.IsNullOrEmpty(word.LevelHigherForm))
                {
                    root = word.LevelHigherForm;
                }
                else
                {
                    prefix = "bardziej ";
                }
                break;
            }

            case AdjectiveLevel.Highest:
            {
                if (!word.IsLevelledComplex && !string.IsNullOrEmpty(word.LevelHighestForm))
                {
                    root = word.LevelHighestForm;
                }
                else
                {
                    prefix = "najbardziej ";
                }
                break;
            }
            }

            #endregion

            // Chnage root / postfix depending of selected gender, number etc

            switch (amount)
            {
                #region DecliantionNumber.Singular

            case DecliantionNumber.Singular:
            {
                switch (genre)
                {
                case GrammaticalGender.MasculinePerson:
                case GrammaticalGender.MasculineLife:
                {
                    switch (aCase)
                    {
                    case InflectionCase.Nominative:
                    case InflectionCase.Vocative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_I_Y);
                        break;
                    }

                    case InflectionCase.Genitive:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "go";
                        break;
                    }

                    case InflectionCase.Dative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "mu";
                        break;
                    }

                    case InflectionCase.Accusative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "go";
                        break;
                    }

                    case InflectionCase.Ablative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }

                    case InflectionCase.Locative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }
                    }
                    break;
                }

                case GrammaticalGender.MasculineThing:
                {
                    switch (aCase)
                    {
                    case InflectionCase.Nominative:
                    case InflectionCase.Vocative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_I_Y);
                        break;
                    }

                    case InflectionCase.Genitive:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "go";
                        break;
                    }

                    case InflectionCase.Dative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "mu";
                        break;
                    }

                    case InflectionCase.Accusative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_I_Y);
                        break;
                    }

                    case InflectionCase.Ablative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }

                    case InflectionCase.Locative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }
                    }
                    break;
                }

                case GrammaticalGender.Feminine:
                {
                    switch (aCase)
                    {
                    case InflectionCase.Nominative:
                    case InflectionCase.Vocative:
                    {
                        //postfix = MakePostfix(word, ref root, ending_A_IA);
                        break;
                    }

                    case InflectionCase.Genitive:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "j";
                        break;
                    }

                    case InflectionCase.Dative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "j";
                        break;
                    }

                    case InflectionCase.Accusative:
                    {
                        postfix = this.MakePostfixBlue(word, ref root, this.ending_Aa_IAa);
                        break;
                    }

                    case InflectionCase.Ablative:
                    {
                        postfix = this.MakePostfixBlue(word, ref root, this.ending_Aa_IAa);
                        break;
                    }

                    case InflectionCase.Locative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "j";
                        break;
                    }
                    }
                    break;
                }

                case GrammaticalGender.Neuter:
                {
                    switch (aCase)
                    {
                    case InflectionCase.Nominative:
                    case InflectionCase.Vocative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_E_IE);
                        break;
                    }

                    case InflectionCase.Genitive:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "go";
                        break;
                    }

                    case InflectionCase.Dative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_E_IE);
                        postfix += "mu";
                        break;
                    }

                    case InflectionCase.Accusative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_E_IE);
                        break;
                    }

                    case InflectionCase.Ablative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }

                    case InflectionCase.Locative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }
                    }
                    break;
                }
                }
                break;
            }

                #endregion

                #region DecliantionNumber.Plural

            case DecliantionNumber.Plural:
            {
                switch (genre)
                {
                case GrammaticalGender.MasculinePerson:
                {
                    switch (aCase)
                    {
                    case InflectionCase.Nominative:
                    case InflectionCase.Vocative:
                    {
                        if (root.EndsWith("cona") || root.EndsWith("iona"))
                        {
                            root    = root.Substring(0, root.Length - 3);
                            postfix = "eni";
                        }
                        else
                        {
                            root = this.MakeWord(word, genre, InflectionCase.Nominative, DecliantionNumber.Singular, level);
                            root = this.Soften(word, root);
                            //postfix = MakePostfix(word, ref root, ending_I_Y);
                            prefix = "";                         // above launch of MakeWord will add prefix either
                        }
                        break;
                    }

                    case InflectionCase.Genitive:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "ch";
                        break;
                    }

                    case InflectionCase.Dative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }

                    case InflectionCase.Accusative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "ch";
                        break;
                    }

                    case InflectionCase.Ablative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "mi";
                        break;
                    }

                    case InflectionCase.Locative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "ch";
                        break;
                    }
                    }
                    break;
                }

                case GrammaticalGender.Feminine:
                case GrammaticalGender.MasculineLife:
                case GrammaticalGender.MasculineThing:
                case GrammaticalGender.Neuter:
                {
                    switch (aCase)
                    {
                    case InflectionCase.Nominative:
                    case InflectionCase.Vocative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_E_IE);
                        break;
                    }

                    case InflectionCase.Genitive:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "ch";
                        break;
                    }

                    case InflectionCase.Dative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "m";
                        break;
                    }

                    case InflectionCase.Accusative:
                    {
                        postfix = this.MakePostfix(word, ref root, this.ending_E_IE);
                        break;
                    }

                    case InflectionCase.Ablative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "mi";
                        break;
                    }

                    case InflectionCase.Locative:
                    {
                        postfix  = this.MakePostfix(word, ref root, this.ending_I_Y);
                        postfix += "ch";
                        break;
                    }
                    }
                    break;
                }
                }
                break;
            }

                #endregion
            }

            return(string.Format("{0}{1}{2}", prefix, root, postfix));
        }
Esempio n. 37
0
        public string MakeWord(Noun word, InflectionCase aCase, DecliantionNumber amount)
        {
            if (aCase == InflectionCase._Unknown || amount == DecliantionNumber._Unknown)
            {
                return(null);
            }

            if ((amount == DecliantionNumber.Singular && !word.CanBeSingular) ||
                (amount == DecliantionNumber.Plural && !word.CanBePlural))
            {
                return(null);
            }

            if (word.IsConstant)
            {
                return(word.Root);
            }

            if (word.IsException)
            {
                string except = NounGrammar.GetForm(word, aCase, amount);
                if (except != null)
                {
                    return(except); // else - calculate own...
                }
            }

            string prefix  = "";
            string postfix = "";
            string root    = ((aCase != InflectionCase.Nominative || amount != DecliantionNumber.Singular) &&
                              !string.IsNullOrEmpty(word.RootOther))
                ? word.RootOther : word.Root;

            #region Switching

            postfix = this.SelectPostfix(word, aCase, amount, root);
            if (postfix == "*")
            {
                postfix = "";
            }

#if SW
            switch (word.Genre)
            {
                #region MasculineLife

            case GrammaticalGender.MasculineLife:
            {
                switch (aCase)
                {
                case InflectionCase.Nominative:             // Mianownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Genitive:             //Dopełniacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Dative:             // Celownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Accusative:             // Biernik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Ablative:             // Narzędnik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Locative:             // Miejscownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Vocative:             //Wołacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }
                }

                break;
            }

                #endregion

                #region MasculinePerson

            case GrammaticalGender.MasculinePerson:
            {
                switch (aCase)
                {
                case InflectionCase.Nominative:             // Mianownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Genitive:             //Dopełniacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Dative:             // Celownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Accusative:             // Biernik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Ablative:             // Narzędnik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Locative:             // Miejscownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Vocative:             //Wołacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }
                }
                break;
            }

                #endregion

                #region MasculineThing

            case GrammaticalGender.MasculineThing:
            {
                switch (aCase)
                {
                case InflectionCase.Nominative:             // Mianownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;                         // Nothing
                    }

                    case DecliantionNumber.Plural:
                    {
                        root    = Soften(word, root);
                        postfix = "y";
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Genitive:             //Dopełniacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        root = Soften(word, root);
                        //postfix = SelectPostfix(word, root, "a", "u");
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        root = Soften(word, root);
                        //postfix = SelectPostfix(word, root, "y", "ów");
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Dative:             // Celownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Accusative:             // Biernik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Ablative:             // Narzędnik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Locative:             // Miejscownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Vocative:             //Wołacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }
                }
                break;
            }

                #endregion

                #region Feminine

            case GrammaticalGender.Feminine:
            {
                switch (aCase)
                {
                case InflectionCase.Nominative:             // Mianownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Genitive:             //Dopełniacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Dative:             // Celownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Accusative:             // Biernik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Ablative:             // Narzędnik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Locative:             // Miejscownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Vocative:             //Wołacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }
                }
                break;
            }

                #endregion

                #region Neuter

            case GrammaticalGender.Neuter:
            {
                switch (aCase)
                {
                case InflectionCase.Nominative:             // Mianownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Genitive:             //Dopełniacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Dative:             // Celownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Accusative:             // Biernik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Ablative:             // Narzędnik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Locative:             // Miejscownik
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }

                case InflectionCase.Vocative:             //Wołacz
                {
                    switch (amount)
                    {
                    case DecliantionNumber.Singular:
                    {
                        break;
                    }

                    case DecliantionNumber.Plural:
                    {
                        break;
                    }
                    }
                    break;
                }
                }
                break;
            }

                #endregion
            }
#endif

            #endregion

            return(string.Format("{0}{1}{2}", prefix, root, postfix));
        }