|
import csv |
|
import sys |
|
|
|
from pathlib import Path |
|
|
|
from markdown_it import MarkdownIt |
|
from mdit_plain.renderer import RendererPlain |
|
from minicli import cli, run |
|
from progressist import ProgressBar |
|
|
|
|
|
csv.field_size_limit(sys.maxsize) |
|
catalog = Path("datasets-filtered.csv") |
|
|
|
|
|
@cli |
|
def generate(): |
|
""" |
|
Loads catalog, parse markdown description, return concatenated title and description |
|
""" |
|
print("Loading corpus...") |
|
corpus = [] |
|
parser = MarkdownIt(renderer_cls=RendererPlain) |
|
with catalog.open() as f: |
|
reader = csv.DictReader(f) |
|
lines = list(reader) |
|
bar = ProgressBar(total=len(lines)) |
|
for line in bar.iter(lines): |
|
description = parser.render(line["description"]) |
|
corpus.append({ |
|
"id": line["id"], |
|
"content": f'{line["title"]} {description}', |
|
"tags": line["tags"], |
|
}) |
|
with open("data/datagouvfr-datasets.csv", "w") as f: |
|
writer = csv.DictWriter(f, fieldnames=["id", "content", "tags"]) |
|
writer.writeheader() |
|
writer.writerows(corpus) |
|
|
|
return corpus |
|
|
|
|
|
if __name__ == "__main__": |
|
run() |
|
|