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 trainModel(data) { | |
| classifier = new Classifier({ | |
| nGramMin: 1, | |
| nGramMax: 3, | |
| }); | |
| for (let key in data) { | |
| classifier.train(data[key], key); | |
| } | |
| } |
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 predictRange() { | |
| // Get saved data and train it | |
| let processed = this.getTrainData() | |
| this.trainModel(processed) | |
| // Get selected range and data | |
| let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
| let resolved = this.resolveRange(sheet) | |
| let range = sheet.getRange(resolved) |
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 setTrainData(trainData) { | |
| PropertiesService.getScriptProperties().setProperty('trainData', JSON.stringify(trainData)); | |
| } |
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
| // Copy range data for training/prediction later | |
| function captureRange(e) { | |
| var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
| let range = this.resolveRange(sheet) | |
| var data = sheet.getRange(range).getValues(); | |
| let processed = this.processData(data) | |
| this.setTrainData(processed) | |
| Browser.msgBox('Captured training set!') | |
| } |
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
| // Import ml-classify-text | |
| eval(UrlFetchApp.fetch('https://cdn.jsdelivr.net/npm/ml-classify-text@2.0.0/lib/index.js').getContentText()); | |
| let classifier = new Classifier() |
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
| let positive = [ | |
| 'This is great, so cool!', | |
| 'Wow, I love it!', | |
| 'It really is amazing', | |
| ] | |
| let negative = [ | |
| 'This is really bad', | |
| 'I hate it with a passion', | |
| 'Just terrible!', |
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
| const http = require('http'); | |
| const hostname = '127.0.0.1'; | |
| const port = 3000; | |
| const server = http.createServer((req, res) => { | |
| res.statusCode = 200; | |
| res.setHeader('Content-Type', 'text/plain'); | |
| res.end('Hello World'); | |
| }); |
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
| functions: | |
| summarize: | |
| handler: handler.summarize | |
| events: | |
| - http: | |
| path: summarize | |
| method: post |