コード例 #1
0
ファイル: process.py プロジェクト: mfomicheva/metric-dev
    def run_processors(self):

        results_target = []
        results_reference = []

        sentences_target = []
        sentences_reference = []

        selected_names = loads(self.config.get('Processors', 'processors'))
        selected_processors = []
        existing_processors = {}
        processors_with_output = []

        for name, my_class in inspect.getmembers(processors):
            existing_processors[name] = my_class

        for proc in selected_names:
            name_class = (proc, existing_processors[proc])
            selected_processors.append(name_class)

        for name, my_class in selected_processors:

            instance = my_class()
            from_file = False
            if self.config.has_option('Processors', 'from_file'):
                if instance.__class__.__name__ in loads(self.config.get('Processors', 'from_file')):
                    from_file = True

            print('Running ' + instance.get_name())
            instance.run(self.config, from_file=from_file)

            print('Getting ' + instance.get_name())
            instance.get(self.config, from_file=from_file)

            print(instance.get_name() + ' ' + 'finished!')

            if instance.get_output() is not None:

                processors_with_output.append((name, my_class))
                results_target.append(instance.get_result_tgt())
                results_reference.append(instance.get_result_ref())

        for i in range(len(results_target[0])):

            my_sentence_tgt = Sentence()
            my_sentence_ref = Sentence()

            for k, (name, my_class) in enumerate(processors_with_output):
                instance = my_class()

                if instance.get_output() is not None:
                    my_sentence_tgt.add_data(instance.get_name(), results_target[k][i])
                    my_sentence_ref.add_data(instance.get_name(), results_reference[k][i])

            sentences_target.append(my_sentence_tgt)
            sentences_reference.append(my_sentence_ref)

        return [sentences_target, sentences_reference]
コード例 #2
0
    def get_clean_sentence(self, punct_cand, punct_ref, cand, ref):

        clean_cand = Sentence()
        clean_ref = Sentence()

        for method in sorted(cand.keys()):
            if method == 'alignments':
                alignments = self.get_clean_alignments(punct_cand, punct_ref, cand, ref)
                clean_data_cand = alignments
                clean_data_ref = alignments
            else:
                clean_data_cand = self.get_clean_data(cand[method], punct_cand)
                clean_data_ref = self.get_clean_data(ref[method], punct_ref)

            clean_cand.add_data(method, clean_data_cand)
            clean_ref.add_data(method, clean_data_ref)

        return clean_cand, clean_ref