private void ProcessPrepositionalPhrase(List <string> gloss, PrepositionalPhrase sub, bool includePos, Dialect formatProvider) { //HACK: I think the parser is wrapping a whole Perp phrase in a complex chain with just one Prep. Maybe that is correct & leave open option of treating chains of preps as a chains. gloss.Add(GlossWithFallBack(includePos, formatProvider, sub.Preposition, PartOfSpeech.Preposition)); ProcessOneChain(includePos, gloss, formatProvider, sub.Complement); }
public PrepositionalPhrase[] RandomPrepChain() { Dictionary <int, int> odds = new Dictionary <int, int> { { 1, 74 }, { 2, 10 }, { 3, 10 }, { 4, 5 }, { 5, 1 }, }; ConvertToCummulative(odds); int dice = random.Next(0, 101); var howMany = odds.Where(x => dice <= x.Value).Select(x => x.Key).First(); List <PrepositionalPhrase> prepositionals = new List <PrepositionalPhrase>(); while (howMany > 0) { Word w = new Word(Particles.Prepositions[random.Next(0, 6)]); PrepositionalPhrase pp = new PrepositionalPhrase(w, RandomEnPiChain()); prepositionals.Add(pp); howMany--; } return(prepositionals.ToArray()); }
public void PrepositionalRoleTest() { IEnumerable <Word> composedWords = new Word[] { new Preposition("for") }; var target = new PrepositionalPhrase(composedWords); var expected = PrepositionRole.Undetermined; PrepositionRole actual = target.PrepositionRole; Assert.Equal(expected, actual); }
public void PrepositionalPhraseConstructorTest() { var composedWords = new[] { new Preposition("on") }; var target = new PrepositionalPhrase(composedWords); Check.That(target.Words).HasSize(composedWords.Length); Check.That(target).Satisfies(() => target.Text is "on" && target.ToTheLeftOf is null && target.ToTheRightOf is null && target.BoundObject is null ); }
public void OnRightSideTest() { var target = new PrepositionalPhrase(new Preposition("for")); ILexical expected = new VerbPhrase(new PresentParticiple("slamming")); ILexical actual; target.ToTheRightOf = expected; actual = target.ToTheRightOf; Check.That(actual).IsEqualTo(expected); }
public void OnLeftSideTest() { var target = new PrepositionalPhrase(new Preposition("for")); ILexical expected = new NounPhrase(new PersonalPronoun("it")); ILexical actual; target.ToTheLeftOf = expected; actual = target.ToTheLeftOf; Check.That(actual).IsEqualTo(expected); }
public void ToTheRightOfTest() { var target = new PrepositionalPhrase(new Preposition("on")); ILexical expected = new ThirdPersonSingularPresentVerb("is"); ILexical actual; target.ToTheRightOf = expected; actual = target.ToTheRightOf; Assert.Equal(expected, actual); }
public void ToTheLeftOfTest() { var target = new PrepositionalPhrase(new Preposition("on")); ILexical expected = new NounPhrase(new Determiner("the"), new CommonSingularNoun("table")); ILexical actual; target.ToTheLeftOf = expected; actual = target.ToTheLeftOf; Assert.Equal(expected, actual); }
public void RoleTest() { var target = new PrepositionalPhrase(new Preposition("on")); var expected = PrepositionRole.LocationOrScopeSpecifier; PrepositionRole actual; target.PrepositionRole = expected; actual = target.PrepositionRole; Assert.Equal(expected, actual); }
public void BindObjectTest() { var target = new PrepositionalPhrase(new Preposition("on")); ILexical prepositionalObject = new NounPhrase(new Determiner("the"), new CommonSingularNoun("table")); target.BindObject(prepositionalObject); Assert.Equal(prepositionalObject, target.BoundObject); IVerbal verbal = new ThirdPersonSingularPresentVerb("is"); verbal.AttachObjectViaPreposition(target); Assert.Equal(prepositionalObject, verbal.ObjectOfThePreposition); }
private static void ProcessLinkingPrepositionalPhrase(PrepositionalPhrase prepPhrase) { if (prepPhrase.Previous != null) { prepPhrase.Previous.BindRightPrepositional(prepPhrase); } else if (prepPhrase.Next != null) { prepPhrase.Next.BindLeftPrepositional(prepPhrase); } prepPhrase.ToTheRightOf = prepPhrase.Next; prepPhrase.ToTheLeftOf = prepPhrase.Previous; prepPhrase.PrepositionRole = PrepositionRole.DiscriptiveLinker; }
public void ToStringTest() { Phrase.VerboseOutput = true; var target = new PrepositionalPhrase(new Preposition("for")); var left = new NounPhrase(new PersonalPronoun("it")); var right = new VerbPhrase(new PresentParticiple("slamming")); target.ToTheLeftOf = left; target.ToTheRightOf = right; var expected = $"PrepositionalPhrase \"for\"\n\tleft linked: {left.Text}\n\tright linked: {right.Text}"; var actual = target.ToString(); Check.That(actual).IsEqualTo(expected); }
// jan li jo e soweli e kili e wawa lon anpa tawa anpa // li jo e soweli e kili e wawa lon anpa tawa anpa public TpPredicate ProcessPredicates(string liPart) { if (String.IsNullOrWhiteSpace(liPart)) { throw new TpParseException("Missing argument, cannot continue"); } if (liPart == "li") { throw new TpParseException("Cannot do anything with just li"); } TokenParserUtils pu = new TokenParserUtils(); Particle verbPhraseParticle; ComplexChain directObjectChain = null; VerbPhrase verbPhrase = null; PrepositionalPhrase[] prepositionalChain = null; ComplexChain nominalPredicate = null; PiPredicate piPredicate = null; //Transitive Path. if (liPart.Split(new[] { ' ', '\t' }).Contains("e")) { string[] eParts = Splitters.SplitOnE(liPart); string[] verbPhraseParts = pu.WordsPunctuationAndCompounds(eParts[0]); //Could contain particles. if (!Token.CheckIsParticle(verbPhraseParts[0])) { throw new TpSyntaxException("uh-oh not a particle: " + verbPhraseParts[0] + " from " + liPart); } verbPhraseParticle = new Particle(verbPhraseParts[0]); //Only process preps in normalized sentences string[] partsWithPreps = null; if (verbPhraseParts.Length > 1) { if (verbPhraseParts.Any(x => x == "pi")) { //nominal predicate nominalPredicate = new ComplexChain(Particles.en, new[] { ProcessPiChain(String.Join(" ", ArrayExtensions.Tail(verbPhraseParts))) }); } else { verbPhrase = VerbPhraseParser(ArrayExtensions.Tail(verbPhraseParts)); } } string verbsMaybePrepositions = eParts[eParts.Length - 1]; if (verbsMaybePrepositions.ContainsCheck("~")) { partsWithPreps = Splitters.SplitOnPrepositions(verbsMaybePrepositions); if (partsWithPreps.Length == 1) { //This is the last e phrase or 1st prep. if (partsWithPreps[0].ContainsCheck("~")) { //That is a prep phrase (is this possible?) } else { eParts[eParts.Length - 1] = partsWithPreps[0]; //No prep phrases. } } } string[] directObjects = ArrayExtensions.Tail(eParts); //List<HeadedPhrase> doNPs = new List<HeadedPhrase>(); List <Chain> doPiChains = new List <Chain>(); //Fancy foot work for when we have e ... ~... & that's all. string[] toUse; if (partsWithPreps != null) { toUse = partsWithPreps.Where(x => x.StartCheck("e ")).ToArray(); directObjects[directObjects.Length - 1] = toUse[0]; toUse = directObjects; } else { toUse = directObjects; } foreach (string directObject in toUse) { if (directObject.Length <= 2) { throw new TpParseException("This is a degenerate e phrase, i.e. it is only e or e space. Missing a ni, e.g. e ni: possibly. ref: " + liPart); } string eFree = directObject.Substring(2); Chain phrase = ProcessPiChain(eFree); doPiChains.Add(phrase); } directObjectChain = new ComplexChain(Particles.e, doPiChains.ToArray()); if (partsWithPreps != null) { prepositionalChain = ProcessPrepositionalPhrases(partsWithPreps).ToArray(); } } else { //Intransitives & Predictates string[] ppParts = Splitters.SplitOnPrepositions(liPart); if (ppParts.Length == 0) //Excect at least "li verb" or "li noun" { throw new TpParseException("Whoa, got " + ppParts.Length + " parts for " + liPart); } if (Punctuation.ContainsPunctuation(ppParts[0])) { throw new TpParseException("This has punctuation, may fail to parse : " + ppParts[0]); } string[] verbPhraseParts = pu.WordsPunctuationAndCompounds(ppParts[0]); if (!Token.CheckIsParticle(verbPhraseParts[0])) { throw new TpSyntaxException("uh-oh not a particle: " + verbPhraseParts[0] + " from " + liPart); } verbPhraseParticle = new Particle(verbPhraseParts[0]); if (verbPhraseParts.Length > 1) { //0:li 1:xxx 2:np... if (verbPhraseParts[1].ContainsCheck("XXXXZiXXXX")) { //Make it go away. Confuses other parsers and will be picked up by container object. verbPhraseParts = ArrayExtensions.Tail(verbPhraseParts); //piPredicate ComplexChain phrase = new ComplexChain(Particles.en, new[] { ProcessPiChain(String.Join(" ", ArrayExtensions.Tail(verbPhraseParts))) }); piPredicate = new PiPredicate(Particles.pi, phrase); } else if (verbPhraseParts.Any(x => x == "pi")) { //nominal predicate nominalPredicate = new ComplexChain(Particles.en, new[] { ProcessPiChain(String.Join(" ", ArrayExtensions.Tail(verbPhraseParts))) } ); } else { verbPhrase = VerbPhraseParser(ArrayExtensions.Tail(verbPhraseParts)); } } string[] prepositions = ArrayExtensions.Tail(ppParts); if (prepositions.Length != 0) { List <PrepositionalPhrase> pChains = new List <PrepositionalPhrase>(); foreach (string pp in prepositions) { string[] phraseParts = pu.WordsPunctuationAndCompounds(pp);//Could contain particles. string preposition = phraseParts[0]; string[] tail = ArrayExtensions.Tail(phraseParts); if (tail.Length == 0) { //uh oh. This is an intransitive verb, like "ni li lon" //HACK: Oh, this is so ugly (still sort of ugly) verbPhrase = new VerbPhrase(new Word(preposition.Replace("~", ""))); //or a noun phrase. continue; } PrepositionalPhrase foundPrepositionalPhrase = new PrepositionalPhrase(new Word(preposition), ProcessEnPiChain(String.Join(" ", tail))); pChains.Add(foundPrepositionalPhrase); } if (pChains.Count > 0) { prepositionalChain = pChains.ToArray(); } else { //We changed our mind about a phrase being a prep phrase. Turned out to be verb phrase or predicate. } } } if (piPredicate != null) { return(new TpPredicate(verbPhraseParticle, piPredicate, prepositionalChain)); } if (nominalPredicate == null) { return(new TpPredicate(verbPhraseParticle, verbPhrase, directObjectChain, prepositionalChain)); } return(new TpPredicate(verbPhraseParticle, nominalPredicate, directObjectChain, prepositionalChain)); }