Sorting problem.

English main discussion
Post Reply
  • Author
  • Message
Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Sorting problem.

Post by sexy96 »

aa
aa
aa
bb
cc
cc
ee
ee
ee
ee

How do you sort words by number of repetitions?
e.g. from the most common to the single.

ee
ee
ee
ee
aa
aa
aa
cc
cc
bb

Offline
Posts: 874
Joined: Sat Jan 16, 2010 2:03 pm

Post by opk44 »

sexy96
Maybe "offtop", but, probably, the easiest way is to use SQL (SQLite for example).
Import text into a database. The database query. Export query results to text file.

1. Import file "qq-1.txt" with non-sorted data.
2. Run query:

Code: Select all

select field1, count(field1) as cnt
from 'qq-1'
group by field1
order by cnt desc
3. Save result as "View" with name 'tmpdata'
4. Run query:

Code: Select all

select tmpdata.field1
from 'qq-1', 'tmpdata'
where tmpdata.field1 = 'qq-1'.field1
order by cnt desc
5. Save result as txt file (Export to CSV).

P.S. Import txt file have some bug (the last row in file can ignored) so you must add 1 extra empty line in the end of your file before.

Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post by sexy96 »

Thanks, too bad you can not do this editor.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

sexy96

Use JS script:

Code: Select all

var oSys   = AkelPad.SystemFunction();
var sNL    = ["\r\n", "\n", "\r"][AkelPad.GetEditNewLine(0) - 1];
var oCount = {};
var aWord;
var n;

if (AkelPad.GetSelStart() == AkelPad.GetSelEnd())
  AkelPad.SetSel(0, -1);

aWord = AkelPad.GetSelText().split("\r");

for (n = 0; n < aWord.length; ++n)
{
  if (aWord[n] in oCount)
    ++oCount[aWord[n]];
  else
    oCount[aWord[n]] = 1;
}

aWord.sort(function CompareValue(sA, sB)
           {
             if (oCount[sA] == oCount[sB])
               return oSys.Call("Kernel32::lstrcmpW", sA, sB);

             return (oCount[sB] - oCount[sA]);
           }
          );

AkelPad.ReplaceSel(aWord.join(sNL));

Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post by sexy96 »

Works great. Thanks so much.

I have a selection of icon sizes (ToolBar): Big or small.
How to set a little smaller than Big?
Post Reply