atareao hat die Gist bearbeitet 1 week ago. Zu Änderung gehen
1 file changed, 43 insertions
grafo-conocimiento.sh(Datei erstellt)
| @@ -0,0 +1,43 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | # ============================================================== | |
| 3 | + | # grafo-conocimiento.sh — Grafo de conocimientos desde front matter | |
| 4 | + | # | |
| 5 | + | # Extrae el front matter de todas las notas Markdown de un vault | |
| 6 | + | # y construye un grafo JSON: nodos = notas, aristas = tags | |
| 7 | + | # compartidos. Sin Python, sin IA. Solo fd, yq y jq. | |
| 8 | + | # | |
| 9 | + | # Uso: ./grafo-conocimiento.sh [ruta-al-vault] [salida.json] | |
| 10 | + | # ./grafo-conocimiento.sh ~/notas grafo.json | |
| 11 | + | # | |
| 12 | + | # Dependencias: fd, yq (Mike Farah), jq | |
| 13 | + | # ============================================================== | |
| 14 | + | ||
| 15 | + | VAULT="${1:-.}" | |
| 16 | + | OUT="${2:-grafo.json}" | |
| 17 | + | ||
| 18 | + | # 1. Un nodo (objeto JSON) por cada nota, con su ruta real como id. | |
| 19 | + | # Se filtran los .md que no empiezan por '---' (sin front matter). | |
| 20 | + | fd -e md . "$VAULT" -x sh -c ' | |
| 21 | + | head -1 "$1" | grep -q "^---" || exit 0 | |
| 22 | + | yq --front-matter=extract -o=json \ | |
| 23 | + | "{\"id\": \"$1\", \"title\": .title, \"created\": .created, | |
| 24 | + | \"updated\": .updated, \"tags\": (.tags // [])}" "$1" 2>/dev/null | |
| 25 | + | ' _ {} \; > /tmp/nodos.ndjson | |
| 26 | + | ||
| 27 | + | # 2. Construye nodos + aristas (dos notas comparten al menos un tag). | |
| 28 | + | jq -s ' | |
| 29 | + | . as $n | |
| 30 | + | | { | |
| 31 | + | nodes: [ $n[] | {id: .id, title: .title, tags: .tags} ], | |
| 32 | + | edges: [ | |
| 33 | + | $n[] as $a | $n[] as $b | |
| 34 | + | | select($a.id < $b.id) | |
| 35 | + | | ([ $a.tags[] | select(. as $t | $b.tags | index($t)) ]) as $c | |
| 36 | + | | select(($c | length) > 0) | |
| 37 | + | | {source: $a.id, target: $b.id, tags: ($c | unique)} | |
| 38 | + | ] | |
| 39 | + | } | |
| 40 | + | ' /tmp/nodos.ndjson > "$OUT" | |
| 41 | + | ||
| 42 | + | echo "Grafo generado en $OUT" | |
| 43 | + | jq '{nodos: (.nodes | length), aristas: (.edges | length)}' "$OUT" | |
Neuer
Älter