parser = argparse.ArgumentParser(description='WSD.') parser.add_argument('--inventory', required=True, type=argparse.FileType('r', encoding='UTF-8')) parser.add_argument('--mystem', required=True, type=argparse.FileType('rb')) parser.add_argument('--mode', choices=('sparse', 'dense'), default='sparse', type=str) group = parser.add_mutually_exclusive_group() group.add_argument('--w2v', default=None, type=argparse.FileType('rb')) group.add_argument('--pyro', default=None, type=str) args = parser.parse_args() inventory = mnogoznal.Inventory(inventory_path=args.inventory.name) if args.mode == 'sparse': wsd = mnogoznal.SparseWSD(inventory=inventory) elif args.mode == 'dense': if args.w2v: from gensim.models import KeyedVectors w2v = KeyedVectors.load_word2vec_format(args.w2v, binary=True, unicode_errors='ignore') w2v.init_sims(replace=True) elif args.pyro: from mnogoznal.pyro_vectors import PyroVectors as PyroVectors w2v = PyroVectors(args.pyro)
import os import sys from flask import Flask, render_template, send_from_directory, url_for, redirect, request, jsonify from flask_misaka import Misaka import mnogoznal import mnogoznal_web_assets app = Flask(__name__) Misaka(app) mnogoznal_web_assets.init(app) inventory = mnogoznal.Inventory(os.environ.get('INVENTORY', 'watset-cw-nolog-mcl-joint-exp-linked.tsv')) WSD = {'sparse': mnogoznal.SparseWSD(inventory)} WSD['lesk'] = mnogoznal.LeskWSD(inventory) if 'W2V_PYRO' in os.environ: from mnogoznal.pyro_vectors import PyroVectors as PyroVectors w2v = PyroVectors(os.environ['W2V_PYRO']) WSD['dense'] = mnogoznal.DenseWSD(inventory, wv=w2v) elif 'W2V_PATH' in os.environ: from gensim.models import KeyedVectors w2v = KeyedVectors.load_word2vec_format(os.environ['W2V_PATH'], binary=True, unicode_errors='ignore') w2v.init_sims(replace=True) WSD['dense'] = mnogoznal.DenseWSD(inventory, wv=w2v)