From 3d31ae53a47a5d7b03ac1f4f59278638e9b433a1 Mon Sep 17 00:00:00 2001 From: SkepticMystic Date: Sat, 3 Feb 2024 17:58:01 +0200 Subject: [PATCH] Complete all existing implied relationships --- .../builders/implied/cousin_is_sibling.ts | 37 ++++++++++++++++++ src/graph/builders/implied/index.ts | 5 ++- .../implied/siblings_parent_is_parent.ts | 39 +++++++++++++++++++ src/interfaces/hierarchies.ts | 2 +- .../ImpliedRelationshipsSettingsModal.ts | 4 +- src/settings/migration.ts | 2 +- src/utils/hierarchies.ts | 2 +- src/utils/links.ts | 2 + 8 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/graph/builders/implied/cousin_is_sibling.ts create mode 100644 src/graph/builders/implied/siblings_parent_is_parent.ts diff --git a/src/graph/builders/implied/cousin_is_sibling.ts b/src/graph/builders/implied/cousin_is_sibling.ts new file mode 100644 index 00000000..23990648 --- /dev/null +++ b/src/graph/builders/implied/cousin_is_sibling.ts @@ -0,0 +1,37 @@ +import type { ImpliedEdgeBuilder } from "src/interfaces/graph"; + +export const _add_implied_edges_cousin_is_sibling: ImpliedEdgeBuilder = ( + graph, + plugin, +) => { + plugin.settings.hierarchies.forEach((hierarchy, hierarchy_i) => { + if (!hierarchy.implied_relationships.cousin_is_sibling) { + return; + } + + graph.forEachNode((source_id) => { + graph + .get_dir_chains_path( + source_id, + ["up", "same", "down"], + (edge) => + edge.attr.hierarchy_i === hierarchy_i && + edge.attr.explicit && + // Don't include the current source_id in the path + edge.target_id !== source_id, + ) + .forEach((path) => { + console.log("path", path); + graph.addDirectedEdge(source_id, path.last()!.target_id, { + dir: "same", + hierarchy_i, + explicit: false, + implied_kind: "cousin_is_sibling", + field: hierarchy.dirs["same"].at(0) ?? null, + }); + }); + }); + }); + + return {}; +}; diff --git a/src/graph/builders/implied/index.ts b/src/graph/builders/implied/index.ts index 8c9a7c33..9517953f 100644 --- a/src/graph/builders/implied/index.ts +++ b/src/graph/builders/implied/index.ts @@ -5,9 +5,10 @@ import { _add_implied_edges_parents_sibling_is_parent } from "./parents_sibling_ import { _add_implied_edges_same_parent_is_sibling } from "./same_parent_is_sibling"; import { _add_implied_edges_same_sibling_is_sibling } from "./same_sibling_is_sibling"; import { _add_implied_edges_self_is_sibling } from "./self_is_sibling"; +import { _add_implied_edges_cousin_is_sibling } from "./cousin_is_sibling"; +import { _add_implied_edges_siblings_parent_is_parent } from "./siblings_parent_is_parent"; // TODO: Flesh out -//@ts-expect-error export const add_implied_edges: Record< keyof Hierarchy["implied_relationships"], ImpliedEdgeBuilder @@ -17,4 +18,6 @@ export const add_implied_edges: Record< same_parent_is_sibling: _add_implied_edges_same_parent_is_sibling, parents_sibling_is_parent: _add_implied_edges_parents_sibling_is_parent, same_sibling_is_sibling: _add_implied_edges_same_sibling_is_sibling, + cousin_is_sibling: _add_implied_edges_cousin_is_sibling, + siblings_parent_is_parent: _add_implied_edges_siblings_parent_is_parent, }; diff --git a/src/graph/builders/implied/siblings_parent_is_parent.ts b/src/graph/builders/implied/siblings_parent_is_parent.ts new file mode 100644 index 00000000..4af17063 --- /dev/null +++ b/src/graph/builders/implied/siblings_parent_is_parent.ts @@ -0,0 +1,39 @@ +import type { ImpliedEdgeBuilder } from "src/interfaces/graph"; + +export const _add_implied_edges_siblings_parent_is_parent: ImpliedEdgeBuilder = + (graph, plugin) => { + plugin.settings.hierarchies.forEach((hierarchy, hierarchy_i) => { + if (!hierarchy.implied_relationships.siblings_parent_is_parent) { + return; + } + + graph.forEachNode((source_id) => { + graph + .get_dir_chains_path( + source_id, + ["same", "up"], + (edge) => + edge.attr.hierarchy_i === hierarchy_i && + edge.attr.explicit && + // Don't include the current source_id in the path + edge.target_id !== source_id, + ) + .forEach((path) => { + console.log("path", path); + graph.addDirectedEdge( + source_id, + path.last()!.target_id, + { + dir: "up", + hierarchy_i, + explicit: false, + implied_kind: "siblings_parent_is_parent", + field: hierarchy.dirs["up"].at(0) ?? null, + }, + ); + }); + }); + }); + + return {}; + }; diff --git a/src/interfaces/hierarchies.ts b/src/interfaces/hierarchies.ts index 26fe2552..2bd6514b 100644 --- a/src/interfaces/hierarchies.ts +++ b/src/interfaces/hierarchies.ts @@ -5,7 +5,7 @@ export type Hierarchy = { implied_relationships: { self_is_sibling: boolean; opposite_direction: boolean; - cousing_is_sibling: boolean; + cousin_is_sibling: boolean; same_parent_is_sibling: boolean; same_sibling_is_sibling: boolean; siblings_parent_is_parent: boolean; diff --git a/src/modals/ImpliedRelationshipsSettingsModal.ts b/src/modals/ImpliedRelationshipsSettingsModal.ts index 69cd0c60..10d0bc7b 100644 --- a/src/modals/ImpliedRelationshipsSettingsModal.ts +++ b/src/modals/ImpliedRelationshipsSettingsModal.ts @@ -155,9 +155,9 @@ export class ImpliedRelationshipsSettingsModal extends Modal { name: "Cousins", desc: "Parents' siblings' children are siblings (cousins)", toggle: { - value: implied_relationships.cousing_is_sibling, + value: implied_relationships.cousin_is_sibling, cb: async (val) => { - implied_relationships.cousing_is_sibling = val; + implied_relationships.cousin_is_sibling = val; await save(); }, }, diff --git a/src/settings/migration.ts b/src/settings/migration.ts index 659654b9..f0840d05 100644 --- a/src/settings/migration.ts +++ b/src/settings/migration.ts @@ -19,7 +19,7 @@ export const migrate_old_settings = async (plugin: BreadcrumbsPlugin) => { ...blank_hierarchy().implied_relationships, self_is_sibling: settings.impliedRelations.siblingIdentity, - cousing_is_sibling: settings.impliedRelations.cousinsIsSibling, + cousin_is_sibling: settings.impliedRelations.cousinsIsSibling, same_parent_is_sibling: settings.impliedRelations.sameParentIsSibling, same_sibling_is_sibling: diff --git a/src/utils/hierarchies.ts b/src/utils/hierarchies.ts index 6323280b..979db65d 100644 --- a/src/utils/hierarchies.ts +++ b/src/utils/hierarchies.ts @@ -14,7 +14,7 @@ export const blank_hierarchy = (): Hierarchy => ({ opposite_direction: true, self_is_sibling: false, parents_sibling_is_parent: false, - cousing_is_sibling: false, + cousin_is_sibling: false, same_parent_is_sibling: false, same_sibling_is_sibling: false, siblings_parent_is_parent: false, diff --git a/src/utils/links.ts b/src/utils/links.ts index 4acfd128..1bfe01a8 100644 --- a/src/utils/links.ts +++ b/src/utils/links.ts @@ -2,6 +2,8 @@ import type { App } from "obsidian"; import path from "path"; import type { LinkKind } from "src/interfaces/links"; +// TODO: Something seems wrong here... a new note was created in the root of the vault, +// even though it used a full path in the link content /** Given an unresolved link path, return the absolute path of where it _would_ get created, * given the file it would be created in */