Ejemplo n.º 1
0
        public string TryGloss(string language, string pos, Dialect dialect)
        {
            //HACK: This is wrong. Should be using Token or some other base class.
            if (word.ContainsCheck("-"))
            {
                CompoundWord cw = new CompoundWord(Text);
                return(cw.TryGloss(language, pos));
            }

            int  digits;
            bool isNumeric = int.TryParse(word, out digits);

            if (word.StartCheck("#") || isNumeric)
            {
                Number n = new Number(Text);
                return(n.TryGloss(language, pos, dialect));
            }

            if (Token.IsNeologism(LookupForm(word)))
            {
                //A neologism is unglossable.
                return(word);
            }

            //HACK: This is a proper modifer
            if (LookupForm(word).IsFirstUpperCased())
            {
                if (!ProperModifier.IsProperModifer(LookupForm(word)))
                {
                    ForeignWord fw = new ForeignWord(word);
                    return(fw.TryGloss(language, pos));
                }
                ProperModifier cw = new ProperModifier(Text);
                return(cw.TryGloss(language, pos));
            }

            Dictionary <string, Dictionary <string, string[]> > glossMap;

            Words.Glosses.TryGetValue(LookupForm(word), out glossMap);

            if (glossMap == null)
            {
                return("[missing map for " + Text + "]");
            }
            if (glossMap.ContainsKey(language))
            {
                if (glossMap[language].ContainsKey(pos))
                {
                    Random   r             = new Random(DateTime.Now.Millisecond);//TODO: Make this a part of config
                    string[] possibilities = glossMap[language][pos];
                    return(possibilities[r.Next(possibilities.Length)]);
                }
            }

            //TraceMissingGloss();

            if (Text.ToUpper()[0] != Text[0])
            {
                return("[Error " + pos + " " + Text + " " + language + "]");
            }
            else
            {
                return(Text);
            }
        }
Ejemplo n.º 2
0
        private static void ValidateConstruction(Word head, WordSet modifiers)
        {
            if (head == null)
            {
                throw new ArgumentNullException("head", "Cannot construct with null");
            }
            //HACK: related to taso in la fragment, and logical operators not implemented yet.
            if (!(Exclamation.IsExclamation(head.Text) || head.Text == "taso" || head.Text == "anu") && Token.CheckIsParticle(head.Text))
            {
                throw new TpSyntaxException(
                          "You cannot have a headed phrase that is headed by a particle. That would be a chain. " + head.Text + " " + (modifiers == null ? "" : modifiers.ToString()));
            }

            if (head.Text == "o" && modifiers != null && modifiers.Count > 0)
            {
                Console.WriteLine("Warning: We have an o with modifiers. This should be crazy rare." + head.Text + " " + modifiers);
                //Warning:
            }

            if (ProperModifier.IsProperModifer(head.Text))
            {
                string warning = string.Empty;
                if (Word.IsWord(head.Text.ToLower()))
                {
                    warning = " (This is a valid word, maybe it shouldn't be capitalized?)";
                }
                if (!Number.IsPomanNumber(head.Text))
                {
                    throw new TpSyntaxException("Proper modifiers cannot be the head of a headed phrase " + head.Text + warning);
                }
            }
            if (modifiers != null)
            {
                foreach (Word word in modifiers)
                {
                    if (word.Text == "en" || word.Text == "anu")
                    {
                        continue;                                          //HACK: Deferring dealing with these.
                    }
                    if (word.Text == "taso")
                    {
                        continue;                      //Taso actually is a modifier. Carry on.
                    }
                    if (Particle.CheckIsParticle(word.Text))
                    {
                        throw new TpSyntaxException("Particles shouldn't be modifiers: " + head.Text + " " + modifiers);
                    }
                }

                if (modifiers.Contains(Words.ona))
                {
                    if (modifiers.Contains(Words.mi))
                    {
                        throw new TpSyntaxException("Can't have ona and mi in modifier list." + head.Text + " " + modifiers);
                    }
                    if (modifiers.Contains(Words.sina))
                    {
                        throw new TpSyntaxException("Can't have ona and sina in modifier list." + head.Text + " " + modifiers);
                    }
                }
                if (modifiers.Contains(Words.sina))
                {
                    if (modifiers.Contains(Words.mi))
                    {
                        throw new TpSyntaxException("Can't have sina and mi in modifier list." + head.Text + " " + modifiers);
                    }
                }
            }
            if (modifiers != null && modifiers.Count > 1)
            {
                var query = modifiers.GroupBy(x => x)
                            .Where(g => g.Count() > 1)
                            .Select(y => y.Key)
                            .ToList();
                if (query.Count > 0)
                {
                    throw new TpSyntaxException("Degenerate modifiers-- doubles " + modifiers);
                }
            }
            //5 about never gets false positives.
            if (modifiers != null && modifiers.Count > 3)
            {
                if (head.Text == "nanpa")
                {
                    //no surprise there
                }
                else if (head.Text == "kama" || head.Text == "kama")
                {
                    //Defer kama/tawa, they take unmarked complements, so they make for long verb phrases.
                }
                //HACK:
                else if (modifiers.Any(x => x.Text == "anu" || x.Text == "en" || x.Text == "kama" || x.Text == "tawa")) //Because we've deferred dealing with conj. & serial verbs
                {
                }
                else
                {
                    throw new TpSyntaxException("Suspiciously long headed phrase " + head + " " + modifiers);
                }
            }
        }