Power Law for Shakespeare Play
by dandiebolt
HTML
<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<script id="template" type="text/x-jquery-tmpl">
<ul>
<li>${content}</li>
</ul>
<hr/>
</script>
<ul id="info"></ul>
JavaScript
var url="http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20%0AFROM%20html%20%0AWHERE%20url%3D%22http%3A%2F%2Fshakespeare.mit.edu%2Fallswell%2Ffull.html%22%20AND%0A%20%20%20%20%20%20xpath%3D%22%2F%2Fa%5Bstarts-with(%40name%2C'1')%20or%20starts-with(%40name%2C'2')%20or%20starts-with(%40name%2C'3')%20or%20starts-with(%40name%2C'4')%20or%20starts-with(%40name%2C'5')%20or%20starts-with(%40name%2C'6')%20or%20starts-with(%40name%2C'7')%20or%20starts-with(%40name%2C'8')%20or%20starts-with(%40name%2C'9')%5D%22&format=json&diagnostics=true&callback=?";
var words=[];
var allwords={};
$.ajax({
url: url,
dataType: 'json',
success: function(data) {
//console.log(data);
$.each(data.query.results.a,function(index1,val1){
//console.log(val1);
words=(val1.content).replace(/[&.:!'"?,;]/g,"").toLowerCase().split(" ");
$.each(words,function(index2,val2){
allwords[val2] = (allwords[val2] || 0) +1;
});
});
//$("#template").tmpl(data.query.results.a).appendTo("#info");
}
});
console.log("allwords",allwords);
/*
for (var word in allwords) {
$("#info").append("<li>" + word + " " + allwords[word] + "</li>");
}
*/
/*
SELECT *
FROM html
WHERE url="http://shakespeare.mit.edu/allswell/full.html" AND
xpath="//a[starts-with(@name,'1') or starts-with(@name,'2') or starts-with(@name,'3') or starts-with(@name,'4') or starts-with(@name,'5') or starts-with(@name,'6') or starts-with(@name,'7') or starts-with(@name,'8') or starts-with(@name,'9')]"
*/