Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// search builds at McGill.
var jsonfile = require('jsonfile');
var lunr = require('lunr');
var request = require('request');
var path = require('path');
var utils = require('../../utils.js');
var chat_builders = require('../../chat_utils.js').builders;
var building_index = lunr.Index.load(jsonfile.readFileSync(path.resolve('./plugins/building_search', 'building_index.json')));
// var building_index = lunr.Index.load(jsonfile.readFileSync(path.resolve('./', 'building_index.json')));
var buildings = require('./BUILDINGS.js').BUILDINGS;
var natural = require('natural')
natural.LancasterStemmer.attach();
function building_search(context){
if(context.completed){
return context;
}
var query = context.location_search ? context.location_search : context.current_query;
if(context.postback){
// we have receieved a deep link from somewhere else.
if(context.postback.substr(0,6) === 'where@'){
query = context.postback.split('where@')[1];
context.completed = true;
}
}
return new Promise((resolve, reject) => {
const tokens = tokenizer.tokenize(phrase);
tokens.map(token => {
console.log(token, Natural.PorterStemmer.stem(token))
});
Natural.LancasterStemmer.attach();
console.log(phrase.tokenizeAndStem());
resolve({
engine: 'compromise',
ms: (new Date() - time),
tokens: tokenizer.tokenize(phrase),
stemmers: Natural.PorterStemmer.stem(phrase)
// glossary: glossary.parse(phrase),
// sentiment: analyser.classify(phrase),
});
});
};
var natural = require('natural')
var csv = require('fast-csv')
var fs = require('fs')
var path = require('path')
var jsonfile = require('jsonfile')
natural.LancasterStemmer.attach();
var query_classify = new natural.BayesClassifier();
var both_streams_ended = false;
var NGrams = natural.NGrams;
console.log('Non-queries');
var stream = fs.createReadStream(path.resolve('./plugins/training', 'conv_bot_db_augmented.csv'))
.pipe(csv.parse())
.on('readable', function(){
var row;
while(null !== (row = stream.read())){
// console.log('unstemmed:',row);
// console.log('stemmed:',)
// console.log('->added document:',row[0])
var bgrams1 = NGrams.ngrams(row[0].toLowerCase(), 2, null, '[end]')
var search = require('./search.js');
var COURSE_REGEX = /[a-z]{4}[0-9]{3}/gi;
var natural = require('natural')
var jsonfile = require('jsonfile')
var fs = require('fs');
var WORDS = require('../WORDS.js').WORDS;
natural.LancasterStemmer.attach();
var NGrams = natural.NGrams;
var path = require('path');
var COURSE_REGEX = /[a-z]{4}[0-9]{3}/gi;
// useful functions
Array.prototype.unique = function(){
// from underscore.js
var u = {}, a = [];
for(var i = 0, l = this.length; i < l; ++i){
if(u.hasOwnProperty(this[i])) {
continue;
}
a.push(this[i]);
// search printers at McGill.
var jsonfile = require('jsonfile');
var lunr = require('lunr');
var request = require('request');
var path = require('path');
var utils = require('../../utils.js');
var chat_builders = require('../../chat_utils.js').builders;
var natural = require('natural')
natural.LancasterStemmer.attach();
var printer_regex = /([u]?print[a-z]*)/gi;
var uprint_index = lunr.Index.load(jsonfile.readFileSync(path.resolve('./plugins/uprintlocator', 'uprint_index.json')));
// var uprint_index = lunr.Index.load(jsonfile.readFileSync(path.resolve('./', 'uprint_index.json')));
// var building_index = lunr.Index.load(jsonfile.readFileSync(path.resolve('../building_search', 'building_index.json')));
var building_index = lunr.Index.load(jsonfile.readFileSync(path.resolve('./plugins/building_search', 'building_index.json')));
var buildings = require('../building_search/BUILDINGS.js').BUILDINGS;
var uprints = jsonfile.readFileSync(path.resolve('./plugins/uprintlocator', 'uprints_json.json')).uprints
function is_uprint_query(query){
var matches = query.match(printer_regex);
return matches && matches.length > 0;
}
var natural = require('natural')
// var WORDS = require('../WORDS.js').WORDS;
var utils = require('../../utils.js');
var chat_builders = require('../../chat_utils.js').builders;
natural.LancasterStemmer.attach();
var NGrams = natural.NGrams;
var WORDS = require('../WORDS.js').WORDS
function help_me(context){
// checks if user input contains a greeting
if(context.postback){
// we have receieved a deep link from somewhere else.
if(context.postback.substr(0,7) === 'help@'){
set_user_needs_help(context)
return context
}
}
var tokenized_input = context.current_query.tokenizeAndStem();
for (var i = 0; i < tokenized_input.length; i++) {
var natural = require('natural')
var WORDS = require('../WORDS.js').WORDS;
var utils = require('../../utils.js');
var chat_builders = require('../../chat_utils.js').builders;
natural.LancasterStemmer.attach();
var NGrams = natural.NGrams;
function contains_hello(context){
// checks if user input contains a greeting
// first do some basic cleaning
context.current_query = context.current_query.toLowerCase().replace(/(show|see|display|view|tell)[^\s]*/g, '');
var tokenized_input = context.current_query.tokenizeAndStem();
if(tokenized_input[0] === 'cours' && tokenized_input.length === 1){
// person looked for something like 'all courses' or 'show courses' or 'see courses'
context.replies.push(
utils.arrays.random_choice(
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var natural = require('natural'),
stemmer = natural.LancasterStemmer;
console.log(stemmer.stem('stemming'));
this.apply( function( text ) {
if ( type === 'Lancaster' ) {
return natural.LancasterStemmer.stem( text );
} else {
return natural.PorterStemmer.stem( text );
}
});
return this;
self.documents = self.documents.map( function( doc ) {
if ( type === "Lancaster" ) {
return natural.LancasterStemmer.stem( doc );
} else {
return natural.PorterStemmer.stem( doc );
}
});
return self;