Created
January 24, 2015 20:09
-
-
Save atduskgreg/ee311e5dead7c758c0aa 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
function findProperNounPhrase(tags){ | |
console.log("find"); | |
var previousTag = ""; | |
var properNounPhrase = ""; | |
for(var i = 0; i < tags.length; i++){ | |
console.log(tags[i].pos); | |
includedTags = ["NNP", "NNPS", "JJ", "PRP$", "NN"]; | |
if(includedTags.indexOf(tags[i].pos) > -1){ | |
if(includedTags.indexOf(previousTag) > -1){ | |
properNounPhrase += " " + tags[i].word; | |
} else { | |
properNounPhrase = tags[i].word; | |
} | |
} else { | |
if(properNounPhrase.length > 0){ | |
break; | |
} | |
} | |
previousTag = tags[i].pos; | |
} | |
return properNounPhrase; | |
} | |
Tools.fetch("http://www.foxnews.com/politics/index.html", function(data){ | |
page = $(data.responseText); | |
news = []; | |
page.find(".c-latest h3").each(function(i, headline){ | |
headlineText = $(headline).text(); | |
news.push(headlineText); | |
}); | |
Tools.fetch("http://news.discovery.com/animals", function(data2){ | |
page2 = $(data2.responseText); | |
console.log(page2); | |
animals = []; | |
page2.find(".media-title a").each(function(i, animal_headline){ | |
animalText = $(animal_headline).text(); | |
animals.push(animalText); | |
}); | |
var headline1 = news[Math.floor(Math.random() * news.length)]; | |
var headline2 = animals[Math.floor(Math.random() * animals.length)]; | |
var tags1 = Tools.tagPos(headline1); | |
var tags2 = Tools.tagPos(headline2); | |
// find proper noun phrases from the pos tags | |
var pn1 = findProperNounPhrase(tags1); | |
var pn2 = findProperNounPhrase(tags2); | |
// generate two tweets by swapping the proper noun phrases | |
var tweet1 = headline1.replace(pn1, pn2); | |
var tweet2 = headline2.replace(pn2, pn1); | |
Tools.renderTweets([tweet1, tweet2]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment