Grakn network visualization
Found this via @achamess's Google Group: http://grakn.ai/
At first glance, it looks like a pretty nice graph/visualization language (called "Graql"). But the "engine" can also deal with logical expressions (when X then Y) and infer information.
This is build for big data and genome analysis. But why shouldn't it produce some useful output when you feed it an analysis of your Zettelkasten?
I imagine this should work:
- Traverse all notes;
- collect all links ("forward" links) of the note and produce entity relations in Graql format;
- produce a graph with Grakn.
You could vary the entity types and distinguish regular notes and structure notes to make the latter look different in the graph. You could also add all your tags to the graph, similar to the example below, as another entity (like "city") or as attributes (like "name"):
Maybe one can get fancy and add rules like "when
a note is not connected to another note then
it gets the "orphan" attribute". I bet you can do even more interesting things to group notes by similarity and proximity of tags, and see where one tag cluster crosses its boundaries and links to another cluster's note, or whatever.
Or maybe not! I don't have a clue, yet, but since I cannot play with this for quite some time, I thought you folks might want to.
Author at Zettelkasten.de • https://christiantietze.de/
Howdy, Stranger!
Comments
I briefly played with making a visualization like this using dot language, but this looks much more extensible than my probably-never-actually-realized idea.
Not too hard to make a gephi-file as well to play with graphs. If you just make a script that searches all files for IDs and make a new line for each hit you can easily convert to many formats.
Dot example:
201712180005 -> 201801241152
Gephi example:
<edge id="606" source="201712180005" target="201801241152" />
Also @EFLS use in Zetteldeft
https://efls.github.io/zetteldeft/#orgdc68570
Oh right! I always forget that he put that in there.
I read this post over lunch and thought it'd be fun to visualize @ctietze 's ba-zettelkasten-justice-for-hedgehogs notes.
I wrote a Python script to scan the
notes
folder, parse the zettel IDs, titles, and links, and build the network using the Pythongraphviz
package. The results looks like this:I've also attached a PDF version, if you'd like to zoom in, as well as the script itself. You'll need to change the extension to
.py
, and to install Graphviz (the tool) and graphviz (the Python package). It's not super flexible but it has some options:If there's some interest, I could turn this into a pip-installable package.
Really cool! I like it!
Now, it would be cool to find a way to label and specify those relations. But the visualization is very interesting. Thanks for doing this!
@achamess What would you label the links with? With markdown links, I could use the link’s text, but there’s no other info in the wiki links. Maybe something taken from the source file?
This looks very interesting, thanks @alexchabot for trying and posting this! I would love to have the opportunity to create such a graph from a selected set of notes. Ideally this would be possible with the selection of notes that shows in the sidebar of The Archive after I've searched for something – that makes it easier to get an overview over existing notes on something and to find existing and missing connections between a set of notes.
What would I need to do in order to make that happen? How do I use the script you posted? Could it for example be a macro in Keyboard Maestro, activated by a keyboard shortcut?
As far as I understand, I need to install Homebrew or MacPorts to install Graphviz. I guess I also need to download Python. Is there an easier way to get this visualisation without your script and having to download all these things (that I don't have any other use for at the moment)? Any (free) app that does this maybe?
@Vinho Those are great ideas. It'd definitely be possible to trigger the script from KeyboardMaestro. I'd need to look into getting the list of selected files from The Archive to create the graph, but I assume it's possible. I created an issue in the repo where I'll be sharing the code.
You don't need to install Python, because it comes standard on the Mac, but I used a third-party packages to create the graph because that's what what easiest. As for Graphviz itself, it does look like it's must be installed with Homebrew of Macports (I recommend Homebrew) and there isn't much I can do about that. I don't know of a pure-Python library that can easily make such graphs.
@alexchabot Getting the list of selected files could work by scripting against the Accessiblity identifiers of the UI components -- it will be easier once I add a proper AppleScript dictionary later this year.
Author at Zettelkasten.de • https://christiantietze.de/
@alexchabot: Would be awesome if that could work. With all these Keyboard Maestro macros The Archive is an incredibly powerful tool...
What I would be almost equally happy with and might be easier to implement is the possibility to create such graphs for tags (enter a tag and a network-graph is created for all the notes with that tag).
I would vote for a pip install! Not to give you more work but just to show my interest and support for this great execution of the idea!
It’ll definitely be pip-installable. But i need to figure out if there’s a sane way to make their network graphs without graphviz. Otherwise, graphviz will need to be installed separately (which is a pain). I’m looking into using NetworkX and matplotlib, which should be ok for small graphs.
@alexchabot: Any news? If I could help with this in any way I would, but unfortunately my few programming skills won’t be of much use...
@Vinho I've not abandoned! But you know, life got in the way. I just finished working on a version that uses plot.ly instead of Graphviz, which means it'll be much easier to install and we'll get interactivity for free! I'll try to publish it this weekend, but it might have to wait to the weekend after that.
@alexchabot Great, very much looking forward to it!
zkviz is live! See the announcement post for more details.
@alexchabot:
I'm just trying to do what you did above to ctietze's zettels with a subset of mine using the script you posted, but can't get it to work so far. I'm quite new to all of this, so have a few basic questions:
brew install graphviz
in the Terminal, but I guess that just installed the Python package?zk_network_viz.py
in the Terminal (with the options in square brackets)? Or do I have to do something else as well?@vinho I just made a new release of
zkviz
that supports Graphviz. I recommend using that instead of this script, since zkviz includes a few more options, is better tested, and is more flexible.@alexchabot: Great, thanks a lot for that!
Still would be interested in knowing how I would have gotten the above script to work, though – just to improve my skills
When you type the name of a program in Terminal.app, your shell (probably Bash) looks through a list of folders for that program. You can see the list of folders by executing the
echo $PATH
command, like so:The text below the
$
is value of thePATH
variable. The folder names are separated by the:
character.If your program, like
zk_network_viz.py
, is in one of those folders, your shell will be able to find it and you'll be able to just type its name:If it's not in one of those folders, you'll have to type the full path to the program, like
~/bin/zk_network_viz.py
, where~
means your "home" folder, where Documents, Downloads, Pictures, etc., are, or maybe~/Dropbox/programs/zk_network_viz.py
if you've put it on Dropbox.You can add folders to the
PATH
variable by adding a line to your shell's "config file," which is~/.bash_profile
. You can open the file from the Terminal with:Add the line below in
~/.bash_profile
to prepend the~/bin
folder to thePATH
variable.And then you'll need to open a new Terminal tab, or restart Terminal for the changes to take effect. After that, if
zk_network_viz.py
is in your~/bin
folder, you'll be able to execute from any folder.There's one more thing: wherever you put
zk_network_viz.py
, you'll have to "mark it as executable" for your shell to treat the script as a program. Otherwise, it's treated as a regular file. You do that by executing thechmod
program with the+x
option, followed by the path to the file you want to make executable:The
+x
options is the one that means "make executable". You can remove the executable mode using-x
instead of+x
.You did the right thing,
brew install graphviz
installs thegraphviz
program (actuallybrew
is a "general purpose" package manager. It can install programs written in different languages, and also install actual languages, like Python, or Ruby. I think that Graphviz is itself written in C++.Each of those languages has, in turn, its own package manager to install libraries (also called packages) for that language. The Python one is called
pip
, the Ruby one is calledgem
. When you dopip install graphviz
, it installs a Python "wrapper" calledgraphviz
to interact with the program calledgraphviz
(super confusing, I know). Homebrew usually installs programs in the/usr/local/bin
folder, which is probably already on your path (thePATH
variable).If
zk_network_viz.py
is on yourPATH
, then yes, you'll be able to just typezk_network_viz.py
. In the help above the square brackets denote options; things you can specify but don't have to. If you're already in your Notes folder, you can just type:But if you want to specify a different folder you should use:
I hope that helps!
@alexchabot: Wow, huge thanks for the time you put into explaining this – that was much more than expected... I think I followed all your instructions, but unfortunately it still doesn't work. When I try to run
$ zk_network_viz.py
the file doesn't seem to be read properly. Commands like "import" are not found and some of the comments are interpreted as commands...Could it have something to do with my version of python being more recent than your's? I had to run
pip3 install graphviz
instead ofpip install graphviz
as well because I have Python 3 installed...@Vinho
It's not your fault, it's because the
zk_network_viz.py
file doesn't inform your shell (Bash) what program to execute it with. You need to add this line at the top of the file, it's called a shebang line. It needs to be the path to the Python executable where you've installed the requirements (when you didpip3 install graphviz
). If you installedgraphviz
in the default Python that you installed with brew then they shebang line will be:If you want to be more general, you can use:
which, according to Wikipedia, will "execute [your program] with a Python interpreter, using the program [you shell] search path to find it".
Unfortunately it still doesn't work. Now the error is
I think I'll just give up the idea of trying to make my own visualisation for now
@Vinho Let's try again.
Use the
which
command to figure out which Python and which pip is on your PATH. Here's my default output for all 4 commands.If you installed graphviz with
pip install graphviz
, then the shebang inzk_network_viz.py
should be the output ofwhich python
. If you usedpip3 install graphviz
, then it should be the output ofwhich python3
.@alexchabot: It worked with
/usr/local/bin/python3
, great! Thanks so much for your efforts, that is very kind of you!!@Vinho Can you try with
#!/usr/bin/env python3
? That should work for people who have their Python 3 installed e.g. in their user/home folder.Author at Zettelkasten.de • https://christiantietze.de/
@ctietze: That seems to work as well.