-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a backlinks query for a given Zettel ID #216
Conversation
Something to think of: are we looking for non-folgezettel backlinks (the list displayed below the zettel), or also uplinks (the tree displayed above the zettel)? |
What I'm personally looking for is the ability to get a list of all zettels that link to the one that I'm editing. This would include |
Then perhaps: GraphQuery_BacklinksOf ::
-- | If a Just value, get only backlinks with that connection type.
Maybe Connection ->
ZettelID ->
GraphQuery [(Connection, Zettel)] And pass
They are all backlinks. An 'uplink' is a kind of backlinks whose connection type = Folgezettel (i.e., non-cf). Uplinks are what are displayed on top of the zettel, as an inverted tree. If using this in editor support, I'd find it useful to be able to navigate by uplinks and downlinks (again, non-cf). |
https://github.com/andymatuschak/note-link-janitor Some inspiration. |
@srid I have the What would the query flag be for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments in your implementation. Based on current terminology we could go for the following cli spec:
--backlinks-of
: include all backlinks (folgezettel & ordinary)--uplinks-of
: include only folgezettel backlinks (aka. 'uplinks')--cf-backlinks-of
: include only ordinary backlinks
Is there a reason to implement the third option in the list? I would think that just the first two would be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pjones This looks good! Just one main change, and we are good to go with the merge.
let includeConn = maybe isJust (const (== conn)) conn | ||
g' = LAM.transpose $ G.getGraph $ G.induceOnEdge includeConn g | ||
ns = Map.toList $ Map.findWithDefault mempty (G.vertexID z) $ LAM.adjacencyMap g' | ||
in mapMaybe (\(v, e) -> (,) <$> e <*> G.findVertex v g) ns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation should be moved to Data.Graph.Labelled.Algorithm
. You can just put them in the existing preSetWithEdgeLabel
function.
Also, you should use getVertex
here instead of findVertex
. The former works with the guarantee that the vertex exists -- which is the case here -- and doesn't have to deal with Maybe. This way you also don't have to ignore the error via the Applicative lift.
Aside: Maybe we should just pass the filter function directly -- i.e., (Maybe Connection -> Bool)
instead Maybe Connection
-- but it is okay if that's not done in this PR>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move about half of the implementation into Data.Graph.Labelled.Algorithm
due to preSetWithEdgeLabel
being polymorphic in the edge type.
In backlinks
the edge type is specialized to Maybe Connection
which is why I post process the postSet
by removing Maybe
from the edges. The other issue with moving more of the code into preSetWithEdgeLabel
is that LAM.traspose
imposes more constraints on the edge type than currently exist. For example, e
would need to be an instance of Monoid
and Ord
.
How does that sound to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preSetWithEdgeLabel
can just take those extra constraints on e
. If you pass (e -> Bool)
instead of Maybe Connection
(as the filter) to it, the function can remain polymorphic - and you can then move all of the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the logic has been moved into preSetWithEdgeLabel
. Please let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pjones Almost there. The backlinks
function should take (Maybe Connection -> Bool)
instead of Maybe Connection
- just to avoid potential confusion.
(Maybe Connection
is used as the edge type only because the algebraic-graphs library relies on it to be a monoid - where the empty value signifies "no connection"; using the same type for the filter can be confusing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. The latest commit has this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Once you mark it non-WIP, I'll merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
0d0dd78
to
5b0e296
Compare
Useful for editors to show a "nearby zettels" view. See felko/neuron-mode#30 for an example.
Work in progress: do not merge.
Will be useful for editors to show a "nearby zettels" view. See
felko/neuron-mode#30 for more details.