Fix invalid Concraft-pl client port
This commit is contained in:
@@ -38,5 +38,9 @@ def run(host, port, workers, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccp
|
||||
'workers': workers,
|
||||
}
|
||||
|
||||
StandaloneApplication(create_app, options).run()
|
||||
app_config = {
|
||||
'CONCRAFT_PL_PORT': ccpl_port,
|
||||
}
|
||||
|
||||
StandaloneApplication(create_app, options, app_config).run()
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from gunicorn.app.base import BaseApplication
|
||||
|
||||
class StandaloneApplication(BaseApplication):
|
||||
def __init__(self, app_factory, options=None):
|
||||
def __init__(self, app_factory, options=None, app_config=None):
|
||||
self.options = options or {}
|
||||
self.app_factory = app_factory
|
||||
self.app_config = app_config or {}
|
||||
super().__init__()
|
||||
|
||||
def load_config(self):
|
||||
@@ -12,4 +13,4 @@ class StandaloneApplication(BaseApplication):
|
||||
self.cfg.set(key.lower(), value)
|
||||
|
||||
def load(self):
|
||||
return self.app_factory()
|
||||
return self.app_factory(self.app_config)
|
||||
|
||||
@@ -63,8 +63,8 @@ def entry_to_dict(entry):
|
||||
}
|
||||
|
||||
|
||||
def analyse(text):
|
||||
def analyse(text, port):
|
||||
morf = morfeusz2.Morfeusz(expand_tags=True)
|
||||
conc = concraft.Concraft()
|
||||
conc = concraft.Concraft(port=port)
|
||||
analysis = morf.analyse(text)
|
||||
return [entry_to_dict(e) for e in conc.disamb(analysis) if len(e) == 6]
|
||||
@@ -1,16 +1,17 @@
|
||||
from flask import Flask
|
||||
from . import analyzer
|
||||
|
||||
def create_app():
|
||||
def create_app(config=None):
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
|
||||
app.config.from_mapping(
|
||||
SECRET_KEY='dev'
|
||||
SECRET_KEY='dev',
|
||||
CONCRAFT_PL_PORT=3000,
|
||||
)
|
||||
|
||||
if config:
|
||||
app.config.update(config)
|
||||
|
||||
app.register_blueprint(analyzer.bp)
|
||||
|
||||
return app
|
||||
|
||||
def start(port):
|
||||
app = create_app()
|
||||
app.run(port=port)
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, request
|
||||
from flask import Blueprint, request, current_app
|
||||
from conmorfeusz.service import analyzer as service
|
||||
|
||||
bp = Blueprint('analyser', __name__, url_prefix='/analyser')
|
||||
@@ -8,5 +8,5 @@ def analyze():
|
||||
data = request.get_json()
|
||||
|
||||
return {
|
||||
"analysis": service.analyse(data["text"])
|
||||
"analysis": service.analyse(data["text"], current_app.config['CONCRAFT_PL_PORT'])
|
||||
}
|
||||
Reference in New Issue
Block a user