Created
January 24, 2018 00:59
-
-
Save sobopla/c523aed38e98289fc8b1d9c31b25a76e to your computer and use it in GitHub Desktop.
modify verbs and nouns
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 verb_style = ['<span style="color:blue;font-size:420%">', | |
'<span style="color:green;font-size:250%">', | |
'<span style="color:orange;font-size:550%">']; | |
$(document).ready(function(){ | |
$("button").on( 'click', function(){ | |
var original_text = $( "#original_text").val(); | |
var doc = nlp(original_text); | |
var nouns = doc.nouns().out('array'); | |
var verbs = doc.verbs().out('array'); | |
var ignoreVerb = ['was', 'is', 'be', 'are', 'do', 'did', 'does', 'was', 'get', 'got', 'began', 'comes', 'has', 'have', 'had']; | |
var ignoreNoun = ['someone', 'somewhere', 'somebody', 'anyone', 'anywhere', 'everyone', 'everywhere', 'no one', 'nowhere', 'nobody', 'all', 'any', 'more', 'most', 'none', 'some', 'such', 'both', 'few', 'many', 'others', 'another', 'anybody', 'anything', 'each', 'either', 'enough', 'everybody', 'everything', 'little', 'much', 'neither', 'nothing', 'one', 'other', 'something'] | |
console.log(nouns); | |
console.log(verbs); | |
var modified_text = original_text; | |
// Filter out nouns to ignore, same as verbs | |
var highNouns = nouns.filter(function (noun) { | |
return ignoreNoun.indexOf(noun) === -1; | |
}); | |
var noun_index = Math.floor(Math.random()*highNouns.length); | |
console.log(noun_index); | |
var noun = highNouns[noun_index]; | |
console.log(noun); | |
// Modify just the first occurrence of one random noun | |
modified_text = modified_text.replace(noun, '<span style="color:red;font-size:200%">'.concat(noun, "</span>")); | |
//Filter out verbs to ignore | |
verbs.filter(function (verb) { | |
return ignoreVerb.indexOf(verb) === -1; | |
// Modify 30% of the verbs | |
}).forEach(function(verb) { | |
if (Math.random() < 0.3) { | |
var re = new RegExp('\\b'.concat(verb, '\\b')); | |
var chosen_style = verb_style[Math.floor(Math.random()*3)]; | |
modified_text = modified_text.replace(re, chosen_style.concat('$&</span>')); | |
} | |
}); | |
$("#rendered").html(modified_text); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment