コード例 #1
0
        public static ComplexChain SinglePiEnChainFactory(HeadedPhrase[] phrases)
        {
            Chain        piChain = new Chain(Particles.pi, phrases);
            ComplexChain c       = new ComplexChain(Particles.en, new Chain[] { piChain });

            return(c);
        }
コード例 #2
0
ファイル: Predicate.cs プロジェクト: Laesod/tokipona.parser
        /// <summary>
        /// Verbal Predicate
        /// </summary>
        public TpPredicate(Particle particle, VerbPhrase verbPhrase, ComplexChain directs = null, PrepositionalPhrase[] prepositionals = null)
        {
            if (particle.Text != Particles.o.Text && particle.Text != Particles.li.Text)
            {
                throw new TpSyntaxException("Tp Predicate can only have a Predicate headed by li or o-- got " + particle.Text);
            }
            if (verbPhrase == null && prepositionals == null)
            {
                throw new TpSyntaxException("A verb phrase or prepositional phrase required. (Directs are optional)");
            }
            if (verbPhrase == null && directs == null && prepositionals == null)
            {
                throw new TpSyntaxException("Verb, directs and prepositional phrases all null, not good");
            }

            //TODO: Validate.
            this.particle   = particle;   //li or o
            this.verbPhrase = verbPhrase; //only pi, en
            if (directs != null && directs.Particle.Text != Particles.e.Text)
            {
                throw new TpSyntaxException("Directs must have e as the particle.");
            }

            this.directs = directs;               //only e, pi, en

            this.prepositionals = prepositionals; //only ~prop, pi, en
        }
コード例 #3
0
        public static ComplexChain SingleEPiChainFactory(HeadedPhrase[] phrases)
        {
            Chain        piChain = new Chain(Particles.pi, phrases);
            ComplexChain directs = new ComplexChain(Particles.e, new[] { piChain });

            return(directs);
        }
コード例 #4
0
 public Vocative(ComplexChain nominal)
 {
     if (nominal == null)
     {
         throw new TpSyntaxException("Nominal required");
     }
     this.nominal = nominal;
 }
コード例 #5
0
        public void ParseAndToString()
        {
            const string value = "jelo esun en kasi esun";
            ComplexChain c     = ComplexChain.Parse(value);

            Console.WriteLine(c.ToJsonDcJs());
            Assert.AreEqual(value, c.ToString(), c.ToString("b"));
        }
コード例 #6
0
        public void ParseEsunEnKasi()
        {
            const string value = "esun en kasi";
            ComplexChain c     = ComplexChain.Parse(value);

            Assert.AreEqual(c.Particle.ToString(), Particles.en.ToString());
            Console.WriteLine(c.ToJsonDcJs());
            Assert.AreEqual(value, c.ToString(), c.ToString("b"));
        }
コード例 #7
0
        public void ParseTwoPiPhrasesPlusEn()
        {
            const string value = "esun pi tenpo suno en kasi pi tenpo suno";
            ComplexChain c     = ComplexChain.Parse(value);

            Assert.AreEqual(c.Particle.ToString(), Particles.en.ToString());
            Console.WriteLine(c.ToJsonDcJs());
            Assert.AreEqual(value, c.ToString(), c.ToString("b"));
        }
コード例 #8
0
        public static ComplexChain SampleDirectsChain()
        {
            Chain c1 = Chain.PiChainFactory(new HeadedPhrase(Words.jelo, new WordSet {
                Words.esun
            }));
            Chain c2 = Chain.PiChainFactory(new HeadedPhrase(Words.kasi, new WordSet {
                Words.esun
            }));
            ComplexChain c = new ComplexChain(Particles.e, new[] { c1, c2 });

            return(c);
        }
コード例 #9
0
        public VerbPhrase(Word headVerb, WordSet modals, ComplexChain nounComplement)
        {
            if (headVerb == null)
            {
                throw new ArgumentNullException("headVerb");
            }
            if (!(headVerb.Text == "tawa" || headVerb.Text == "kama"))
            {
                throw new ArgumentException("Don't know what these are called but this sort of phrase can only have tawa or kama as the head verb.");
            }
            if (Particle.NonContentParticles.Contains(headVerb.Text))
            {
                throw new TpSyntaxException("Head verb cannot be a particle.");
            }
            if (modals != null)
            {
                foreach (Word modal in modals)
                {
                    if (modal.Text != "pi" && Particle.NonContentParticles.Contains(modal.Text))
                    {
                        throw new TpSyntaxException("Modals cannot be a particle.");
                    }
                    if (!Token.IsModal(modal))
                    {
                        throw new TpSyntaxException("Modals must be one of these: " + string.Join(",", Token.Modals) + " but got " + modal);
                    }
                }
            }

            //jan li (ken, wile) kama jan pali pi tomo pi telo nasa.
            //How to split?  jan li kama sona. => ? jan li kama wawa sona.
            //How to split?  jan li kama sona. => jan li ken kama sona. (modals are fine)
            //if (adverbs != null)
            //{
            //    foreach (Word adverb in adverbs)
            //    {
            //        if (adverb.Text != "pi" && Particle.NonContentParticles.Contains(adverb.Text))
            //        {
            //            throw new TpSyntaxException("Adverbs cannot be a particle. (maybe we have a nominal predicate here?)");
            //        }
            //    }
            //}

            this.headVerb = headVerb; //Any content word.
            this.modals   = modals;
            //this.adverbs = adverbs;
            this.nounComplement = nounComplement;
        }
コード例 #10
0
 //1 of these per Different preps strung together  //~sama x ~sama x2 ~kepeken y
 public PrepositionalPhrase(Word preposition, ComplexChain complexChain)
 {
     if (Particles.Prepositions.Contains(preposition.Text))
     {
         preposition = new Word("~" + preposition.Text);
     }
     else if (!Particles.Prepositions.Contains(preposition.Text.Remove(0, 1)))
     {
         throw new ArgumentException("Invlaid prep: " + preposition.Text);
     }
     if (complexChain == null)
     {
         throw new ArgumentNullException("complexChain", "prepositional phrases cannot be a stand alone preposition");
     }
     this.preposition  = preposition;
     this.complexChain = complexChain;
 }
コード例 #11
0
 public void TwoWordsAfterPiRequired()
 {
     try
     {
         //mi pana e sike sewi laso pi telo
         const string value = "sike sewi laso pi telo";
         ComplexChain c     = ComplexChain.Parse(value);
         Assert.AreEqual(c.Particle.ToString(), Particles.en.ToString());
         Console.WriteLine(c.ToJsonDcJs());
         Assert.AreEqual(value, c.ToString(), c.ToString("b"));
     }
     catch (TpSyntaxException ex)
     {
         Assert.Pass();
         return;
     }
     Assert.Fail();
 }
コード例 #12
0
ファイル: Predicate.cs プロジェクト: Laesod/tokipona.parser
        /// <summary>
        /// Nominal or Predicate
        /// </summary>
        public TpPredicate(Particle particle, ComplexChain nominalPredicate, ComplexChain directs = null, PrepositionalPhrase[] prepositionals = null)
        {
            if (particle.Text != Particles.o.Text && particle.Text != Particles.li.Text)
            {
                throw new TpSyntaxException("Tp Predicate can only have a Predicate headed by li or o-- got " + particle.Text);
            }
            if (nominalPredicate == null && prepositionals == null)
            {
                throw new TpSyntaxException("A nominal predicate phrase or prepositional phrase required. (Directs are optional)");
            }
            if (nominalPredicate == null && directs == null && prepositionals == null)
            {
                throw new TpSyntaxException("Nominal Predicate, directs(transformatives) and prepositional phrases all null, not good");
            }

            //TODO: Validate.
            this.particle         = particle;         //li or o
            this.nominalPredicate = nominalPredicate; //only pi, en
            this.directs          = directs;          //only e, pi, en
            this.prepositionals   = prepositionals;   //only ~prop, pi, en
        }
コード例 #13
0
        public static PrepositionalPhrase[] SamplePrepsChain()
        {
            //Bit over kill.
            Chain simpleChain = new Chain(Particles.pi, new[]
            {
                new HeadedPhrase(Words.jelo, new WordSet {
                    Words.esun
                })
            });
            ComplexChain complexChain = new ComplexChain(Particles.en, new[] { simpleChain });

            Chain simpleChain2 = new Chain(Particles.pi, new[]
            {
                new HeadedPhrase(Words.jelo, new WordSet {
                    Words.esun
                })
            });
            ComplexChain complexChain2 = new ComplexChain(Particles.en, new[] { simpleChain2 });

            PrepositionalPhrase phrase1 = new PrepositionalPhrase(Words.kepeken, complexChain);
            PrepositionalPhrase phrase2 = new PrepositionalPhrase(Words.kepeken, complexChain2);

            return(new[] { phrase1, phrase2 });//should these be it's own concept?
        }
コード例 #14
0
 public VerbPhrase(ComplexChain nounComplement = null)
 {
     this.nounComplement = nounComplement;
 }
コード例 #15
0
 public PiPredicate(Particle particle, ComplexChain nounPhrase)
 {
     this.particle   = particle;
     this.nounPhrase = nounPhrase;
 }