Example #1
0
        public virtual void multipleAdjPremodifiersTest()
        {
            NPPhraseSpec np = phraseFactory.createNounPhrase("a", "stenosis");

            np.addPreModifier(phraseFactory.createAdjectivePhrase("eccentric"));
            np.addPreModifier(phraseFactory.createAdjectivePhrase("discrete"));
            Assert.AreEqual("an eccentric, discrete stenosis", realiser.realise(np).Realisation);
        }
Example #2
0
        public void dwightTest()
        {
            // Rachel Dwight's test
            SetupForExternalTest.phraseFactory.setLexicon(SetupForExternalTest.lexicon);

            NPPhraseSpec noun4 = SetupForExternalTest.phraseFactory
                                 .createNounPhrase("FGFR3 gene in every cell");

            noun4.setSpecifier("the");

            PPPhraseSpec prep1 = SetupForExternalTest.phraseFactory.createPrepositionPhrase(
                "of", noun4);

            NPPhraseSpec noun1 = SetupForExternalTest.phraseFactory.createNounPhrase(
                "the", "patient's mother");

            NPPhraseSpec noun2 = SetupForExternalTest.phraseFactory.createNounPhrase(
                "the", "patient's father");

            NPPhraseSpec noun3 = SetupForExternalTest.phraseFactory
                                 .createNounPhrase("changed copy");

            noun3.addPreModifier("one");
            noun3.addComplement(prep1);

            var coordNoun1 = new CoordinatedPhraseElement(
                noun1, noun2);

            coordNoun1.setConjunction("or");

            VPPhraseSpec verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("have");

            verbPhrase1.setFeature(Feature.TENSE.ToString(), Tense.PRESENT);

            SPhraseSpec sentence1 = SetupForExternalTest.phraseFactory.createClause(coordNoun1,
                                                                                    verbPhrase1, noun3);

            Assert
            .AreEqual(
                "the patient's mother or the patient's father has one changed copy of the FGFR3 gene in every cell",

                SetupForExternalTest.realiser.realise(sentence1).getRealisation());

            // Rachel's second test
            noun3       = SetupForExternalTest.phraseFactory.createNounPhrase("a", "gene test");
            noun2       = SetupForExternalTest.phraseFactory.createNounPhrase("an", "LDL test");
            noun1       = SetupForExternalTest.phraseFactory.createNounPhrase("the", "clinic");
            verbPhrase1 = SetupForExternalTest.phraseFactory.createVerbPhrase("perform");

            var coord1 = new CoordinatedPhraseElement(noun2,
                                                      noun3);

            sentence1 = SetupForExternalTest.phraseFactory.createClause(noun1, verbPhrase1, coord1);
            sentence1.setFeature(Feature.TENSE.ToString(), Tense.PAST);

            Assert
            .AreEqual(
                "the clinic performed an LDL test and a gene test", SetupForExternalTest.realiser
                .realise(sentence1).getRealisation());
        }
Example #3
0
        public virtual void testAAnCoord()
        {
            NPPhraseSpec _dog = phraseFactory.createNounPhrase("a", "dog");

            _dog.addPreModifier(phraseFactory.createCoordinatedPhrase("enormous", "black"));
            string realisation = realiser.realise(_dog).Realisation;

            Assert.AreEqual("an enormous and black dog", realisation);
        }
Example #4
0
        public virtual void testAgreement()
        {
            // basic agreement
            NPPhraseSpec np = phraseFactory.createNounPhrase("dog");                         //$NON-NLS-1$

            np.setSpecifier("the");                                                          //$NON-NLS-1$
            np.addPreModifier("angry");                                                      //$NON-NLS-1$
            PhraseElement _s1 = phraseFactory.createClause(np, "chase", "John");             //$NON-NLS-1$ //$NON-NLS-2$

            Assert.AreEqual("the angry dog chases John", realiser.realise(_s1).Realisation); //$NON-NLS-1$


            // plural
            np = phraseFactory.createNounPhrase("dog");                                      //$NON-NLS-1$
            np.setSpecifier("the");                                                          //$NON-NLS-1$
            np.addPreModifier("angry");                                                      //$NON-NLS-1$
            np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            _s1 = phraseFactory.createClause(np, "chase", "John");                           //$NON-NLS-1$ //$NON-NLS-2$
            Assert.AreEqual("the angry dogs chase John", realiser.realise(_s1).Realisation); //$NON-NLS-1$


            // test agreement with "there is"
            np = phraseFactory.createNounPhrase("dog");                                  //$NON-NLS-1$
            np.addPreModifier("angry");                                                  //$NON-NLS-1$
            np.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);
            np.setSpecifier("a");                                                        //$NON-NLS-1$
            PhraseElement _s2 = phraseFactory.createClause("there", "be", np);           //$NON-NLS-1$ //$NON-NLS-2$

            Assert.AreEqual("there is an angry dog", realiser.realise(_s2).Realisation); //$NON-NLS-1$


            // plural with "there"
            np = phraseFactory.createNounPhrase("dog");                                      //$NON-NLS-1$
            np.addPreModifier("angry");                                                      //$NON-NLS-1$
            np.setSpecifier("a");                                                            //$NON-NLS-1$
            np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            _s2 = phraseFactory.createClause("there", "be", np);                             //$NON-NLS-1$ //$NON-NLS-2$
            Assert.AreEqual("there are some angry dogs", realiser.realise(_s2).Realisation); //$NON-NLS-1$
        }
Example #5
0
        public virtual void indefiniteWithPremodifierTest()
        {
            SPhraseSpec s = phraseFactory.createClause("there", "be");

            s.setFeature(Feature.TENSE, Tense.PRESENT);
            NPPhraseSpec np = phraseFactory.createNounPhrase("a", "stenosis");

            s.setObject(np);

            // check without modifiers -- article should be "a"
            Assert.AreEqual("there is a stenosis", realiser.realise(s).Realisation);


            // add a single modifier -- should turn article to "an"
            np.addPreModifier(phraseFactory.createAdjectivePhrase("eccentric"));
            Assert.AreEqual("there is an eccentric stenosis", realiser.realise(s).Realisation);
        }
        public virtual void testCoordinateVPComplexSubject()
        {
            // "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock."
            SPhraseSpec s = phraseFactory.createClause();

            s.setSubject(phraseFactory.createNounPhrase("the", "patient"));

            // first VP
            VPPhraseSpec vp1 = phraseFactory.createVerbPhrase(lexicon.getWord("have",
                                                                              new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)));
            NPPhraseSpec np1 = phraseFactory.createNounPhrase("a",
                                                              lexicon.getWord("contrast media reaction",
                                                                              new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)));

            np1.addPreModifier(lexicon.getWord("adverse",
                                               new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)));
            vp1.addComplement(np1);

            // second VP
            VPPhraseSpec vp2 = phraseFactory.createVerbPhrase(lexicon.getWord("go",
                                                                              new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)));
            PPPhraseSpec pp = phraseFactory.createPrepositionPhrase("into",
                                                                    lexicon.getWord("cardiogenic shock", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)));

            vp2.addComplement(pp);

            // coordinate
            CoordinatedPhraseElement coord = phraseFactory.createCoordinatedPhrase(vp1, vp2);

            coord.setFeature(Feature.TENSE, Tense.PAST);
            Assert.AreEqual("had an adverse contrast media reaction and went into cardiogenic shock",
                            realiser.realise(coord).Realisation);


            // now put this in the sentence
            s.VerbPhrase = coord;
            s.addFrontModifier("As a result of the procedure");
            Assert.AreEqual(
                "As a result of the procedure the patient had an adverse contrast media reaction and went into cardiogenic shock",
                realiser.realise(s).Realisation);
        }
Example #7
0
        public virtual void section11_Test()
        {
            Lexicon    lexicon    = Lexicon.DefaultLexicon;  // default simplenlg lexicon
            NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon

            Realiser realiser = new Realiser(lexicon);

            SPhraseSpec pA = nlgFactory.createClause("Mary", "chase", "the monkey");

            pA.addComplement("in the park");

            string outputA = realiser.realiseSentence(pA);

            Assert.AreEqual("Mary chases the monkey in the park.", outputA);

            // alternative build paradigm
            NPPhraseSpec place = nlgFactory.createNounPhrase("park");
            SPhraseSpec  pB    = nlgFactory.createClause("Mary", "chase", "the monkey");

            // next line is depreciated ~ may be corrected in the API
            place.setDeterminer("the");
            PPPhraseSpec pp = nlgFactory.createPrepositionPhrase();

            pp.addComplement(place);
            pp.setPreposition("in");

            pB.addComplement(pp);

            string outputB = realiser.realiseSentence(pB);

            Assert.AreEqual("Mary chases the monkey in the park.", outputB);

            place.addPreModifier("leafy");

            string outputC = realiser.realiseSentence(pB);

            Assert.AreEqual("Mary chases the monkey in the leafy park.", outputC);
        } // testSection11