Dictionary rewrite - thoughts, please

This forum is a working group for community contributors to the LiveCode IDE included in the main LiveCode distribution.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Re: Dictionary rewrite - thoughts, please

Postby bn » Wed May 10, 2017 8:39 pm

Hi Alejandro,

did you try the new version of tinyDictionary? You can add notes and can use the notes file to share notes between users.
This is not a full featured bug/technotes system. But may be useful in some cases.

Kind regards
Bernd
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3175
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Dictionary rewrite - thoughts, please

Postby AndyP » Thu May 11, 2017 11:01 am

Hi Bernd,

tinyDictionary is great! using it all the time now in preference to LCs own.

Add notes is a really useful feature... have you considered having a community notes section than is stored in the cloud?
That way we would all benefit from others insights.

Anyway again, many thanks for your efforts.
Andy Piddock

http://2108.co.uk/tinyide/ - TinyIDE gives you more space to develop your ideas

http://2108.co.uk/script-editor-themer/ Script Editor Themer - Your code has never looked so good

My software never has bugs. It just develops random features
AndyP
 
Posts: 279
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)

Re: Dictionary rewrite - thoughts, please

Postby bn » Thu May 11, 2017 9:34 pm

Hi Andy,

thank you for your kind words.
have you considered having a community notes section than is stored in the cloud?

actually that would be an obvious extension of the current notes. Others have asked for it too.

However there are a couple of hurdles here for me.
Technically it probably wouldn't be too complicated to add a central repository for notes somewhere in the "cloud".
But the "cloud" is a bit cloudy for me... :) I am not familiar with server stuff.

Then there is a layer of administration. Someone has to look at the notes. Are they still uptodate, are there redundancies, etc.
Who is going to do that, it is not something that can be automated completely in my opinion.

And who knows, the built-in dictionary actually needs a couple of tweaks and tinyDictionary would be redundant. Then what about the notes.

I prefer to think of tinyDictionary as a quick and "dirty" dictionary which probably suits more experienced developers that don't need the structured approach of the built-in dictionary.

By the way I think what Livecode has done to the dictionary is fantastic, it now covers the various sub-languages and extensions, libraries, community contributed widgets etc. I think Ali did it mostly but whoever did it, did a good job. Just the actual framework to display the dictionary seems to be "Bootstrap" and that is not easy to change in layout etc.

Kind regards
Bernd
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3175
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Dictionary rewrite - thoughts, please

Postby jmburnod » Fri May 12, 2017 12:33 pm

Hi Bernd,
Thanks again for the job.
I noticed an unexpected behavior (for me) about notes.
If I save a new note, it appears after fld "fRes" but if I use history to change topic and return by history to the topic where I saved my note it disapeared. I have to click on notes icon to see it.
Is it what you want ? (tinyDictionary_0_8_1_0)
the "cloud" is a bit cloudy for me... :)

and as you said, we need humans to manage it
Kind regards
Jean-Marc
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 1874
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève

Re: Dictionary rewrite - thoughts, please

Postby bn » Fri May 12, 2017 2:12 pm

Bonjour Jean-Marc,

glad you like it.

If I save a new note, it appears after fld "fRes" but if I use history to change topic and return by history to the topic where I saved my note it disapeared. I have to click on notes icon to see it.

it is as you describe. The history is not updated until the next time you choose the entry in the table field. Then the note is shown. If you only move using history the note is not yet appended since history currently stores the htmlText of the details when you click an entry in the table field.

Actually I had not thought of this. History for me is just a temporary memory of your reading and as such volatile. But I will look how to add the newly created note to an entry in history.

KInd regards
Bernd
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3175
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Thu Jun 22, 2017 5:49 am

Not sure how appropriate it is to post to an old thread, but I have a suggestion for tinyDictionary. If you perform a search and there is only a single result, the only way to view the dictionary entry is to click on the result. My suggestion is to add the following handler to the field "fData" code:
Code: Select all
on rawKeyUp pWhich
    if pWhich = 65293 then
        send "arrowKeyChanged" to me in 0 milliseconds
    end if
    pass rawKeyUp
end rawKeyUp

This will map the enter key (at least on the Windows laptop I'm using at the moment) to the code that displays what is currently hilighted. I can think of two other alternatives:
  • Remove bounds checking for left/up arrow keys so arrowKeyChanged handler always gets called
  • Send arrowKeyChanged in the search field handler when the tab key is pressed (display first entry, but I see some code commented out that may have tried that)
P.S. - I really like this dictionary on the smaller screen of my laptop.

Thanks,
Brian
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Fri Jun 23, 2017 3:23 am

After a little thought, I think this may be a better approach:

Code: Select all
on tabKey
    focus on field "fData" of group "modTableField 1"
    if the hilitedline of field "fData" of group "modTableField 1" is 1 then
        send "arrowKeyChanged" to field "fData" of group "modTableField 1" in 0 milliseconds
    end if
end tabKey

If you tab back and forth between the list and the search without changing it, the hilite does not move. If you change the search term, then the hilight is normally reset to the first line but the dictionary entry wasn't changed. With the above code, the dictionary entry will always match the hilighted line in the list after a tab (unless there is nothing in the list).

Thanks,
Brian

(fixed typo)
Last edited by bwmilby on Mon Jun 26, 2017 12:25 am, edited 1 time in total.
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

Re: Dictionary rewrite - thoughts, please

Postby bn » Fri Jun 23, 2017 8:13 pm

Hi Brian,

thanks for suggesting this

I would prefer not to change field "fData" itself but to apply a change to the behavior of group "modTableField"

To do that you edit button "behavMTF"

I have put the following code at the end of the script

Code: Select all
###########################
## if only one entry is displayed the arrowkeys don't activate the details display
## this is a patch for that suggested by Brian (bwmilby)

after focusIn
   if the number of lines of field "fData" of me is 1 then  send "arrowKeyChanged" to field "fData" of group "modTableField 1" 
end focusIn

###########################


Now you apply the changes in the script editor and then from the message box you enter
Code: Select all
closecard

and hit the return key this clears all kinds of things and now you save tinyDict.

then again from the message box you enter (just copy the code below)
Code: Select all
preopenCard;opencard

and hit the return key. This will restart the initialization of tinyDict.

The advantage is that you don't save a couple of megabytes of temparary data in tinyDict and it stays small. The temporary data will be generated by preopencard and opencard anyways.

Please tell me if this patch does what you want.

Kind regards
Bernd
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3175
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Sat Jun 24, 2017 3:36 am

Works great if there is a single result. If there is more than one result, then you have to arrow down and back up to see the first item though.
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

Re: Dictionary rewrite - thoughts, please

Postby jameshale » Sat Jun 24, 2017 4:07 am

Your initial request was to auto show the detail for a single result.
This second request is to auto show the first listed of the found results.
They really are quite different.
While the showing of the detail automatically if there is a single result makes sense.
Showing the detail of the first listed result doesn't and to my mind would become annoying very quickly.
My 2 cents.
jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 175
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Sat Jun 24, 2017 4:59 am

The second idea only displayed the first entry after the tab key was pressed to leave the search field. My thought was that at that point you see the term you want defined and if it is the first one it requires two additional key presses to get. I'm very new to LC though, so maybe I'm missing something.

This is what I settled on for my copy:
Code: Select all
after focusIn
   if the hilitedLine of field "fData" of me is 1 then  send "mtfUserChangedHilitedLine 1" to group "modTableField 1"
end focusIn

I didn't notice any lag, flicker, or problems when tabbing between the search and list while on line 1. I did discover that the arrow keys work to change items while in the popup state.

Also, just found the package for modTextField and understand about not changing the script on the field directly. Reading the documentation on it now. It's a really cool control. For some things that I have in mind it would probably be a better fit than trying to use the data grid.

Further up in the thread it was discussed how synonyms are not able to be searched. I read the bug report and did some digging. In LC 7, the synonyms were added to the index as discrete entries. Someone that knows their way around the build system could probably add that in as the bug fix (when generating the api.sqlite file, would just need to add duplicate entries for the synonym keywords like LC 7 did). I don't think it would be that hard, I just don't even know where to start looking.
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Wed Jun 28, 2017 1:53 pm

If you add the below code to the mtfOpen handler just below the repeat loop that builds the global array, it will add duplicate dictionary entries for all of the synonyms. Not quite as clean as LC 7 since the "Synonym of" shows in the Keyword column of the table but it does allow searching for synonyms.

Code: Select all
    -- add synonyms to dictionary array
    local tCount, aValue
    repeat for each key anEntry in sCompleteDictsArray
        if sCompleteDictsArray[anEntry]["Synonyms"] is "" then -- no synonyms for entry
            next repeat
        end if
        put sCompleteDictsArray[anEntry]["display name"] into tKeyWord
        put sCompleteDictsArray[anEntry]["Synonyms"] into tSubarray
        put 1 into tCount
        repeat for each element aValue in tSubarray
            if aValue is tKeyWord then next repeat -- glossary entries include themselves
            put sCompleteDictsArray[anEntry] into sCompleteDictsArray[anEntry & "." & tCount]
            put aValue & " (Synonym of " & tKeyWord & ")" into sCompleteDictsArray[anEntry & "." & tCount]["display name"]
            add 1 to tCount
        end repeat
    end repeat
    -- end add synonyms
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

Re: Dictionary rewrite - thoughts, please

Postby bn » Thu Jun 29, 2017 1:18 am

Hi Brian,

thank you for the code. It is a nice addition to the dictionary. I think it is useful for finding abbreviated entries and for completeness (# is only listed in synonyms, not an entry on its own). I don't quite agree with some "synonyms" (e.g. "card control" as synonym for "card field", "card button" etc) but that is another discussion.
Although the synonyms add 1358 entries to "All" (1355 to LCS, 3 to Datagrid) it has no real impact on searching and opening tinyDictionary.

I have implemented a modified version and it will be in the next release of tinyDictionary. Duly credited in the code.
The modifications have a twofold reason.

The first and most important one is that you use "repeat for each key aValue in Array"
the reason that "repeat for each" is vastly faster than "repeat with i = 1 to the number of keys in Array" or some such is that "repeat for each" assumes that the data does not change when doing the repeat. "repeat with i = 1 to the number of keys" counts the number of keys on every iteration, this makes it slow.
Here you add keys to the array. This is not recommended, although it worked in your code, funny things can happen. Hence I filled a new array and appended it to the "master" array.
You can test what happens if you add entries to the "master" array with sequential integer keys. You get into recursion and it messes it all up. Somehow "repeat for each key" in your real number version did not find the newly created keys and it worked. But that is more a "happy accident" than something you can count on.

The second one is that you use a real number instead of an integer as key. That is perfectly alright since the keys are strings anyways. However if keys are integers you can use the "extents" function to determine the min and max value of the _integer_ keys in an array. To be consistent in the array I prefer an integer as a key, sequential if possible at all.

The changed code is appended below.

BTW hats off to you for finding a way and a place for this addition. In my opinion this is no small feat for someone who just started with Livecode. It shows a thorough understanding of the data structure of the "raw" data and the working of arrays.

Kind regards
Bernd

Code: Select all
-- addition by Brian Milby to also show synonyms as entries in LCS
   -- http://forums.livecode.com/viewtopic.php?f=67&t=28731&sid=78ca55655559ba5d7bab94f6e5c244d1&p=155331#p155331
   -- add synonyms to dictionary array
   local aValue, tSynonymsArray
   put the number of lines of the keys of sCompleteDictsArray into tExtents
   put tExtents + 1 into tMax
   repeat for each key anEntry in sCompleteDictsArray
      if sCompleteDictsArray[anEntry]["Synonyms"] is "" then -- no synonyms for entry
         next repeat
      end if
      put sCompleteDictsArray[anEntry]["display name"] into tKeyWord
      put sCompleteDictsArray[anEntry]["Synonyms"] into tSubarray
      repeat for each element aValue in tSubarray
         if aValue is tKeyWord then next repeat -- glossary entries include themselves
         put sCompleteDictsArray[anEntry] into tSynonymsArray[tMax]
         put aValue & " (Synonym of " & tKeyWord & ")" into tSynonymsArray[tMax]["display name"]
         add 1 to tMax
      end repeat
   end repeat
   repeat for each key aKey in tSynonymsArray
      put tSynonymsArray[aKey] into sCompleteDictsArray[aKey]
   end repeat
   -- end add synonyms
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3175
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Thu Jun 29, 2017 3:49 am

Thanks Bernd! Some good stuff for me to think about. (I initially tried to put it at the end of your loop, but you call next repeat so it wouldn't work there. Wasn't sure if anything you did would have been important to copy, so I just added another loop. If not, it could have gone at the top of the loop.) What's funny is that I really wanted to be able to search for synonyms after seeing "grc" in a script and it took me a bit to figure out that was short for "graphic". Looked at the synonym search bug report and went back to LC 7 to see how it looked and tried to copy that. Started looking to see how to fix the bug itself. Found where I think the fix needs to go, but figuring out the structure of the array became a little difficult. Decided I needed to take a step back first. Your code allowed me to figure out the array structure and was a much easier place to test.

Now I want to figure out how to get this into revDocsParseDictionaryToLibraryArray so the changes will make it into the api.sqlite file. (Writing the code should be pretty easy - it is mostly already done, figuring out how to test it on the other hand...)

Update:
Code suggestion posted to http://quality.livecode.com/show_bug.cgi?id=18305
Not sure, but you may be able to see it here on GitHub.
Anyone know a fast/easy way to test rebuilding the dictionary from scratch?
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

Re: Dictionary rewrite - thoughts, please

Postby bwmilby » Thu Jun 29, 2017 3:58 pm

I see what you mean about glossary entries. For those, I think the "synonym" definition is not quite the same as for the rest of the dictionary. Maybe we should have the code check to see if it is a glossary entry and not add the "(Synonym of" for those.

Change this line:
Code: Select all
         put aValue & " (Synonym of " & tKeyWord & ")" into tSynonymsArray[tMax]["display name"]


To:
Code: Select all
            put aValue into tSynonymsArray[tMax]["display name"]
            if sCompleteDictsArray[anEntry]["Type"] is not "glossary" then
                put " (Synonym of " & tKeyWord & ")" after tSynonymsArray[tMax]["display name"]
            end if


That code does 2 assignments for non-glossary entries, so it is probably faster to just use if/then/else with separate put statements.
bwmilby
 
Posts: 12
Joined: Wed Jun 07, 2017 5:37 am

PreviousNext

Return to IDE Contributors

Who is online

Users browsing this forum: No registered users and 1 guest