Commit 1106f1a5 authored by priit's avatar priit
Browse files

todo fix

parent 12c300f1
......@@ -8,6 +8,7 @@
},
"dependencies": {
"JSONStream": "^1.0.4",
"async": "^1.4.0",
"body-parser": "~1.12.4",
"debug": "~2.2.0",
"express": "~4.12.4",
......
......@@ -13,20 +13,23 @@ dataX = dataX + dataX + dataX +dataX +dataX +dataX +dataX + dataX + dataX + data
var encoding = 'utf-8';
var i = 0;
function loop(){
function loop(cb){
i++;
if(i % 100000 == 0){
console.log(i);
}
if(i < 2300000){
writer.write(dataX, encoding, function () {
loop();
loop(cb);
});
} else {
parse();
cb();
}
}
loop();
loop( function(){ parse(); } );
function parse(){
......
......@@ -3,7 +3,7 @@ var config = require('./../config');
var localExecutor = require('./../src/service/executor/localExecutor');
var Session = require('../src/model/session');
var SessionService = require('./../src/service/sessionService');
var async = require('async');
var CommandModel = require('../src/mapper/commandModel');
var fs = require('fs');
......@@ -13,58 +13,61 @@ function ContentTokenizer(){
this.process = function ( session, callback) {
var contentFile = session.requestFiles.content;
var sourceText = fs.readFileSync(contentFile).toString(); //todo: peaks olema async
self.getCommandModel(session, function (err, model) {
logger.debug('getCommandModel callback');
if(err) return callback(err);
fs.readFile(contentFile, 'utf-8', function (err, sourceText) {
self.getCommandModel(session, function (err, model) {
logger.debug('getCommandModel callback');
if(err) return callback(err);
localExecutor.execute( model, function ( err, response ) {
localExecutor.execute( model, function ( err, response ) {
if(err){
session.setErrors(err);
return callback( err, session );
}
if(!response.isSuccess){
session.setErrors(response.errors);
return callback( err, session );
}
if(err){
session.setErrors(err);
return callback( err, session );
}
if(!response.isSuccess){
session.setErrors(response.errors);
return callback( err, session );
}
fs.readFile(model.outputPaths.outputPath1, function (err, output) {
if(err) return callback(err);
fs.readFile(model.outputPaths.outputPath1, function (err, output) {
if(err) return callback(err);
var wrapperOutput = output.toString();
var outputStrings = wrapperOutput.split("\n");
var tokens = [];
var wrapperOutput = output.toString();
var outputStrings = wrapperOutput.split("\n");
var tokens = [];
var globalStart = 0;
var globalStart = 0;
for(i in outputStrings){
var string = outputStrings[i];
for(i in outputStrings){
var string = outputStrings[i];
var start = sourceText.indexOf(string);
var stringStart = globalStart + start;
var stringLength = string.length;
var start = sourceText.indexOf(string);
var stringStart = globalStart + start;
var stringLength = string.length;
sourceText = sourceText.slice(start + stringLength); //eemaldan lähteteksti alguse, et korduvad sõnad ei jääks sama asukohaga
sourceText = sourceText.slice(start + stringLength); //eemaldan lähteteksti alguse, et korduvad sõnad ei jääks sama asukohaga
globalStart = stringStart + stringLength;
globalStart = stringStart + stringLength;
var token = {
idx: i,
location: [stringStart, globalStart ]
};
tokens.push(token);
}
var token = {
idx: i,
location: [stringStart, globalStart ]
};
tokens.push(token);
}
session.message = Session.messages.OK;
session.message = Session.messages.OK;
var mapping = JSON.stringify(tokens);
logger.debug('Failide mappimine on lõpetatud');
SessionService.storeToFile(session.id, mapping, function (error, mappingPath) {
session.addOutputFile('output', model.outputPaths.outputPath1);
session.addOutputFile('mapping', mappingPath);
return callback( error, session );
});
var mapping = JSON.stringify(tokens);
logger.debug('Failide mappimine on lõpetatud');
SessionService.storeToFile(session.id, mapping, function (error, mappingPath) {
session.addOutputFile('output', model.outputPaths.outputPath1);
session.addOutputFile('mapping', mappingPath);
return callback( error, session );
});
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment