-
Notifications
You must be signed in to change notification settings - Fork 15
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
Functions that determine if a given sequence is a subsequence of another sequence #94
Comments
Maybe the second argument of |
@ChristianGruen This would become too complex and in some cases the code may be difficult to understand. Why we have the |
I wonder whether
Examples seem to give the right/expected result at https://xqueryfiddle.liberty-development.net/bdxZ93 (had to change to
|
So I wondered how the non-contiguous version could be found, what are your thoughts on
? |
I would use: let $has-non-cont-subsequence := function($seq1 as item()*, $seq2 as item()*, $self as function(*))
{
empty($seq2)
or
(for $fst in head($seq2),
$ind1 in index-of($seq1, $fst)
return
$ind1 gt 0 and $self(subsequence($seq1, $ind1+1), tail($seq2), $self)
)
}
return
$has-non-cont-subsequence(('a', 'b', 'c', 'd'), ('b', 'd'), $has-non-cont-subsequence) As for comparing items that are nodes, we probably need another parameter to indicate whether we want identity semantics or value semantics to be used in comparing the corresponding items. Also need to agree on a good default value for this parameter. |
We also don't have a function for testing whether two sequences are "the same". And for the same reason: we don't have a function or operator for testing if two items are "the same". For some items -- notably functions -- it's intrinsically hard to come up with a definition. For other items it's hard to come up with a definition that will suit all users all of the time. |
Let us define these useful functions for all sequences that don't contain functions! It would be a pity not to have this useful and user-needed functionality just because of one type (the function type) out of zillions of other types of items. @michaelhkay Can we define a type the is Obviously, we can define a function that takes an item() and returns true if it isn't a function: |
If we decide to add new functions of this type, I think it would be consistent to apply the same rules as for |
I have updated the function definitions in the proposal to include an optional Obviously we are good, if our comparer returns |
So I assume that the behavior of the function cannot be simulated with What about collations (which are also applicable to |
@ChristianGruen I believe we can add collation arguments -- I didn't do this for now so that we could agree on the main semantics first. |
@martin-honnen My preferred pure-XPath implementation is below. This also defines the implementation (and uses it) of another proposal: let $starts-with-sequence := function($seq1 as item()*, $seq2 as item()*, $self as function(*))
{
empty($seq2)
or
head($seq1) eq head($seq2) and $self(subsequence($seq1, 2), subsequence($seq2, 2), $self)
},
$has-subsequence := function($seq1 as item()*, $seq2 as item()*)
{
empty($seq2)
or
(some $ind in index-of($seq1, head($seq2))
satisfies $starts-with-sequence(subsequence($seq1, $ind+1), tail($seq2), $starts-with-sequence)
)
}
return
$has-subsequence(('a', 'b', 'c', 'd'), ('b', 'd')) |
I think adding the |
Maybe |
I included a definition of |
Could the non-contiguous version be done as:
To be honest, I'm struggling to think what one might want to use it for. |
For this non-contiguous containment-check I would prefer Maybe even a name like One use-case would be to prove easily that Or to put it in other words, each sequence can be obtained from the other using a series of "topology-preserving" operations. If we had the On the other side the existing, standard |
@dnovatchev Now that we have |
The CG agreed to close this issue without action at meeting 066 |
It is surprising that we are at version 4 and still are missing:
and
and
(3) above is a shorthand for:
Examples:
fn:has-subsequence(('a', 'b', 'c', 'd'), ('b', 'c'))
returnstrue()
fn:has-subsequence(('a', 'b', 'c', 'd'), ('b', 'd'))
returnsfalse()
fn:has-non-contigous-subsequence(('a', 'b', 'c', 'd'), ('b', 'd'))
returnstrue()
fn:has-non-contigous-subsequence(('a', 'b', 'c', 'd'), ('d', 'b'))
returnsfalse()
('a', 'b', 'c', 'd') => has-subsequence(('b', 'c'))
returnstrue()
('a', 'b', 'c', 'd') => has-subsequence(('b', 'd'))
returnsfalse()
('a', 'b', 'c', 'd') => has-non-contigous-subsequence(('b', 'd'))
returnstrue()
('a', 'b', 'c', 'd') => has-non-contigous-subsequence(('d, 'b'))
returnsfalse()
The text was updated successfully, but these errors were encountered: