Queries that resolve entire Vertex, nut just named fields on it? #211
Answered
by
obi1kenobi
felipesere
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Hi! I'm traveling at the moment and don't have easy access to my laptop, so
I won't be able to help as much as usual. What you've described so far
sounds doable, but with a slightly different approach and schema.
In Trustfall, properties must be either scalar types or lists of such types
(or lists of lists etc.). That means the child relationship is an edge,
since trees are (probably?) not scalar -- they have multiple properties of
their own.
To get the entire node together with all children and their contents, I'd
recommend adding a string-typed property to your `Tree` schema called e.g.
`content`. This can be the entire markdown contained within, and *does not*
have to physically exist as a field on your underlying struct -- you can
compute its value on demand in `resolve_property` when needed.
Trustfall doesn't have an operator for returning all properties of a vertex
and all descendant vertices, because most schemas and data sets aren't DAGs
-- markdown is a rare DAG here! On a non-DAG, such an operator would cause
an infinite loop. In this case, since properties of the schema and data set
guarantee safety, we use the schema design to express that guarantee.
In general, when applying Trustfall to a problem I recommend writing a
schema and a few queries that express your use cases as a "paper prototype"
without any code. Most Trustfall problems are ones of schema design, not
implementation, so looking at code predominantly tends to misdirect and
confuse.
Good luck! I'm traveling so my replies may be delayed, but I'll try to
check back here as often as I can in case you have follow up questions.
I'm excited to see what you build! Please share your progress!
…On Sat, Mar 11, 2023, 3:03 AM Felipe Seré ***@***.***> wrote:
👋 A friend of mine nudged me towards trustfall for a little side-project
idea of mine to build somthing like jq/yq but for markdown, with
hopefully a more CSS like query syntax. Something like `mdql ./README "h p"
would return all paragraphs that follow a heading...
I've now played with Comrak to get an initial Tree of nodes built - this
is my personal flavour, there is no such structure/hierarchy inherent in
Markdown.
I now wanted to write a BasicAdapter that for my Tree but I am struggling
with 2 aspects
-
I have no concept of edge_name. A Tree has a node and children. Node
is a enum of all possible types, children is a Vec<Box<Tree>> for
recursion. There is no relation ship between "## A level-2 titleand aLorem
ipsum` paragraph other than I have nested the paragraph as a child of the
title.
-
I may not always want to return just a property of a node, but the
entire node. E.g. the entire title with any fields, not just its depth.
Not super sure this is easily doable in trustfall?
—
Reply to this email directly, view it on GitHub
<#211>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR5MSWQESQLNDGJ4YCEYVLW3REYJANCNFSM6AAAAAAVXMTHXY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
obi1kenobi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
👋 A friend of mine nudged me towards trustfall for a little side-project idea of mine to build somthing like
jq
/yq
but for markdown, with hopefully a more CSS like query syntax. Something like `mdql ./README "h p" would return all paragraphs that follow a heading...I've now played with Comrak to get an initial
Tree
of nodes built - this is my personal flavour, there is no such structure/hierarchy inherent in Markdown.I now wanted to write a
BasicAdapter
that for myTree
but I am struggling with 2 aspectsI have no concept of
edge_name
. ATree
has anode
andchildren
. Node is a enum of all possible types, children is aVec<Box<Tree>>
for recursion. There is no relation ship between "## A level-2 titleand a
Lorem ipsum` paragraph other than I have nested the paragraph as a child of the title.I may not always want to return just a property of a node, but the entire node. E.g. the entire title with any fields, not just its
depth
.Not super sure this is easily doable in trustfall?
Beta Was this translation helpful? Give feedback.
All reactions