예제 #1
0
        //This only works for 1 subject!
        //kule pi walo en pimeja
        public ComplexChain ProcessBackwardsPiEnChain(string subjects)
        {
            if (String.IsNullOrEmpty(subjects))
            {
                throw new ArgumentException("Cannot parse null/empty subjects");
            }
            foreach (var particle in new[] { "la", "li" })
            {
                if (subjects.StartsOrContainsOrEnds(particle))
                {
                    throw new ArgumentException("Subject phrase : " + subjects + " Contains " + particle + ". This is not possible.");
                }
            }

            string[] singleSubjectWithCompoundModifers = Splitters.SplitOnPi(subjects);

            //Split on pi
            //jan pi pali suli en soweli pi tawa wawa

            //jan ~tan ma pi pali suli ~tawa mani pi ma suli en soweli pi tawa wawa
            //jan ~tan ma pi pali suli ~tawa mani pi ma suli /en/ soweli pi tawa wawa
            //jan ~tan ma //pi// pali suli ~tawa mani //pi// ma suli /en/ soweli //pi// tawa wawa

            //BUG: Following code wraps simple chain in unnecessary complex chain.
            List <ComplexChain> subChains = new List <ComplexChain>();

            for (int i = 0; i < singleSubjectWithCompoundModifers.Length; i++)
            {
                string piChains = singleSubjectWithCompoundModifers[i];

                if (piChains == "")
                {
                    continue; //But how did that happen?
                }
                string[] enLessTokens = Splitters.SplitOnEn(piChains);

                List <Chain> piCollection = new List <Chain>();
                foreach (string enLessToken in enLessTokens)
                {
                    Chain piPhrase = ProcessPiChain(enLessToken);
                    piCollection.Add(piPhrase);
                }
                ComplexChain piChain = new ComplexChain(Particles.en, piCollection.ToArray());
                subChains.Add(piChain);
            }

            //if (subChains[0].SubChains.Length > 1 && subChains[0].SubChains.Last().ToString().Split(new char[] { '*', ' ', '-' }).Length == 1)
            //{
            //    throw new TpSyntaxException("final pi in pi chain must be followed by 2 words, otherwise just use juxtaposition (i.e. 2 adjacent words with no particle) : " + subjects);
            //}

            ComplexChain subject = new ComplexChain(Particles.pi, subChains.ToArray());

            return(subject);
        }
예제 #2
0
        public ComplexChain ProcessEnPiChain(string subjects)
        {
            if (String.IsNullOrEmpty(subjects))
            {
                throw new ArgumentException("Cannot parse null/empty subjects");
            }

            //if (processEnPiChainMemo.ContainsKey(value))
            //{
            //    return processEnPiChainMemo[value];
            //}

            foreach (var particle in new[] { "la", "li" })
            {
                if (subjects.StartsOrContainsOrEnds(particle))
                {
                    throw new ArgumentException("Subject phrase : " + subjects + " Contains " + particle + ". This is not possible.");
                }
            }

            string[] subjectTokens = Splitters.SplitOnEn(subjects);

            //Split on pi
            //jan pi pali suli en soweli pi tawa wawa

            //jan ~tan ma pi pali suli ~tawa mani pi ma suli en soweli pi tawa wawa
            //jan ~tan ma pi pali suli ~tawa mani pi ma suli /en/ soweli pi tawa wawa
            //jan ~tan ma //pi// pali suli ~tawa mani //pi// ma suli /en/ soweli //pi// tawa wawa

            //BUG: Following code wraps simple chain in unnecessary complex chain.
            List <ComplexChain> subChains = new List <ComplexChain>();

            for (int i = 0; i < subjectTokens.Length; i++)
            {
                string piChains = subjectTokens[i];

                if (piChains == "")
                {
                    continue; //But how did that happen?
                }
                string[] piLessTokens = Splitters.SplitOnPi(piChains);

                List <Chain> piCollection = new List <Chain>();
                foreach (string piLessToken in piLessTokens)
                {
                    Chain piPhrase = ProcessPiChain(piLessToken);
                    piCollection.Add(piPhrase);
                }
                ComplexChain piChain = new ComplexChain(Particles.pi, piCollection.ToArray());
                subChains.Add(piChain);
            }

            if (subChains[0].SubChains.Length > 1 && subChains[0].SubChains.Last().ToString().Split(new[] { '*', ' ', '-' }).Length == 1)
            {
                string lastWord = subChains[0].SubChains.Last().ToString();
                if (Number.IsPomanNumber(lastWord) && lastWord.Replace("#", "").Length > 1)
                {
                    //Poman numbers with 2 letters or more represent 2+ words.
                }
                else if (subjects.Contains(" en "))
                {
                    //HACK: maybe a compound modifier.  This actually usually fails.
                    return(ProcessBackwardsPiEnChain(subjects));
                }
                else
                {
                    throw new TpSyntaxException("final pi in pi chain must be followed by 2 words, otherwise just use juxtaposition (i.e. 2 adjacent words with no particle) : " + subjects);
                }
            }

            ComplexChain subjectChain = new ComplexChain(Particles.en, subChains.ToArray());

            //processEnPiChainMemo.Add(subjects,subjectChain);
            return(subjectChain);
        }