Skip to content
Snippets Groups Projects
Commit 17188750 authored by mateuszg's avatar mateuszg
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
; PLIK KONFIGURACYJNY WORKERA
; Plik zawiera konfigurację zarówno Api usługi sieciowej jak i narzędzia.
;
; Autor: Tomasz Walkowiak
; email: tomasz.walkowiak@pwr.edu.pl
; --------- CZĘŚĆ DLA Serwisu ---------
[service]
#root = /mnt2/requests/
root = /samba/requests/
tool = maca
rabbit_host =10.17.0.85
rabbit_user =clarin
rabbit_password =clarin123
; --------- CZĘŚĆ DLA Narzedzia ---------
[tool]
workers_number = 1
[logging]
port = 9995
local_log_level = INFO
#!/usr/bin/python
# -*- coding: utf-8 -*-
import nlp_ws
import logging
import maca
import corpus2
def sentences(reader):
"""Yields subsequent sentences from a reader."""
while True:
sentence = reader.get_next_sentence()
if not sentence:
break
yield sentence
def chunks(reader):
"""Yields subsequent sentences from a reader."""
while True:
chunk = reader.get_next_chunk()
if not chunk:
break
yield chunk
_log = logging.getLogger(__name__)
class MacaWorker(nlp_ws.NLPWorker):
@classmethod
def static_init(cls, config):
_log.info( "Worker started loading models %s","AS" )
cls.configtool = config['tool'];
return
def init(self):
_log.info( "Worker started loading models" )
def process(self, inputFile, taskOptions, outputFile):
maca_config='morfeusz2-nkjp'
if 'morfeusz2' in taskOptions:
if not taskOptions['morfeusz2']:
maca_config='morfeusz-nkjp-official'
_log.info( "Config %s",maca_config)
reader = maca.PlainTextReader.create_file_reader(str(inputFile), maca_config)
writer = corpus2.TokenWriter.create_path_writer("ccl",str(outputFile),reader.tagset())
for chunk in chunks(reader):
writer.write_chunk(chunk)
if __name__ == '__main__':
nlp_ws.NLPService.main(MacaWorker)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from nlp_service import Service, create_service_option_parser
import shutil
from subprocess import call
import maca
import corpus2
def sentences(reader):
"""Yields subsequent sentences from a reader."""
while True:
sentence = reader.get_next_sentence()
if not sentence:
break
yield sentence
def chunks(reader):
"""Yields subsequent sentences from a reader."""
while True:
chunk = reader.get_next_chunk()
if not chunk:
break
yield chunk
class MacaService(Service):
def __init__(self, *args, **kwargs):
self.maca_config='morfeusz2-nkjp'
super(MacaService, self).__init__(*args, **kwargs)
def process(self, inputFile, taskOptions, outputFile):
reader = maca.PlainTextReader.create_file_reader(inputFile, self.maca_config)
writer = corpus2.TokenWriter.create_path_writer("ccl",outputFile,reader.tagset())
for chunk in chunks(reader):
writer.write_chunk(chunk)
#shutil.move(inputFile, outputFile)
def test(service):
service.process('test.txt',0,'out.ccl')
if __name__ == '__main__':
parser = create_service_option_parser()
args = parser.parse_args()
config_path = args.config_path
logfile_path = args.log_file
logging_lvl = args.logging_lvl
run_as_daemon = args.daemon
service = MacaService(config_path, logfile_path, logging_lvl, run_as_daemon)
#test(service);
service.run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment