Beispiel #1
0
 def test_elements(self):
     expected = [
         String('Title'),
         Document('Section 1', 'para 1', 'para 2'),
         Document('Section 2', 'para 3', 'para 4')
     ]
     self.assertEqual(expected, list(self.doc.elements()))
Beispiel #2
0
    def test_str(self):
        expected = "MyDoc\n\nOne\n\nfoo bar"
        m = RhetRel('Elaboration', 'foo', 'bar')
        one = Document('One', Paragraph(m))
        d = Document('MyDoc', one)
        descr = str(d)
        self.assertEqual(expected, descr)

        expected = "MyDoc\n\nOne\n\nfoo bar\n\nTwo\n\nbaz bar"
        m2 = RhetRel('Contrast', 'baz', 'bar')
        two = Document('Two', Paragraph(m2))
        d = Document('MyDoc', one, two)
        descr = str(d)
        self.assertEqual(expected, descr)
 def test_lexicalise_document(self):
     """ Test lexicalisation of Document. """
     m1 = RhetRel('Leaf', DummyMsg())
     m2 = RhetRel('Elaboration', DummyMsg(), DummyMsg())
     s1 = Document('Section One', m1)
     s2 = Document('Section Two', m2)
     d = Document('Doc Title', s1, s2)
     tmp = lex.document(d)
     expected = 'Doc Title\n\n' + \
         'Section One' + \
         '\n\nBoris is fast.' + \
         '\n\nSection Two' + \
         '\n\nBoris is fast. Boris is fast.'
     actual = realiser(tmp)
     self.assertEqual(expected, str(actual))
Beispiel #4
0
 def document(self, doc, **kwargs):
     """ Perform aggregation on a document - possibly before lexicalisation. """
     self.logger.debug('Aggregating document.')
     if doc is None: return None
     title = self.aggregate(doc.title, **kwargs)
     sections = [self.aggregate(x, **kwargs) for x in doc.sections if x is not None]
     return Document(title, *sections)
Beispiel #5
0
 def document(self, msg, **kwargs):
     """ Return a copy of a Document with strings. """
     self.logger.debug('Realising document.')
     if msg is None:
         return None
     title = self.realise(msg.title, **kwargs)
     if not kwargs.get('keep_title_punctuation') and title.endswith('.'):
         title = title[:-1]
     sections = [self.realise(x, **kwargs) for x in msg.sections]
     return Document(title, *sections)
Beispiel #6
0
    def test_repr(self):
        expected = """\
<Document: (MyDoc)
<Document: (One)
String('foo bar')>>"""
        m = RhetRel('Elaboration', 'foo', 'bar')
        one = Document('One', Paragraph(m))
        d = Document('MyDoc', one)
        self.assertEqual(expected, repr(d))

        expected = """\
<Document: (MyDoc)
<Document: (One)
String('foo bar')>
<Document: (Two)
String('baz bar')>>"""
        m2 = RhetRel('Contrast', 'baz', 'bar')
        two = Document('Two', Paragraph(m2))
        d = Document('MyDoc', one, two)
        self.assertEqual(expected, repr(d))
Beispiel #7
0
 def test_eq(self):
     d2 = Document('Title', Document('Section 1', 'para 1', 'para 2'),
                   Document('Section 2', 'para 3', 'para 4'))
     self.assertEqual(self.doc, d2)
     self.assertEqual(hash(self.doc), hash(d2))
Beispiel #8
0
 def setUp(self):
     self.doc = Document('Title', Document('Section 1', 'para 1', 'para 2'),
                         Document('Section 2', 'para 3', 'para 4'))