File size: 11,495 Bytes
9756872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Try It Out - Forward Flow</title>
    <link rel="stylesheet" href="style.css" />
    <style>
      .forward-flow-test {
        text-align: center;
      }
      table {
        margin: 0 auto;
        border-collapse: collapse;
        width: 80%;
      }
      th,
      td {
        border: 1px solid black;
        padding: 8px;
        text-align: center;
      }
      th {
        background-color: #f2f2f2;
      }
      .plot-creativity {
        margin-top: 20px;
        padding: 10px 20px;
        background-color: #333;
        color: white;
        border: none;
        cursor: pointer;
        border-radius: 5px;
      }
      .plot-creativity:hover {
        background-color: #555;
      }
      .graph {
        margin-top: 20px;
        padding: 10px 20px;
        background-color: #333;
        color: white;
        border: none;
        cursor: pointer;
        border-radius: 5px;
      }
      .graph:hover {
        background-color: #555;
      }
      .dropdown {
        margin-top: 20px;
      }
      select {
        padding: 5px;
        font-size: 16px;
      }
      .results {
        margin-top: 20px;
      }
      #image-container {
        margin-top: 20px;
        display: none;
      }
      #image-container img {
        max-width: 30%;
        height: auto;
      }
      .large-input {
        width: 600px; /* Adjust the width as needed */
        height: 10px; /* Adjust the height as needed */
        font-size: 12px; /* Adjust the font size as needed */
        padding: 6px; /* Adjust the padding as needed */
      }
    </style>
  </head>
  <body>
    <header class="header">
      <h1>Forward Flow</h1>
      <nav>
        <ul>
          <li><a href="index.html">Home</a></li>
          <li><a href="page2.html">About Forward Flow</a></li>
          <li><a href="page3.html">Try it out</a></li>
          <li><a href="page4.html">Analyze data</a></li>
          <li><a href="page5.html">Visual Creativity</a></li>
          <li><a href="page6.html">Visual Forward Flow</a></li>
        </ul>
      </nav>
    </header>
    <main class="main">
      <section class="forward-flow-test">
        <h2><strong>What is your forward flow?</strong></h2>
        <p>
          <strong>
            Beginning with the word <span id="starting-word">sleep</span>, in
            each of the following blanks, write the next word that comes to mind
            from the previous word. Please use only single words and no proper
            nouns.
          </strong>
        </p>
        <form id="word-form">
          <p>Starting word: <strong id="starting-word-text">sleep</strong></p>
          <table>
            <tr>
              <th>Word</th>
              <th>Input</th>
            </tr>
            <tr>
              <td>Word 1</td>
              <td>
                <input
                  type="text"
                  name="word1"
                  id="word1"
                  value="sleep"
                  class="large-input"
                  readonly
                />
              </td>
            </tr>
            <tr>
              <td>Word 2</td>
              <td><input type="text" name="word2" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 3</td>
              <td><input type="text" name="word3" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 4</td>
              <td><input type="text" name="word4" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 5</td>
              <td><input type="text" name="word5" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 6</td>
              <td><input type="text" name="word6" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 7</td>
              <td><input type="text" name="word7" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 8</td>
              <td><input type="text" name="word8" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 9</td>
              <td><input type="text" name="word9" class="large-input" /></td>
            </tr>
            <tr>
              <td>Word 10</td>
              <td><input type="text" name="word10" class="large-input" /></td>
            </tr>
          </table>
          <div class="dropdown">
            <label for="word-options">Choose a word list:</label>
            <select id="word-options">
              <option value="sleep">Sleep</option>
              <option value="I am dreaming of ships">
                I am dreaming of ships
              </option>
              <option value="rest">Rest</option>
              <option value="nap">Nap</option>
              <option value="joy">Joy</option>
              <option value="fear">Fear</option>
              <option value="anger">Anger</option>
              <option value="love">Love</option>
              <option value="hope">Hope</option>
              <option value="sadness">Sadness</option>
              <option value="peace">Peace</option>
              <option value="conflict">Conflict</option>
              <option value="freedom">Freedom</option>
              <option value="guilt">Guilt</option>
              <option value="happiness">Happiness</option>
              <option value="trust">Trust</option>
              <option value="grief">Grief</option>
              <option value="surprise">Surprise</option>
              <option value="boredom">Boredom</option>
              <option value="toaster">toaster</option>
              <option value="excitement">Excitement</option>
              <option value="curiosity">Curiosity</option>
            </select>
          </div>
          <button class="plot-creativity" onclick="plotCreativity(event)">
            Plot the Creativity
          </button>
          <br />
          <a href="graph.html">
            <button class="graph" type="button">Graph</button>
          </a>
        </form>

        <div class="results">
          <h3>Similarity Matrix</h3>
          <table id="results-table">
            <thead>
              <tr>
                <th></th>
                <!-- Table headers will be appended here -->
              </tr>
            </thead>
            <tbody>
              <!-- Matrix will be appended here -->
            </tbody>
          </table>
          <h3>Serial Scores</h3>
          <table id="serial-scores-table">
            <thead>
              <tr>
                <th>Word</th>
                <th>Serial Score</th>
                <th>Sentiment</th>
              </tr>
            </thead>
            <tbody>
              <!-- Serial scores will be appended here -->
            </tbody>
          </table>
          <h2>Forward Flow Score</h2>
          <p id="forward-flow-score"></p>
        </div>
      </section>
    </main>
    <footer class="footer">
      <p>Copyright &copy; 2024 Forward Flow</p>
    </footer>

    <script>
      // JavaScript to update the word1 value based on the dropdown selection
      document
        .getElementById("word-options")
        .addEventListener("change", function () {
          const selectedWord = this.value;
          document.getElementById("word1").value = selectedWord;
          document.getElementById("starting-word-text").textContent =
            selectedWord;
        });

      let serialsentencearray = [];

      function plotCreativity(event) {
        event.preventDefault(); // Prevent the form from submitting normally

        // Collect form data
        const form = document.getElementById("word-form");
        const formData = new FormData(form);
        const sentences = Array.from(formData.values());

        // Send data to the backend
        fetch("/similarity", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({ sentences }),
        })
          .then((response) => response.json())
          .then((data) => {
            console.log("Similarity matrix:", data.matrix);
            console.log("Serial score:", data.serial_score);
            console.log("Sentiment:", data.sentiments);

            serialsentencearray = data.serial_score.map((score, index) => {
              return { serial_score: score, sentence: sentences[index] };
            });
            displayMatrix(data.matrix, sentences);
            displaySerialScore(data.serial_score, sentences, data.sentiments);
            displayForwardFlowScore(data.serial_score);

            navigateToGraph(data.serial_score, sentences);
          })
          .catch((error) => console.error("Error:", error));
      }

      function displayMatrix(matrix, sentences) {
        const resultsTable = document.getElementById("results-table");
        const thead = resultsTable.getElementsByTagName("thead")[0];
        const tbody = resultsTable.getElementsByTagName("tbody")[0];

        // Clear previous results
        thead.innerHTML = "<tr><th></th></tr>";
        tbody.innerHTML = "";

        // Append headers
        sentences.forEach((sentence) => {
          const th = document.createElement("th");
          th.textContent = sentence;
          thead.getElementsByTagName("tr")[0].appendChild(th);
        });

        // Append matrix values
        matrix.forEach((row, i) => {
          const tr = document.createElement("tr");
          const rowHeader = document.createElement("th");
          rowHeader.textContent = sentences[i];
          tr.appendChild(rowHeader);

          row.forEach((value) => {
            const td = document.createElement("td");
            td.textContent = value.toFixed(2); // Format score to 2 decimal places
            tr.appendChild(td);
          });

          tbody.appendChild(tr);
        });
      }

      function displaySerialScore(scores, sentences, sentiments) {
        const scoresTable = document.getElementById("serial-scores-table");
        const tbody = scoresTable.getElementsByTagName("tbody")[0];

        tbody.innerHTML = "";

        sentences.forEach((sentence, index) => {
          const tr = document.createElement("tr");

          const wordTd = document.createElement("td");
          wordTd.textContent = sentence;
          tr.appendChild(wordTd);

          const scoreTd = document.createElement("td");
          scoreTd.textContent = scores[index].toFixed(2); // Format score to 2 decimal places
          tr.appendChild(scoreTd);

          const sentimentTd = document.createElement("td");
          sentimentTd.textContent = sentiments[index];
          tr.appendChild(sentimentTd);

          tbody.appendChild(tr);
        });
      }

      function displayForwardFlowScore(scores) {
        const forwardFlowScoreElement =
          document.getElementById("forward-flow-score");

        const total = scores.reduce((sum, score) => sum + score, 0);
        const average = total / 9;

        forwardFlowScoreElement.textContent = average.toFixed(3);
      }

      // Add event listener to the button
      document
        .querySelector(".plot-creativity")
        .addEventListener("click", plotCreativity);
    </script>

    <script src="script.js"></script>
  </body>
</html>