Skip to content
Snippets Groups Projects
Commit 4fce5770 authored by Alice Brenon's avatar Alice Brenon
Browse files

Put format autodector with the classes themselves to allow reuse

parent cb64e745
No related branches found
No related tags found
No related merge requests found
import pandas
import os
from os import makedirs
from os.path import dirname, isdir, isfile
def abstract(f):
def wrapped(*args, **kwargs):
......@@ -128,7 +129,7 @@ class Directory(TSVIndexed):
def write_text(self, primary_key, content):
path = self.path_to(primary_key)
os.makedirs(os.path.dirname(path), exist_ok=True)
makedirs(dirname(path), exist_ok=True)
with open(path, 'w') as file:
file.write(content)
......@@ -138,3 +139,11 @@ class Directory(TSVIndexed):
for _, row in self.data.iterrows():
self.write_text(row, row[self.column_name])
self.data[self.keys].to_csv(self.tsv_path, sep='\t', index=False)
def corpus(path):
if path[-1:] == '/':
return Directory(path)
elif path[-4:] == '.tsv':
return SelfContained(path)
else:
raise FileNotFoundError(path)
#!/usr/bin/env python3
import Corpus
from os.path import isdir
from Corpus import corpus
import sys
def detect(path):
if isdir(path):
return Corpus.Directory(path)
else:
return Corpus.SelfContained(path)
if __name__ == '__main__':
source = detect(sys.argv[1])
destination = detect(sys.argv[2])
source = corpus(sys.argv[1])
destination = corpus(sys.argv[2])
destination.save(source.get_all())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment