食谱数据集
RecipeNLG 数据集可在 此处 下载。其中包含 220 万份食谱。大小略小于 1 GB。
下载并解压数据集
- 进入下载页面https://recipenlg.cs.put.poznan.pl/dataset。
- 接受条款和条件并下载 zip 文件。
- 使用 unzip解压 zip 文件,得到full_dataset.csv文件。
创建表
运行 clickhouse-client 并执行以下 CREATE 请求:
CREATE TABLE recipes
(
    title String,
    ingredients Array(String),
    directions Array(String),
    link String,
    source LowCardinality(String),
    NER Array(String)
) ENGINE = MergeTree ORDER BY title;
插入数据
运行以下命令:
clickhouse-client --query "
    INSERT INTO recipes
    SELECT
        title,
        JSONExtract(ingredients, 'Array(String)'),
        JSONExtract(directions, 'Array(String)'),
        link,
        source,
        JSONExtract(NER, 'Array(String)')
    FROM input('num UInt32, title String, ingredients String, directions String, link String, source LowCardinality(String), NER String')
    FORMAT CSVWithNames
" --input_format_with_names_use_header 0 --format_csv_allow_single_quote 0 --input_format_allow_errors_num 10 < full_dataset.csv
这是一个展示如何解析自定义 CSV,这其中涉及了许多调整。
说明:
- 数据集为 CSV 格式,但在插入时需要一些预处理;使用表函数 input 进行预处理;
- CSV 文件的结构在表函数 input的参数中指定;
- 字段 num(行号)是不需要的 - 可以忽略并从文件中进行解析;
- 使用 FORMAT CSVWithNames,因为标题不包含第一个字段的名称,因此 CSV 中的标题将被忽略(通过命令行参数--input_format_with_names_use_header 0);
- 文件仅使用双引号将 CSV 字符串括起来;一些字符串没有用双引号括起来,单引号也不能被解析为括起来的字符串 - 所以添加--format_csv_allow_single_quote 0