<commit_before>var alpha_report_service = require('../database/alpha_report.js');
var nlp_parser = require('../parsers/nlp_parser.js');

module.exports = function(app, models, io, logger){
	var me = this;

	me.logger = logger;
	me.app = app;
	me.io = io;
	me.models = models;

	nlp_parser.load(logger);
	
	// start the parser
	app.get('/nlp-parser/parse', function(req, res){
		if(logger.DO_LOG){
			logger.info('Request for nlp parser start.');
		}
		
		me.parse_reports(req.query, res);
	});
	
	// post text to get back tuples
	app.post('/nlp-parser/parse/', function(req, res){
		if(logger.DO_LOG){
			logger.info('Request for nlp parser to parse text.');
		}
		
		nlp_parser.parseToTuples(req.body, function(tuples) {
			if (tuples) {
				res.json(tuples);
			}
			res.end();
		});
	});

	// turn text into semanticgraphs
	app.post('/nlp-parser/semanticgraph/', function(req, res){
		if(logger.DO_LOG){
			logger.info('Request for nlp parser to parse text to a semanticgraph.');
		}
		
		nlp_parser.parseToSemanticGraphs(req.body, function(graphs) {
			if (graphs) {
				res.json(graphs);
			}
			res.end();
		});
	});

	me.parse_reports = function(){
		alpha_report_service.readAlphaReports(function(err,docs){
			if(err) {
				logger.info({error: "Error getting all alpha reports "+err});
			} else if(0 !== docs.length) {
				for (var i = 0; i < docs.length; i++){
					nlp_parser.parseAndSave(docs[i]);
				}
			} else {
				logger.info({error: "Not found"});
			}
		});<commit_msg>fixing nlp parser<commit_after>var AlphaReportService = require('../database/alpha_report.js');
var AssertionService = require('../database/assertion.js');
var Nlp_Parser = require('../parsers/nlp_parser.js');

module.exports = function(app, models, io, logger){
	var me = this;

	me.logger = logger;
	me.app = app;
	me.io = io;
	me.models = models;

	var alphaReportService = new AlphaReportService(models, io, logger);

	var services = {assertion: new AssertionService(models, io, logger)};
	var nlp_parser = new Nlp_Parser(services, logger);
	
	// start the parser
	app.get('/nlp-parser/parse', function(req, res){
		if(logger.DO_LOG){
			logger.info('Request for nlp parser start.');
		}
		
		me.parse_reports(req.query, res);
	});
	
	// post text to get back tuples
	app.post('/nlp-parser/parse/', function(req, res){
		if(logger.DO_LOG){
			logger.info('Request for nlp parser to parse text.');
		}
		
		nlp_parser.parseToTuples(req.body, function(tuples) {
			if (tuples) {
				res.json(tuples);
			}
			res.end();
		});
	});

	// turn text into semanticgraphs
	app.post('/nlp-parser/semanticgraph/', function(req, res){
		if(logger.DO_LOG){
			logger.info('Request for nlp parser to parse text to a semanticgraph.');
		}
		
		nlp_parser.parseToSemanticGraphs(req.body, function(graphs) {
			if (graphs) {
				res.json(graphs);
			}
			res.end();
		});
	});

	me.parse_reports = function(){
		alphaReportService.readAlphaReports(function(err,docs){
			if(err) {
				logger.info({error: "Error getting all alpha reports "+err});
			} else if(0 !== docs.length) {
				for (var i = 0; i < docs.length; i++){
					nlp_parser.parseAndSave(docs[i]);
				}
			} else {
				logger.info({error: "Not found"});
			}
		});
{'fraction_non_alphanumeric': 0.1667705735660848, 'fraction_numerical': 0.0012468827930174563, 'mean_word_length': 3.545325779036827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348061', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1130, 'n_words': 242}