reddit / emacs

Syntax highlighting for natural languages?

cerka · 2022-10-10 03:52
For example, highlight nouns, verbs, adjectives in specific colors. Has anyone attempted to do this in Emacs? It seems that the way that Emacs can (eventually) use an AST built by tree-sitter to do syntax highlighting on program code should be applicable to natural languages using NLP libraries that build syntax trees. Here is a non-Emacs example: https://english.edward.io/
lebensterben · 2022-10-10 03:54
what's the use of it...
Shirugentoo · 2022-10-10 05:36
Applied linguistics research/ teaching
danderzei · 2022-10-10 05:45
[Writegood mode](https://github.com/bnbeckwith/writegood-mode) highlights passive voice. That could be starting point. This application would need a dictionary that defines all nouns, verbs and adjectives. Or is there an algorithm to detect word type?
nakuaga · 2022-10-10 06:49
I think that in this case it must be an algorithm that determines the function of a word based on its place and sentence structure. Otherwise you would have to implement the entire English dictionary (to start), and still you would have to create an algorithm to identify the function of those words that have multiple meanings.
danderzei · 2022-10-10 08:00
Is it open source?
NoisyFrequency · 2022-10-10 10:57
I haven't seen anything like that unfortunately. It's a much much more difficult than programming languages highlighting as well.
WallyMetropolis · 2022-10-10 13:48
This is a cutting-edge research level project in the field of NLP.
nakuaga · 2022-10-10 13:50
I know, some time ago I was interested in the subject while dealing
jakub1842 · 2022-10-10 16:06
Langtool is not exactly what you ask for, but maybe it can be hacked to do what you need: https://melpa.org/#/langtool
AngryFilament · 2022-10-10 16:28
As a [comment](https://www.reddit.com/r/emacs/comments/y04qik/syntax_highlighting_for_natural_languages/irrdxsi/) says, to do this correctly sounds like a cutting-edge NLP project. To approach it in the same way as tree-sitter (i.e. using a dictionary to build an AST) doesn't provide much value as it is very likely to be wrong in critical sections - the bits that would confuse a human reader. There is also no easy way for a dictionary approach to figure out where it could be wrong which makes the syntax highlighting even less effective as there's no way to show 'this word is *definitely* a noun/verb/whatever' much less 'this word is part of a phrase that is interpreted as a noun here' - which is something that is incredibly common in language.
cerka · 2022-10-10 18:18
The same as for program code: to visualize the structure of the text. A few use cases: - Highlight nouns or noun phrases so that I can see more quickly what each paragraph is about. - Highlight adverbs because I tend to use them as weasel words. ("Basically," "in fact," "really," "just," etc.) If there's an NLP library already pulled in, then other features could be: - Search for Org files or do `M-x occur` within a buffer for a word and its synonyms. - Find grammatically complex sentences and suggest ways to rewrite them.
lebensterben · 2022-10-10 18:30
sounds like you need grammarly
cerka · 2022-10-10 18:43
Do you mean something like [lsp-grammarly](https://github.com/emacs-grammarly/lsp-grammarly)?
lebensterben · 2022-10-10 18:58
yep