How to use the underthesea.util.file_io.write function in underthesea

To help you get started, we’ve selected a few underthesea examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github undertheseanlp / underthesea / tests / ner / test_ner.py View on Github external
def save_temp(id, output):
    temp_file = join(samples_dir, "%s.actual" % id)
    content = u"\n".join([u"\t".join(item) for item in output])
    write(temp_file, content)
github undertheseanlp / automatic_speech_recognition / egs / diadiem / extension / analyze.py View on Github external
except:
            pass
        finally:
            os.mkdir(wav_folder)
        for wav in wavs_test:
            new_path = join(wav_folder, basename(wav))
            shutil.copyfile(wav, new_path)
        wavs_test_new_path = [join("wav", basename(wav)) for wav in wavs_test]
        speech_recognition = {
            "texts_test": texts_test,
            "texts_pred": texts_pred,
            "wavs_test": wavs_test_new_path,
        }
        content = json.dumps(speech_recognition, ensure_ascii=False)
        log_file = join(log_folder, "speechrecognition.json")
        write(log_file, content)

        print("Result is written in {}".format(log_file))
        print("WER: {}%".format(wer * 100))
github undertheseanlp / ner / util / evaluation.py View on Github external
model_id = "1"
    try:
        shutil.rmtree(join(test_dir, model_id))
    except:
        pass
    mkdir(join(test_dir, model_id))
    for f in files:
        input = load_input(join(test_dir, f))
        output = ner(input)
        actual = "\n".join(["\t".join(tokens) for tokens in output])
        expected = load_output(join(test_dir, f))
        if actual != expected:
            print("\n{}".format(f))
            diff = '\n'.join(ndiff(expected.splitlines(), actual.splitlines()))
            write(join(test_dir, model_id, f), "\n".join([extract_sentence(actual), actual]))
            write(join(test_dir, model_id, f + ".diff"), "\n".join([extract_sentence(actual), diff]))
github undertheseanlp / underthesea / underthesea / corpus / ws.py View on Github external
def save(self, folder, format):
        """save wscorpus to files

        :param str folder: path to directory
        :type folder: string
        :param str format: either TEXT or COLUMN
        :type format: str
        """
        try:
            mkdir(folder)
        except Exception:
            pass
        for document in self.documents:
            f = join(folder, document.id)
            content = u"\n".join(document.sentences)
            write(f, content)
github undertheseanlp / underthesea / underthesea / corpus / plaintext.py View on Github external
def save(self, folder):
        """save corpus to files

        :param str folder: path to directory
        :type folder: string
        """
        try:
            mkdir(folder)
        except Exception:
            pass
        for document in self.documents:
            filename = join(folder, document.id)
            content = u"\n".join(document.sentences)
            write(filename, content)