//Maximal phrase: (subject) //jan pona anu ike lon tomo ...li pona tawa mi. //kili suwi en namako lon tomo ...li pona tawa mi. //kili suwi en namako anu loje lon tomo .... li pona tawa mi. //kili suwi namako anu loje public HeadedPhrase(Word head, WordSet modifiers = null, PrepositionalPhrase[] prepositionalPhrases = null, WordSet joinedModifiers = null, WordSet alternativeModifiers = null) { //if (new[] { "mi", "sina", "ona" }.Contains(head.Text)) //{ // throw new ArgumentException("mi, sina, ona can only be pronouns, so you must use ComplexPronoun"); //} if (modifiers != null && (modifiers.Contains(Words.kin) || modifiers.Contains(Words.ala))) { ParserUtils pu = new ParserUtils(Dialect.LooseyGoosey); var mergedTail = pu.TurnThisWordsIntoWordsWithTaggedWords(modifiers.ToArray()); modifiers = new WordSet(mergedTail); } ValidateConstruction(head, modifiers); this.head = head; this.modifiers = modifiers; this.prepositionalPhrases = prepositionalPhrases; this.joinedModifiers = joinedModifiers; this.alternativeModifiers = alternativeModifiers; }
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); } } }