kupfer icon indicating copy to clipboard operation
kupfer copied to clipboard

New Idea/Plugin: Identifier Resolver

Open emareg opened this issue 2 years ago • 4 comments

Hi, I have written a new plugin for detecting and resolving over 40 different types of identifiers (e.g. DOIs) using regular expressions. You can simply paste the identifier string as plain text into the Kupfer prompt and it will open a website that shows the content behind it.

What kind of identifiers? Some Examples:

  • DOI: "10.1109/FDL.2018.8524068" → PDF Document
  • EAN/UPC: "04010118474743" → Article / Product Info
  • BitCoin: "3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZc5" → Crypto Transactions
  • Unicode: "U+1F194" → Symbol & Info
  • Location: "8FWH4HX8+QR" → Map showing position
  • ScholarID: "qc6CJjYAAAAJ" → Researcher Profile

For a full list (but not all are included to avoid false alarms), see https://id2.dev

Why do we need this?

  • Fast Lookup: If you want to resolve a DOI or EAN that is text only, you currently first need to search for a web-service that resolves them, navigate on their website to the lookup form and submit the ID as query. This takes time. With Kupfer, it is now just copy&paste+Enter for many of these IDs.
  • Identifier Identification: If you find a long random looking string without context, web-searches might fail but Kupfer now has a chance to tell you what it is.
  • Shorter memos: Instead of copying the full 200 character URL of some Amazon products into your notes, you only need the 10 char ASIN now. Kupfer will jump to the product for you.

How is it implemented?

The dictionary in id2_support.py contains the list of IDs, a RegEx to match them, possible lengths of the ID, and a URL to resolve the ID. When the input of the user exceeds 5 characters, the plugin is activated and first filters the RegEx candidates by input length (e.g. a BitCoin address needs at least 26 chars). Afterwards, each potential RegEx is tested on the input and matches are returned as an Action to open the corresponding URL.

Overall, the plugin is

  • specific and will only offer an action when the input matches the regex of an identifier perfectly.
  • efficient because it will only trigger when the input exceeds 5 chars and filters the regex before running them. On my laptop it takes less than 0.5ms for most inputs and 5ms in the worst case (tested all example IDs).
  • easily extensible: Each supported identifier needs just 6 lines of JSON containing key, regex, length, example, and a URL.

This is useful if the user copy&pastes an ID into kupfer. Right now, 99% of the covered IDs would most likely not match any file, application, or command and leave the user with a failed query. With this plugin, Kupfer will gain even more power and use-cases that further exceed the typical launcher features of just opening files and applications.

emareg avatar Nov 30 '21 15:11 emareg

Hi, Looks better now.

Still - code looks ugly; why don't you use some automatic formatter like black? It can make code more readable without any additional work.I know, other parts of Kupfer are not too pretty, but we don't touch it if we don't have. Also then we don't have that cool tools.

Parsing configuration is bad; if you want reuse some configuration from somewhere you should create lite tool that generate right python code from it. Now we need to much time to understand how it work.

As bluss wrote - we don't want 2 separate files - it's old approach; please create package if you don't want merge this two files.

KarolBedkowski avatar Jan 07 '22 09:01 KarolBedkowski

Hi Karol, thanks for the update.

  • I have moved the files to the submodule "id2" similar to the plugin "virtualbox".
  • Regarding coding style: I manually try to follow PEP8, then I run autopep8 on the code, and now I have also run black (v. 21.12b0) on the code as a final step. Let me know if you still see room for improvement.
  • I have generated the settings code using another python file. Should this generator script also go into the repo? Where?

Also I have not received any answers regarding the the open conversations above. Should I just resolve them? I am quite new to open-source contributions, so am not sure which exact workflow or steps are expected from my side. Do I miss something?

Kind regards Emanuel

emareg avatar Jan 18 '22 17:01 emareg

Hi, Look almost ok. Some comments above.

Some people (I) don't like lines longer than 80 characters in python code, but this is detail.

Additional scripts may by placed in contrib folder.

I don't think, there is one, right workflow for handling pr. "Resolve Conversation" usually mean "I resolve all problems requested in comments". For me - changing this status it's optional.

Regards, Karol

KarolBedkowski avatar Feb 12 '22 18:02 KarolBedkowski

Hi @KarolBedkowski, can you have another look? Thanks

emareg avatar Apr 12 '22 13:04 emareg

Ping @KarolBedkowski

thomas-mc-work avatar Feb 24 '24 18:02 thomas-mc-work

This plugin need update, but still i don't like it. Is hard to understand and maintain. Sorry.

Maybe we can simple call https://id2.dev/ from "search the web" plugin with custom url.

KarolBedkowski avatar Feb 26 '24 19:02 KarolBedkowski