terminology-maintenance-script.rieks 7.83 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)"
20
ss = "(?:['’]?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 37 38 39 40 41

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

// We might want to 'undo' %%...|...%% markers in case some 'show text' needs to be associated wiht another 'reftext'
// replace-regex "(\W%)%([^\|\n\r]+)\|[^%\n\r]+%(%\W)"
// with "$1$2$3"

// First, convert %show text% into %%show text%%
42 43 44 45
// Test set: none may match: %verif%er, %verif"ier%, "%verifier%", `%verifier%`
// Test set: all must match:  %my verifier%, (%verifiers%), %verifier's%, %verifier’s%, (%(ver)/ifier%):., %(our) (vfyr)%, %verifier's%. %verifier’s%.....
// replace-regex "(?<=\s\(?%)(\w|\s|\(|\)|[/-’'"])+(?=%([)":,.!?]*\s|-\w))"
replace-regex "(?<=\s\(?%)([^%]+)(?=%(([):,.!?]|\[[^\]]*\]){0,2}\s|-\w))"
46 47 48
with "%$1%"

// Only thereafter can we convert %showtext (words without trailing `%`-char) into %%showtext%%
49 50 51
// Test set: none may match: %verif%er, %(our) (verifier)%,
// Test set: all must match: %verifier non-matching-text, %verifiers, %verifier's, %verifier’s, %verifier:, (%verifiers), %verifier's..... %verifier’s,?.!?
replace-regex "(?<=(?:\s\(?|/)%)((\w+((/|-|’|')\w)?)+)(?=(\)?[:,.!?]*\s))"
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
with "%$1%%"

// Then, we can expand %%show text%% into %%show text|show text%%
replace-regex "(?<=\W%%)([^\|]*?)(?=%%\W)"
with "$1|$1"

// 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]
77
replace-regex "%{mid}(action|actor|agent|assertion|author)%{ss}%{end}"
78 79 80
with "$1"

// [B]
81
replace-regex "%{mid}(business-transaction)%{ss}?%{end}"
82 83 84 85
with "$1"

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

89
replace-regex "%{mid}communications?-(channel|session)%{ss}?%{end}"
90 91 92
with "communication-$1"

// [D]
93
replace-regex "%{mid}(definition|dependent|dictionary-file|dictionary|documentation-interop)%{ss}?%{end}"
94
with "$1"
95
replace-regex "%{mid}\(?(?:electronic|digital)\)?-(actor|agent|colleague|communication-channel|policy)%{ss}%{end}"
96 97 98 99 100 101 102
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"
103
replace-regex "%{mid}data-(collector|discloser)%{ss}?%{end}"
104 105 106
with "data-$1"

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

// [G]
113
replace-regex "%{mid}(glossary-file|guardian(ship)?(-relationship)?(-type)?)%{ss}%{end}"
114 115 116 117 118 119 120 121 122 123 124 125
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]
126
replace-regex "%{mid}(holder|issuer|verifier|wallet|identifier|jurisdiction(-governor)?|knowledge(-governor)?)%{ss}%{end}"
127 128 129
with "$1"

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

// [O]
135
replace-regex "%{mid}(objective|organization|owned|owner|ownership)%{ss}%{end}"
136 137 138
with "$1"

// [P]
139
replace-regex "%{mid}(participant|pattern-file|pattern|(peer-)(actor|agent)|policy-governor|presentation-request|presentation|principal)%{ss}%{end}"
140 141 142 143 144 145 146 147
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
148
replace-regex "%{mid}(risk|scope-file|scope|ssi-agent)%{ss}%{end}"
149
with "$1"
150
replace-regex "%{mid}(statement|claim)%{ss}%{end}"
151 152 153 154
with "assertion"

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

// [V]
// for verifier stuff - see holder
162
replace-regex "%{mid}(verifiable-credential|verifier)%{ss}%{end}"
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
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.
replace-regex "(^---\s*\nid:(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*\n---)"
with "$1$2$4"
replace-regex "(^---\s*\nid:(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*\n---)"
with "$1$2$4"
replace-regex "(^---\s*\nid:(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*\n---)"
with "$1$2$4"
replace-regex "(^---\s*\nid:(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*\n---)"
with "$1$2$4"
replace-regex "(^---\s*\nid:(?:.|[\n\r])*?)%%([^\|]*)\|([^%]*)%%((?:.|[\n\r])*\n---)"
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"