A way to make TW ignore certain characters in alphabetizing?

3 views
Skip to first unread message

Dave Gifford - http://www.giffmex.org/

unread,
Sep 2, 2008, 11:54:01 PM9/2/08
to TiddlyWiki
I am working in Greek and want to have an alphabetized list of
tiddlers with Greek words as tiddler titles. But Greek letters often
have accents and breathing marks in front of the first letter. Is
there a way to tell TW that when it alphabetizes tiddlers it should
exclude certain characters?

Dave

FND

unread,
Sep 3, 2008, 5:18:26 AM9/3/08
to Tiddl...@googlegroups.com
> Is there a way to tell TW that when it alphabetizes tiddlers it
> should exclude certain characters?

Well, it might be possible to use a custom sort function - what's the
context of this (e.g. a FET macro call)?


-- F.

Dave Gifford - http://www.giffmex.org/

unread,
Sep 3, 2008, 8:17:50 AM9/3/08
to TiddlyWiki
Yeah Fred, either I'm going to use the Tagtreeplugin to make a list of
tiddlers that have a tag, or, more likely, a number of FET codes each
based on a tag.

Specifically,

<<forEachTiddler where 'tiddler.tags.contains("Preposiciones")' write
'"| {{greekpadding{"+tiddler.title+"}}}|"+tiddler.text+" |\n"' >>

and so on.

Dave

FND

unread,
Sep 3, 2008, 1:44:44 PM9/3/08
to Tiddl...@googlegroups.com
> Yeah Fred, either I'm going to use the Tagtreeplugin to make a list of
> tiddlers that have a tag, or, more likely, a number of FET codes each
> based on a tag.

For FET, you could use something like this:
---------------
<<forEachTiddler
sortBy 'stripNonAlphaNumerics(tiddler.title)'
script 'function stripNonAlphaNumerics(str) {
return str.replace(/[^A-Za-z0-9]/g, "");
}'
>>
---------------
(The stripNonAlphaNumerics function simply removes all characters that
are not Latin letters on digits, so those are ignored when sorting.)

However, TagsTreePlugin* doesn't support a custom sort function, so
you'd have to take that up with Pascal...


-- F.

FND

unread,
Sep 3, 2008, 1:51:30 PM9/3/08
to Tiddl...@googlegroups.com
A few minor notes:

> (The stripNonAlphaNumerics function simply removes all characters that
> are not Latin letters on digits, so those are ignored when sorting.)

... make that "letter or digits"...

Also, you could simplify this:
<<forEachTiddler
sortBy 'tiddler.title.replace(/[^A-Za-z1-9]/g, "")'
>>

> However, TagsTreePlugin* doesn't support a custom sort function

* http://visualtw.ouvaton.org/VisualTW.html#TagsTreePlugin


-- F.

Dave Gifford - http://www.giffmex.org/

unread,
Sep 3, 2008, 3:44:28 PM9/3/08
to TiddlyWiki
Hi Fred

Thanks for the reply but neither one worked.

Here is the file, with default tiddler being one in which the code
didn't work:

http://www.giffmex.org/experiments/GreekVocab.html

Dave

FND

unread,
Sep 3, 2008, 5:14:42 PM9/3/08
to Tiddl...@googlegroups.com
> neither one worked

Yeah, it wouldn't - I went only by the title of this thread, but
stripping all non-alphanumeric characters obviously doesn't suffice,
because that doesn't leave anything to sort by.

Now, we could come up with a list of problematic letters and leave the
rest to the standard sorting mechanism - would that work?
You can try it yourself by using this expression:
sortBy 'tiddler.title.replace(/[abcdefg]/g, "")'
Where "abcdefg" is the list of characters to ignore.

The alternative is to write an entirely different sorting algorithm that
properly handles the entire Greek alphabet...


-- F.

Dave Gifford - http://www.giffmex.org/

unread,
Sep 3, 2008, 6:50:33 PM9/3/08
to TiddlyWiki
This is worse than I thought. Turns out the breathing marks and
accents are not individual characters that can be replaced. They are
actually tied to the vowels at the beginning of the words, so each one
needs to be replaced by the vowel by itself.

Is there a way to do:

"replace á with a, replace é with e", etc?

I could hand do the changes individually, but I just want to know if
such a thing can be done. Unfortunately we are talking about 4
different breathing marks or accents in combination, times seven
vowels. I imagine that would slow down the FET a bit?

Dave

Dave Gifford - http://www.giffmex.org/

unread,
Sep 3, 2008, 6:51:30 PM9/3/08
to TiddlyWiki
Make that 4 punctuation combinations times 7 vowels times 2, one for
caps and one for lowercase.

Dave

FND

unread,
Sep 4, 2008, 5:14:41 AM9/4/08
to Tiddl...@googlegroups.com
> Is there a way to do:
> "replace á with a, replace é with e", etc?

Yes; instead of the single generic pattern ...
tiddler.title.replace(/[^A-Za-z0-9]/g, "")
... you can specify one replacement operation for each such character:
tiddler.title.replace(/a/g, "x").
replace(/b/g, "y").
replace(/c/g, "z");
where a, b, c are the original characters, and x, y, z are the letters
to replace them.
So that's gonna be a bit of a lengthy expression, but it works. There
might be an impact on performance, but that remains to be seen.

> 4 punctuation combinations times 7 vowels times 2, one for
> caps and one for lowercase.

If a group of character is to be replaced with the same letter, you can
group those by enclosing them in square brackets:
tiddler.title.replace(/[abc]/g, "x").
replace(/[def]/g, "y").
replace(/[ghi]/g, "z");
This would convert a title "abcdefghi" to "xxxyyyzzz".

HTH.


-- F.

Dave Gifford - http://www.giffmex.org/

unread,
Sep 5, 2008, 11:12:34 AM9/5/08
to TiddlyWiki
Thanks Fred I'll give this a try! Yer awesome.

Dave
Reply all
Reply to author
Forward
0 new messages