File size: 1,160 Bytes
3325021 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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()
|