Last active
October 9, 2016 05:29
-
-
Save czinn/b8c840e489b534db8b9ce2127769d148 to your computer and use it in GitHub Desktop.
Script for fixing irregular lujvo place labels in definitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var definitions = require('./definitions.js'); | |
function fixDefinition(def) { | |
if (/;/.test(def)) { | |
// split at ; and recombine | |
return def.split(';').map(fixDefinition).join(';'); | |
} | |
// remove all $ signs | |
def = def.replace(/\$/g, ''); | |
// magic regexes | |
var termMatch = /[A-Za-z]+_?{?(\d+)}?(\s*[=~]\s*[A-Za-z]+_?{?\d+}?)*/g; | |
var xTermMatch = /[Xx]_?{?(\d+)}?(\s*[=~]\s*[A-Za-z]+_?{?\d+}?)*/g; | |
if (xTermMatch.test(def)) { | |
// get the list of matches and see if they're out of order | |
var match; | |
var n = 1; | |
xTermMatch.lastIndex = 0; | |
while ((match = xTermMatch.exec(def)) !== null) { | |
if (match[1] !== '' + n) { | |
// places are out of order | |
// hope that all terms have [a-z]_n in them as first thing with correct n | |
return def.replace(termMatch, 'x$1'); | |
} | |
n += 1; | |
} | |
// places are in order; rely on fixer below to fix stuff | |
} | |
if (!termMatch.test(def)) { | |
return def; // it's probably fine! non-selbri definition | |
} | |
// replace all instances of termMatch with placeholder | |
def = def.replace(termMatch, '~!~'); | |
var x_index = 1; | |
while (/~!~/.test(def)) { | |
def = def.replace(/~!~/, 'x' + x_index); | |
x_index += 1; | |
} | |
return def; | |
} | |
var scaryWords = ['selbengo', 'krefu', 'plikai', 'selbeika\'e', 'xelfanvyxelfanva']; | |
for (var i = 0; i < definitions.length; i++) { | |
var w = definitions[i].w; | |
var oldDef = definitions[i].d; | |
if (/\$/.test(oldDef) && Math.random() < 0.01 || scaryWords.indexOf(w) !== -1) { | |
var newDef = fixDefinition(oldDef); | |
console.log(w); | |
console.log(oldDef); | |
console.log(newDef); | |
console.log(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment