0

I'm looking for a word/sentence annotation tool/plugin to be used INSIDE vim editor. Specifically I'm looking for a cli tool NER (named entity) tagging. Any idea/suggestion/tip?

By example, I would like to select a word or a list of contiguous words (using all vim conveniences) associating them to a a tag/label, say from a menu of tags (read form a config file, TBD).

The tagged text would be coloured with a nice background color and the file would be saved in a desired (configurable format). By example I would tag each NER span with a format like

[entity text span literal](entity_name)

By example, suppose I edit in vim a .txt or .yaml format (input) like this:

Original file (without tagging)

  - intent: body_temperature_data
    examples: |
      - il termometro misura 36.3 gradi
      - 36.9
      - 35.9
      - 35,9
      - la temperatura è di 36 e 7 gradi
      - 36 , 8

Tagged file: desired output file

I want to tag some numbers are entity body_temperature, saving the file (in output) like this:

  - intent: body_temperature_data
    examples: |
      - il termometro misura [36.3](body_temperature) gradi
      - [36.9](body_temperature)
      - [35.9](body_temperature) gradi
      - temperatura: [35,9](body_temperature)
      - la temperatura è di [36 e 7](body_temperature) gradi
      - [36 , 8](body_temperature)

Tagged file: visualization in NORMAL mode

enter image description here

Visually, during editing inside vim, I would like to see tagged words (numbers in the example) visualized with a background color (changing for each (preselected from a menu) label).

Example of visualization with web-based interface:

enter image description here

See visualization examples:

I guess one could realize al this coding a plugin in vimscript.

I have in mind a similar example, the plugin https://github.com/elzr/vim-json to escape double quotes in editing JSON. In that case when you are editing the current line, double quotes are visible, otherwise aren't. In analogy:

  • when in INSERT mode I would like to edit full text LINE
  • whereas, when in NORMAL mode I would like to tag with the above mentioned experience (selecting& tag). By example: the cursor is INSIDE a word or I selected a span pf text in VISUAL mode, afterwad, maybe with a special key, I display a menu with all possible enitiy labels and I chose a label from menu, tagging the text.

BTW, related question: How to replace selected text T with some function(T), using a keyboard shortcut?

Any suggestion is welcome. Thanks

7
  • 1
    Well, you'll probably want to start with :h conceal and :h 'conceallevel'. That's Vim's mechanism for showing/hiding text. Note that you get "show concealed text when cursor is on the same line" behavior for free with this which is not the same as "show concealed text when editing" but perhaps an acceptable substitute.
    – B Layer
    Commented Oct 23, 2021 at 10:39
  • @BLayer there’s an option concealcursor
    – D. Ben Knoble
    Commented Oct 23, 2021 at 11:46
  • I updated the question with a screenshot to better explain desired visualization in normal mode Commented Oct 23, 2021 at 12:42
  • You mention vim-json revealing double quotes when you are editing but it reveals things regardless of mode as long as the cursor is on the line...I just tried it. (The 'concealcursor' setting that DBK mentioned which could produce the "while editing only" behavior for the cursor line is explicitly unset).
    – B Layer
    Commented Oct 23, 2021 at 13:19
  • 1
    I don't see that behavior out of the box so you must have some setting that enables it. Anyways, now it's clear what you're going for.
    – B Layer
    Commented Oct 23, 2021 at 13:30

1 Answer 1

1

I answer myself, just to share a solution I'm working on:

Any comment/improvement here or on the plugin repo is absolutely welcome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.