我正在尝试加载包含JSON格式的训练数据的Yummly Data。以下是单个记录的示例:
{
"id": 10259,
"cuisine": "greek",
"ingredients": [
"romaine lettuce",
"black olives",
"grape tomatoes",
"garlic",
"pepper",
"purple onion",
"seasoning",
"garbanzo beans",
"feta cheese crumbles"
]
}
这是我尝试加载此数据
use IO;
const test_data_f: string = "/home/buddha314/datasets/yummly/test.json",
train_data_f:string = "single_recipe.json";
writeln("let's load some json, shall we?");
record Recipe {
var cuisine: string,
id: int,
ingredients: [1..1] string;
}
var f = open(train_data_f, iomode.r);
var r = f.reader();
var final : Recipe;
r.readf("%jt\n", final);
writeln(final);
我显然不知道先验成分的数量,所以我尝试了ingredients: [1..1] string;
这一行无济于事。搞砸了之后,我无法让它发挥作用。
答案 0 :(得分:3)
使用'列表'应该工作:
http://chapel.cray.com/docs/1.15/modules/standard/List.html
var ingredients : list(string);