def get_personalized_cwi(user_id):
    if user_id in personalized_cwi:
        logger.info("Using personalized cwi, still in memory.")
        cwi = personalized_cwi[user_id]
    else:
        logger.info("Gotta load cwi or use default...")
        try:
            # retrieve model
            path = CWI_PATH_TEMPLATE.format(user_id)
            cwi = MounicaCWI.staticload(path)
        except:
            logger.warning("Could not load personalized model. "
                           "Loading default cwi.")
            cwi = copy.copy(personalized_cwi["default"])
            logger.debug(cwi)
            cwi.set_userId(user_id)
        cwi.set_scorer(get_personalized_scorer(user_id))
        personalized_cwi[user_id] = cwi
    return cwi
示例#2
0
 def save(self, userId):
     json = jsonpickle.encode(self)
     with open(CWI_PATH_TEMPLATE.format(userId), 'w') as jsonfile:
         jsonfile.write(json)
# FLASK SETUP
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

if not hasattr(args, "disable_ssl") or args.disable_ssl is False:
    logger.info("Using SSL connection.")
    sslify = SSLify(app)
else:
    logger.info("Not using SSL connection.")
app.debug = False

# LOADING DEFAULT CWI
default_scorer = MounicaScorer.staticload(
    SCORER_PATH_TEMPLATE.format("default"))
default_cwi = MounicaCWI.staticload(CWI_PATH_TEMPLATE.format("default"))
default_cwi.set_scorer(default_scorer)
logger.debug("SCORER PATH: {}".format(default_scorer.path))

# LOADING DEFAULT RANKER
nrr_featurizer = FeatureExtractorFast(RESOURCES['en']['nrr'])
default_nrr = MounicaNRR.staticload(NRR_PATH_TEMPLATE.format('default'),
                                    nrr_featurizer)
default_ranker = MounicaRanker.staticload(
    RANKER_PATH_TEMPLATE.format('default'), nrr_featurizer)
logger.debug("NRR PATH: {}".format(default_ranker.nrr.model_path))

# LOADING SIMPLIFICATION MODELS
simplification_pipeline = MounicaSimplificationPipeline("default")
simplification_pipeline.setCwi(default_cwi)
simplification_pipeline.setGenerator(MounicaGenerator())
示例#4
0
else:
    logger.info("Not using SSL connection.")
app.debug = False


# LOADING DEFAULT MODEL
simplification_pipeline = LexicalSimplificationPipeline("default")
generator = LexiGenerator(synonyms_files=RESOURCES["da"]["synonyms"],
                          embedding_files=RESOURCES["da"]["embeddings"])
simplification_pipeline.setGenerator(generator)

default_scorer = LexiScorer.staticload(SCORER_PATH_TEMPLATE.format("default"))
logger.debug("SCORER PATH: {}".format(default_scorer.path))
default_ranker = LexiRanker.staticload(RANKER_PATH_TEMPLATE.format("default"))
default_ranker.set_scorer(default_scorer)
default_cwi = LexiCWI.staticload(CWI_PATH_TEMPLATE.format("default"))
default_cwi.set_scorer(default_scorer)

personalized_rankers = {"default": default_ranker}
personalized_cwi = {"default": default_cwi}
personalized_scorers = {"default": default_scorer}

logger.debug("Default ranker: {} ({})".format(default_ranker,
                                              type(default_ranker)))
logger.info("Base simplifier loaded.")

# BLACKLISTED WORDS, not to be simplified
GENERIC_BLACKLIST = db_connection.get_blacklist(None)
logger.debug("Generic blacklist: {}".format(GENERIC_BLACKLIST))