From 77d6dc605875235a240208ac5258ea7f9dacec5e Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Tue, 26 Oct 2021 09:06:39 +0200 Subject: [PATCH] refactor: :recycle: All analysis types into constants, not their own files --- src/Algorithms/Centrality.ts | 41 -------- src/Algorithms/LinkPrediction.ts | 44 -------- src/Algorithms/Similarity.ts | 34 ------ src/AnalysisView.ts | 3 +- src/Components/Centrality.svelte | 15 ++- src/Components/CoCitations.svelte | 4 +- src/Components/LinkPrediction.svelte | 11 +- src/Components/Similarity.svelte | 11 +- src/Constants.ts | 42 +++++--- src/MyGraph.ts | 2 +- src/Settings.ts | 149 +++++++++++++-------------- src/Utility.ts | 4 +- src/main.ts | 2 +- 13 files changed, 129 insertions(+), 233 deletions(-) delete mode 100644 src/Algorithms/Centrality.ts delete mode 100644 src/Algorithms/LinkPrediction.ts delete mode 100644 src/Algorithms/Similarity.ts diff --git a/src/Algorithms/Centrality.ts b/src/Algorithms/Centrality.ts deleted file mode 100644 index 1f3f0ba..0000000 --- a/src/Algorithms/Centrality.ts +++ /dev/null @@ -1,41 +0,0 @@ - -// export const closenessCentrality: CentralityAlg = (g: Graph, a: string) => { -// const paths = graphlib.alg.dijkstra(g, a); - -// const distances = []; -// for (const target in paths) { -// const dist = paths[target].distance; -// if (dist < Infinity) { -// distances.push(dist); -// } -// } - -// if (distances.length > 0) { -// const closeness = roundNumber((g.nodes().length - 1) / sum(distances)); -// return closeness; -// } else { -// return 0; -// } -// } - -// export const centralityForAll: AnalysisForAll = ( -// alg: CentralityAlg, -// g: Graph, -// currNode: string) => { - -// const nodes = g.nodes(); -// const centralityArr: AnalysisObj[] = []; -// nodes.forEach(node => centralityArr.push({ -// from: currNode, -// to: node, -// measure: alg(g, node), -// linked: g.hasEdge(currNode, node) -// })); -// return centralityArr -// } - -export const CENTRALITY_TYPES: { - subtype: string -}[] = [ - { subtype: 'Closeness' } - ] \ No newline at end of file diff --git a/src/Algorithms/LinkPrediction.ts b/src/Algorithms/LinkPrediction.ts deleted file mode 100644 index d31f47d..0000000 --- a/src/Algorithms/LinkPrediction.ts +++ /dev/null @@ -1,44 +0,0 @@ -// export const adamicAdarLinkPrediction: LinkPredictionAlg = (g: Graph, a: string, b: string): number => { -// const [Na, Nb] = [g.neighbors(a) as string[], g.neighbors(b) as string[]]; -// const Nab = nodeIntersection(Na, Nb); - -// if (Nab.length) { -// const neighbours: number[] = Nab.map(node => (g.successors(node) as string[]).length) -// return roundNumber(sum(neighbours.map(neighbour => 1 / Math.log(neighbour)))) -// } else { -// return Infinity -// } -// } - -// export { adamicAdarLinkPrediction }; - -// export const commonNeighboursLinkPrediction: LinkPredictionAlg = (g: Graph, a: string, b: string): number => { -// const [Na, Nb] = [g.neighbors(a) as string[], g.neighbors(b) as string[]]; -// const Nab = nodeIntersection(Na, Nb) -// return Nab.length -// } - -// export const linkPredictionsForAll: AnalysisForAll = ( -// alg: LinkPredictionAlg, -// g: Graph, -// currNode: string) => { -// const predictionsArr: AnalysisObj[] = [] -// const paths = g.nodes(); - -// for (let i = 0; i < paths.length; i++) { -// const node = paths[i]; - -// const prediction = alg(g, node, currNode) -// predictionsArr[i] = { -// from: currNode, -// to: node, -// measure: prediction, -// linked: g.hasEdge(currNode, node) -// } -// } -// return predictionsArr -// } - -export const LINK_PREDICTION_TYPES: { - subtype: string -}[] = [{ subtype: 'Adamic Adar' }, { subtype: 'Common Neighbours' }] diff --git a/src/Algorithms/Similarity.ts b/src/Algorithms/Similarity.ts deleted file mode 100644 index 7a6ed47..0000000 --- a/src/Algorithms/Similarity.ts +++ /dev/null @@ -1,34 +0,0 @@ - -// export const JaccardSimilarity: SimilarityAlg = (g: Graph, a: string, b: string) => { -// const [Na, Nb] = [ -// g.neighbors(a) as string[], -// g.neighbors(b) as string[] -// ]; -// const Nab = nodeIntersection(Na, Nb); -// return (Nab.length / (Na.length + Nb.length - Nab.length)) -// } - -// export const similarityForAll: AnalysisForAll = ( -// alg: SimilarityAlg, -// g: MyGraph, -// currNode: string) => { - -// const similarityArr: AnalysisObj[] = []; -// const nodes = g.nodes(); -// nodes.forEach(node => { -// const similarity = roundNumber(alg(g, node, currNode)); -// similarityArr.push({ -// from: currNode, -// to: node, -// measure: similarity, -// linked: g.hasEdge(currNode, node) -// }) -// }) -// return similarityArr; -// } - -export const SIMILARITY_TYPES: { - subtype: string -}[] = [ - { subtype: 'Jaccard' }, - ] \ No newline at end of file diff --git a/src/AnalysisView.ts b/src/AnalysisView.ts index a35ed5e..bacb7cb 100644 --- a/src/AnalysisView.ts +++ b/src/AnalysisView.ts @@ -1,8 +1,7 @@ import { ItemView, WorkspaceLeaf } from 'obsidian' -import { ANALYSIS_TYPES, VIEW_TYPE_GRAPH_ANALYSIS } from 'src/Constants' +import { ANALYSIS_TYPES, VIEW_TYPE_GRAPH_ANALYSIS } from 'src/constants' import type { Analyses } from 'src/Interfaces' import type GraphAnalysisPlugin from 'src/main' -import { claim_component } from 'svelte/internal' import CoCitations from './Components/CoCitations.svelte' import LinkPrediction from './Components/LinkPrediction.svelte' import Similarity from './Components/Similarity.svelte' diff --git a/src/Components/Centrality.svelte b/src/Components/Centrality.svelte index 47701c2..3565eeb 100644 --- a/src/Components/Centrality.svelte +++ b/src/Components/Centrality.svelte @@ -1,12 +1,17 @@