i just used the searchabledictionary sample of android, which is available in samples folder of android sdk for windows. ( API level 9 )
i completed the definitions.txt file with the same format like
key - value
when i type a word in search area, the app tries to suggest words, but it doesn't find the exact word.here is an example. i searched the word test , and this is definitions.txt :
acceptance test - meaning
acid test - meaning
alpha test - meaning
benchmark tests - meaning
....
flight test - meaning
load test - meaning
....
test - meaning
it finds 15 first words of this list, ( hopefully it doesn't search words like attestaion) but it doesn't show the exact word test !
i read the DictionaryProvider and DictionaryDatabase but i could not realize the root of problem!
the question is how can i suggest the exact word test at first of the list?
Check Dictionary.java, you will see loadWords function.
That function opens definitions.txt file and iterates all lines, and splits every line with "-" and adds to a Hashmap dictionary.
And again in same file there is getMatches function, which takes your search keyword and gets result from dictionary.
Not sure but because when you are searching a suggestion, first couple of matches displays.
And because of "test" keyword exists on too many lines and ("test - meaning") is your last definition, you can't see on suggesting list.
You could try to move "test -meaning" line to the very first line on definitions.txt.
Related
I am trying to build an android app that the user can enter a string, and a list emoji related to that string would show up. (Just like Venmo app) For example:
case 1: User enters "pizz", and in the list there would be "π", note that the users enter "pizz", not pizza!
case 2: User enters "rabb", and in the list there would be "π" and "π°", note that the users enter "rabb", not rabbit!
What would be a good data structure and algorithm for this problem?
A trie is what your looking for. From Wikipedia
A trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is a kind of search treeβan ordered tree data structure ...
A trie is similar to a HashMap<K,V>, you can perform a lookup with keys and get a value. The difference is that you can also search by prefix. Given a prefix, it will find all the key-value pairs in the structure that have that prefix. It's basically the data structure for generating search suggestions.
General Idea:
Trie<String, String> t = new Trie<String, String>();
t.insert("pizza", "π");
t.insert("rabbit1", "π");
t.insert("rabbit2", "π°");
// then later...
t.findByPrefix("rabb"); // [π,π°]
Unfortunately, tries are too generic and are not present in any popular data structure libraries (like Java Collections Framework or Google Guava, for example). You'd have to implement one yourself or find an existing implementation and modify it.
I'd recommend:
Learning the theory. Watch this video. There are many more on YouTube that will teach you the basics. You can also search google for "N-way trie" and read notes about it.
Taking this class TrieST and modifying it. It's very similar (or already perfect) for what you need: http://algs4.cs.princeton.edu/52trie/TrieST.java.html see specifically thekeysWithPrefix method.
I have a table
And try to execute this command :
SELECT * FROM projects WHERE (UPPER(title) LIKE '%ΠΠ£%' OR UPPER(description) LIKE '%ΠΠ£%')
In the end i want to get a row with id 2 but nothing returns to me.
But, when i change request to :
SELECT * FROM projects WHERE (UPPER(title) LIKE '%ΠΡ%' OR UPPER(description) LIKE '%ΠΡ%')
It returns row (as expected) with id 2.
What i doing wrong? Why UPPER not worked?
The problem is in Russian language :) UPPER is working only for latin alphabet. There is question about it in ru.stackoverflow
a newbie to Meteor, but I have created under localhost a simple passenger counter I intend to use on an android app for a passenger survey (holding a laptop in an airport isn't a particularly wise idea). It works, but there is no export function. Basically uses meteor.collection as simple rows of data - one row been one passenger with a date/time stamp, two buttons - Add Passenger and Reset. I have tried looking everywhere for a simple answer, but what I want to do is now add to the client side (on browser - but ultimately on the mobile) a button called export, and when clicked, takes each row in the meteor.collection and export it to a text file - line by line. Very simple. Alas right now I haven't got a clue how to proceed. Seen some references to FS.collection, but don't think there is what I want. This is ultimately for a mobile application.
Thanks.
JSON.stringify each object into a larger object of pure text, say bytes
Create a blob from that text object, ex: blob = new Blob([bytes]);
Use the filesaver package to save to a file locally.
In my project I have one requirement to show the number of pages in Word documents (.doc, .docx) files and number of sheets in Excel documents (.xls, .xlsx). I have tried to read the .docx file using Docx4j but the performance is very poor but I need just the word count and tried using Apache POI. I am getting an error, something like:
"trouble writing output: Too many methods: 94086; max is 65536. By package:"
I want to know whether there is any paid/open source library available for android.
There is just no way to show exact number of pages in MS Word file, because it will be different for different users. The exact number depends on printer settings, paper settings, fonts, available images, etc.
Still, you can do the following for binary files:
open file use POIFSFileSystem or NPOIFSFileSystem
extract only FileInformationBlock as it is done in the constructor HWPFDocumentCore
create DocumentProperties using information from FileInformationBlock as it is done in constuctor of HWPFDocument
get value of property cPg of DOP: DocumentProperties::getCPg()
The description of this field is: "A signed integer value that specifies the last calculated or estimated count of pages in the main document, depending on the values of fExactCWords and fIncludeSubdocsInStats."
For DOCX/XLSX documents you will need to access the same (I assume) property but using SAX or StAX methods.
I am writing a dictionary-type app. I have a list of hash-mapped terms and definitions. The basic premise is that there is a list of words that you tap on to see the definitions.
I have this functionality up and running - I am now trying to put dynamic links between the definitions.
Example: say the user taps on an item in the list, "dog". The definition might pop up, saying "A small furry [animal], commonly kept as a pet. See also [cat].". The intention is that the user can click on the word [animal] or [cat] and go to the appropriate definition. I've already gone to the trouble of making sure that any links in definitions are bounded by square brackets, so it's just a case of scanning the pop-up string for text [surrounded by brackets] and providing a link to that definition.
Note that definitions can contain multiple links, whilst some don't contain any links.
I have access to the string before it is displayed, so I guess the best way to do this is to do the scanning and ready the links before the dialog box is displayed.
The question is, how would I go about scanning for text surrounded by square brackets, and returning the text contained within those brackets?
Ideally the actual dialog box that is displayed would be devoid of the square brackets, and I need to also figure out a way of putting hyperlinks into a dialog box's text, but I'll cross that bridge when I come to it.
I'm new to Java - I've come from MATLAB and am just about staying afloat, but this is a less common task than I've had to deal with so far!
You could probably do this with a regular expression; something like this:
([^[]*)(\[[^]]+\])
which describes two "match groups"; the first of which means any string of zero or more characters that aren't "[" and the second of which means any string starting with "[", containing one or more characters that aren't "]", and ending with "]".
Then you could scan through your input for matches to this pattern. The first match group is passed through unchanged, and the second match group gets converted to a link. When the pattern stops matching your input, take whatever's left over and transmit that unchanged as well.
You'll have to experiment a little; regular expressions typically take some debugging. If your link text can only contain alphanumerics and spaces, your pattern would look more like this:
([^[]*)(\[[\s\w]+\])
Also, you may find that regular expression matching under Android is too slow to be practical, in which case you'll have to use wasyl's suggestion.
Quite simple, I think... As the text is in brackets, you need to scan every letter. So the basic recipe would be :
in a while loop scan every character (let's say, while i < len(text))
If scanned character is [:
i++;
Add letter at index i to some temporary variable
while (character # i) != ']' append it to the temporary variable
store this temporary variable in a list of results.
Some tips:
If you use solution above, use StringBuilder to append text (as regular string is immutable)
You might also want (and it's better, I think) to store starting and ending positions of all square brackets first, and then use string.substring() on each pair to get the text inside. This way you'd first iterate definition to find brackets (maybe catch unmatched ones, for early error handling), then iterate pairs of indices...
As for links, maybe this will be of use: How can I get clickable hyperlinks in AlertDialog from a string resource?