本文整理汇总了Python中quanthistling.model.meta.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quanthistling.model.meta.Session
的用法示例。
在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"jakway2008"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=109,pos_on_page=18).all()
#entries = []
startletters = set()
for e in entries:
if dictdata.startpage == 129:
heads = annotate_head_without_comma(e)
else:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
for e in manual_entries:
dictdata = model.meta.Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).filter("startpage<=:pagenr and endpage>=:pagenr").params(pagenr=int(e["startpage"])).first()
entry_db = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id, startpage=e["startpage"], pos_on_page=e["pos_on_page"]).first()
if difflib.SequenceMatcher(None, e["fullentry"].decode('utf-8'), entry_db.fullentry).ratio() > 0.95:
entry_db.fullentry = e["fullentry"].decode('utf-8')
# delete all annotations in db
for a in entry_db.annotations:
Session.delete(a)
# insert new annotations
for a in e["annotations"]:
entry_db.append_annotation(a["start"], a["end"], a["value"].decode('utf-8'), a["type"].decode('utf-8'), a["string"].decode('utf-8'))
else:
print "We have a problem, manual entry on page %i pos %i seems not to be the same entry as in db, it was not inserted to db. Please correct the problem." % (e["startpage"], e["pos_on_page"])
Session.commit()
示例2: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"dooley2006"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=1,pos_on_page=4).all()
startletters = set()
for e in entries:
#split on newline, but ignore newline at pagebreak
pagebreaks = [b[0] for b in functions.get_list_ranges_for_annotation(e, 'pagebreak')]
newlines = [n[0] for n in functions.get_list_ranges_for_annotation(e, 'newline')
if not [ b for b in pagebreaks if abs(n[0] - b) < 3 ]]
lines = []
n = last = 0
for n in newlines:
lines.append((last, n))
last = n
lines.append((n, len(e.fullentry)))
heads = annotate_first_line(e, *lines.pop(0))
for l in lines:
heads.extend(annotate_secondary_line(e, *l))
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例3: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
if len(argv) < 2:
print "call: updatelanguages.py ini_file"
exit(1)
ini_file = argv[1]
dictdata_path = 'quanthistling/dictdata'
log = logging.getLogger()
logging.basicConfig(level=logging.INFO)
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
# update languages
for l in quanthistling.dictdata.languages.list:
db_lang = Session.query(model.LanguageIso).filter_by(name=l['name']).first()
if db_lang == None:
lname = l['name']
#lname = importfunctions.normalize_stroke(lname)
#lname = unicodedata.normalize("NFD", lname)
language = model.LanguageIso()
language.name = l['name']
language.langcode = l['langcode']
language.description = l['description']
language.url = l['url']
Session.add(language)
Session.commit()
log.info("Inserted language " + l['name'] + ".")
示例4: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
if len(argv) < 2:
print "call: updateversion.py ini_file"
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
new_version = False
corpusversion = Session.query(model.Corpusversion).filter_by(version=version,revision=revision).first()
if corpusversion == None:
corpusversion = model.Corpusversion()
new_version = True
corpusversion.version = version
corpusversion.revision = revision
corpusversion.updated = datetime.datetime.now()
if new_version:
Session.add(corpusversion)
Session.commit()
示例5: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
if len(argv) < 2:
print "call: updatecomponents.py ini_file"
exit(1)
ini_file = argv[1]
dictdata_path = 'quanthistling/dictdata'
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
# update languages
for c in quanthistling.dictdata.components.list:
db_lang = Session.query(model.Component).filter_by(name=c['name']).first()
if db_lang == None:
component = model.Component()
component.name = c['name']
component.description = c['description']
Session.add(component)
Session.commit()
print("Inserted component " + c['name'] + ".")
示例6: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"thiesen1998"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
# create orthography parser
base_qlc_path = "/media/Daten/Projects/git-github/qlc"
sys.path.append(os.path.join(base_qlc_path, "src"))
#import qlc.OrthographyProfile
#orthography_profile_location = os.path.join(base_qlc_path, "data", "orthography_profiles", "{0}.txt".format(bibtex_key))
#o_parser = qlc.OrthographyProfile.OrthographyProfile(orthography_profile_location)
# load dictionary data for this book
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=128,pos_on_page=18).all()
startletters = set()
for e in entries:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
annotate_translations(e)
annotate_examples(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例7: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"morse1999"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
cmd = """\
delete from annotation
using book tb, entry te
where tb.bibtex_key = :bibtex_key and tb.id = te.book_id and te.id = entry_id
and annotationtype_id = (select id from annotationtype where type = 'dictinterpretation')"""
Session.execute(cmd, dict(bibtex_key=bibtex_key))
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=21,pos_on_page=12).all()
startletters = set()
for e in entries:
heads = annotate_everything(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
#annotate_dialect(e)
#annotate_pos(e)
#annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例8: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"fastmowitz2008"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
#print "Processing %s - %s dictdata..." %(dictdata.src_language.langcode, dictdata.tgt_language.langcode)
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#print len(entries)
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=343,pos_on_page=3).all()
#entries = []
startletters = set()
for e in entries:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
#Session.commit()
annotate_translations(e)
annotate_crossrefs(e)
annotate_dialect(e)
annotate_stratum(e)
#annotate_examples(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例9: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"rolland1999"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=101,pos_on_page=23).all()
startletters = set()
for e in entries:
#skip subentries which start with '||'
if e.is_subentry and (e.fullentry.startswith('||') or e.fullentry.startswith(' ||')):
for a in e.annotations:
if a.annotationtype.type == 'dictinterpretation':
Session.delete(a)
continue
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例10: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"tuggy1966"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entry = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=345,pos_on_page=21).first()
if entry:
for a in entry.annotations:
Session.delete(a)
Session.delete(entry)
Session.commit()
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
# entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=1,pos_on_page=1).all()
startletters = set()
for e in entries:
heads = annotate_everything(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例11: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"gerdelslocum1983"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
# entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=21,pos_on_page=3).all()
# entries.extend(Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=2,pos_on_page=2).all())
# entries.extend(Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=2,pos_on_page=7).all())
startletters = set()
for e in entries:
try:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
annotate_translation(e)
except TypeError:
print " error on startpage: %i, pos_on_page: %i" % (e.startpage, e.pos_on_page)
raise
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例12: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u"parker2010a"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=15,pos_on_page=5).all()
startletters = set()
for e in entries:
#one time data conversion
if e.fullentry.find('[email protected]') != -1 or e.fullentry.find('[email protected]') != -1:
e.fullentry = e.fullentry.replace(u'[email protected]', u's\u0308').replace(u'[email protected]', u'c\u0308')
functions.print_error_in_entry(e, 'Replacing [email protected] and [email protected]')
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例13: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u'headland1997'
if len(argv) < 2:
print 'call: annotations_for%s.py ini_file' % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata)\
.join(model.Book, model.Dictdata.book_id == model.Book.id)\
.filter(model.Book.bibtex_key == bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
# entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=216,pos_on_page=16).all()
# entries.extend(Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=62,pos_on_page=7).all())
# entries.extend(Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=61,pos_on_page=1).all())
startletters = set()
for e in entries:
delete_dictinterpretation(e)
heads, start = annotate_head(e)
start = annotate_pos(e, start, len(e.fullentry))
annotate_translations(e, start, len(e.fullentry))
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
dictdata.startletters = unicode(repr(sorted(startletters)))
Session.commit()
示例14: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def main(argv):
bibtex_key = u'salzerchapman1998'
if len(argv) < 2:
print "call: annotations_for_%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id == model.Book.id)
).filter(model.Book.bibtex_key == bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
# entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=45,pos_on_page=2).all()
startletters = set()
for e in entries:
# print "current page: %i, pos_on_page: %i" % (e.startpage, e.pos_on_page)
heads, start = annotate_head_and_pos(e)
annotate_translation(e, start)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
dictdata.startletters = unicode(repr(sorted(startletters)))
Session.commit()
示例15: insert_counterpart
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import query [as 别名]
def insert_counterpart(entry, start, end, data):
if entry.fullentry.strip() == "":
return
entry.append_annotation(start, end, "counterpart", "dictinterpretation",
entry.fullentry)
entry.append_annotation(start, end, u'doculect',
u'dictinterpretation', data["language_bookname"])
language_iso = Session.query(model.LanguageIso).filter_by(
name=data["language_name"]).first()
if language_iso is not None:
entry.append_annotation(start, end, u'iso639-3',
u'dictinterpretation', language_iso.langcode)