示例#1
0
    def process_document(self, document):
        sub_path, class_name = _parse_block_name(self.block)
        module = "udapi.block." + sub_path + "." + class_name.lower()
        try:
            command = "from " + module + " import " + class_name + " as b"
            logging.debug("Trying to run command: %s", command)
            exec(command)  # pylint: disable=exec-used
        except Exception:
            logging.warning("Error when trying import the block %s", self.block)
            raise

        command = "b()"  # TODO params as kwargs
        logging.debug("Trying to evaluate this: %s", command)
        new_block = eval(command)  # pylint: disable=eval-used

        doc_copy = copy.deepcopy(document)
        writer = Conllu(files=self.orig_files)

        for bundle_no, bundle in enumerate(doc_copy.bundles, 1):
            logging.debug('Block %s processing bundle #%d (id=%s)',
                          self.block, bundle_no, bundle.bundle_id)
            try:
                new_block.process_bundle(bundle)
            except Exception as exc:  # pylint: disable=broad-except
                logging.warning('util.FindBug found a problem in bundle %d in block %s: %r',
                                bundle_no, self.block, exc)
                logging.warning('Printing a minimal example to %s', self.orig_files)

                for tree in document.bundles[bundle_no - 1].trees:
                    writer.process_tree(tree)

                if self.first_error_only:
                    raise
示例#2
0
def main():
    doc = Document()
    doc.from_conllu_string(conllu_string1)
    tree = doc.bundles[0].get_tree()
    nodes = tree.descendants
    writer = ConlluWriter()

    # Shifter
    shifter = ShiftArtificials()
    shifter.apply_on_document(doc)

    # writer.apply_on_document(doc)

    # Converter
    converter = SubTreeConverter(with_enhanced=True)
    converter.apply_on_document(doc)

    print(len(tree.empty_nodes))

    # Writer
    writer.apply_on_document(doc)
示例#3
0
    def process_document(self, document):
        sub_path, class_name = _parse_block_name(self.block)
        module = "udapi.block." + sub_path + "." + class_name.lower()
        try:
            command = "from " + module + " import " + class_name + " as b"
            logging.debug("Trying to run command: %s", command)
            exec(command)  # pylint: disable=exec-used
        except Exception:
            logging.warning("Error when trying import the block %s",
                            self.block)
            raise

        command = "b()"  # TODO params as kwargs
        logging.debug("Trying to evaluate this: %s", command)
        new_block = eval(command)  # pylint: disable=eval-used

        doc_copy = copy.deepcopy(document)
        writer = Conllu(files=self.orig_files)

        for bundle_no, bundle in enumerate(doc_copy.bundles, 1):
            logging.debug('Block %s processing bundle #%d (id=%s)', self.block,
                          bundle_no, bundle.bundle_id)
            try:
                new_block.process_bundle(bundle)
            except Exception as exc:  # pylint: disable=broad-except
                logging.warning(
                    'util.FindBug found a problem in bundle %d in block %s: %r',
                    bundle_no, self.block, exc)
                logging.warning('Printing a minimal example to %s',
                                self.orig_files)

                for tree in document.bundles[bundle_no - 1].trees:
                    writer.process_tree(tree)

                if self.first_error_only:
                    raise
示例#4
0
 def test_create_empty(self):
     writer = ConlluWriter()
     writer.apply_on_document(self.doc)
     # self.tree.draw()
     self.assertGreater(len(self.tree.empty_nodes), 0)
示例#5
0
 def store_conllu(self, filename):
     """Store a document into a conllu-formatted file."""
     writer = ConlluWriter(files=filename)
     writer.process_document(self)
 def test_write_converted(self):
     #self.apply_converter()
     writer = ConlluWriter(files='test_artificial_deps.conllu')
     writer.apply_on_document(self.doc)
示例#7
0
 def to_conllu_string(self):
     """Return the document as a conllu-formatted string."""
     fh = io.StringIO()
     writer = ConlluWriter(filehandle=fh)
     writer.apply_on_document(self)
     return fh.getvalue()
示例#8
0
 def store_conllu(self, filename):
     """Store a document into a conllu-formatted file."""
     writer = ConlluWriter(files=filename)
     writer.apply_on_document(self)
示例#9
0
    def store(self,args = {}):  # TODO: to je otazka, jestli by ten ukladaci kod nemel byt spis v Document, at nema core zavislost na blocich

        from udapi.block.write.conllu import Conllu
        writer = Conllu()
        writer.process_document(self)