Created
October 17, 2016 06:26
-
-
Save joelalejandro/b466b4c20c7ceaf22175cb3fd98e5c8b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function getRhymes(word, tweets = this.tweets) { | |
| const rhymingContext = this.settings.rhyming_plugins[this.settings.detournement_context.language]; | |
| let rhymingPackage = require(rhymingContext.package); | |
| if (rhymingContext.requires_new) { | |
| rhymingPackage = new rhymingPackage(); | |
| } | |
| const sanitizedWord = word.replace(/[^a-záéíóúñü]+/gi, ''); | |
| try { | |
| const rhymingRawOutput = rhymingPackage[rhymingContext.input].call(null, sanitizedWord); | |
| let rhymingOutput = {}; | |
| if (rhymingContext.output.type === 'object' && typeof rhymingRawOutput === 'object') { | |
| Object.keys(rhymingContext.output.mapping).forEach((destination) => { | |
| rhymingOutput[destination] = rhymingRawOutput[rhymingContext.output.mapping[destination]]; | |
| }); | |
| } | |
| if (rhymingOutput.rhyme === '') { | |
| console.log('Rhyme not found'); | |
| return []; | |
| } else { | |
| console.log('Rhyme found', rhymingOutput); | |
| let filtered = tweets.filter(tweet => { | |
| return new RegExp(`${rhymingOutput.rhyme}(\.)?$`, 'i').test(this.sanitize(tweet)); | |
| }); | |
| console.log(`Rhyming tweets: ${filtered.length}`); | |
| return filtered; | |
| } | |
| } catch (e) { | |
| console.log('Invalid word: ' + sanitizedWord); | |
| return []; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment