Example #1
0
 def testEnumeratedList(self):
     lexicon = Lexicon.getDefaultLexicon()
     nlgFactory = NLGFactory(lexicon)
     realiser = Realiser(lexicon)
     realiser.setFormatter(HTMLFormatter())
     document = nlgFactory.createDocument("Document")
     paragraph = nlgFactory.createParagraph()
     list_1 = nlgFactory.createEnumeratedList()
     item1 = nlgFactory.createListItem()
     item2 = nlgFactory.createListItem()
     # NB: a list item employs orthographical operations only until sentence level;
     # nest clauses within a sentence to generate more than 1 clause per list item.
     sentence1 = nlgFactory.createSentence("this", "be",
                                           "the first sentence")
     sentence2 = nlgFactory.createSentence("this", "be",
                                           "the second sentence")
     item1.addComponent(sentence1)
     item2.addComponent(sentence2)
     list_1.addComponent(item1)
     list_1.addComponent(item2)
     paragraph.addComponent(list_1)
     document.addComponent(paragraph)
     expectedOutput = "<h1>Document</h1>" + "<p>" + "<ol>" + "This is the first sentence." \
                    + "This is the second sentence." + "</ol>" + "</p>"
     realisedOutput = realiser.realise(document).getRealisation()
     self.assertEqual(expectedOutput, realisedOutput)
    def testEnumeratedList(self):
        lexicon = Lexicon.getDefaultLexicon()
        nlgFactory = NLGFactory(lexicon)
        realiser = Realiser(lexicon)
        realiser.setFormatter(TextFormatter())
        document = nlgFactory.createDocument("Document")
        paragraph = nlgFactory.createParagraph()

        subListItem1 = nlgFactory.createListItem()
        subListSentence1 = nlgFactory.createSentence("this", "be",
                                                     "sub-list sentence 1")
        subListItem1.addComponent(subListSentence1)

        subListItem2 = nlgFactory.createListItem()
        subListSentence2 = nlgFactory.createSentence("this", "be",
                                                     "sub-list sentence 2")
        subListItem2.addComponent(subListSentence2)

        subList = nlgFactory.createEnumeratedList()
        subList.addComponent(subListItem1)
        subList.addComponent(subListItem2)

        item1 = nlgFactory.createListItem()
        sentence1 = nlgFactory.createSentence("this", "be",
                                              "the first sentence")
        item1.addComponent(sentence1)

        item2 = nlgFactory.createListItem()
        sentence2 = nlgFactory.createSentence("this", "be",
                                              "the second sentence")
        item2.addComponent(sentence2)

        list_1 = nlgFactory.createEnumeratedList()
        list_1.addComponent(subList)
        list_1.addComponent(item1)
        list_1.addComponent(item2)
        paragraph.addComponent(list_1)
        document.addComponent(paragraph)
        expectedOutput = "Document\n" + \
                         "\n" + \
                         "1.1 - This is sub-list sentence 1.\n" + \
                         "1.2 - This is sub-list sentence 2.\n"+ \
                         "2 - This is the first sentence.\n" + \
                         "3 - This is the second sentence.\n" + \
                         "\n\n" # for the end of a paragraph

        realisedOutput = realiser.realise(document).getRealisation()
        self.assertEquals(expectedOutput, realisedOutput)
    def testEnumeratedListWithSeveralLevelsOfNesting(self):
        lexicon = Lexicon.getDefaultLexicon()
        nlgFactory = NLGFactory(lexicon)
        realiser = Realiser(lexicon)
        realiser.setFormatter(TextFormatter())
        document = nlgFactory.createDocument("Document")
        paragraph = nlgFactory.createParagraph()

        # sub item 1
        subList1Item1 = nlgFactory.createListItem()
        subList1Sentence1 = nlgFactory.createSentence("sub-list item 1")
        subList1Item1.addComponent(subList1Sentence1)

        # sub sub item 1
        subSubList1Item1 = nlgFactory.createListItem()
        subSubList1Sentence1 = nlgFactory.createSentence("sub-sub-list item 1")
        subSubList1Item1.addComponent(subSubList1Sentence1)

        # sub sub item 2
        subSubList1Item2 = nlgFactory.createListItem()
        subSubList1Sentence2 = nlgFactory.createSentence("sub-sub-list item 2")
        subSubList1Item2.addComponent(subSubList1Sentence2)

        # sub sub list
        subSubList1 = nlgFactory.createEnumeratedList()
        subSubList1.addComponent(subSubList1Item1)
        subSubList1.addComponent(subSubList1Item2)

        # sub item 2
        subList1Item2 = nlgFactory.createListItem()
        subList1Sentence2 = nlgFactory.createSentence("sub-list item 3")
        subList1Item2.addComponent(subList1Sentence2)

        # sub list 1
        subList1 = nlgFactory.createEnumeratedList()
        subList1.addComponent(subList1Item1)
        subList1.addComponent(subSubList1)
        subList1.addComponent(subList1Item2)

        # item 2
        item2 = nlgFactory.createListItem()
        sentence2 = nlgFactory.createSentence("item 2")
        item2.addComponent(sentence2)

        # item 3
        item3 = nlgFactory.createListItem()
        sentence3 = nlgFactory.createSentence("item 3")
        item3.addComponent(sentence3)

        # list
        list_1 = nlgFactory.createEnumeratedList()
        list_1.addComponent(subList1)
        list_1.addComponent(item2)
        list_1.addComponent(item3)

        paragraph.addComponent(list_1)

        document.addComponent(paragraph)

        expectedOutput = "Document\n" + \
                         "\n" + \
                         "1.1 - Sub-list item 1.\n" + \
                         "1.2.1 - Sub-sub-list item 1.\n" + \
                         "1.2.2 - Sub-sub-list item 2.\n" + \
                         "1.3 - Sub-list item 3.\n"+ \
                         "2 - Item 2.\n" + \
                         "3 - Item 3.\n" + \
                         "\n\n"

        realisedOutput = realiser.realise(document).getRealisation()
        self.assertEquals(expectedOutput, realisedOutput)