Commit 2b330c84 authored by priit's avatar priit
Browse files

Morph taggeri teenus & wrapper universaalsemaks

parent 26ce45f6
......@@ -2,15 +2,13 @@ var logger = require('log4js').getLogger('wrapper');
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');
var mime = require('mime');
var path = require('path');
var FileUtil = require('./../src/util/file');
function Tokenizer(){
function InputOutputLocalCommand(){
var self = this;
......@@ -30,65 +28,23 @@ function Tokenizer(){
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 );
}
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 globalStart = 0;
for(i in outputStrings){
var string = outputStrings[i];
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
globalStart = stringStart + stringLength;
var token = {
idx: i,
location: [stringStart, globalStart ]
};
tokens.push(token);
}
if(err) return callback(err);
logger.debug('Program is finished');
if(response.isSuccess){
session.message = Session.messages.OK;
} else {
session.setErrors(response.errors);
}
var mapping = JSON.stringify(tokens);
logger.debug('Failide mappimine on lõpetatud');
session.addOutputFile('output', {
type: 'output',
fileName: config.wrapper.id + '_output.' + FileUtil.getExtension( model.outputPaths.outputPath1 ),
filePath: model.outputPaths.outputPath1,
contentType: mime.lookup(model.outputPaths.outputPath1)
});
SessionService.storeToFile(session.id, mapping, { extension:'txt' }, function (error, mappingPath) {
session.addOutputFile('mapping', {
type: 'mapping',
fileName: config.wrapper.id + '_mapping.' + FileUtil.getExtension( mappingPath ),
filePath: mappingPath,
contentType: mime.lookup(mappingPath)
});
return callback( error, session );
});
session.addOutputFile('output', {
type: 'output',
fileName: config.wrapper.id + '_output.' + FileUtil.getExtension( model.outputPaths.output ),
filePath: model.outputPaths.output,
contentType: mime.lookup(model.outputPaths.output)
});
return callback( err, session );
});
});
});
......@@ -100,7 +56,7 @@ function Tokenizer(){
model.serviceProperties.commandTemplate = config.wrapper.command.commandTemplate;
model.init( session );
model.setKeyValue('data', session.getFile('content'));
model.addOutputPath('outputPath1', {extension: 'txt'});
model.addOutputPath('output', {extension: 'txt'});
model.render(function (err) {
logger.debug('Render callback');
callback(err, model);
......@@ -108,4 +64,4 @@ function Tokenizer(){
}
}
module.exports = Tokenizer;
\ No newline at end of file
module.exports = InputOutputLocalCommand;
\ No newline at end of file
......@@ -139,7 +139,7 @@ var simpleCommandRequest = {
config.availableCommands = {
TOKENIZER : {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/tokenizer/tokenizer.py -i [data] -o [outputPath1]'
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/picoutils/tokenizer.py -i [data] -o [output]'
},
MORFANALYSAATOR : {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfanalyzer.sh [data]'
......@@ -161,6 +161,9 @@ config.availableCommands = {
},
CONCAT : {
commandTemplate: 'cat [data]'
},
MORPH_TAGGER : {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/picoutils/morph_tagger.py -i [data] -o [output]'
}
};
......@@ -246,9 +249,9 @@ config.availableWappers = {
},
TOKENIZER : {
title: 'Sõnestaja',
id: 's6n',
id: 'tok',
port: 3008,
class: 'tokenizer',
class: 'inputOutputLocalCommand',
command: config.availableCommands.TOKENIZER,
requestConf: simpleCommandRequest
},
......@@ -259,6 +262,14 @@ config.availableWappers = {
class: 'simpleLocalCommand',
command: config.availableCommands.CONCAT,
requestConf: simpleCommandRequest
},
MORPH_TAGGER : {
title: 'Lihtne konkateneerija',
id: 'tag',
port: 3010,
class: 'inputOutputLocalCommand',
command: config.availableCommands.MORPH_TAGGER,
requestConf: simpleCommandRequest
}
};
......
Markdown is supported
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