def test_deps_getter(self): """Test enhanced dependencies.""" # Create a path to the test CoNLLU file. data_filename = os.path.join(os.path.dirname(__file__), 'data', 'enh_deps.conllu') # Read a test CoNLLU file. document = Document() reader = Conllu(files=data_filename) reader.process_document(document) # Exactly one bundle should be loaded. self.assertEqual(len(document.bundles), 1) # Obtain the dependency tree and check its sentence ID. root = document.bundles[0].get_tree() self.assertEqual(root.bundle.bundle_id, 'a-mf920901-001-p1s1A') # Check raw secondary dependencies for each node. nodes = root.descendants() self.assertEqual(nodes[0].raw_deps, '0:root|2:amod') self.assertEqual(nodes[1].raw_deps, '0:root') self.assertEqual(nodes[2].raw_deps, '0:root') self.assertEqual(nodes[3].raw_deps, '0:root') self.assertEqual(nodes[4].raw_deps, '1:amod') self.assertEqual(nodes[5].raw_deps, '5:conj') # Check deserialized dependencies. self.assertEqual(nodes[0].deps[0]['parent'], root) self.assertEqual(nodes[0].deps[0]['deprel'], 'root') self.assertEqual(nodes[5].deps[0]['parent'], nodes[4])
def load_conllu(self, filename): """Load a document from a conllu-formatted file.""" reader = ConlluReader(files=filename) reader.process_document(self)