$ cat workspace-template.yaml
Drive Materials to Ontology
// Maps course documents already in Drive onto the organization ontology as CourseMaterial objects, linked to the Course they belong to. The assignment rule lives on the canvas as an editable JSON node, because nothing in Drive states which course a document serves — that mapping is a modelling choice.
// Canvas Preview
// Instruction
Drive Materials to Ontology
Overview
Maps course documents that already live in Drive onto the ontology as CourseMaterial objects, each linked to its Course by material_of. It reads Drive, it does not write to it.
Nothing in Drive states which course a document serves — these documents sit at root with no per-course folder. The assignment is therefore a modelling choice, and it lives on the canvas in the "Material Rules" node so it can be read and argued with rather than buried in code.
Requires the seven ontology types and the Course objects (run the Odoo to Ontology Feeder first, or materials will upsert with nothing to link to).
Workflow Chain
Node Reference
- "Material Rules" (JSON Object) — course code → regex over the document NAME. Rules are evaluated in order, first match wins, so a document lands in exactly one course and the counts sum to the population. Put specific topics before broad ones. Configurable:
value. - "Upsert Course Materials" (Custom Code) — pages Drive, applies the rules, de-duplicates (
01 - Foo.pdfandFooare one material, preferring the row with a file extension), and mints CourseMaterial +material_of. Documents matching no rule are counted and reported, never silently dropped. Configurable:maxItems. - "Sync Result" (Preview) — shows the per-course breakdown on the canvas.
Execution Strategy
You MUST complete both phases in order: Phase 1 → Phase 2. Do NOT skip either.
Writing to the ontology is a side effect. It is gated once, in Phase 1.
Phase 1: Confirm the mapping
applyCanvasDatato commit the template, thennodeFinderfor ids — preview ids are stale.nodeFinder"Material Rules" andgetNodeOutput, or read itsvalue, and show the user the rules in full. They decide the taxonomy, not you.- Call
requestUserDecisionONCE: "These rules assign each Drive document to a course, first match wins. Apply them?",allowFreeText: false, optionsproceed/edit/cancel. Onedit, ask which rule to change,upsertNodethe newvalue, and ask again. Oncancelorcancelled: true, STOP and write nothing.
Phase 1 complete. Now proceed to Phase 2.
Phase 2: Load and report
nodeExecutor"Upsert Course Materials", then "Sync Result".getNodeOutputand readsummaryandperCourse. Report the per-course counts, and say explicitly how many documents matched no rule — an unmatched document is a gap in the taxonomy, not a failure.- If
linkedCountis lower thanmaterialCount, say which courses were missing: materials were created but have nothing to hang off, which means the feeder has not run. - Call
verificationwith the counts, thenfollowUpoffering to (a) refine the rules and re-run, (b) open the ontology graph view, (c) run the console.
Configuration Tips
Error Handling
// Dependencies
1from input import JSONObject2from process import CustomCode3from control import Preview