private void ProcessHeadVocatives(string[] vocativeParts, List <Vocative> headVocatives, bool allAreVocatives) { bool vocativesDone = false; //Process head vocatives. for (int i = 0; i < vocativeParts.Length; i++) { if (!allAreVocatives) { if (i == vocativeParts.Length - 1) { continue; } } string vocativePart = vocativeParts[i]; if (vocativesDone) { continue; } if (vocativePart.ContainsCheck(" li ", " e ")) { vocativesDone = true; } ComplexChain vocativeChain = ProcessEnPiChain(vocativePart); Vocative v = new Vocative(vocativeChain); headVocatives.Add(v); } }
private Sentence SingleVocative() { Vocative e = new Vocative(RandomEnPiChainOfProperModifers()); Sentence s = new Sentence(e, new Punctuation("!"), SentenceDiagnostics.NotFromParser); return(s); }
//Suggest that vocatives don't chain. o jan o meli o soweli o => o! jan o! meli o! soweli o! public Sentence(Vocative vocative, Punctuation punctuation, SentenceDiagnostics diagnostics) { LaFragment = new List <Fragment>(); this.degenerateVocative = vocative; this.punctuation = punctuation; this.diagnostics = diagnostics; }
public Sentence ProcessSimpleSentence(string sentence, Punctuation punctuation, string original) { //Think this is causing a bug. ////HACK: Still need a better way to deal with quotes. //if (sentence.EndCheck("»") || sentence.EndCheck("«")) //{ // sentence = sentence.Substring(0, sentence.Length - 1); //} //Comment? Get out of here! if (sentence.StartCheck("///")) { Comment c = new Comment(sentence); return(new Sentence(c, diagnostics)); } //Simple exclamation! Get out of here! if (Exclamation.IsExclamation(sentence)) { return(new Sentence(new Exclamation(new HeadedPhrase(new Word(sentence))), punctuation, new SentenceDiagnostics(original, sentence))); } List <Vocative> headVocatives = null; //jan Mato o, ale li pona. Head vocative! //kin la o moku. //not a vocative (hopefully dealt with elsewhere) //jan Mato o moku! //Head vocative, & imperative, with 2nd o discarded //jan Mato o o moku! //Head vocative, & imperative, with 2nd o discarded if (sentence.ContainsCheck(" o o "))//Explicit vocative & imperative { //Okay, we know exactly when the head vocatives end. headVocatives = new List <Vocative>(); string justHeadVocatives = sentence.Substring(0, sentence.IndexOf(" o o ", StringComparison.Ordinal)); //Process head vocatives. ProcessHeadVocatives(Splitters.SplitOnO(justHeadVocatives), headVocatives, allAreVocatives: true); //BUG: Add the dummy! (And it still doesn't work!) sentence = "jan Sanwan o " + sentence.Substring(sentence.IndexOf(" o o ", StringComparison.Ordinal) + 5); } //Starts with o, then we have imperative & no head vocatives. bool endsOrStartsWithO = sentence.StartCheck("o ") && sentence.EndCheck(" o"); if (!endsOrStartsWithO) { //jan So o! (We already deal with degenerate vocative sentences elsewhere) //jan So o sina li nasa. //jan So o nasa! //jan So o mi mute o nasa. <-- This is the problem. //These could be vocatives or imperatives. if (sentence.ContainsCheck(" o ", " o,", ",o ") && sentence.ContainsCheck(" li ")) { headVocatives = new List <Vocative>(); ProcessHeadVocatives(Splitters.SplitOnO(sentence), headVocatives, allAreVocatives: false); //int firstLi = sentence.IndexOf(" li "); int lastO = sentence.LastIndexOf(" o ", StringComparison.Ordinal); if (lastO < 0) { lastO = sentence.LastIndexOf(" o,", StringComparison.Ordinal); } sentence = sentence.Substring(lastO + 2); } } //Process tag conjunctions and tag questions Particle conjunction = null; TagQuestion tagQuestion = null; if (sentence.StartCheck("taso ")) { conjunction = Particles.taso; sentence = sentence.Substring(5); } else if (sentence.StartCheck("anu ")) { conjunction = Particles.anu; sentence = sentence.Substring(4); } else if (sentence.StartCheck("en ")) { //Well, either parse it or throw. Otherwise, this gets skipped. //is this legal? conjunction = Particles.en; sentence = sentence.Substring(3); } else if (sentence.StartCheck("ante ")) //never seen it. { conjunction = Particles.ante; sentence = sentence.Substring(5); } //Should already have ? stripped off if (sentence.EndsWith(" anu seme")) { tagQuestion = new TagQuestion(); sentence = sentence.Substring(0, sentence.LastIndexOf(" anu seme", StringComparison.Ordinal)); } if (sentence.EndCheck(" li")) { throw new TpParseException("Something went wrong-- sentenc ends with li. " + sentence); } if (sentence.StartsOrContainsOrEnds("la")) { throw new TpParseException("If it contains a la, anywhere, it isn't a simple sentence. " + sentence); } bool isHortative = false; bool isImperative = false; if (sentence.StartCheck("o ") && sentence.ContainsCheck(" li ")) { //o mi mute li moku isHortative = true; sentence = sentence.RemoveLeadingWholeWord("o"); } if (sentence.StartCheck("o ") && !sentence.ContainsCheck(" li ")) { //o pana e pan isImperative = true; //sentence = sentence.RemoveLeadingWholeWord("o"); } // someting o ==> vocative string[] liParts = Splitters.SplitOnLiOrO(sentence); if (liParts.Length == 1 && Exclamation.IsExclamation(liParts[0])) { //HACK: Duplicate code. & it only deals with a single final puncution mark. string possiblePunctuation = sentence[sentence.Length - 1].ToString(); if (Punctuation.TryParse(possiblePunctuation, out punctuation)) { sentence = sentence.Substring(0, sentence.Length - 1); } //The whole thing is o! (or pakala! or the like) //pona a! a a a! ike a! TokenParserUtils tpu = new TokenParserUtils(); Word[] tokes = tpu.ValidWords(sentence); HeadedPhrase parts = new HeadedPhrase(tokes[0], new WordSet(ArrayExtensions.Tail(tokes))); bool modifiersAreA = true; foreach (Word w in parts.Modifiers) { if (w == "a") { continue; //peculiar to exclamations & repeats. } if (w == "kin") { continue; //modifies just about anything } modifiersAreA = false; } if (modifiersAreA) { Exclamation exclamation = new Exclamation(parts); Sentence s = new Sentence(exclamation, punctuation, diagnostics); return(s); } } //Degenerate sentences. if (liParts[liParts.Length - 1].Trim(new char[] { ',', '«', '»', '!', ' ' }) == "o") { //We have a vocative sentence... Vocative vocative = new Vocative(ProcessEnPiChain(liParts[0])); Sentence s = new Sentence(vocative, punctuation, diagnostics); return(s); } string subjects = liParts[0].Trim(); ComplexChain subjectChain = null; int startAt = 1; //slot 0 is normally a subject if (subjects.Contains("«")) { int foo = 3; } if (subjects.StartCheck("o ") || subjects.StartCheck("«o ")) { //This is a verb phrase with implicit subjects! startAt = 0; } else { subjectChain = ProcessEnPiChain(subjects); } PredicateList verbPhrases = new PredicateList(); for (int i = startAt; i < liParts.Length; i++) { string predicate = liParts[i].Trim(); verbPhrases.Add(ProcessPredicates(predicate)); } //Head or complete sentence. Sentence parsedSentence = new Sentence(subjectChain, verbPhrases, diagnostics, new SentenceOptionalParts { Conjunction = conjunction, //Etc Punctuation = punctuation, IsHortative = isHortative, TagQuestion = tagQuestion, HeadVocatives = headVocatives != null ? headVocatives.ToArray() : null }); return(parsedSentence); }