text-fabric icon indicating copy to clipboard operation
text-fabric copied to clipboard

Outer Names in Inner Quantifiers

Open codykingham opened this issue 6 years ago • 21 comments

I want to revisit the issue of multiple names in quantifiers. There are certain relationships which the present implementation is not able to express.

Here is an example template that is currently not possible. There are two words in a phrase. And we want to specify that a preposition should not intervene between them:

phrase
    w1:word
    [...]
    w2:word

/without/
w1
< word pdp=prep
< w2
/-/

In the current implementation, these kinds of relation expressions can only be approximated by repeating all of the specifications under w1 under a quantifier:

phrase
    w1:word
    [...]
    w2:word
    /without/
    phrase
        w1:word
        [...]
        < word pdp=prep
        w2
    /-/

In cases where [...] contains lots of specs, this becomes unwieldy. Furthermore, there is no guarantee in the above pattern that the w1 in the phrase template will be identical to the w1 in the quantifier template.

I know that there are major difficulties to implementing multiple names in quantifiers. However, if each name is assigned to a node in an outer level, perhaps it is possible to pass those nodes as sets to the inner levels, so that a w1 defined in level 0 can be directly referred to in level 1. Or perhaps there is yet a better way.

codykingham avatar Dec 04 '18 15:12 codykingham

I see what you mean. Yet it is a lot of work to get it right. I will not be able to do that in 2018, I'm afraid. Let's keep it on the list.

dirkroorda avatar Dec 05 '18 14:12 dirkroorda

When I think of it, it should definitely be possible, but there will be an addtional restriction:

  • the stuff between the parent and the quantifier may not contain names from elsewhere in the template

dirkroorda avatar Dec 05 '18 16:12 dirkroorda

Maybe we can think of contextual parentage: the parent node itself comes with its template context. Then TF does not run 2 separate queries from scratch. Could it pass results from a parental template down to a daughter template? Maybe rather than running a second query in the daughter template, you use the first results to narrow the second search. If there is a container relationship expressed, then you can use the container object as a set argument in query 2. If the daughter template goes above the highest object from the mother, you could use an L.u to go straight to the target.

In such a set-up you would probably get better performance, and the inheritance of context would ensure your subtemplates are mutually intelligible. But maybe there are some drawbacks to such an approach?

codykingham avatar Apr 04 '19 09:04 codykingham

Internally a template is translated into a set of query nodes and query edges, without specific order. That query graph gets executed. At the point of execution there is no indentation and scope anymore.

dirkroorda avatar Apr 11 '19 07:04 dirkroorda

I think the way forward is to let quantifiers quantify not a single parent but a complete subtemplate. The subtemplate must be marked in case if it is more than one parent atom.

dirkroorda avatar Apr 11 '19 07:04 dirkroorda

---t1
w1:word
< w2:word
---

% other parts of the template

t1
/without/
w1
< word pdp=prep
< w2
/-/

dirkroorda avatar Apr 11 '19 08:04 dirkroorda

So: named subtemplates. If the quantifier follows the subtemplate immediately, no naming is needed.

dirkroorda avatar Apr 11 '19 08:04 dirkroorda

But wait, the subtemplates might become nested: if they contain quantifiers themselves. So we need a slightly different bracketing syntax:

{t1
w1:word
< w2:word
}

% other parts of the template

t1
/without/
w1
< word pdp=prep
< w2
/-/

dirkroorda avatar Apr 11 '19 08:04 dirkroorda

But in this case we may also say

{
w1:word
< w2:word
}
/without/
w1
< word pdp=prep
< w2
/-/

dirkroorda avatar Apr 11 '19 08:04 dirkroorda

{ and } should occur on a line on their own, the position in the line does not matter.

dirkroorda avatar Apr 11 '19 08:04 dirkroorda

What if instead of curly braces it were simply the same slashes as a quantifier? It is interesting, though, that we seem to be working back toward a format that looks nearly MQL-like!

codykingham avatar Apr 11 '19 09:04 codykingham

In other words, what if instead of “quantifiers” or “named templates” we have “blocks”

codykingham avatar Apr 11 '19 10:04 codykingham

MQL makes you think about your data as a tree. TF search is more conducive to graph thinking, so I am a bit wary about blocks.

Named templates might be useful as an abbreviation mechanism for reusing bits of template. But that will have complications with names.

About using the /: yes that could be nice. Inner subtemplates should be indented with the quantifier they belong too. Hm: that could be a really nice option.

dirkroorda avatar Apr 11 '19 16:04 dirkroorda

/all/
w1:word
< w2:word
/without/
w1
< word pdp=prep
< w2
/-/

dirkroorda avatar Apr 11 '19 16:04 dirkroorda

So we only have to add /all/ at the beginning of the template we want to quantify. It almost sounds doable!

And it sounds right too for all quantifiers:

/all/
things
/where/
these things
/have/
those things
/-/
/all/
things
/with/
these things
/or/
those things
/-/
/all/
things
/without/
them things
/-/

dirkroorda avatar Apr 11 '19 16:04 dirkroorda

I like that...But maybe the subtemplate should follow an all termination. As it is above, we cannot issue a template on w2 by itself. What about:

/all/
w1:word
< w2: word
/-/
/without/
w1
< word pdp=prep
< w2
/-/

At the same time, these two templates would return identical results:

w1:word
< w2: word
/all/
w1:word
< w2:word
/-/

So the all quantifier is optional, if you want to quantify an entire template you can use it. If not, you can ignore it.

codykingham avatar Apr 11 '19 16:04 codykingham

Why do we need the extra /-/ ?

dirkroorda avatar Apr 11 '19 17:04 dirkroorda

This should be possible too:

w1:word
/all/
< w2:word
/without/
< word pdp=prep
< w2
/-/

dirkroorda avatar Apr 11 '19 17:04 dirkroorda

Reason I was thinking the extra ending marker...the diff between this:

/all/
w1:word
< w2:word
/without/
w1
< word pdp=prep
< w2
/-/

and this:

/all/
w1:word
< w2:word
/without/
ls=card
/-/
/without/
w1
< word pdp=prep
< w2
/-/

is a bit subtle. But it does work

codykingham avatar Apr 11 '19 17:04 codykingham

I think you need an extra /all/ for that. But I have to admit that I should sleep on this one first

dirkroorda avatar Apr 11 '19 20:04 dirkroorda

This is a resumption of #9.

dirkroorda avatar Jun 29 '19 07:06 dirkroorda

I am not able to follow this up in the foreseeable future.

dirkroorda avatar Sep 12 '22 18:09 dirkroorda