![]() It shows, btw, that the use of constructs such a PWordRec and manual allocation and de-allocation of the 'tokens' are not necessary. In 'WORDS' precludes a direct comparison between the Target stringĪnd Parser.TokenString and necessitates the derivation of Fragment as written. Of course, the OP's requirement that the code should match the 'WORD' Tokenizes the input in the same way Delphi's compiler does. ![]() Largely for my own amusement, I decided to write an answer which Had I not chosen to use a function, but placed all code in one block, I could have iterated over the TList in exactly the same way: for var Match in List do Now, let's use this function: procedure TWordFinderForm.ePhraseChange(Sender: TObject) įor var Match in GetPhraseMatches(mText.Text, ePhrase.Text) do Also notice how easy it is to work with the TList: it's just like a TStringList but with word records instead of strings! Notice that I chose an alternative to the regular expression approach, just for educational reasons. Match.Text := Copy(AText, p, APhrase.Length) Instead, I populate a local TList and then, as a last step, create an array from it: typeįunction GetPhraseMatches(const AText, APhrase: string): TArray By definition, this is simply array of TWordRec, that is, a dynamic array of TWordRecs.īut how to efficiently populate such an array? We all know you shouldn't increase the length of a dynamic array one element at a time besides, that requires a lot of code. I could have this function return or populate a TList, but then it would be tiresome to work with it, because the user of the function would then need to add try.finally blocks every time the function is used. On request, here is how I would do this myself:įirst, I want to create a function that performs this operation, so it can be reused every time we need to do this. When the project's Build Configuration is set to Release then there is no AV. Unfortunately, it has a strange bug: It gets an AV exactly at the THIRD for loop!ĮDIT2: It seems that the AV happens only when the project's Build Configuration is set to Debug. WriteLn(' Press Enter to free the list') Writeln('WordPos: ', WordList.WordPos, ' WordStr: ', WordList.WordStr) MyPhrase := 'A crossword contains words but not WORD' Result := PWordRec(inherited Get(Index)) Property Items: PWordRec read Get default įunction TWordList.Add(Value: PWordRec): Integer įunction TWordList.Get(Index: Integer): PWordRec Of course, writing such a function is trivial, but I wonder if there already is a procedure for this in the existing huge Delphi code treasure.ĮDIT: I am experimenting with a wordlist that should have the required features: program MyTokenize Searching for "tokenize string" in the Delphi documentation did not get any useful results for this purpose. (IntToStr(MyTokens.Pos) + ': ' + MyTokens.String) ![]() MyTokens := MyTokenize(MyPhrase, 'word') To learn more, see the privacy policy.Does Delphi (10.4) have a string-tokenizer that extracts string-token-objects from a string in a similar way as below? MyPhrase := 'I have a simple word and a complex Word: A lot of WORDS.' Special thanks to the contributors of the open-source code that was used in this project: Elastic Search, WordNet, and note that Reverse Dictionary uses third party scripts (such as Google Analytics and advertisements) which use cookies. The definitions are sourced from the famous and open-source WordNet database, so a huge thanks to the many contributors for creating such an awesome free resource. In case you didn't notice, you can click on words in the search results and you'll be presented with the definition of that word (if available). For those interested, I also developed Describing Words which helps you find adjectives and interesting descriptors for things (e.g. So this project, Reverse Dictionary, is meant to go hand-in-hand with Related Words to act as a word-finding and brainstorming toolset. That project is closer to a thesaurus in the sense that it returns synonyms for a word (or short phrase) query, but it also returns many broadly related words that aren't included in thesauri. I made this tool after working on Related Words which is a very similar tool, except it uses a bunch of algorithms and multiple databases to find similar words to a search query. So in a sense, this tool is a "search engine for words", or a sentence to word converter. It acts a lot like a thesaurus except that it allows you to search with a definition, rather than a single word. The engine has indexed several million definitions so far, and at this stage it's starting to give consistently good results (though it may return weird results sometimes). For example, if you type something like "longing for a time in the past", then the engine will return "nostalgia". It simply looks through tonnes of dictionary definitions and grabs the ones that most closely match your search query. The way Reverse Dictionary works is pretty simple.
0 Comments
Leave a Reply. |