XQuery compare order of two sequencesDividing the screen in two halves using LinearLayoutFinding the minimum...

Why are the books in the Game of Thrones citadel library shelved spine inwards?

How would a Dictatorship make a country more successful?

Placing an adverb between a verb and an object?

What is better: yes / no radio, or simple checkbox?

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

Why is "points exist" not an axiom in geometry?

Is there any differences between "Gucken" and "Schauen"?

Slow moving projectiles from a hand-held weapon - how do they reach the target?

Would these multi-classing house rules cause unintended problems?

Recrystallisation of dibenzylideneactone

How to tag distinct options/entities without giving any an implicit priority or suggested order?

Would a National Army of mercenaries be a feasible idea?

Book where aliens are selecting humans for food consumption

Using only 1s, make 29 with the minimum number of digits

Am I a Rude Number?

Check if the digits in the number are in increasing sequence in python

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Can I write a book of my D&D game?

If I sold a PS4 game I owned the disc for, can I reinstall it digitally?

Explain the objections to these measures against human trafficking

Every character has a name - does this lead to too many named characters?

Eww, those bytes are gross

What is this metal M-shaped device for?

Can an insurance company drop you after receiving a bill and refusing to pay?



XQuery compare order of two sequences


Dividing the screen in two halves using LinearLayoutFinding the minimum of two numbersMerging two XMLs together in PythonMerging tags in two XML files with same attributes and different contentUsing LINQ to output SQL data from two tables into XMLOpening the same CSV file in two different ways in order to transform data in one column and update original CSV using PythonFunctional-style Cocoa XML serializer and object mapperSQL query to compare two XML columnsRecursive function to compare XML files using MSXML DOM













0












$begingroup$


I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.



This is best illustrated with an example



E.G.
let $baseSequence := ('a','b','c'..'x','y','z')



Tested against



('a','b','c') => true appears in the same order in $baseSequence



('a','b','a') => false is not in the same order in $baseSequence



('c','h','x','y') => true appears in the same order in $baseSequence



I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?



declare function local:testOrder($baseSequence, $testSequence, $position) {
let $itemPosition :=
if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
return
if ($itemPosition > $position) then (
local:testOrder($baseSequence, tail($testSequence), $itemPosition)
) else (
count($testSequence) = 0
)
};

(:Test cases:)
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('a','c','e','h','w')
return local:testOrder($baseSequence, $testAgainst, 0)


Would return true



let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('f','d','l','m','n')
return local:testOrder($baseSequence, $testAgainst, 0)


Would return false










share|improve this question











$endgroup$

















    0












    $begingroup$


    I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.



    This is best illustrated with an example



    E.G.
    let $baseSequence := ('a','b','c'..'x','y','z')



    Tested against



    ('a','b','c') => true appears in the same order in $baseSequence



    ('a','b','a') => false is not in the same order in $baseSequence



    ('c','h','x','y') => true appears in the same order in $baseSequence



    I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?



    declare function local:testOrder($baseSequence, $testSequence, $position) {
    let $itemPosition :=
    if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
    return
    if ($itemPosition > $position) then (
    local:testOrder($baseSequence, tail($testSequence), $itemPosition)
    ) else (
    count($testSequence) = 0
    )
    };

    (:Test cases:)
    let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
    let $testAgainst := ('a','c','e','h','w')
    return local:testOrder($baseSequence, $testAgainst, 0)


    Would return true



    let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
    let $testAgainst := ('f','d','l','m','n')
    return local:testOrder($baseSequence, $testAgainst, 0)


    Would return false










    share|improve this question











    $endgroup$















      0












      0








      0





      $begingroup$


      I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.



      This is best illustrated with an example



      E.G.
      let $baseSequence := ('a','b','c'..'x','y','z')



      Tested against



      ('a','b','c') => true appears in the same order in $baseSequence



      ('a','b','a') => false is not in the same order in $baseSequence



      ('c','h','x','y') => true appears in the same order in $baseSequence



      I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?



      declare function local:testOrder($baseSequence, $testSequence, $position) {
      let $itemPosition :=
      if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
      return
      if ($itemPosition > $position) then (
      local:testOrder($baseSequence, tail($testSequence), $itemPosition)
      ) else (
      count($testSequence) = 0
      )
      };

      (:Test cases:)
      let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
      let $testAgainst := ('a','c','e','h','w')
      return local:testOrder($baseSequence, $testAgainst, 0)


      Would return true



      let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
      let $testAgainst := ('f','d','l','m','n')
      return local:testOrder($baseSequence, $testAgainst, 0)


      Would return false










      share|improve this question











      $endgroup$




      I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.



      This is best illustrated with an example



      E.G.
      let $baseSequence := ('a','b','c'..'x','y','z')



      Tested against



      ('a','b','c') => true appears in the same order in $baseSequence



      ('a','b','a') => false is not in the same order in $baseSequence



      ('c','h','x','y') => true appears in the same order in $baseSequence



      I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?



      declare function local:testOrder($baseSequence, $testSequence, $position) {
      let $itemPosition :=
      if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
      return
      if ($itemPosition > $position) then (
      local:testOrder($baseSequence, tail($testSequence), $itemPosition)
      ) else (
      count($testSequence) = 0
      )
      };

      (:Test cases:)
      let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
      let $testAgainst := ('a','c','e','h','w')
      return local:testOrder($baseSequence, $testAgainst, 0)


      Would return true



      let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
      let $testAgainst := ('f','d','l','m','n')
      return local:testOrder($baseSequence, $testAgainst, 0)


      Would return false







      xml xquery






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 10 hours ago









      200_success

      130k16153417




      130k16153417










      asked 10 hours ago









      swshaunswshaun

      486




      486






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):



          declare function local:testOrder2($baseSequence, $testSequence) {
          let $positions := $testSequence ! index-of($baseSequence, .)
          return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
          };


          Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!






          share|improve this answer










          New contributor




          Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214571%2fxquery-compare-order-of-two-sequences%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):



            declare function local:testOrder2($baseSequence, $testSequence) {
            let $positions := $testSequence ! index-of($baseSequence, .)
            return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
            };


            Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!






            share|improve this answer










            New contributor




            Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            $endgroup$


















              0












              $begingroup$

              There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):



              declare function local:testOrder2($baseSequence, $testSequence) {
              let $positions := $testSequence ! index-of($baseSequence, .)
              return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
              };


              Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!






              share|improve this answer










              New contributor




              Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              $endgroup$
















                0












                0








                0





                $begingroup$

                There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):



                declare function local:testOrder2($baseSequence, $testSequence) {
                let $positions := $testSequence ! index-of($baseSequence, .)
                return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
                };


                Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!






                share|improve this answer










                New contributor




                Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                $endgroup$



                There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):



                declare function local:testOrder2($baseSequence, $testSequence) {
                let $positions := $testSequence ! index-of($baseSequence, .)
                return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
                };


                Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!







                share|improve this answer










                New contributor




                Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer








                edited 15 mins ago





















                New contributor




                Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 4 hours ago









                Alain CouthuresAlain Couthures

                1011




                1011




                New contributor




                Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                Alain Couthures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Code Review Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214571%2fxquery-compare-order-of-two-sequences%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

                    How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

                    Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...