How to use the smt.db.tables.Tables function in smt

To help you get started, we’ve selected a few smt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kenkov / smt / dbtest / jec_createdb.py View on Github external
from __future__ import division, print_function
from progressline import ProgressLine
import xlrd
from smt.db.createdb import createdb

# import SQLAlchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, TEXT, REAL, INTEGER

# import smt module
import smt.db.tables as tables
import math

Sentence = tables.Tables().get_sentence_table()


def excel_convert(db="sqlite:///:memory:",
                  excel_file="./JEC_basic_sentence_v1-2.xls"):
    engine = create_engine(db)
    # first, remove table
    Sentence.__table__.drop(engine, checkfirst=True)
    # create table
    Sentence.__table__.create(engine)
    print("created table: sentence")

    # create session
    Session = sessionmaker(bind=engine)
    session = Session()

    # get sentence from excel file
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
def _future_cost_langmodel(word,
                           tn,
                           transfrom=2,
                           transto=1,
                           alpha=0.00017,
                           db="sqlite:///:memory:"):
    tablename = "lang{}unigramprob".format(transto)
    # create session
    engine = create_engine(db)
    Session = sessionmaker(bind=engine)
    session = Session()

    UnigramProb = Tables().get_unigramprob_table(tablename)
    query = session.query(UnigramProb).filter_by(first=word)
    try:
        item = query.one()
        return item.prob
    except sqlalchemy.orm.exc.NoResultFound:
        sm = tn['sm']
        totalnumber = tn['totalnumber']
        return math.log(alpha) - math.log(sm + alpha*totalnumber)
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
def _get_total_number(transto=1, db="sqlite:///:memory:"):
    """
    return v
    """

    Trigram = Tables().get_trigram_table('lang{}trigram'.format(transto))

    # create connection in SQLAlchemy
    engine = create_engine(db)
    # create session
    Session = sessionmaker(bind=engine)
    session = Session()

    # calculate total number
    query = session.query(Trigram)

    return len(list(query))
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
def _get_total_number_for_fce(transto=1, db="sqlite:///:memory:"):
    """
    return v
    """
    # create connection in SQLAlchemy
    engine = create_engine(db)
    # create session
    Session = sessionmaker(bind=engine)
    session = Session()

    tablename = 'lang{}unigram'.format(transto)
    Unigram = Tables().get_unigram_table(tablename)

    # calculate total number
    query = session.query(Unigram)
    sm = 0
    totalnumber = 0
    for item in query:
        totalnumber += 1
        sm += item.count
    return {'totalnumber': totalnumber,
            'sm': sm}