N4L — Notes For Learning
N4L is a lightweight markup language for entering knowledge as semi-structured notes. You write natural notes and N4L compiles them into a typed knowledge graph.
Parsing N4L
using SemanticSpacetime
add_mandatory_arrows!()
result = parse_n4l("""
-chapter nursery rhymes
Mary had a little lamb
(then)
Its fleece was white as snow
""")
println(has_errors(result)) # falseThe parser returns an N4LResult containing the parsed NodeDirectory, any errors or warnings, and the final parser state.
Compiling to a Store
Once parsed, compile the result into a store:
store = MemoryStore()
cr = compile_n4l!(store, result)
println(cr.nodes_created)
println(cr.edges_created)Or use the convenience functions to parse and compile in one step:
store = MemoryStore()
compile_n4l_string!(store, "...")
compile_n4l_file!(store, "notes.n4l")Validation
Validate N4L text without compiling:
vr = validate_n4l("-chapter test\nhello\n(then)\nworld")
println(vr.valid)
println(vr.node_count)Get a human-readable summary:
n4l_summary(result)N4L Syntax
| Syntax | Meaning |
|---|---|
-section name | Start a new chapter/section |
text | Create a node with this text |
(arrow) | Link previous node to next node via arrow |
:: ctx :: | Set context |
+:: ctx :: | Add to context |
-:: ctx :: | Remove from context |
@alias | Create a line alias |
$alias | Reference a previous alias |
" | Ditto — reference the previous item |
# or // | Comment |
See the N4L vignette for detailed examples and the SSTorytime N4L documentation for the full language specification.
Configuration Files
N4L supports configuration files for custom arrows, contexts, and closures. Use find_config_dir to locate the configuration directory and read_config_files to load them:
config_dir = find_config_dir()
read_config_files(config_dir)