mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-12 02:28:37 +02:00
tried to code a syllabe counter into neovim
This commit is contained in:
@@ -183,11 +183,11 @@ If you **don’t have the physical macropad**, the table below shows which keybi
|
|||||||
| `§` | Cheatsheet |
|
| `§` | Cheatsheet |
|
||||||
| `<leader>1` | Open fold |
|
| `<leader>1` | Open fold |
|
||||||
| `<leader>2` | Close fold |
|
| `<leader>2` | Close fold |
|
||||||
| `<leader>e1` | Previous error |
|
| `<leader>e4` | Previous error |
|
||||||
| `<leader>e2` | Next error |
|
| `<leader>e5` | Next error |
|
||||||
| `<leader>e3` | See error message |
|
| `<leader>e1` | See error message |
|
||||||
| `<leader>e4` | See list of errors |
|
| `<leader>e3` | See list of errors |
|
||||||
| `<leader>e5` | Show correction |
|
| `<leader>e2` | Show correction |
|
||||||
| `<leader>e<Tab>` | Stop grammar LSP |
|
| `<leader>e<Tab>` | Stop grammar LSP |
|
||||||
| `<leader>f1` | Telescope files |
|
| `<leader>f1` | Telescope files |
|
||||||
| `<leader>f2` | Telescope grep |
|
| `<leader>f2` | Telescope grep |
|
||||||
@@ -199,6 +199,8 @@ If you **don’t have the physical macropad**, the table below shows which keybi
|
|||||||
| `<leader>g4` | Go to implementation |
|
| `<leader>g4` | Go to implementation |
|
||||||
| `<leader>g5` | Show references |
|
| `<leader>g5` | Show references |
|
||||||
| `<leader><leader>` | Launch runner (terminal) |
|
| `<leader><leader>` | Launch runner (terminal) |
|
||||||
|
| `<leader>r1` | Run fugit |
|
||||||
|
| `t` | Count syllabes (french) |
|
||||||
|
|
||||||
All moving macros with `<Space>`, `g`, and the recording with `q` are disabled.
|
All moving macros with `<Space>`, `g`, and the recording with `q` are disabled.
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
(pkgs.callPackage ../../modules/scripts/manix.nix {})
|
(pkgs.callPackage ../../modules/scripts/manix.nix {})
|
||||||
(pkgs.callPackage ../../modules/scripts/man.nix {})
|
(pkgs.callPackage ../../modules/scripts/man.nix {})
|
||||||
(pkgs.callPackage ../../modules/scripts/trimmer.nix {})
|
(pkgs.callPackage ../../modules/scripts/trimmer.nix {})
|
||||||
|
(pkgs.callPackage ../../modules/scripts/syllabes.nix {}) # python script to get number of syllabes in french
|
||||||
(pkgs.callPackage ../../hostsModules/laptop/qt/qtbatticon.nix {})
|
(pkgs.callPackage ../../hostsModules/laptop/qt/qtbatticon.nix {})
|
||||||
#pkgs
|
#pkgs
|
||||||
pkgs.gruvbox-gtk-theme
|
pkgs.gruvbox-gtk-theme
|
||||||
|
|||||||
@@ -249,11 +249,11 @@
|
|||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||||
|
|
||||||
-- Diagnostics
|
-- Diagnostics
|
||||||
vim.keymap.set("n", "<leader>e1", function() vim.diagnostic.jump({ prev=true, count = 1 }) end, { desc = "Previous diagnostic" })
|
vim.keymap.set("n", "<leader>e4", function() vim.diagnostic.jump({ prev=true, count = 1 }) end, { desc = "Previous diagnostic" })
|
||||||
vim.keymap.set("n", "<leader>e2", function() vim.diagnostic.jump({ prev=false, count = 1 }) end, { desc = "Next diagnostic" })
|
vim.keymap.set("n", "<leader>e5", function() vim.diagnostic.jump({ prev=false, count = 1 }) end, { desc = "Next diagnostic" })
|
||||||
vim.keymap.set("n", "<leader>e3", vim.diagnostic.open_float, { desc = "Show diagnostic" })
|
vim.keymap.set("n", "<leader>e1", vim.diagnostic.open_float, { desc = "Show diagnostic" })
|
||||||
vim.keymap.set("n", "<leader>e4", vim.diagnostic.setloclist, { desc = "Diagnostic list" })
|
vim.keymap.set("n", "<leader>e3", vim.diagnostic.setloclist, { desc = "Diagnostic list" })
|
||||||
vim.keymap.set("n", "<leader>e5", vim.lsp.buf.code_action, { desc = "Show correction" })
|
vim.keymap.set("n", "<leader>e2", vim.lsp.buf.code_action, { desc = "Show correction" })
|
||||||
|
|
||||||
vim.keymap.set("n", "<leader>e<Tab>", function()
|
vim.keymap.set("n", "<leader>e<Tab>", function()
|
||||||
local clients = vim.lsp.get_clients({ name = "ltex" })
|
local clients = vim.lsp.get_clients({ name = "ltex" })
|
||||||
@@ -364,7 +364,8 @@
|
|||||||
"maldoror",
|
"maldoror",
|
||||||
"evariste",
|
"evariste",
|
||||||
"galois",
|
"galois",
|
||||||
"arno"
|
"arno",
|
||||||
|
"dessacrer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -480,6 +481,13 @@
|
|||||||
--==================
|
--==================
|
||||||
vim.keymap.set('n', '<leader>r1', '<cmd>Fugit2<CR>', { desc = 'Open git helper' })
|
vim.keymap.set('n', '<leader>r1', '<cmd>Fugit2<CR>', { desc = 'Open git helper' })
|
||||||
|
|
||||||
|
vim.keymap.set("n", "t", function()
|
||||||
|
local line = vim.api.nvim_get_current_line()
|
||||||
|
|
||||||
|
local result = vim.fn.system({ "custom-syllabes" }, line)
|
||||||
|
|
||||||
|
print(vim.trim(result))
|
||||||
|
end, { desc = "Count syllables (current line)" })
|
||||||
-- =========================
|
-- =========================
|
||||||
-- telescope
|
-- telescope
|
||||||
-- =======================
|
-- =======================
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
/* old version
|
||||||
|
{ pkgs, python3Packages, ... }:
|
||||||
|
|
||||||
|
pkgs.writers.writePython3Bin "custom-syllabes" {
|
||||||
|
libraries = [
|
||||||
|
python3Packages.pyphen
|
||||||
|
];
|
||||||
|
} ''
|
||||||
|
import sys
|
||||||
|
import pyphen
|
||||||
|
|
||||||
|
dic = pyphen.Pyphen(lang="fr")
|
||||||
|
|
||||||
|
text = sys.stdin.read().strip()
|
||||||
|
|
||||||
|
chunks = []
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
for w in text.split():
|
||||||
|
hyphenated = dic.inserted(w)
|
||||||
|
parts = hyphenated.split("-")
|
||||||
|
chunks.append("/".join(parts))
|
||||||
|
total += len(parts)
|
||||||
|
|
||||||
|
print(f"{total} ({'/'.join(chunks)})")
|
||||||
|
''*/
|
||||||
|
/* used IPA but had a deprecated dependency
|
||||||
|
{ pkgs, python3Packages, ... }:
|
||||||
|
|
||||||
|
pkgs.writers.writePython3Bin "custom-syllabes" {
|
||||||
|
libraries = [
|
||||||
|
python3Packages.epitran
|
||||||
|
python3Packages.setuptools
|
||||||
|
];
|
||||||
|
} ''
|
||||||
|
import sys
|
||||||
|
import epitran
|
||||||
|
import re
|
||||||
|
|
||||||
|
epi = epitran.Epitran("fra-Latn")
|
||||||
|
|
||||||
|
|
||||||
|
def count_syllables_ipa(ipa):
|
||||||
|
return len(re.findall(r"[aeiouyɑɛœɔ̃ɑ̃ɛ̃œ̃]", ipa))
|
||||||
|
|
||||||
|
|
||||||
|
text = sys.stdin.read().strip()
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
chunks = []
|
||||||
|
|
||||||
|
for word in text.split():
|
||||||
|
ipa = epi.transliterate(word)
|
||||||
|
syllables = count_syllables_ipa(ipa)
|
||||||
|
|
||||||
|
total += syllables
|
||||||
|
chunks.append(f"{word}/{ipa}")
|
||||||
|
|
||||||
|
print(f"{total} ({' | '.join(chunks)})")
|
||||||
|
''*/
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
lexique = pkgs.fetchurl {
|
||||||
|
url = "http://www.lexique.org/databases/Lexique383/Lexique383.tsv";
|
||||||
|
sha256 = "sha256-Y3ujenZ6ZmecSDcdZz7OUMv1QbSaTkDlmJY9Tz+85Ss=";
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
pkgs.writers.writePython3Bin "custom-syllabes" {
|
||||||
|
libraries = [ pkgs.python3Packages.pandas ];
|
||||||
|
} ''
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import pandas as pd
|
||||||
|
import re
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# Load Lexique383
|
||||||
|
# ----------------------------
|
||||||
|
LEX_PATH = os.environ.get(
|
||||||
|
"LEXIQUE_PATH",
|
||||||
|
"${lexique}"
|
||||||
|
)
|
||||||
|
|
||||||
|
df = pd.read_csv(LEX_PATH, sep="\t", low_memory=False)
|
||||||
|
|
||||||
|
lex = dict(zip(df["ortho"].str.lower(), df["phon"]))
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# phoneme-based syllabification
|
||||||
|
# ----------------------------
|
||||||
|
|
||||||
|
VOWELS = set([
|
||||||
|
"a", "e", "ɛ", "ə", "i", "o", "ɔ", "u", "y",
|
||||||
|
"ɑ̃", "ɛ̃", "ɔ̃", "œ̃"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def is_vowel(ph):
|
||||||
|
return any(v in ph for v in VOWELS)
|
||||||
|
|
||||||
|
|
||||||
|
def syllabify_phonemes(phonemes):
|
||||||
|
syllables = []
|
||||||
|
cur = ""
|
||||||
|
|
||||||
|
for p in phonemes:
|
||||||
|
cur += p
|
||||||
|
|
||||||
|
if is_vowel(p):
|
||||||
|
syllables.append(cur)
|
||||||
|
cur = ""
|
||||||
|
|
||||||
|
if cur and syllables:
|
||||||
|
syllables[-1] += cur
|
||||||
|
elif cur:
|
||||||
|
syllables.append(cur)
|
||||||
|
|
||||||
|
return syllables
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# poetic adjustment (basic)
|
||||||
|
# ----------------------------
|
||||||
|
|
||||||
|
def apply_rules(word, phon, syllables):
|
||||||
|
# e muet at end (very rough heuristic)
|
||||||
|
if phon.endswith("ə") or phon.endswith("e"):
|
||||||
|
if len(syllables) > 1:
|
||||||
|
syllables = syllables[:-1]
|
||||||
|
return syllables
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# main counter
|
||||||
|
# ----------------------------
|
||||||
|
|
||||||
|
def count_word(word):
|
||||||
|
w = re.sub(r"[^a-zàâçéèêëîïôûùœæ']", "", word.lower())
|
||||||
|
if not w:
|
||||||
|
return 0, []
|
||||||
|
|
||||||
|
phon = lex.get(w)
|
||||||
|
if not phon:
|
||||||
|
# fallback heuristic
|
||||||
|
syls = re.findall(r"[aeiouyàâéèêëîïôûùœæ]+", w)
|
||||||
|
return len(syls), syls
|
||||||
|
|
||||||
|
phonemes = phon.split()
|
||||||
|
syls = syllabify_phonemes(phonemes)
|
||||||
|
syls = apply_rules(w, phon, syls)
|
||||||
|
|
||||||
|
return len(syls), syls
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
text = sys.stdin.read().strip()
|
||||||
|
total = 0
|
||||||
|
out = []
|
||||||
|
|
||||||
|
for w in text.split():
|
||||||
|
c, syls = count_word(w)
|
||||||
|
total += c
|
||||||
|
if syls:
|
||||||
|
out.append("/".join(syls))
|
||||||
|
|
||||||
|
print(f"{total} ({' '.join(out)})")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
''
|
||||||
Reference in New Issue
Block a user