public void TestTwoWordsWihtProperModifierToString() { WordSet set = new WordSet(new String[] { "jan", "Mato" }); Assert.AreEqual(2, set.Count); Assert.AreEqual("jan Mato", set.ToString()); }
public void TestTwoWordsToString() { WordSet set = new WordSet(new String[] { "jan", "soweli" }); Assert.AreEqual(2, set.Count); Assert.AreEqual("jan soweli", set.ToString()); }
public void TestTwoWordsWihtProperModifierToStringUsingDictionaryWord() { WordSet set = new WordSet(); set.Add(Words.jan); set.Add(new Word("Mato")); Assert.AreEqual(2, set.Count); Assert.AreEqual("jan Mato", set.ToString()); }
public static WordSet Parse(object value) { TokenParserUtils pu = new TokenParserUtils(); Word[] words = pu.ValidWords(value.ToString()); //Can't be particles WordSet wordSet = new WordSet(words); return(wordSet); }
public static bool TryParse(string value, out WordSet result) { try { result = WordSetTypeConverter.Parse(value); return(true); } catch (Exception) { result = null; return(false); } }
//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; }
/// <summary> /// Convenience constructor. /// </summary> public HeadedPhrase(Word head, Word modifier1, Word modifier2 = null, Word modifier3 = null) { //if (new[] {"mi", "sina", "ona"}.Contains(head.Text)) //{ // throw new ArgumentException("mi, sina, ona can only be pronouns, so you must use ComplexPronoun"); //} WordSet set = new WordSet(); set.Add(modifier1); if (modifier2 != null) { set.Add(modifier2); } if (modifier3 != null) { set.Add(modifier3); } ValidateConstruction(head, set); this.head = head; this.modifiers = set; }
private VerbPhrase VerbPhraseParser(string[] verbPhraseText) { //Adjectives & noun phrases will sneak in here. Maybe need more punctuation? Word[] asWords = verbPhraseText.Select(x => new Word(x)).ToArray(); List <Word> tokens = TurnThisWordsIntoWordsWithTaggedWords(asWords); WordSet modals = new WordSet(); Word headVerb = null; WordSet adverbs = new WordSet(); foreach (Word token in tokens) { //modals until used up. Strictly by dictionary. if (headVerb == null) { if (Token.IsModal(token)) { modals.Add(token); continue; } } //head verb, only because we ran out of modals. (unless there is only one word!) if (headVerb == null) { headVerb = token; //If number, proper modifier, etc, then this is not really a verb! continue; } //Adverbs thereafter. adverbs.Add(token); } if (headVerb == null) { //Shoot! modals = new WordSet(); headVerb = null; adverbs = new WordSet(); foreach (Word token in tokens) { //modals until used up. Strictly by dictionary. //if (headVerb == null) //{ // if (Token.IsModal(token)) // { // modals.Add(token); // continue; // } //} //head verb, only because we ran out of modals. (unless there is only one word!) if (headVerb == null) { headVerb = token; //If number, proper modifier, etc, then this is not really a verb! continue; } //Adverbs thereafter. adverbs.Add(token); } } if (headVerb != null && (headVerb.Text == "tawa" || headVerb.Text == "kama") && adverbs.Count > 0) { //This could be a noun complement. string possibleNounPhrase = adverbs.ToString("g"); Console.WriteLine(possibleNounPhrase); } return(new VerbPhrase(headVerb, modals, adverbs)); }
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); } } }