Last active
March 10, 2018 05:10
-
-
Save amundo/b35c133ccbf70e92f9f6a88f717829c3 to your computer and use it in GitHub Desktop.
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
let orthographyInput = document.querySelector('#conversion-table') | |
let transcriptionInput = document.querySelector('#tokenize-input') | |
let transcriptionOutput = document.querySelector('#transcription-output') | |
let tokenize = transcription => { | |
return transcription | |
.trim() | |
.normalize("NFD") | |
.split(" ") | |
} | |
escape(pattern) { | |
return pattern.replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&'); | |
} | |
transcriptionInput.addEventListener('keyup', keyupEvent => { | |
let tokens = tokenize(transcriptionInput.value) | |
transcriptionOutput.innerHTML = ''; | |
tokens.forEach(token => { | |
let oldText = token | |
let newText = convert(oldText) | |
document.getElementById("transcription-output").innerHTML += newText + " " | |
}) | |
}) | |
let convert = inString => { | |
let graphemePairList = orthographyInput.value.split("\n").map(graphemePair => { | |
return graphemePair.normalize("NFD").split("\t") | |
}) | |
// for some reason it sorts it without me doing this so I'm just leaving it here commented out | |
let sortedGraphemePairList = graphemePairList.sort((a,b) => { | |
return b[0].length - a[0].length | |
}) | |
graphemePairList.forEach(([before, after]) => { | |
inString = inString.replace(new RegExp(before, 'g'), after) | |
}) | |
return inString | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment