Skip to content

Instantly share code, notes, and snippets.

@amundo
Last active March 10, 2018 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amundo/b35c133ccbf70e92f9f6a88f717829c3 to your computer and use it in GitHub Desktop.
Save amundo/b35c133ccbf70e92f9f6a88f717829c3 to your computer and use it in GitHub Desktop.
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