<commit_before>#!/usr/bin/env zsh

lang=$1 ; shift
names=$1 ; shift

function tag_name () {
	md=$1 ; shift
	name=$@
	clear
	git co -- $md
	msg="Tag instances of name '$name' as language '$lang'"
	perl -i -pne "s/(?<!\{)$name(?!\})/\\\\lang$lang{$name}/g if ! /^(\[\^\d+\]|#+ )/" -- $md
	git add -- $md
	git --no-pager diff --cached -U0 --word-diff=color --word-diff-regex=. --minimal --ignore-all-space -- $md |
		grep -v '@@'
	git diff-index --quiet --cached HEAD && continue 1
	read -q "?$msg? (y/n)" || continue 1
	git commit -m "[auto] $msg"
}

for file in $@; do
	perl -e 'print sort { length($b) <=> length($a) } <>' < $names |
		while read name; do
			tag_name $file $name
		done
done<commit_msg>Split names into 3+ letter segments and tag by block<commit_after>#!/usr/bin/env zsh

lang=$1 ; shift
names=$1 ; shift

function tag_name () {
	md=$1 ; shift
	name=$@
	clear
	git co -- $md
	msg="Tag instances of name '$name' as language '$lang'"
	perl -i -pne "s/(?<!\{)$name(?!\})/\\\\lang$lang{$name}/g if ! /^(\[\^\d+\]|#+ )/" -- $md
	git add -- $md
	git --no-pager diff --cached -U0 --word-diff=color --word-diff-regex=. --minimal --ignore-all-space -- $md |
		grep -v '@@'
	git diff-index --quiet --cached HEAD && continue 1
	read -q "?$msg? (y/n)" || continue 1
	git commit -m "[auto] $msg"
}

# First catch instances of whole names
for file in $@; do
	perl -e 'print sort { length($b) <=> length($a) } <>' < $names |
		while read name; do
			tag_name $file $name
		done
done

# Next try permutations of first, last, etc. (within reason)
for file in $@; do
	perl -ne 's/ /\n/g;print if /^.{3,}/' < $names |
		perl -e 'print sort { length($b) <=> length($a) } <>' |
		while read name; do
			tag_name $file $name
		done
done
{'fraction_non_alphanumeric': 0.22241478913922588, 'fraction_numerical': 0.008087810514153668, 'mean_word_length': 2.7982456140350878, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '184027', 'n_tokens_mistral': 719, 'n_tokens_neox': 670, 'n_words': 215}