def test_repr(self): expected = "<Paragraph (1):\n\t" \ "<RhetRel (Elaboration): String('foo') String('bar')>>" m = RhetRel('Elaboration', 'foo', 'bar') p = Paragraph(m) descr = repr(p) self.assertEqual(expected, descr) expected = "<Paragraph (1):\n\t" \ "<RhetRel (Contrast): " \ "<RhetRel (Elaboration): String('foo') String('bar')> " \ "String('bar') String('baz')>>" m2 = RhetRel('Contrast', m, 'bar', 'baz') p = Paragraph(m2) descr = repr(p) self.assertEqual(expected, descr) expected = "<Paragraph (2):\n\t" \ "<RhetRel (Contrast): " \ "<RhetRel (Elaboration): String('foo') String('bar')> " \ "String('bar') String('baz')>" \ "\n\t<RhetRel (Leaf): String('foobar') String('')>>" m3 = RhetRel('Leaf', 'foobar') p = Paragraph(m2, m3) descr = repr(p) self.assertEqual(expected, descr)
def test_lexicalise_paragraph(self): """ Test lexicalisation of Document. """ m1 = RhetRel('Leaf', DummyMsg()) m2 = RhetRel('Elaboration', DummyMsg(), DummyMsg()) p = Paragraph(m1, m2) tmp = lex.paragraph(p) expected = 'Boris is fast. Boris is fast. Boris is fast.' actual = realiser(tmp) self.assertEqual(expected, str(actual))
def test_str(self): expected = 'foo bar baz' m = RhetRel('Elaboration', 'foo', 'bar', 'baz') descr = str(m) self.assertEqual(expected, descr) expected = 'foo bar baz bar baz' m2 = RhetRel('Contrast', m, 'bar', 'baz') descr = str(m2) self.assertEqual(expected, descr)
def test_repr(self): expected = "<RhetRel (Elaboration): String('foo') String('bar') String('baz')>" m = RhetRel('Elaboration', 'foo', 'bar', 'baz') descr = repr(m) self.assertEqual(expected, descr) expected = "<RhetRel (Contrast): <RhetRel (Elaboration): " \ "String('foo') String('bar') String('baz')> " \ "String('bar') String('baz')>" m2 = RhetRel('Contrast', m, 'bar', 'baz') descr = repr(m2) self.assertEqual(expected, descr)
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))
def test_str(self): expected = 'foo bar' m = RhetRel('Elaboration', 'foo', 'bar') p = Paragraph(m) descr = str(p) self.assertEqual(expected, descr) expected = 'foo bar bar baz' m2 = RhetRel('Contrast', m, 'bar', 'baz') p = Paragraph(m2) descr = str(p) self.assertEqual(expected, descr) expected = 'foo bar bar baz foobar' m3 = RhetRel('Leaf', 'foobar') p = Paragraph(m2, m3) descr = str(p) self.assertEqual(expected, descr)
def test_lexicalise_rst_relation(self): """ Test lexicalisation of RhetRel. """ # a rhet relation with 3 nuclei m = RhetRel('Elaboration', DummyMsg(), DummyMsg(), DummyMsg()) lexicalised = lex.rst_relation(m) tmp = list( lex.message_specification(DummyMsg()).elements(recursive=True)) expected = tmp + tmp + tmp self.assertEqual(expected, list(lexicalised.elements(recursive=True)))
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))
def test_init(self): nucleus = 'This is the nucleus' satellite = 'this is the satellite' r = RhetRel('elaboration', nucleus, satellite=satellite, marker='and') self.assertEqual(self.expected1, r.to_xml(1)) nucleus2 = 'this is another nucleus' r2 = RhetRel('concession', nucleus2, satellite=satellite, marker='however') r = RhetRel('elaboration', nucleus, satellite=r2, marker='and') self.assertEqual(self.expected2, r.to_xml(1))