1

I'm trying to load the Yummly Data which includes JSON formatted training data. Here is a sample of a single record:

  {
    "id": 10259,
    "cuisine": "greek",
    "ingredients": [
      "romaine lettuce",
      "black olives",
      "grape tomatoes",
      "garlic",
      "pepper",
      "purple onion",
      "seasoning",
      "garbanzo beans",
      "feta cheese crumbles"
    ]
  }

And here is my attempt to load this data

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);

I clearly won't know the number of ingredients a priori, so I tried the line ingredients: [1..1] string; to no avail. After messing around with it, I couldn't get it to work.

Brian Dolan
  • 3,086
  • 2
  • 24
  • 35

1 Answers1

3

Using a 'list' should work:

http://chapel.cray.com/docs/1.15/modules/standard/List.html

var ingredients : list(string);
benharsh
  • 396
  • 1
  • 8