Пример #1
0
def main():
    logging.basicConfig(
        level=__LOGLEVEL__,
        format="%(asctime)s : " +
        "%(module)s (%(lineno)s) - %(levelname)s - %(message)s")
    cfg_file = sys.argv[1] if len(sys.argv) > 1 else None
    cfg = get_cfg(cfg_file)
    tester = Tester(cfg)
    while True:
        text = raw_input('>').strip().decode('utf-8')
        tester.process(text)
Пример #2
0
def main():
    logging.basicConfig(
        level="INFO",
        format="%(asctime)s : " +
        "%(module)s (%(lineno)s) - %(levelname)s - %(message)s")
    cfg_file = sys.argv[1]
    cfg = get_cfg(cfg_file)
    text_to_4lang = TextTo4lang(cfg)
    fn = cfg.get('text', 'input_sens')
    base_fn = os.path.basename(fn)
    deps_fn = os.path.join(text_to_4lang.deps_dir, "{0}.deps".format(base_fn))

    if text_to_4lang.lang == 'hu':
        id_field, word_field, lemma_field, msd_field, gov_field, dep_field = (
            0, 1, 3, 4, -4, -2)
    else:
        id_field, word_field, lemma_field, msd_field, gov_field, dep_field = (
            0, 1, None, None, -4, -3)

    deps = map(lambda s: get_dependencies(
        s, id_field, word_field, lemma_field, msd_field, gov_field, dep_field),
        sentence_iterator(open(fn)))

    if text_to_4lang.lang == 'en':
        c_deps = []
        for sen in deps:
            c_deps.append([])
            for d in sen:
                c_deps[-1].append((
                    d['type'],
                    (d['gov']['word'], d['gov']['id']),
                    (d['dep']['word'], d['dep']['id'])))
                # convert to old deps (for now, see issue #51)
    else:
        c_deps = deps
    with open(deps_fn, 'w') as out_f:
        out_f.write("{0}\n".format(json.dumps({
            "deps": c_deps,
            "corefs": []})))

    text_to_4lang.process_deps(deps_fn)
Пример #3
0
def main():
    logging.basicConfig(level="INFO", format="%(asctime)s : " + "%(module)s (%(lineno)s) - %(levelname)s - %(message)s")
    cfg_file = sys.argv[1]
    cfg = get_cfg(cfg_file)
    text_to_4lang = TextTo4lang(cfg)
    fn = cfg.get("text", "input_sens")
    base_fn = os.path.basename(fn)
    deps_fn = os.path.join(text_to_4lang.deps_dir, "{0}.deps".format(base_fn))

    deps = [[]]
    for line in open(fn):
        dep_str = line.strip()
        if not dep_str:
            deps.append([])
        else:
            deps[-1].append(dep_str)

    with open(deps_fn, "w") as out_f:
        out_f.write("{0}\n".format(json.dumps({"deps": deps, "corefs": []})))

    text_to_4lang.process_deps(deps_fn)
Пример #4
0
def main():
    logging.basicConfig(
        level="INFO",
        format="%(asctime)s : " +
        "%(module)s (%(lineno)s) - %(levelname)s - %(message)s")
    cfg_file = sys.argv[1]
    cfg = get_cfg(cfg_file)
    text_to_4lang = TextTo4lang(cfg)
    fn = cfg.get('text', 'input_sens')
    base_fn = os.path.basename(fn)
    deps_fn = os.path.join(text_to_4lang.deps_dir, "{0}.deps".format(base_fn))

    if text_to_4lang.lang == 'hu':
        id_field, word_field, lemma_field, msd_field, gov_field, dep_field = (
            0, 1, 3, 4, -4, -2)
    else:
        id_field, word_field, lemma_field, msd_field, gov_field, dep_field = (
            0, 1, None, None, -4, -3)

    deps = map(
        lambda s: get_dependencies(s, id_field, word_field, lemma_field,
                                   msd_field, gov_field, dep_field),
        sentence_iterator(open(fn)))

    if text_to_4lang.lang == 'en':
        c_deps = []
        for sen in deps:
            c_deps.append([])
            for d in sen:
                c_deps[-1].append(
                    (d['type'], (d['gov']['word'], d['gov']['id']),
                     (d['dep']['word'], d['dep']['id'])))
                # convert to old deps (for now, see issue #51)
    else:
        c_deps = deps
    with open(deps_fn, 'w') as out_f:
        out_f.write("{0}\n".format(json.dumps({"deps": c_deps, "corefs": []})))

    text_to_4lang.process_deps(deps_fn)
Пример #5
0
def main():
    logging.basicConfig(
        level="INFO",
        format="%(asctime)s : " +
        "%(module)s (%(lineno)s) - %(levelname)s - %(message)s")
    cfg_file = sys.argv[1]
    cfg = get_cfg(cfg_file)
    text_to_4lang = TextTo4lang(cfg)
    fn = cfg.get('text', 'input_sens')
    base_fn = os.path.basename(fn)
    deps_fn = os.path.join(text_to_4lang.deps_dir, "{0}.deps".format(base_fn))

    deps = [[]]
    for line in open(fn):
        dep_str = line.strip()
        if not dep_str:
            deps.append([])
        else:
            deps[-1].append(dep_str)

    with open(deps_fn, 'w') as out_f:
        out_f.write("{0}\n".format(json.dumps({"deps": deps, "corefs": []})))

    text_to_4lang.process_deps(deps_fn)
Пример #6
0
    def backend_test(self):
        u_pic_fn = self.text_to_graph(
            'A man stands in the door', False, 'test_unexpanded')
        logging.info('unexpanded pic drawn to {0}'.format(u_pic_fn))
        e_pic_fn = self.text_to_graph(
            'A man stands in the door', True, 'test_expanded')
        logging.info('expanded pic drawn to {0}'.format(e_pic_fn))


logging.basicConfig(
    level=__LOGLEVEL__,
    format="%(asctime)s : " +
    "%(module)s (%(lineno)s) - %(levelname)s - %(message)s")

cfg_file = os.path.join(os.environ['FOURLANGPATH'], 'conf/demo.cfg')
cfg = get_cfg(cfg_file)
demo = FourlangDemo(cfg)

app = Flask(__name__, static_folder=demo.tmp_dir)
app.debug = True


@app.route('/', methods=['GET'])
def test():
    return render_template('test.html')


@app.route('/dfl', methods=['POST'])
def dfl_demo():
    word = request.form['word']
    source, sen, dep_fn, pic_fn = demo.dict_to_4lang_demo(word)