![[Pasted image 20250314141620.png]] A graph is a general term for a structure consisting of nodes connected by zero-to-many edges. They are (at least in my opinion, and possibly factually verifiable) the most versatile means of organizing information. Using graphs you can recreate _any_ other form of data structure (e.g. [[Hierarchy]] or [[Relational Databases]]). This versatility is the graph's killer feature, but also perhaps its Achilles heel. There's no wrong way to do a graph, and because they are so flexible and general it is hard to write efficient tools that operate in such a flexible structure. Many things you **could** do in a graph are better optimized by things like [[Relational Databases]]. Graphs are stored in [[Graph Database]]s. [[Graph Theory]] is the branch of mathematics having to do with the study of graphs. Misc facts: - Graphs can be directed (a directed graph is a "digraph"), or undirected. - Directed graphs may be cyclic (you can draw a loop using edges), or [[DAG|acyclic]] (where no loops exist). - [[Resource Description Framework|RDF]] is essentially a graph structure - node, node, edge. - Allowed nodes & edges in a graph are its [[Ontology]]. - More complex relations are possible through the use of hyperedges & edge nodes - **Hyperedge** - in "hypergraphs", an edge connecting >2 nodes - Edge Node - an edge that acts like a node, can be connected to by other edges and/or have its own properties - [[Wikidata]] uses edge nodes # Constructing a Graph You can create an arbitrary graph structure using [[JSON]]. ```json { nodes: [ { id: "A",f label: "Aaron", // any other arbitrary data type: "human", age: 36, }, { id: "B", label: "Loki", type: "cat" // nodes may or may not be forced to have the same set of properties } ], edges: [ { from: "A", to: "B", label: "Owns" }], } ``` Doing this, though, introduces interpretation errors. This actually makes for a perfect lead-in to the concept of [[Ontology]] engineering and [[Resource Description Framework]]. In short, those concepts remove ambiguity by pointing to globally unique [[URI]]s that define properties in unambiguous terms. It also introduces conventions like prefixing known, important properties with "@", like in the example below. ```JSON { "@context": { "foaf": "http://xmlns.com/foaf/spec/" }, "@graph": [ { "@id": "https://example.org/my-profile", // Your unique identifier "@type": "foaf:Person", "foaf:name": "Your Name", "foaf:mbox": "mailto:[email protected]" // Example FOAF property } ] } ``` Also demonstrated in that example is the aliasing of known ontological source prefixes. There `foaf` used in the graph is an alias for the text referred to in by the `foaf` key in the @context. ## Other graph constructions You don't have to use [[JSON]]. You could construct a graph using [[CSV]] files, like how [[Archi]] exports work. There is also [[Turtle]]. # Graphs in the Wild - Graphs are behind so-called "friend of a friend" recommendation algorithms - The [[JavaScript]] visualization library "GoJS" and VisJS use graph structures for their visualizations - The productivity product **Asana** credits their graph-based approach for how to scale work-related - see [[Asana Work Graph]] **** # More ## Source - Self/experience - Bit of Gemini, for the RDF syntax ## Related