Community
    • Login

    ComparePlus - improve alignment of similar lines

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    15 Posts 7 Posters 1.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • guy038G
      guy038
      last edited by

      Hello, @stefan-pendl, @mark-olson, @tbugreporter and All,

      I’ve tried to understand what @stefan-pendl meant but, even with the help of the Compare Plus plugin, I could not understand which kind of alignment was desired :-((

      @stefan-pendl, could you try to shorten your File_1, to the approximative number of lines of File_2, in order to easily identify where alignments must occur, when running the Compare Plus plugin ?

      Best Regards,

      guy038

      Stefan PendlS 1 Reply Last reply Reply Quote 1
      • Stefan PendlS
        Stefan Pendl @guy038
        last edited by

        @guy038
        The problem is, that if I shorten the file, the issue is gone.
        It only happens when the files are really different.

        Mark OlsonM 1 Reply Last reply Reply Quote 0
        • Mark OlsonM
          Mark Olson @Stefan Pendl
          last edited by

          @Stefan-Pendl said in ComparePlus - improve alignment of similar lines:

          It only happens when the files are really different.

          Well then, that’s the problem. Diff/alignment algorithms try their best, but if two files are really different, you shouldn’t be too surprised if it seems like the alignment is bad. Even Git’s diff algorithm, which is probably the best around, produces diffs/alignment that seem suboptimal when the diff is big.

          1 Reply Last reply Reply Quote 2
          • wonkawillyW
            wonkawilly
            last edited by wonkawilly

            @Stefan-Pendl said in ComparePlus - improve alignment of similar lines:

            I am not completely sure I understand the right way you mean about Improve alignment but maybe these suggestions can be also useful:
            replace spaces with tabs and install and activate the Elastic Tab Stop Plugin: with it is possible to get alignment like the following screenshot:

            e32f6344-b046-405e-9458-23b6e5dc5c56-image.png

            If you prefer you can use another plugin: CsvQuery to get alignment as the following screenshot:

            c0d2474c-4bd7-46e1-931c-a128e3ffc211-image.png

            Right click on CsvQuery plugin window and show the line numbers like the following screenshot is also possible:

            e9c64322-ce77-4e19-ae73-c3f0ca7e2599-image.png

            with CsvQuery You can also query the database using SQL syntax to filter the rows using criteria you need.

            66d1d409-d683-4636-99dc-06948372922f-image.png

            Stefan PendlS 1 Reply Last reply Reply Quote 1
            • Stefan PendlS
              Stefan Pendl @wonkawilly
              last edited by

              @wonkawilly
              Thanks for that, but I did not mean the alignment of columns, but the alignment of the diff result => lines starting with the same word should be aligned, not lines with a similar word.

              1 Reply Last reply Reply Quote 0
              • mpheathM
                mpheath @Stefan Pendl
                last edited by mpheath

                @Stefan-Pendl IMO, not the correct plugin for the job. Try PythonScript plugin.

                1. Open the 2 documents in separate views (view1 (main) and view2 (extra)).
                2. Run the script named DBMergeReport.py and it will open a new tab on the focused view with the merged report.
                import re
                
                def db_merge_report():
                    def get_dic(text):
                        dic = {}
                        for m in re.finditer(r'^(\w+ \w+) ([\d.]+)\r{0,1}$', text, re.M):
                            k = m.group(1)
                            dic[k] = m.group(2)
                        return dic
                
                    text1 = editor1.getText()
                    text2 = editor2.getText()
                    dic_a = get_dic(text1)
                    dic_b = get_dic(text2)
                    names = set(dic_a) | set(dic_b)
                    names = sorted(names)
                    length = max(len(item) for item in names)
                    text1 = ''
                
                    for name in names:
                        a, b = '', ''
                        if name in dic_a:
                            a = dic_a[name]
                        if name in dic_b:
                            b = dic_b[name]
                        text1 += ('{:<' + str(length + 1) + '} {:<20} {}\n').format(name, a, b)
                
                    if text1:
                        notepad.new()
                        editor.addText(text1)
                
                if __name__ == '__main__':
                    db_merge_report()
                

                New document tab with just the 1st 5 lines as an example.

                ACCT_TABLE_INDEX ACCT_TABLE                                 62.148458872879807   89.86486486486487
                ACCT_TABLE_INDEX2 ACCT_TABLE                                39.810607669115463   70.634920634920633
                ACCT_TABLE_INDEX3 ACCT_TABLE                                59.226190476190474   100.0
                ACCT_TABLE_INDEX4 ACCT_TABLE                                10.735930735930737   
                PIPABSOCCDATA PABSOCCDATA                                   88.099315068493155 
                

                The spacing is quite wide for the 1st column as the largest value is 58 characters. This might make comparison of the data being in 1 document alittle easier as the float numbers are next to each other.

                1 Reply Last reply Reply Quote 0
                • pnedevP
                  pnedev
                  last edited by

                  Hello @Stefan-Pendl ,

                  I will check your case and if some improvements could be made but it might take time.
                  Could you please in the meantime tell me which lines should be aligned according to your expectations (except lines PIPDATASET_0 - I already got that)?
                  Thanks.

                  BR

                  pnedevP 1 Reply Last reply Reply Quote 1
                  • pnedevP
                    pnedev @pnedev
                    last edited by

                    @pnedev said in ComparePlus - improve alignment of similar lines:

                    Could you please in the meantime tell me which lines should be aligned according to your expectations

                    Hello again @Stefan-Pendl ,

                    I analyzed your example data and I understand what you would expect as a result of the comparison. Please disregard my request for further clarifications.

                    BR

                    Stefan PendlS 1 Reply Last reply Reply Quote 1
                    • Stefan PendlS
                      Stefan Pendl @pnedev
                      last edited by

                      @pnedev
                      Thanks for checking this issue.
                      If you need more data just ask.

                      1 Reply Last reply Reply Quote 0
                      • pnedevP
                        pnedev
                        last edited by

                        Hello @Stefan-Pendl ,

                        I have just released ComparePlus v1.2.0 - it has a bug-fix for and overall improved changed lines detection algo - your example files compare as expected now.
                        It doesn’t mean that now the plugin will always consider the most intuitive lines as changed in all cases (that is simply not possible because of the different scenarios and user expectations) but it does a much better job now.

                        I am sorry about the long time it took for releasing this update - there were also other pending issues that required attention and I didn’t had enough spare time to work on ComparePlus.

                        1 Reply Last reply Reply Quote 4
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors