/** * Determines the maximim position at which this modifier can occur. * * @param modifier * the modifier to be checked. * @return the maximum position for this modifier. */ private static int getMaxPos(NLGElement modifier) { int position = NOUN_POSITION; if (modifier.isA(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)) || modifier.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.ADJECTIVE_PHRASE))) { WordElement adjective = getHeadWordElement(modifier); if (adjective.getFeatureAsBoolean(LexicalFeature.CLASSIFYING)) { position = CLASSIFYING_POSITION; } else if (adjective.getFeatureAsBoolean(LexicalFeature.COLOUR)) { position = COLOUR_POSITION; } else if (adjective.getFeatureAsBoolean(LexicalFeature.QUALITATIVE)) { position = QUALITATIVE_POSITION; } else { position = CLASSIFYING_POSITION; } } return(position); }
// get string for head of constituent private string getBaseForm(NLGElement constituent) { if (constituent == null) { return(null); } else if (constituent is StringElement) { return(constituent.Realisation); } else if (constituent is WordElement) { return(((WordElement)constituent).BaseForm); } else if (constituent is InflectedWordElement) { return(getBaseForm(((InflectedWordElement)constituent).BaseWord)); } else if (constituent is PhraseElement) { return(getBaseForm(((PhraseElement)constituent).getHead())); } else { return(null); } }
public virtual void testFutureTense() { SPhraseSpec test = phraseFactory.createClause(); NPPhraseSpec subj = phraseFactory.createNounPhrase("I"); VPPhraseSpec verb = phraseFactory.createVerbPhrase("go"); AdvPhraseSpec adverb = phraseFactory.createAdverbPhrase("tomorrow"); test.setSubject(subj); test.VerbPhrase = verb; test.setFeature(Feature.TENSE, Tense.FUTURE); test.addPostModifier(adverb); string sentence = realiser.realiseSentence(test); Assert.AreEqual("I will go tomorrow.", sentence); SPhraseSpec test2 = phraseFactory.createClause(); NLGElement vb = phraseFactory.createWord("go", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); test2.setSubject(subj); test2.setVerb(vb); test2.setFeature(Feature.TENSE, Tense.FUTURE); test2.addPostModifier(adverb); string sentence2 = realiser.realiseSentence(test); Assert.AreEqual("I will go tomorrow.", sentence2); }
/** * Utility method to set the discourse function for phrase components, * unless set by user * * @param function * the function * @param phrase * the phrase */ private void checkFunction(DiscourseFunction function, NLGElement phrase) { if (!phrase.hasFeature(InternalFeature.DISCOURSE_FUNCTION)) { phrase.setFeature(InternalFeature.DISCOURSE_FUNCTION, function); } }
public virtual void testForwardConjReduction() { NLGElement aggregated = fcr.apply(s2, s3); Assert.AreEqual("the woman kicks the dog on the rock and kicks the dog behind the curtain", realiser.realise(aggregated).Realisation); //$NON-NLS-1$ }
public override IList <NLGElement> realise(IList <NLGElement> elements) { IList <NLGElement> realisedList = new List <NLGElement>(); NLGElement childRealisation = null; if (elements != null) { foreach (NLGElement eachElement in elements) { if (eachElement != null) { childRealisation = realise(eachElement); if (childRealisation != null) { if (childRealisation is ListElement) { ((List <NLGElement>)realisedList).AddRange(((ListElement)childRealisation).Children); } else { realisedList.Add(childRealisation); } } } } } return(realisedList); }
/** * Collect a list of pairs of constituents with the same syntactic function * from the right periphery of two sentences. The right periphery * encompasses the complements of the main verb, and its postmodifiers. * * @param sentences * the list of sentences * @return a list of pairs of constituents with the same function, if any * are found */ public static IList <PhraseSet> rightPeriphery(params NLGElement[] sentences) { IList <PhraseSet> funcsets = new List <PhraseSet>(); PhraseSet comps = new PhraseSet(DiscourseFunction.OBJECT); // new PhraseSet(DiscourseFunction.INDIRECT_OBJECT); PhraseSet pmods = new PhraseSet(DiscourseFunction.POST_MODIFIER); foreach (NLGElement s in sentences) { NLGElement vp = s.getFeatureAsElement(InternalFeature.VERB_PHRASE); if (vp != null) { if (vp.hasFeature(InternalFeature.COMPLEMENTS)) { comps.addPhrases(vp.getFeatureAsElementList(InternalFeature.COMPLEMENTS)); } if (vp.hasFeature(InternalFeature.POSTMODIFIERS)) { pmods.addPhrases(vp.getFeatureAsElementList(InternalFeature.POSTMODIFIERS)); } } if (s.hasFeature(InternalFeature.POSTMODIFIERS)) { pmods.addPhrases(s.getFeatureAsElementList(InternalFeature.POSTMODIFIERS)); } } funcsets.Add(comps); funcsets.Add(pmods); return(funcsets); }
/** * Realises a list of elements appending the result to the on-going * realisation. * * @param realisation * the <code>StringBuffer<code> containing the current * realisation of the sentence. * @param components * the <code>List</code> of <code>NLGElement</code>s representing * the components that make up the sentence. * @param listSeparator * the string to use to separate elements of the list, empty if * no separator needed */ private void realiseList(StringBuilder realisation, IList <NLGElement> components, string listSeparator) { NLGElement realisedChild = null; for (int i = 0; i < components.Count; i++) { NLGElement thisElement = components[i]; realisedChild = realise(thisElement); string childRealisation = realisedChild.Realisation; // check that the child realisation is non-empty if (!ReferenceEquals(childRealisation, null) && childRealisation.Length > 0 && !Regex.IsMatch(childRealisation, "^[\\s\\n]+$")) { realisation.Append(realisedChild.Realisation); if (components.Count > 1 && i < components.Count - 1) { realisation.Append(listSeparator); } realisation.Append(' '); } } if (realisation.Length > 0) { realisation.Length = realisation.Length - 1; } }
/** * Iterates through a <code>List</code> of <code>NLGElement</code>s * realisation each element and adding it to the on-going realisation of * this clause. * * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param elementList * the <code>List</code> of <code>NLGElement</code>s to be * realised. * @param function * the <code>DiscourseFunction</code> each element in the list is * to take. If this is <code>null</code> then the function is not * set and any existing discourse function is kept. */ internal static void realiseList(SyntaxProcessor parent, ListElement realisedElement, IList <NLGElement> elementList, DiscourseFunction function) { // AG: Change here: the original list structure is kept, i.e. rather // than taking the elements of the list and putting them in the realised // element, we now add the realised elements to a new list and put that // in the realised element list. This preserves constituency for // orthography and morphology processing later. ListElement realisedList = new ListElement(); NLGElement currentElement = null; foreach (NLGElement eachElement in elementList) { currentElement = parent.realise(eachElement); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, function); if (eachElement.getFeatureAsBoolean(Feature.APPOSITIVE)) { currentElement.setFeature(Feature.APPOSITIVE, true); } // realisedElement.addComponent(currentElement); realisedList.addComponent(currentElement); } } if (realisedList.Children.Any()) { realisedElement.addComponent(realisedList); } }
/** * Checks to see if the base form of the word is copular, i.e. <em>be</em>. * * @param element * the element to be checked * @return <code>true</code> if the element is copular. */ public static bool isCopular(NLGElement element) { bool copular = false; if (element is InflectedWordElement) { copular = "be".Equals(((InflectedWordElement)element).BaseForm, StringComparison.OrdinalIgnoreCase); //$NON-NLS-1$ } else if (element is WordElement) { copular = "be".Equals(((WordElement)element).BaseForm, StringComparison.OrdinalIgnoreCase); //$NON-NLS-1$ } else if (element is PhraseElement) { // get the head and check if it's "be" NLGElement head = element is SPhraseSpec ? ((SPhraseSpec)element).getVerb() : ((PhraseElement)element).getHead(); if (head != null) { copular = (head is WordElement && "be".Equals(((WordElement)head).BaseForm)); } } return(copular); }
/** * Determines the number agreement for the phrase ensuring that any number * agreement on the parent element is inherited by the phrase. * * @param parent * the parent element of the phrase. * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @return the <code>NumberAgreement</code> to be used for the phrase. */ private static NumberAgreement?determineNumber(NLGElement parent, PhraseElement phrase) { object numberValue = phrase.getFeature(Feature.NUMBER); NumberAgreement?number = null; if (numberValue != null && numberValue is NumberAgreement) { number = (NumberAgreement)numberValue; } else { number = NumberAgreement.SINGULAR; } // Ehud Reiter = modified below to force number from VP for WHAT_SUBJECT // and WHO_SUBJECT interrogatuves if (parent is PhraseElement) { if (parent.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.CLAUSE)) && (PhraseHelper.isExpletiveSubject((PhraseElement)parent) || InterrogativeType.WHO_SUBJECT.Equals(parent.getFeature(Feature.INTERROGATIVE_TYPE)) || InterrogativeType.WHAT_SUBJECT.Equals(parent.getFeature(Feature.INTERROGATIVE_TYPE))) && isCopular(phrase.getHead())) { if (hasPluralComplement(phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS))) { number = NumberAgreement.PLURAL; } else { number = NumberAgreement.SINGULAR; } } } return(number); }
/** * Grabs the head verb of the verb phrase and sets it to future tense if the * phrase is future tense. It also turns off negation if the group has a * modal. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param tenseValue * the <code>Tense</code> of the phrase. * @param hasModal * <code>true</code> if the verb phrase has a modal. * @return the modified head element */ private static NLGElement grabHeadVerb(PhraseElement phrase, Tense?tenseValue, bool hasModal) { NLGElement frontVG = phrase.getHead(); if (frontVG != null) { if (frontVG is WordElement) { frontVG = new InflectedWordElement((WordElement)frontVG); } // AG: tense value should always be set on frontVG if (tenseValue != null) { frontVG.setFeature(Feature.TENSE, tenseValue); } // if (Tense.FUTURE.equals(tenseValue) && frontVG != null) { // frontVG.setFeature(Feature.TENSE, Tense.FUTURE); // } if (hasModal) { frontVG.setFeature(Feature.NEGATED, false); } } return(frontVG); }
/** * Sort the list of premodifiers for this noun phrase using adjective * ordering (ie, "big" comes before "red") * * @param originalModifiers * the original listing of the premodifiers. * @return the sorted <code>List</code> of premodifiers. */ private static IList <NLGElement> sortNPPreModifiers(IList <NLGElement> originalModifiers) { IList <NLGElement> orderedModifiers = null; if (originalModifiers == null || originalModifiers.Count <= 1) { orderedModifiers = originalModifiers; } else { orderedModifiers = new List <NLGElement>(originalModifiers); bool changesMade = false; do { changesMade = false; for (int i = 0; i < orderedModifiers.Count - 1; i++) { if (getMinPos(orderedModifiers[i]) > getMaxPos(orderedModifiers[i + 1])) { NLGElement temp = orderedModifiers[i]; orderedModifiers[i] = orderedModifiers[i + 1]; orderedModifiers[i + 1] = temp; changesMade = true; } } } while (changesMade == true); } return(orderedModifiers); }
public virtual void testBackwardConjunctionReduction() { NLGElement aggregated = bcr.apply(s3, s6); Assert.AreEqual("the woman kicks and the woman kisses the dog behind the curtain", realiser.realise(aggregated).Realisation); }
public virtual void testProgressiveComplementiserFeatures_PastTense() { phraseFactory.Lexicon = lexicon; NLGElement sandwich = phraseFactory.createNounPhrase(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN), "sandwich"); sandwich.Plural = true; PhraseElement first = phraseFactory.createClause("I", "make", sandwich); first.setFeature(Feature.TENSE, Tense.PAST); first.setFeature(Feature.PROGRESSIVE, true); first.Plural = false; PhraseElement second = phraseFactory.createClause("the mayonnaise", "run out"); second.setFeature(Feature.TENSE, Tense.PAST); second.setFeature(Feature.COMPLEMENTISER, "when"); first.addComplement(second); DocumentElement sentence = docFactory.createSentence(first); NLGElement realised = realiser.realise(sentence); // Retrieve the realisation and dump it to the console Assert.AreEqual("I was making sandwiches when the mayonnaise ran out.", realised.Realisation); }
/** * Set the verb of a clause * * @param verb */ public virtual void setVerb(object verb) { // get verb phrase element (create if necessary) NLGElement verbPhraseElement = VerbPhrase; // set head of VP to verb (if this is VPPhraseSpec, and not a coord) if (verbPhraseElement != null && verbPhraseElement is VPPhraseSpec) { ((VPPhraseSpec)verbPhraseElement).setVerb(verb); } /* * // WARNING - I don't understand verb phrase, so this may not work!! * NLGElement verbElement = getFactory().createWord(verb, * LexicalCategory.VERB); * * // get verb phrase element (create if necessary) NLGElement * verbPhraseElement = getVerbPhrase(); * * // set head of VP to verb (if this is VPPhraseSpec, and not a coord) * if (verbPhraseElement != null && verbPhraseElement instanceof * VPPhraseSpec) ((VPPhraseSpec) * verbPhraseElement).setHead(verbElement); */ }
public virtual void testComplementiserFeatureInACoordinatePhrase_PastTense() { phraseFactory.Lexicon = lexicon; NLGElement dave = phraseFactory.createWord("Dave Bus", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); NLGElement albert = phraseFactory.createWord("Albert", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); CoordinatedPhraseElement coord1 = new CoordinatedPhraseElement(dave, albert); PhraseElement born = phraseFactory.createClause(coord1, "be", "born"); born.setFeature(Feature.TENSE, Tense.PAST); born.addPostModifier("in"); born.setFeature(Feature.COMPLEMENTISER, "which"); PhraseElement theHouse = phraseFactory.createNounPhrase("the", "house"); theHouse.addComplement(born); PhraseElement clause = phraseFactory.createClause(theHouse, "be", phraseFactory.createPrepositionPhrase("in", "Edinburgh")); DocumentElement sentence = docFactory.createSentence(clause); NLGElement realised = realiser.realise(sentence); // Retrieve the realisation and dump it to the console Assert.AreEqual("The house which Dave Bus and Albert were born in is in Edinburgh.", realised.Realisation); }
public virtual void testComplementiserPassivePerfectFeatures_PastTense() { setUp(); realiser.Lexicon = lexicon; PhraseElement inner = phraseFactory.createClause("I", "play", "poker"); inner.setFeature(Feature.TENSE, Tense.PAST); inner.setFeature(Feature.COMPLEMENTISER, "where"); PhraseElement house = phraseFactory.createNounPhrase("the", "house"); house.addComplement(inner); SPhraseSpec outer = phraseFactory.createClause(null, "abandon", house); outer.addPostModifier("since 1986"); outer.setFeature(Feature.PASSIVE, true); outer.setFeature(Feature.PERFECT, true); DocumentElement sentence = docFactory.createSentence(outer); NLGElement realised = realiser.realise(sentence); // Retrieve the realisation and dump it to the console Assert.AreEqual("The house where I played poker has been abandoned since 1986.", realised.Realisation); }
/** * Perform aggregation on a single phrase. This method only works on a * {@link simplenlg.framework.CoordinatedPhraseElement}, in which case it * calls {@link #apply(List)} on the children of the coordinated phrase, * returning a coordinated phrase whose children are the result. * * @param phrase * @return aggregated result */ public virtual NLGElement apply(NLGElement phrase) { NLGElement result = null; if (phrase is CoordinatedPhraseElement) { IList <NLGElement> children = ((CoordinatedPhraseElement)phrase).Children; IList <NLGElement> aggregated = apply(children); if (aggregated.Count == 1) { result = aggregated[0]; } else { result = factory.createCoordinatedPhrase(); foreach (NLGElement agg in aggregated) { ((CoordinatedPhraseElement)result).addCoordinate(agg); } } } if (result != null) { foreach (string feature in phrase.AllFeatureNames) { result.setFeature(feature, phrase.getFeature(feature)); } } return(result); }
/** * Realise. * * @param wt * the wt * @return the string * @throws XMLRealiserException * the xML realiser exception */ public static string realise(wrapper.XmlDocumentElement wt) { string output = ""; if (wt != null) { try { if (lexicon == null) { lexicon = Lexicon.DefaultLexicon; } UnWrapper w = new UnWrapper(lexicon); DocumentElement t = w.UnwrapDocumentElement(wt); if (t != null) { Realiser r = new Realiser(lexicon); r.initialise(); NLGElement tr = r.realise(t); output = tr.Realisation; } } catch (Exception e) { throw new XMLRealiserException("NLG XMLRealiser Error", e); } } return output; }
/** * Ensures that the verb inherits the features from the clause. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param verbElement * the <code>NLGElement</code> representing the verb phrase for * this clause. */ private static void setVerbFeatures(PhraseElement phrase, NLGElement verbElement) { // this routine copies features from the clause to the VP. // it is disabled, as this copying is now done automatically // when features are set in SPhraseSpec // if (verbElement != null) { // verbElement.setFeature(Feature.INTERROGATIVE_TYPE, phrase // .getFeature(Feature.INTERROGATIVE_TYPE)); // verbElement.setFeature(InternalFeature.COMPLEMENTS, phrase // .getFeature(InternalFeature.COMPLEMENTS)); // verbElement.setFeature(InternalFeature.PREMODIFIERS, phrase // .getFeature(InternalFeature.PREMODIFIERS)); // verbElement.setFeature(Feature.FORM, phrase // .getFeature(Feature.FORM)); // verbElement.setFeature(Feature.MODAL, phrase // .getFeature(Feature.MODAL)); // verbElement.setNegated(phrase.isNegated()); // verbElement.setFeature(Feature.PASSIVE, phrase // .getFeature(Feature.PASSIVE)); // verbElement.setFeature(Feature.PERFECT, phrase // .getFeature(Feature.PERFECT)); // verbElement.setFeature(Feature.PROGRESSIVE, phrase // .getFeature(Feature.PROGRESSIVE)); // verbElement.setTense(phrase.getTense()); // verbElement.setFeature(Feature.FORM, phrase // .getFeature(Feature.FORM)); // verbElement.setFeature(LexicalFeature.GENDER, phrase // .getFeature(LexicalFeature.GENDER)); // } }
/** * Realises the subjects of a passive clause. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param phraseFactory * the phrase factory to be used. */ private static void addPassiveSubjects(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory) { NLGElement currentElement = null; if (phrase.getFeatureAsBoolean(Feature.PASSIVE)) { IList <NLGElement> allSubjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS); if (allSubjects.Any() || phrase.hasFeature(Feature.INTERROGATIVE_TYPE)) { realisedElement.addComponent(parent.realise(phraseFactory.createPrepositionPhrase("by"))); //$NON-NLS-1$ } foreach (NLGElement subject in allSubjects) { subject.setFeature(Feature.PASSIVE, true); if (subject.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)) || subject is CoordinatedPhraseElement) { currentElement = parent.realise(subject); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SUBJECT); realisedElement.addComponent(currentElement); } } } } }
/** * Checks to see if the phrase is in imperative, infinitive or bare * infinitive form. If it is then no morphology is done on the main verb. * * @param formValue * the <code>Form</code> of the phrase. * @param frontVG * the first verb in the verb group. */ private static void checkImperativeInfinitive(object formValue, NLGElement frontVG) { if ((Form.IMPERATIVE.Equals(formValue) || Form.INFINITIVE.Equals(formValue) || Form.BARE_INFINITIVE.Equals(formValue)) && frontVG != null) { frontVG.setFeature(InternalFeature.NON_MORPH, true); } }
/** * Applies aggregation to two NLGElements e1 and e2, succeeding only if they * are clauses (that is, e1.getCategory() == e2.getCategory == * {@link simplenlg.framework.PhraseCategory#CLAUSE}). */ public override NLGElement apply(NLGElement previous, NLGElement next) { NLGElement aggregated = null; if (previous.Category == PhraseCategory.PhraseCategoryEnum.CLAUSE && next.Category == PhraseCategory.PhraseCategoryEnum.CLAUSE && PhraseChecker.nonePassive(previous, next) && !PhraseChecker.expletiveSubjects(previous, next)) { if (PhraseChecker.sameSentences(previous, next)) { // case 1: identical sentences: remove the current aggregated = previous; } else if (PhraseChecker.sameFrontMods(previous, next) && PhraseChecker.sameSubjects(previous, next) && PhraseChecker.samePostMods(previous, next)) { // case 2: subjects identical: coordinate VPs aggregated = factory.createClause(); aggregated.setFeature(InternalFeature.SUBJECTS, previous.getFeatureAsElementList(InternalFeature.SUBJECTS)); aggregated.setFeature(InternalFeature.FRONT_MODIFIERS, previous.getFeatureAsElement(InternalFeature.FRONT_MODIFIERS)); aggregated.setFeature(Feature.CUE_PHRASE, previous.getFeatureAsElement(Feature.CUE_PHRASE)); aggregated.setFeature(InternalFeature.POSTMODIFIERS, previous.getFeatureAsElementList(InternalFeature.POSTMODIFIERS)); NLGElement vp; if (!PhraseChecker.sameVPArgs(previous, next) && PhraseChecker.sameVPHead(previous, next) && PhraseChecker.sameVPModifiers(previous, next)) { // case 2.1: VPs have different arguments but same head & mods NLGElement vp1 = previous.getFeatureAsElement(InternalFeature.VERB_PHRASE); vp = factory.createVerbPhrase(); vp.setFeature(InternalFeature.HEAD, vp1.getFeatureAsElement(InternalFeature.HEAD)); vp.setFeature(InternalFeature.COMPLEMENTS, vp1.getFeatureAsElementList(InternalFeature.COMPLEMENTS)); vp.setFeature(InternalFeature.PREMODIFIERS, vp1.getFeatureAsElementList(InternalFeature.PREMODIFIERS)); vp.setFeature(InternalFeature.POSTMODIFIERS, vp1.getFeatureAsElementList(InternalFeature.POSTMODIFIERS)); } else { // case 2.2: just create a coordinate vP NLGElement vp1 = previous.getFeatureAsElement(InternalFeature.VERB_PHRASE); NLGElement vp2 = next.getFeatureAsElement(InternalFeature.VERB_PHRASE); vp = factory.createCoordinatedPhrase(vp1, vp2); } // case 2.3: expletive subjects aggregated.setFeature(InternalFeature.VERB_PHRASE, vp); } else if (PhraseChecker.sameFrontMods(previous, next) && PhraseChecker.sameVP(previous, next) && PhraseChecker.samePostMods(previous, next)) { // case 3: identical VPs: conjoin subjects and front modifiers aggregated = factory.createClause(); aggregated.setFeature(InternalFeature.FRONT_MODIFIERS, previous.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS)); CoordinatedPhraseElement subjects = factory.createCoordinatedPhrase(); subjects.Category = new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE); IList <NLGElement> allSubjects = previous.getFeatureAsElementList(InternalFeature.SUBJECTS); ((List <NLGElement>)allSubjects).AddRange(next.getFeatureAsElementList(InternalFeature.SUBJECTS)); foreach (NLGElement subj in allSubjects) { subjects.addCoordinate(subj); } aggregated.setFeature(InternalFeature.SUBJECTS, subjects); aggregated.setFeature(InternalFeature.POSTMODIFIERS, previous.getFeatureAsElementList(InternalFeature.POSTMODIFIERS)); aggregated.setFeature(InternalFeature.VERB_PHRASE, previous.getFeature(InternalFeature.VERB_PHRASE)); } } return(aggregated); }
public virtual void testPronounArguments() { // the subject of s2 should have been cast into a pronominal NP NLGElement subj = s2.getFeatureAsElementList(InternalFeature.SUBJECTS)[0]; Assert.IsTrue(subj.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE))); // Assert.assertTrue(LexicalCategory.PRONOUN.equals(((PhraseElement) subj).getCategory())); }
/** * Adds <em>to</em> to the end of interrogatives concerning indirect * objects. For example, <em>who did John give the flower <b>to</b></em>. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param phraseFactory * the phrase factory to be used. */ private static void addEndingTo(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory) { if (InterrogativeType.WHO_INDIRECT_OBJECT.Equals(phrase.getFeature(Feature.INTERROGATIVE_TYPE))) { NLGElement word = phraseFactory.createWord("to", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PREPOSITION)); //$NON-NLS-1$ realisedElement.addComponent(parent.realise(word)); } }
public override NLGElement realise(NLGElement element) { NLGElement realisedElement = null; if (element is InflectedWordElement) { realisedElement = doMorphology((InflectedWordElement)element); } else if (element is StringElement) { realisedElement = element; } else if (element is WordElement) { // AG: now retrieves the default spelling variant, not the baseform // String baseForm = ((WordElement) element).getBaseForm(); string defaultSpell = ((WordElement)element).DefaultSpellingVariant; if (!ReferenceEquals(defaultSpell, null)) { realisedElement = new StringElement(defaultSpell); } } else if (element is DocumentElement) { IList <NLGElement> children = element.Children; ((DocumentElement)element).Components = realise(children); realisedElement = element; } else if (element is ListElement) { realisedElement = new ListElement(); ((ListElement)realisedElement).addComponents(realise(element.Children)); } else if (element is CoordinatedPhraseElement) { IList <NLGElement> children = element.Children; ((CoordinatedPhraseElement)element).clearCoordinates(); if (children != null && children.Any()) { ((CoordinatedPhraseElement)element).addCoordinate(realise(children[0])); for (int index = 1; index < children.Count; index++) { ((CoordinatedPhraseElement)element).addCoordinate(realise(children[index])); } realisedElement = element; } } else if (element != null) { realisedElement = element; } return(realisedElement); }
/** * Adds the <em>be</em> verb to the front of the group. * * @param frontVG * the first verb in the verb group. * @param vgComponents * the stack of verb components in the verb group. * @param frontForm * the form the current front verb is to take. * @return the new element for the front of the group. */ private static NLGElement addBe(NLGElement frontVG, Stack <NLGElement> vgComponents, Form frontForm) { if (frontVG != null) { frontVG.setFeature(Feature.FORM, frontForm); vgComponents.Push(frontVG); } return(new InflectedWordElement("be", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB))); //$NON-NLS-1$ }
public virtual void nullAndEmptyStringElementTest() { NLGElement nullStringElement = phraseFactory.createStringElement(null); NLGElement emptyStringElement = phraseFactory.createStringElement(""); NLGElement beautiful = phraseFactory.createStringElement("beautiful"); NLGElement horseLike = phraseFactory.createStringElement("horse-like"); NLGElement creature = phraseFactory.createStringElement("creature"); // Test1: null or empty at beginning SPhraseSpec test1 = phraseFactory.createClause("a unicorn", "be", "regarded as a"); test1.addPostModifier(emptyStringElement); test1.addPostModifier(beautiful); test1.addPostModifier(horseLike); test1.addPostModifier(creature); Console.WriteLine(realiser.realiseSentence(test1)); Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.", realiser.realiseSentence(test1)); // Test2: empty or null at end SPhraseSpec test2 = phraseFactory.createClause("a unicorn", "be", "regarded as a"); test2.addPostModifier(beautiful); test2.addPostModifier(horseLike); test2.addPostModifier(creature); test2.addPostModifier(nullStringElement); Console.WriteLine(realiser.realiseSentence(test2)); Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.", realiser.realiseSentence(test2)); // Test3: empty or null in the middle SPhraseSpec test3 = phraseFactory.createClause("a unicorn", "be", "regarded as a"); test3.addPostModifier("beautiful"); test3.addPostModifier("horse-like"); test3.addPostModifier(""); test3.addPostModifier("creature"); Console.WriteLine(realiser.realiseSentence(test3)); Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.", realiser.realiseSentence(test3)); // Test4: empty or null in the middle with empty or null at beginning SPhraseSpec test4 = phraseFactory.createClause("a unicorn", "be", "regarded as a"); test4.addPostModifier(""); test4.addPostModifier("beautiful"); test4.addPostModifier("horse-like"); test4.addPostModifier(nullStringElement); test4.addPostModifier("creature"); Console.WriteLine(realiser.realiseSentence(test4)); Assert.AreEqual("A unicorn is regarded as a beautiful horse-like creature.", realiser.realiseSentence(test4)); }
public virtual void data2TextTest() { SPhraseSpec p = phraseFactory.createClause("the dog", "weigh", "12"); Assert.AreEqual("The dog weighes 12.", realiser.realiseSentence(p)); NLGElement dataDropout2 = phraseFactory.createNLGElement("data dropouts"); dataDropout2.Plural = true; SPhraseSpec sentence2 = phraseFactory.createClause(); sentence2.setSubject(phraseFactory.createStringElement("there")); sentence2.setVerb("be"); sentence2.setObject(dataDropout2); Assert.AreEqual("There are data dropouts.", realiser.realiseSentence(sentence2)); SPhraseSpec weather1 = phraseFactory.createClause("SE 10-15", "veer", "S 15-20"); weather1.setFeature(Feature.FORM, Form.GERUND); Assert.AreEqual("SE 10-15 veering S 15-20.", realiser.realiseSentence(weather1)); SPhraseSpec weather2 = phraseFactory.createClause("cloudy and misty", "be", "XXX"); weather2.VerbPhrase.setFeature(Feature.ELIDED, true); Assert.AreEqual("Cloudy and misty.", realiser.realiseSentence(weather2)); SPhraseSpec weather3 = phraseFactory.createClause("S 15-20", "increase", "20-25"); weather3.setFeature(Feature.FORM, Form.GERUND); weather3.getSubject().setFeature(Feature.ELIDED, true); Assert.AreEqual("Increasing 20-25.", realiser.realiseSentence(weather3)); SPhraseSpec weather4 = phraseFactory.createClause("S 20-25", "back", "SSE"); weather4.setFeature(Feature.FORM, Form.GERUND); weather4.getSubject().setFeature(Feature.ELIDED, true); CoordinatedPhraseElement coord = new CoordinatedPhraseElement(); coord.addCoordinate(weather1); coord.addCoordinate(weather3); coord.addCoordinate(weather4); coord.Conjunction = "then"; Assert.AreEqual("SE 10-15 veering S 15-20, increasing 20-25 then backing SSE.", realiser.realiseSentence(coord)); SPhraseSpec weather5 = phraseFactory.createClause("rain", null, "likely"); Assert.AreEqual("Rain likely.", realiser.realiseSentence(weather5)); }