Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
TGen 5
</title>
<script type="text/javascript" src="optionmaker.js"></script>
<script type="text/javascript" src="sentencefinder.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">

Expand All @@ -20,10 +21,8 @@
</head>

<body>



<button class="button" style="text-align: center" onclick='begin()'>Start</button>

<button class="button" style="text-align: center" onclick='canUseSentence("As Mr. Trump inches closer to being the party’s presidential nominee, Republicans fear he won’t back the conservative agenda pushed by Mr. Ryan, the House speaker.")'>Start</button>

<div id="stem" class="stem"> &nbsp; </div>

Expand Down
226 changes: 114 additions & 112 deletions optionmaker.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
var theSentence,
//temporary dummy variable so I don't have to keep calling the API
wordsInSentence = [],
/*[{
"position": 0,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 1,
"word": "online",
"onlynoun": false,
"frequency": 4.04
},
{
"position": 2,
"word": "edition",
"onlynoun": true,
"frequency": 3.71
},
{
"position": 3,
"word": "of",
"onlynoun": false,
"frequency": 7.05
},
{
"position": 4,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 5,
"word": "daily",
"onlynoun": false,
"frequency": 4.3
},
{
"position": 6,
"word": "post",
"onlynoun": false,
"frequency": 4.57
},
{
"position": 7,
"word": "is",
"onlynoun": false,
"frequency": 7.03
},
{
"position": 8,
"word": "scheduled",
"onlynoun": false,
"frequency": 3.81
},
{
"position": 9,
"word": "to",
"onlynoun": false,
"frequency": 7.35
},
{
"position": 10,
"word": "launch",
"onlynoun": false,
"frequency": 4.23
},
{
"position": 11,
"word": "before",
"onlynoun": false,
"frequency": 5.86
},
{
"position": 12,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 13,
"word": "end",
"onlynoun": false,
"frequency": 5.5
},
{
"position": 14,
"word": "of",
"onlynoun": false,
"frequency": 7.05
},
{
"position": 15,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 16,
"word": "year",
"onlynoun": true,
"frequency": 5.54
//wordsInSentence = [],
/*[{
"position": 0,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 1,
"word": "online",
"onlynoun": false,
"frequency": 4.04
},
{
"position": 2,
"word": "edition",
"onlynoun": true,
"frequency": 3.71
},
{
"position": 3,
"word": "of",
"onlynoun": false,
"frequency": 7.05
},
{
"position": 4,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 5,
"word": "daily",
"onlynoun": false,
"frequency": 4.3
},
{
"position": 6,
"word": "post",
"onlynoun": false,
"frequency": 4.57
},
{
"position": 7,
"word": "is",
"onlynoun": false,
"frequency": 7.03
},
{
"position": 8,
"word": "scheduled",
"onlynoun": false,
"frequency": 3.81
},
{
"position": 9,
"word": "to",
"onlynoun": false,
"frequency": 7.35
},
{
"position": 10,
"word": "launch",
"onlynoun": false,
"frequency": 4.23
},
{
"position": 11,
"word": "before",
"onlynoun": false,
"frequency": 5.86
},
{
"position": 12,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 13,
"word": "end",
"onlynoun": false,
"frequency": 5.5
},
{
"position": 14,
"word": "of",
"onlynoun": false,
"frequency": 7.05
},
{
"position": 15,
"word": "the",
"onlynoun": false,
"frequency": 7.48
},
{
"position": 16,
"word": "year",
"onlynoun": true,
"frequency": 5.54
}], */

/*dummyData =
Expand Down Expand Up @@ -132,8 +132,6 @@ function begin() {
optionD=undefined;

//Clear DOM
document.getElementById("stem").innerHTML = "&nbsp";

document.getElementById("optionA").innerHTML = "(A)";
document.getElementById("optionB").innerHTML = "(B)";
document.getElementById("optionC").innerHTML = "(C)";
Expand All @@ -153,18 +151,21 @@ function begin() {
formatTheSentence(theSentence);
}

function formatTheSentence(theSentence) {
function formatTheSentence(sentence) {


//console.log("formatTheSentence called\n");

//I need to create a check for bad sentences

var theSentence = theSentence, placeHolder = "", pattern = /[a-z\s]/;
var
theSentence = sentence.toLowerCase().split(""),
placeHolder = "",
newArray = [],
pattern = /[a-z\s]/;

theSentence = theSentence.toLowerCase();

theSentence = theSentence.split("");


//remove punctuation, looping by letter
for(var i = 0; i < theSentence.length; i++) {
Expand All @@ -174,14 +175,14 @@ function formatTheSentence(theSentence) {
}

theSentence = placeHolder;

console.log(theSentence);
//build an array with the values I need for each word {word: frequency: part: position:}

theSentence = theSentence.split(" ");
////console.log(theSentence);
//looping by word
for(var i = 0; i < theSentence.length; i++) {
wordsInSentence.push(
newArray.push(
{"position": i,
"word": theSentence[i],
"onlynoun": true,
Expand All @@ -192,7 +193,8 @@ function formatTheSentence(theSentence) {
}
//if(!badSentenceFlag)

requestDataOnWords(wordsInSentence);
//requestDataOnWords(wordsInSentence);
return newArray;

//skipping the API step to save my quota =)
//assignDataToWord(dummyData, wordsInSentence);
Expand All @@ -214,7 +216,7 @@ function requestDataOnWords(array) {//Currently only retrieving frequency. I sti
type: 'GET', // The HTTP Method, can be GET POST PUT DELETE etc
data: {}, // Additional parameters here
dataType: 'json',
success: function(data) {assignDataToWord(data, array);},
success: function(data) { assignDataToWord(data, array);},
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "ahIVxzexrJmshIjB3DsqKwyiNQUpp1ZgepCjsnXfyo2BHPrC5m"); // Enter here your Mashape key
Expand Down
Loading