store a dictionary to tinydb

308 views
Skip to first unread message

Dallon Asnes

unread,
Jul 2, 2018, 4:59:47 AM7/2/18
to MIT App Inventor Forum
I'd like to upload a dictionary of 3000+ words into tinyDB so that users can search an english word and see the foreign language definition. How can I store so many terms in the db at once? Thanks!

Chris Ward

unread,
Jul 2, 2018, 5:24:58 AM7/2/18
to MIT App Inventor Forum
Hi Dallon

That is a big ask of TinyDB, but you can try it. In the app, you can define temporary Blocks that load a text file containing the data, and run a loop to populate TinyDB. TinyDB is a permanent file, so once that job is done it would not need to be repeated every time the app is loaded.

The problem I think will be the time it takes to search - you will only really know by experimenting.

You could consider making 2 fixed lists instead - one for the English words and one related for the definitions. Again, this would only require to be set-up once. It might be quicker for search purposes than TinyDB, I don't really know - it's a matter of test test test. It would be quicker to set up because I have a desktop tool to make the lists from text files if you need a hand :)

If your Users are typically on line, you could store the data in the Cloud (CloudDb) and download on demand (English word | definition).

Dallon Asnes

unread,
Jul 2, 2018, 6:05:36 AM7/2/18
to MIT App Inventor Forum
Hi Chris

Thanks for your response! Could you share the desktop tool you have to make lists from text files?

Chris Ward

unread,
Jul 2, 2018, 6:44:56 AM7/2/18
to MIT App Inventor Forum
Hi Dallon

I intend to share next month, probably after the App Inventor API update. In the mean time, you can post your text files to me and I can return App Inventor .aia files containing static list Blocks - these can be placed into your own Project via the BackPack. 

Dallon Asnes

unread,
Jul 2, 2018, 7:17:43 AM7/2/18
to MIT App Inventor Forum
Hi Chris, I've uploaded the files both as the original word doc and as a .txt.

I hope that's workable!
Thanks!
sakalava_dictionary.doc
sakalava_dictionary.txt

Chris Ward

unread,
Jul 2, 2018, 7:33:07 AM7/2/18
to MIT App Inventor Forum
Hi Dallon

An idea - if there is a list for each letter, as organised in your text file, the search should be fast.....

Chris Ward

unread,
Jul 2, 2018, 8:17:42 AM7/2/18
to MIT App Inventor Forum
So, here we go.

Each list is in it's own Project File (.aia). Load them into App Inventor, Copy the Block (1 per file) into the BackPack, then in your Project File, "Paste All Blocks from Backpack".




DICTIONARY.zip

Chris Ward

unread,
Jul 2, 2018, 9:27:58 AM7/2/18
to mitappinv...@googlegroups.com
Hi Dallon

A crude but working example app attached. It only has the A, B and C lists to search.

(blocks image added  for reference purposes - ABG)
DictionaryTest_01.aia
blocks.png

Dallon Asnes

unread,
Jul 2, 2018, 11:07:00 AM7/2/18
to MIT App Inventor Forum
You're amazing thank you so much for this!
Is there a way for me to flip the lists to make the dictionary English search-based rather than Malagasy-search based?

Abraham Getzler

unread,
Jul 2, 2018, 11:22:10 AM7/2/18
to MIT App Inventor Forum
Look at this sample app for a reasonably fast file-based approach ...

ABG

Chris Ward

unread,
Jul 2, 2018, 11:26:38 AM7/2/18
to MIT App Inventor Forum
Hi Dallon

No need to flip the lists - just change the search in FindText - swap index 2 with index 1 and you are there. You could add a search option to your GUI too, and programmatically swap the indexes.......

Dallon Asnes

unread,
Jul 3, 2018, 9:54:13 AM7/3/18
to MIT App Inventor Forum
Hi Chris,

Did you mean to switch index 2 with index 1 (and vice versa) underneath get ResultsListPair? That's what I tried, and it switches the location of posted result between the entry text box and the result display box.

Is that what you meant? / Is there another way I can make the switch to be able to search by English instead of the current search by Malagasy (as Malagasy is the language in first index while English is in second)?

Thanks!
Dallon
Screen Shot 2018-07-03 at 4.50.17 PM.png

Chris Ward

unread,
Jul 4, 2018, 8:12:31 AM7/4/18
to MIT App Inventor Forum
Hi Dallon

More detailed explanation of how the code works.

1) Whatever text string is in the TextBox "TextBox_Find" is used to find a match in one of the Lists
2) To narrow the search down to a specific list, e.g. gListA, gListB etc, the first Character of the text string is used. So:

Let's say the text string to find is "andafy"

The code on Button_Find gets the first character, which will be "a", and calls the Procedure SelectList to narrow down the search, which will therefore be "gListA".

3) The FindText Procedure searches "gListA" for the StringToFind "andafy". What it finds is the complete List Item that contains "andafy".
The List Item found is "andafy|abroad" - so you can see that if the StringToFind was the English word "abroad", the find result would be the same.

4) If the StringToFind is indeed found, it is temporarily stored in a two-item "mini list" called "ResultListPair".
    The items in "ResultListPair" are in this order:
     Index 1:  "andafy"
     Index 2;  "abroad"

     This is always true, whether the search was for  "andafy" or for "abroad".

5)  On the app GUI, there is a label to display the find result "Label_Result"
      If the StringToFind was "andafy", we would want to display the English word "abroad" as the result, so we would set the "Label_Result" text to Index 2;
      If the StringToFind was "abroad", we would want to display the Malagasy word  "andafy" as the result, so we would set the "Label_Result" text to Index 1;

6) Note that the example above only works because both the English word and the Malagasy word are in a List that exists. To complete the code you need to add the other lists (via the Backpack, as explained before) and the SelectList Procedure needs expanding to include those other lists. Also, some lists are missing completely - there were no words in Malagasy starting with "x" for example.

7) You could add an option to your GUI:
     o Search for English Word Meaning in Malagasy
     o Search for Malagasy Word Meaning in English

     ... and enhance the result reporting accordingly with an "If Then Else"

    








Chris Ward

unread,
Jul 4, 2018, 9:30:33 AM7/4/18
to MIT App Inventor Forum
Hi Dallon

So, something like below. Remember though that your lists are currently designed for looking up words in Malagasy and getting a description in English. For a truly Bilingual dictionary you also need descriptions of English words in Malagasy. If you have access to that data, we would simply make an additional set of Lists and modify the search code slightly. 





makiwara

unread,
Jul 9, 2018, 3:57:18 PM7/9/18
to MIT App Inventor Forum
Hello everybody!

I have learnt a lot from your conversation, however one thing is not clear for me.

From that TXT how could you make the lists? As far as I know I have to add piece of the list one by one.

Is there a faster way?

Thank you for your reply! Have a nice day!

Chris Ward

unread,
Jul 14, 2018, 9:47:20 PM7/14/18
to MIT App Inventor Forum
Hello makiwara

The App Inventor lists where generated from text files using a Desktop app that I have written (MS Windows only). 
Reply all
Reply to author
Forward
0 new messages