public void testCheckEndsWithIndefiniteArticle2() { var cannedText = "I see a"; var np = "cow"; var expected = "I see a"; var actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np); Assert.AreEqual(expected, actual); }
public virtual void testCheckEndsWithIndefiniteArticle2() { string cannedText = "I see a"; string np = "cow"; string expected = "I see a"; string actual = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(cannedText, np); Assert.AreEqual(expected, actual); }
public void testRequiresAn() { Assert.IsTrue(DeterminerAgrHelper.requiresAn("elephant")); Assert.IsFalse(DeterminerAgrHelper.requiresAn("cow")); // Does not hand phonetics Assert.IsFalse(DeterminerAgrHelper.requiresAn("hour")); // But does have exceptions for some numerals Assert.IsFalse(DeterminerAgrHelper.requiresAn("one")); Assert.IsFalse(DeterminerAgrHelper.requiresAn("100")); }
/** * Check to see if a string ends with the indefinite article "a" and it agrees with {@code np}. * @param text * @param np * @return an altered version of {@code text} to use "an" if it agrees with {@code np}, the original string otherwise. */ public static string checkEndsWithIndefiniteArticle(string text, string np) { var tokens = text.Split(' '); var lastToken = tokens[tokens.Length - 1]; if (lastToken.equalsIgnoreCase("a") && DeterminerAgrHelper.requiresAn(np)) { tokens[tokens.Length - 1] = "an"; return(stringArrayToString(tokens)); } return(text); }
/** * This method performs the morphology for determiners. * * @param determiner * the <code>InflectedWordElement</code>. * @param realisation * the current realisation of the determiner. */ public static void doDeterminerMorphology(INLGElement determiner, string realisation) { if (realisation != null) { if (!(determiner.getRealisation().Equals("a"))) { if (determiner.isPlural()) { // Use default inflection rules: if ("that".Equals(determiner.getRealisation())) { determiner.setRealisation("those"); } else if ("this".Equals(determiner.getRealisation())) { determiner.setRealisation("these"); } } else if (!determiner.isPlural()) { // Use default push back to base form rules: if ("those".Equals(determiner.getRealisation())) { determiner.setRealisation("that"); } else if ("these".Equals(determiner.getRealisation())) { determiner.setRealisation("this"); } } } // Special "a" determiner and perform a/an agreement: if (determiner.getRealisation().Equals("a")) { if (determiner.isPlural()) { determiner.setRealisation("some"); } else if (DeterminerAgrHelper.requiresAn(realisation)) { determiner.setRealisation("an"); } } } }
public override List <INLGElement> realise(List <INLGElement> elements) { var realisedElements = new List <INLGElement>(); INLGElement currentElement = null; INLGElement determiner = null; INLGElement prevElement = null; if (elements != null) { foreach (var eachElement in elements) { currentElement = realise(eachElement); if (currentElement != null) { //pass the discourse function and appositive features -- important for orth processor currentElement.setFeature(Feature.APPOSITIVE.ToString(), eachElement.getFeature(Feature.APPOSITIVE.ToString())); var function = eachElement.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()); if (function != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), function); } if (prevElement != null && prevElement is StringElement && eachElement is InflectedWordElement && (eachElement.getCategory().enumType == (int)LexicalCategoryEnum.NOUN)) { var prevString = prevElement.getRealisation(); //realisedElements.get(realisedElements.size() - 1) prevElement.setRealisation(DeterminerAgrHelper.checkEndsWithIndefiniteArticle(prevString, currentElement.getRealisation())); } // realisedElements.add(realise(currentElement)); realisedElements.add(currentElement); if (determiner == null && DiscourseFunction.SPECIFIER.Equals(currentElement.getFeature( InternalFeature.DISCOURSE_FUNCTION.ToString()))) { determiner = currentElement; determiner.setFeature(Feature.NUMBER.ToString(), eachElement.getFeature(Feature.NUMBER.ToString())); // MorphologyRules.doDeterminerMorphology(determiner, // currentElement.getRealisation()); } else if (determiner != null) { if (currentElement is ListElement) { // list elements: ensure det matches first element INLGElement firstChild = ((ListElement)currentElement).getChildren().get(0); if (firstChild != null) { //AG: need to check if child is a coordinate if (firstChild is CoordinatedPhraseElement) { MorphologyRules.doDeterminerMorphology(determiner, firstChild.getChildren().get(0).getRealisation()); } else { MorphologyRules.doDeterminerMorphology(determiner, firstChild.getRealisation()); } } } else { // everything else: ensure det matches realisation MorphologyRules.doDeterminerMorphology(determiner, currentElement.getRealisation()); } determiner = null; } } prevElement = eachElement; } } return(realisedElements); }