diff --git a/layouts/tests/distill.rs b/layouts/tests/distill.rs index c1cbdfc..fd2219e 100644 --- a/layouts/tests/distill.rs +++ b/layouts/tests/distill.rs @@ -245,3 +245,13 @@ negative_test! { /// Missing required field. e01 (Term::blank(BlankIdBuf::new("_:john_smith".to_string()).unwrap())) } + +#[test] +fn dehydrate_t16() { + dehydrate( + "t16", + [Term::blank( + BlankIdBuf::new("_:subject".to_string()).unwrap(), + )], + ) +} diff --git a/layouts/tests/distill/t16-in.nq b/layouts/tests/distill/t16-in.nq new file mode 100644 index 0000000..924bf9a --- /dev/null +++ b/layouts/tests/distill/t16-in.nq @@ -0,0 +1,7 @@ +_:subject "John Smith" . +_:subject "john.smith@example.com" . +_:subject . + . + "Project execution"@en . + . + "Contribute to solution design and implementation."@en . \ No newline at end of file diff --git a/layouts/tests/distill/t16-layout.json b/layouts/tests/distill/t16-layout.json new file mode 100644 index 0000000..36ac7cb --- /dev/null +++ b/layouts/tests/distill/t16-layout.json @@ -0,0 +1,35 @@ +{ + "type": "record", + "fields": { + "name": { "property": "https://schema.org/name", "value": { "type": "string" } }, + "email": { "property": "https://schema.org/email", "value": { "type": "string" } }, + "achievement": { + "intro": [], + "value": { + "input": ["_:self"], + "layout": { + "type": "sum", + "variants": { + "projectExecution": { + "intro": [], + "value": { + "input": ["_:self"], + "layout": { + "type": "unit", + "const": "projectExecution", + "dataset": [ + ["_:self", "https://purl.imsglobal.org/spec/vc/ob/vocab.html#achievement", "http://example.com/#projectExecution"], + ["http://example.com/#projectExecution", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "https://purl.imsglobal.org/spec/vc/ob/vocab.html#Achievement"], + ["http://example.com/#projectExecution", "https://schema.org/name", { "value": "Project execution", "language": "en" }], + ["http://example.com/#projectExecution", "https://purl.imsglobal.org/spec/vc/ob/vocab.html#Criteria", "http://example.com/#projectExecutionCriteria"], + ["http://example.com/#projectExecutionCriteria", "https://purl.imsglobal.org/spec/vc/ob/vocab.html#narrative", { "value": "Contribute to solution design and implementation.", "language": "en" }] + ] + } + } + } + } + } + } + } + } +} diff --git a/layouts/tests/distill/t16-out.json b/layouts/tests/distill/t16-out.json new file mode 100644 index 0000000..5365a6a --- /dev/null +++ b/layouts/tests/distill/t16-out.json @@ -0,0 +1,5 @@ +{ + "name": "John Smith", + "email": "john.smith@example.com", + "achievement": "projectExecution" +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cf25de6..514519e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use codespan_reporting::{ termcolor::{ColorChoice, StandardStream}, }, }; -use rdf_types::Term; +use rdf_types::{generator, Generator, Term}; use std::{ fs, io::{self, BufReader}, @@ -190,19 +190,20 @@ impl DefaultLayoutRef { fn run(files: &mut SimpleFiles, args: Args) -> Result<(), Error> { let mut layouts = Layouts::new(); + let mut generator = generator::Blank::new(); let prelude = args.prelude(); let mut default_layout = DefaultLayoutRef::None; for filename in args.layouts { let content = fs::read_to_string(&filename).map_err(Error::IO)?; let file_id = files.add(filename.to_string_lossy().into_owned(), content); - let layout_ref = load_layout(files, file_id, &mut layouts)?; + let layout_ref = load_layout(files, file_id, &mut layouts, &mut generator)?; default_layout.set(layout_ref); } for filename in args.include { let content = fs::read_to_string(&filename).map_err(Error::IO)?; let file_id = files.add(filename.to_string_lossy().into_owned(), content); - load_layout(files, file_id, &mut layouts)?; + load_layout(files, file_id, &mut layouts, &mut generator)?; } let layouts = layouts.with(prelude); @@ -357,14 +358,17 @@ fn load_layout( files: &SimpleFiles, file_id: usize, layouts: &mut Layouts, + generator: &mut impl Generator, ) -> Result, Error> { use json_syntax::{Parse, TryFromJson}; let mut builder = treeldr_layouts::abs::Builder::new(); + let mut context = builder.with_generator_mut(generator); + match json_syntax::Value::parse_str(files.get(file_id).unwrap().source().as_str()) { Ok((json, code_map)) => { match treeldr_layouts::abs::syntax::Layout::try_from_json(&json, &code_map) { - Ok(layout) => match layout.build(&mut builder) { + Ok(layout) => match layout.build_with_context(&mut context) { Ok(layout_ref) => { let new_layouts = builder.build();