terminology-maintenance-script.rieks 8.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Purpose: replace %-marked words (including some varieties such as plurals) with %%-syntax for those words.

// This is a script that can be run by the Batch Replacer extension of VSCode .
// Press Ctrl-Shift-P as you are editing this script, then search for `Batch Replacer`, and execute it.

// Executing the script will do the following replacements consecutively:
// 1. `%text with possibly spaces%` --> `%%text with possibly spaces%%`
// 2. `%text-without-spaces` --> `%%text-without-spaces%%` (some punctuation around it is allowed)
// 3. `%%Show Text%%` --> `%%Show Text|Show-Text%%` (sorry, we cannot make the reftext lowercase)
// Now, you have to manually execute /(?<=\|)([A-Z][^%]*)(?=%%)/\L$1/g/
// 4. `|ref-text%% is being checked to see if modifications need to be made (e.g. plurals to singular etc.)
// 5. There is a cleanup phase that removes any %%...|...%% syntax from the docusaurus header, markdown headers, and <img /> constructs.

// Complex regular expressions can be created using variables. Variables are applied to the entire script, and should be defined at the beginning of the script. Variables are defined as ... = "..." and are used as %{...}. Variables can only be used in the replace and replace-regex instructions.
// variables can reference themselves and be overwritten - see documentation of 'batch replacer' extension

beg = "(?<=\W%%)"
mid = "(?<=\|)"
end = "(?=%%\W)"
Rieks Joosten's avatar
Rieks Joosten committed
20
ss = "(?:['’]?s|\(s\))?"
21 22 23 24 25 26 27 28 29 30 31 32

dutyright = "(?:dut(?:y|ies)|rights?)"
dutyright = "%{dutyright}(?:-*(?:/|and|or|and/or)-*%{dutyright})?"
dutyrighttype = "%{dutyright}-types?"

// If you do not specify the files to work on, the replace will be global (throughout the workspace).
// `filter "document.txt"`           - document.txt file in the root folder
// `filter "Documents/document.txt"` - document.txt file in the Documents folder in the root folder
// `filter "**/document.txt"`        - document.txt files anywhere
// `filter "*.txt"`                  - any .txt file in the root folder
// `filter "**/*.txt"`               - any .txt file

33
filter "docs/functional-architecture.md"
34 35 36

// PREPROCESSING: convert single-%-notations into %%-notations.

Rieks Joosten's avatar
Rieks Joosten committed
37 38 39 40
// Convert quotes so that only two types remain: ' an "For starte
replace-regex "[‘’]"
with "'"

41
// We might want to 'undo' %%...|...%% markers in case some 'show text' needs to be associated wiht another 'reftext'
42 43
// replace-regex "(?<=\W)%%([^\|\n\r]+)\|[^%\n\r]+%%(?=\W)"
// with "%$1%"
44 45

// First, convert %show text% into %%show text%%
46
// Test set: none may match: %verif%er, %verif"ier%, "%verifier%", `%verifier%`
Rieks Joosten's avatar
Rieks Joosten committed
47
// Test set: all must match:  %my verifier%, ('%verifiers%'), %verifier's%, %verifier’s%, (%(ver)/ifier%):., %(our) (vfyr)%, %verifier's%. %verifier’s%... single-%party%), '**subject (of a %party%)**' to 
48
// replace-regex "(?<=\s\(?%)(\w|\s|\(|\)|[/-’'"])+(?=%([)":,.!?]*\s|-\w))"
Rieks Joosten's avatar
Rieks Joosten committed
49
replace-regex "(?<=[-\s]\(?'?%)([^%]+)(?=%(([*_):;,.'!?]|\[[^\]]*\]){0,5}\s|-\w))"
50 51 52
with "%$1%"

// Only thereafter can we convert %showtext (words without trailing `%`-char) into %%showtext%%
53
// Test set: none may match: %verif%er, %(our) (verifier)%,
Rieks Joosten's avatar
Rieks Joosten committed
54 55
// Test set: all must match: %verifier %verifiers, '%verifier'), %verifier's, %verifier’s, %verifier:, (%verifiers), %verifier's..... %verifier’s,?.!?  its %principal.[^DC.4] Also a %party)'
replace-regex "(?<=(?:\s\(?'?|/)%)((\w+((/|-|’|')\w)?)+)(?='?\)?[:;,.!?]*(\[[^\]]*\])?\s)"
56 57 58
with "%$1%%"

// Then, we can expand %%show text%% into %%show text|show text%%
59 60
replace-regex "(?<=\W)%%([^\|]*?)%%(?=\W)"
with "%%$1|$1%%"
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

// Next, we convert the latter part into lowercase
replace-regex "(?<=\|)([^A-Z%]*?[A-Z].*?)(?=%%)"
with-case "lowercase"

// Next, we replace whitespace in `lowercase show text` instances with `-` characters
replace-regex "(?<=\|)([^%\|\n\r\s]+)\s+([^%]+)(?=%%)"
with "$1-$2"
replace-regex "(?<=\|)([^%\|\n\r\s]+)\s+([^%]+)(?=%%)"
with "$1-$2"
replace-regex "(?<=\|)([^%\|\n\r\s]+)\s+([^%]+)(?=%%)"
with "$1-$2"
replace-regex "(?<=\|)([^%\|\n\r\s]+)\s+([^%]+)(?=%%)"
with "$1-$2"
replace-regex "(?<=\|)([^%\|\n\r\s]+)\s+([^%]+)(?=%%)"
with "$1-$2"

// ACTUAL PROCESSING: now we need to convert well-known `lowercase-show-text`s to appropriate `reftexts`

// [A]
81
replace-regex "%{mid}(action|actor|agent|assertion|author)%{ss}%{end}"
82 83 84
with "$1"

// [B]
85
replace-regex "%{mid}(business-transaction)%{ss}?%{end}"
86 87 88 89
with "$1"

// [C]
// for 'claim', see 'statement'
90
replace-regex "%{mid}(colleague|concept|credential(-type)?|commitment-decision)%{ss}?%{end}"
91 92
with "$1"

93
replace-regex "%{mid}communications?-(channel|session)%{ss}?%{end}"
94 95 96
with "communication-$1"

// [D]
97
replace-regex "%{mid}(definition|dependent|dictionary-file|dictionary|documentation-interop)%{ss}?%{end}"
98
with "$1"
99
replace-regex "%{mid}\(?(?:electronic|digital)\)?-(actor|agent|colleague|communication-channel|policy)%{ss}%{end}"
100 101 102 103 104 105 106
with "digital-$1"

replace-regex "%{mid}(%{dutyrighttype}|%{dutyright})%{end}"
with "pattern-duties-and-rights"

replace-regex "%{mid}data-(collector|discloser)-polic(y's|ies)%{end}"
with "data-$1-policy"
107
replace-regex "%{mid}data-(collector|discloser)%{ss}?%{end}"
108 109 110
with "data-$1"

// [E]
111
replace-regex "%{mid}(employee|employer)%{ss}%{end}"
112 113 114 115 116
with "$1"
replace-regex "%{mid}(legal-)?entit(y's|ies)%{end}"
with "$1entity"

// [G]
117
replace-regex "%{mid}(glossary-file|guardian(ship)?(-relationship)?(-type)?)%{ss}%{end}"
118 119 120 121 122 123 124 125 126 127 128 129
with "$1"
replace-regex "%{mid}glossar(y's|ies)%{end}"
with "glossary"
replace-regex "%{mid}guardianship(-relationship)?%{end}"
with "guardianship"
replace-regex "%{mid}guardianship(-relationship)?-type%{end}"
with "guardianship-type"
replace-regex "%{mid}govern(or)?s?%{end}"
with "governance"

// [H-I-J-K] (all holder, issuer, verifier and wallet stuff, too)
// for associated policies, see [P]
130
replace-regex "%{mid}(holder|issuer|verifier|wallet|identifier|jurisdiction(-governor)?|knowledge(-governor)?)%{ss}%{end}"
131 132 133
with "$1"

// [L-M]
134
replace-regex "%{mid}(legal-jurisdiction|legal-system|mental-model)%{ss}%{end}"
135 136 137 138
with "$1"
// for 'legal entities', see 'entities'

// [O]
139
replace-regex "%{mid}(objective|organization|owned|owner|ownership)%{ss}%{end}"
140 141 142
with "$1"

// [P]
143
replace-regex "%{mid}(participant|pattern-file|pattern|(peer-)(actor|agent)|policy-governor|presentation-request|presentation|principal)%{ss}%{end}"
144 145 146 147 148 149 150 151
with "$1"
replace-regex "%{mid}(|peer-)part(y's|ies)%{end}"
with "$1party"
replace-regex "%{mid}(|issuer-|holder-|verifier-|wallet-|transaction-data-(collector|discloser)-)polic(y's|ies)%{end}"
with "$1policy"

// [R-S]
// For 'rights', see [D]uties
152
replace-regex "%{mid}(risk|scope-file|scope|ssi-agent)%{ss}%{end}"
153
with "$1"
154
replace-regex "%{mid}(statement|claim|statement%{ss}/claim)%{ss}%{end}"
155 156 157 158
with "assertion"

// [T]
// for transaction data collector/discloers policies, see [P]
159
replace-regex "%{mid}(term-file|term|transaction-(agreement|data-(collector|discloser)|form|proposal))%{ss}%{end}"
160
with "$1"
161
replace-regex "%{mid}transaction%{ss}?%{end}"
162 163 164 165
with "business-transaction"

// [V]
// for verifier stuff - see holder
166
replace-regex "%{mid}(verifiable-credential|verifier)%{ss}%{end}"
167 168 169 170 171 172 173 174 175 176
with "$1"
replace-regex "%{mid}vocabular(y's|ies)%{end}"
with "vocabulary"

// [W]
// for wallet stuff - see holder

// CLEANING UP UNINTENDED CHANGES

// Remove all `%%showtext|reftext%%` in docusaurus header.
Rieks Joosten's avatar
Rieks Joosten committed
177
replace-regex "(^---\s*\nid:(?:[^%]*[\n\r]){0,8})[^%]*%%([^\|]*)\|([^%]*)%%(?:[^%]*[\n\r]){0,8}---"
178
with "$1$2$4"
Rieks Joosten's avatar
Rieks Joosten committed
179
replace-regex "(^---\s*\nid:(?:[^%]*[\n\r]){0,8})[^%]*%%([^\|]*)\|([^%]*)%%(?:[^%]*[\n\r]){0,8}---"
180
with "$1$2$4"
Rieks Joosten's avatar
Rieks Joosten committed
181
replace-regex "(^---\s*\nid:(?:[^%]*[\n\r]){0,8})[^%]*%%([^\|]*)\|([^%]*)%%(?:[^%]*[\n\r]){0,8}---"
182
with "$1$2$4"
Rieks Joosten's avatar
Rieks Joosten committed
183
replace-regex "(^---\s*\nid:(?:[^%]*[\n\r]){0,8})[^%]*%%([^\|]*)\|([^%]*)%%(?:[^%]*[\n\r]){0,8}---"
184
with "$1$2$4"
Rieks Joosten's avatar
Rieks Joosten committed
185
replace-regex "(^---\s*\nid:(?:[^%]*[\n\r]){0,8})[^%]*%%([^\|]*)\|([^%]*)%%(?:[^%]*[\n\r]){0,8}---"
186 187 188 189 190 191 192 193 194 195 196 197 198
with "$1$2$4"

// Remove all `%%showtext|reftext%%` occurrences in markdown headers
replace-regex "(^#+\s+.*?)%%([^\|]*)\|([^%]*)%%(.*$)"
with "$1$2$4"
replace-regex "(^#+\s+.*?)%%([^\|]*)\|([^%]*)%%(.*$)"
with "$1$2$4"

// Remove all `%%showtext|reftext%%` occurrences in `<img />`-constructs
replace-regex "(<img(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*)(?=/>)"
with "$1$2$4"
replace-regex "(<img(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*)(?=/>)"
with "$1$2$4"