Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    HE Chong
    Hi @perelo , currently I have only exposed synonym for replacement. Designing for anonym replacement is a bit awkward (I mean, I can't think of a case where you type in the exact opposite of what you want to say, then search for its anonym to replace it 😅) in text editing so I didn't expose it. But I think an expansion in query's functionality is possible.
    I am busy with graduation ceremony this weekend
    Will take a look and merge your PR before next weekend. Thank you for the new back end you made 😁😁😁
    Eloi Perdereau

    haha you're right about replacing words by their antonyms! Though, I like querying antonyms, so for now, I just made a small hack to do this for my french backends. Implementing it for real would require quite some refactoring imo.

    Moreover, I think your plugin is great but could benefit some improvements. Few things that came in mind right now :

    • fix missing space after last comma of the lists (done it in my fork)
    • use user-defaults of splitbelow and splitright instead of forcing belowright split
    • fix next and previous queries. The split gets on 1 line with a "--- More ---" prompt if I do 'n' then 'p'
    • possibility to 'n' and 'p' to query next and previous backends in query mode and not only replacement mode
    • maybe add buffer-local mapping <C-n> and <C-p> instead of 'n' and 'p' characters in a prompt
    • better algorithm for local thesaurus.txt queries (results are too long, how to truncate?)
    • maybe make a generic backend which searches in &thesaurus vim variable ? we should see how to integrate this with g:tq_language

    Anyhow, congratz! for your graduation :D :D I'm myself in the process of writing my PhD thesis in CS theory, and when motivation goes down, I 'sharpen my (vim) tools' ;)
    So let me know if you're interrested in pull request, and/or talking further!

    HE Chong

    fix next and previous queries. The split gets on 1 line with a "--- More ---" prompt if I do 'n' then 'p'

    Yes, Vim's messaging system is not ideal for frequent user interaction. But currently I don't have much idea on what can be done on it.

    possibility to 'n' and 'p' to query next and previous backends in query mode and not only replacement mode

    The query mode was kind of an after-thought. But what you proposed is a good idea. To achieve this, we should allow the key press on thesaurus buffer to control the tq_framework's query session, and tq_framework.session_terminate() only when user leave the buffer.

    better algorithm for local thesaurus.txt queries (results are too long, how to truncate?)

    A truncate mechanism already exists, actually, you can truncate the result based on two criteria, albeit neither of them ideal:

    " This variable is for replacing candidate display. If value is -1, no
    " truncate of output is made upon number of definitions. Else, if number is n,
    " only synonyms of the first n word definitions were retained.
    if !exists("g:tq_truncation_on_definition_num")
        let g:tq_truncation_on_definition_num = -1
    " This variable is for replacing candidate display. If value is -1, no
    " truncate of output is made upon number of synonyms from a single definition.
    " Else, if number is n, only first n synonyms of that definition will be
    " retained.
    if !exists("g:tq_truncation_on_syno_list_size")
        let g:tq_truncation_on_syno_list_size = -1

    Glad to know that you are wrapping up with your phD as well~ It's always exciting moving from one phase of life into another. Mine was in Physics. Though nowadays I am working on Applied Cryptography in a small Software company. So... although I do enjoy myself these days, the Doctor I got was a wrong kind, I think 😅. Hopefully you'll have a better time finding interesting opportunity in consistent of what you studied.

    I think most of this plugin was created when I was spending most of my time writing. I made it to address my pain point of not being able to efficiently finding appropriate words while writing essays with Vim. As you are also spending most of your time writing nowadays, I believe you already have your assessment on addressing what problem can help you with your productivity the most. If you find some of the items you mentioned above addressing your pain point, please help with the feature development. PR is always welcomed~

    Aaron Hayman

    @perelo Hi! So, I forked the repo and added a new backend for my own use: http://dictionaryapi.com (Merriam-Webster API). Is this something you would be interested in merging back into your repo? Here's the details of what the backend does:

    This is the Merriam-Webster API and as such is a very high-quality back end. However, it does require registration on their website as a developer in order to gain access to the API Keys. They do explicitly state that it is free for non-commercial use up to 1,000 queries a day, which should be sufficient for most needs. Make sure you select the Thesaurus api key, as that is what you will need in order for this backend to work.

    In order to use this backend, add dictionary_api_com to g:tq_enabled_backend and set your api key to g:tq_dictionary_api_key, ex:

    let g:tq_dictionary_api_key='cxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxa'

    This backend cannot work without an API key.

    The DictionaryApi.com backend returns several categories of information in this order:

    • Synonyms: The most relevant synonyms.
    • Related: Words that are no exactly synonyms, but can be considered related to the word in question.
    • Near: Words that are neither synonyms or antonyms, but are near by words.
    • Antonyms: The most relevant antonyms
    • Definitions: Short definitions. You can replace your word with these, but they're mostly there for information purposes.

    Also, if the word cannot be found, the API may sometimes return a list of word suggestions. These will be returned as Unknown word
    and allow you to choose a replacement from the list.

    Aaron Hayman

    Also, the output is a little weird because you don't technically support anything but Synonyms. The output format ends up being something like:

    Found as: Synonyms
    Synonyms: .... word list
    Found as: Related
    Synonyms: ... word list

    I think it would probably look better if the Synonyms: tag said Select List: or Word List: or something like that, but I didn't want to hack the rest of the project to change it.

    Aaron Hayman

    @Ron89 My apologies. Please see my posts above if you have time. I didn't even realize til now that I had originally pinged the wrong person.

    Also, I added a secondary option to the output format to break up synonyms only by the short definition. This may actually be the better default, as I think it aligns with your output format perfectly.

    Aaron Hayman
    Okay, I'm not sure anyone is actually reading these messages, but I updated my fork to handle antonyms. I had to change the core code to do this, but antonyms are now bound to <leader>ca. Back-ends can optionally return antonyms by simply returning them as an additional list (identical to synonyms) in the query result. Those are then use only if <leader>ca (bound to: ThesaurusQueryReplaceCurrentWordAntonym, a new function) is used.
    Also, I noticed that use_cache wasn't actually being used. So I added a very simple caching system (basically a list). It's currently boundless, so I may limit the cache if I run into problems with memory. Honestly, on any moderately recent machine, I kind of doubt this will be a problem. I'll probably add a cache_limit variable, but for now I'm out of capacity. Gotta an actual job to do. :-)
    HE Chong
    Oh, sorry for replying late. Thanks for taking the interests in help improving it. Let me take a look at the code in week ends~
    Aaron Hayman
    No worries, and thanks for taking the time. This has mostly been a way for me to customize your plugin to exactly what I need (high quality synonyms and antonyms) and as that goes it's been wonderful having Merriam-Webster quality thesaurus at my fingertips. I've even been able to use the plugin on my iPad, which has made me giddy. I'd be happy if those changes can help make your project better (and keep the projects from diverging), but either way is fine.
    HE Chong

    @ahayman , hmm, I notice it's rather difficult for me to make comments on the exact location without a PR or sth. I think it is also a good practise to send in PR in order to merge in new feature.

    Could you branch out the existing changes of your code into a dedicated feature branch, then send in PR into my testing branch? We can then communicate in detail from there. After we made all the necessary revision, I can merge in your changes in testing, trying it on my few devices. Then merge into master when it is stable.

    Aaron Hayman
    @Ron89 I agree on using a PR, but I’m not quite ready to submit one yet. I will want to clean up my code first, add some docs, etc.
    I’ll try to do that this week.
    Aaron Hayman
    I would like to know if the approach I’m using for antonyms is reasonable, especially as it regards the other Back Ends. The Merriam-Webster Api returns all data for a single word, allowing me to return antonyms as a separate list along with the synonyms. This allowed me to cache everything at once, but I dont know of the other Apis work the same way. If antonyms require a separate Api call in tge other backends, I need to change the caching logic.
    Also, as a separate issue: Retrieving Antonyms is done using a separate binding. You cannot display both aynonyms and antonyms at the same time. I did this because it was easier, but also because the Merriam Api often returns too much data to display on screen if both antonyms and synonyms are displayed ar once.
    While that seems like a reasonable approach, I want to check with you before I submit a PR.
    HE Chong
    hmm, using a separate binding is good to me. cs was short for change with synonym. ca for changing with antonym is natural. The API key config keyword is a bit to generic. We better anchor this keyword under the scope of MW backend itself.
    I haven't take a look at caching logic yet. Am thinking of doing so when reviewing the PR.
    HE Chong
    Both cs and ca are used for changing the current word. Displaying the full list was made as an after thought. Come to think of it, showing both synonym and antonym really only make sense if you are just displaying the full thesaurus information without any changing goal in mind. So I think eventually if we want to do so, we should just change the behavior of :Thesaurus.
    In current implementation, display is made as a substep of query, making it difficult to implement the change stated above. So, later if we want to do that, we probably need to refactor the code a bit.
    Aaron Hayman
    So the API is literally at https://dictionaryapi.com, which is were I pulled the name from. I waffled on the BE naming, but chose dictionary_api because I thought it would avoid confusion. But you may be right; it does sound a bit generic. I'll look into renaming it merriam_webster.
    Part of my motivation for using ca instead of listing all data was to avoid refactoring. While I've become somewhat familiar with the code, I'm far from being able to accomplish a refactor like that. It sounds like using ca lines up with your approach, though, so I'll leave that alone.
    Aaron Hayman
    My caching logic is very simple. All I do is keep an array of: [ word, synonyms, antonyms ] and search through it on a query. At the very least, I should add a configurable "limit". What I was concerned about was BackEnds that might return either synonyms or antonyms, but not both. In that case, for example, if the user searches for synonyms, the whole cache is updated for that word. Then, if they search for antonyms for that same word, it would return an empty array. Like I said, the caching is simple, but it worked for merriam-webster, and that was my initial use case. I think I'd need to update it for production, though.
    Aaron Hayman
    @Ron89 , I submitted a PR for my changes here: Ron89/thesaurus_query.vim#48
    I would recommend squashing the commits when you merge. It took me way too long to realize I could just edit the plugin repository instead of trying something, committing, and updating the plugin to test.
    I did get the caching logic working, and I renamed the backend to merriam-webster for clarity.