本文整理汇总了Python中quanthistling.model.meta.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Session.delete方法的具体用法?Python Session.delete怎么用?Python Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quanthistling.model.meta.Session
的用法示例。
在下文中一共展示了Session.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: annotate_head
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head(entry):
# delete head annotations
head_annotations = [ a for a in entry.annotations if a.value=='head' or a.value=="iso-639-3" or a.value=="doculect"]
for a in head_annotations:
Session.delete(a)
head = None
heads = []
in_brackets = functions.get_in_brackets_func(entry)
bolds = functions.get_list_bold_ranges(entry)
bolds += functions.get_list_italic_ranges(entry)
for b in bolds:
if in_brackets(*b):
continue
start = b[0]
for match_comma in re.finditer("(?:[,;:] ?|$)", entry.fullentry[b[0]:b[1]]):
end = b[0] + match_comma.start(0)
start, end, translation = functions.remove_parts(entry, start, end)
if translation.startswith(u'e\u0301l/ella'):
start += 4
translation = translation[4:]
head = functions.insert_head(entry, start, end, translation)
heads.append(head)
start = b[0] + match_comma.end(0)
return heads
示例2: annotate_head
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head(entry):
# delete head annotations
head_annotations = [a for a in entry.annotations if a.value == 'head' or
a.value == 'iso-639-3' or a.value == 'doculect']
for a in head_annotations:
Session.delete(a)
in_brackets = functions.get_in_brackets_func(entry)
heads = []
head_start = 0
smallcaps = functions.get_list_ranges_for_annotation(entry, 'smallcaps')
trans_end = functions.find_first_point(entry, 0, len(entry.fullentry), in_brackets)
italics = [i for i in functions.get_list_italic_ranges(entry) if not in_brackets(*i) and i[0]<trans_end]
if italics:
head_end = italics[0][0]
else:
head_end = functions.get_last_bold_pos_at_start(entry)
for h_start, h_end in functions.split_entry_at(entry, ',|$', head_start, head_end):
h_end = functions.find_first(entry, '(', h_start, h_end, in_brackets)
h_end = next((s[0] for s in smallcaps if s[0]>h_start and s[0] < h_end), h_end)
h_start, h_end = functions.strip(entry, h_start, h_end, u' -¡¿?!0123456789')
head = functions.insert_head(entry, h_start, h_end)
if head:
heads.append(head)
return heads
示例3: annotate_translations
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_translations(entry):
# delete pos annotations
trans_annotations = [ a for a in entry.annotations if a.value=='translation']
for a in trans_annotations:
Session.delete(a)
translations_start = functions.get_pos_or_head_end(entry) + 1
translations_end = len(entry.fullentry)
if re.match(u"\.? ?Vea ", entry.fullentry[translations_start:]):
return
first_bold_after_pos = functions.get_first_bold_start_in_range(entry, translations_start, translations_end)
if first_bold_after_pos != -1:
translations_end = first_bold_after_pos
start = translations_start
for match in re.finditer(u"(?:[,;] ?|$)", entry.fullentry[translations_start:translations_end]):
mybreak = False
# are we in a bracket?
for m in re.finditer(r'\(.*?\)', entry.fullentry[translations_start:translations_end]):
if match.start(0) >= m.start(0) and match.end(0) <= m.end(0):
mybreak = True
if not mybreak:
end = match.start(0) + translations_start
subsubstr = entry.fullentry[start:end]
if not(re.match(r"\s*$", subsubstr)):
functions.insert_translation(entry, start, end)
start = match.end(0) + translations_start
示例4: annotate_translations
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_translations(entry):
# delete translation annotations
trans_annotations = [ a for a in entry.annotations if a.value=='translation']
for a in trans_annotations:
Session.delete(a)
translation_start = functions.get_last_bold_pos_at_start(entry) + 1
translation_end = functions.get_first_bold_start_in_range(entry, translation_start, len(entry.fullentry))
if translation_end == -1:
translation_end = len(entry.fullentry)
match_bracket = re.search("^ ?\([^\)]*\) ?", entry.fullentry[translation_start:translation_end])
if match_bracket:
translation_start += len(match_bracket.group(0))
match_capitals = re.search("^ ?(?:PI|PE) ?", entry.fullentry[translation_start:translation_end])
if match_capitals:
translation_start += len(match_capitals.group(0))
start = translation_start
for t_start, t_end in functions.split_entry_at(entry, r'[,;] |/|$', translation_start, translation_end):
t_start, t_end, translation = functions.remove_parts(entry, t_start, t_end)
match = re.match(r'\(vr-[it]\.( irr\.)?\)|\(vt\.\)', translation)
if match:
translation = translation[len(match.group()):]
functions.insert_translation(entry, t_start, t_end, translation)
示例5: annotate_head
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head(entry):
# delete head annotations
head_annotations = [a for a in entry.annotations if a.value == 'head' or a.value == "iso-639-3" or a.value == "doculect"]
for a in head_annotations:
Session.delete(a)
heads = []
newlines = [a for a in entry.annotations if a.value == 'newline']
newlines = sorted(newlines, key=attrgetter('start'))
if len(newlines) > 0:
head_end = functions.get_last_bold_pos_at_start(entry)
for h_start, h_end in functions.split_entry_at(entry, ',|$', 0, head_end):
for i in ( index for index in xrange(h_start, h_end) if entry.fullentry[index] == '-' ):
entry.append_annotation(i, i+1, u'boundary', u'dictinterpretation', u"morpheme boundary")
h_start, h_end, head = functions.remove_parts(entry, h_start, h_end)
if not head.strip():
functions.print_error_in_entry(entry, "head is None")
else:
head = head.replace('-', '')
head = functions.insert_head(entry, h_start, h_end, head)
heads.append(head)
return heads
示例6: annotate_head
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head(entry):
# delete head annotations
head_annotations = [ a for a in entry.annotations if a.value=='head' or a.value=="iso-639-3" or a.value=="doculect"]
for a in head_annotations:
Session.delete(a)
# Delete this code and insert your code
head = None
heads = []
bold = functions.get_list_bold_ranges(entry)
if not bold:
functions.print_error_in_entry(entry, "Found no bold part at the beginning.")
return heads
head_end = bold[0][1]
for (s, e) in functions.split_entry_at(entry, r"(?:, |$)", 0, head_end):
s,e, head = functions.remove_parts(entry, s,e)
while head and (head[-1].isdigit() or head[-1] == '!'):
head = head[:-1]
head = functions.insert_head(entry, s, e, head)
if head is None:
functions.print_error_in_entry(entry, "head is None")
else:
heads.append(head)
return heads
示例7: annotate_pos_and_translation
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_pos_and_translation(entry):
# delete pos annotations
pos_annotations = [ a for a in entry.annotations if a.value=='pos' or a.value=="translation" ]
for a in pos_annotations:
Session.delete(a)
newline_annotations = [ a for a in entry.annotations if a.value=='newline']
newline_annotations = sorted(newline_annotations, key=attrgetter('start'))
if len(newline_annotations) < 2:
functions.print_error_in_entry(entry)
return
else:
first_newline = newline_annotations[1]
first_line = entry.fullentry[:first_newline.start]
match_pos = re.search("\(([^)]{1,8})\)", first_line)
translation_end = newline_annotations[0].start
if match_pos.end(0) > newline_annotations[0].start:
translation_end = newline_annotations[1].start
if match_pos:
entry.append_annotation(match_pos.start(1), match_pos.end(1), u"pos", u"dictinterpretation")
functions.insert_translation(entry, match_pos.end(0), translation_end)
else:
functions.print_error_in_entry(entry)
示例8: annotate_translations
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_translations(entry):
# delete translation annotations
trans_annotations = [ a for a in entry.annotations if a.value=='translation']
for a in trans_annotations:
Session.delete(a)
#head_end_pos = functions.get_last_bold_pos_at_start(entry)
head_starts, head_ends = get_bold_annotations(entry)
for i in range(len(head_starts)):
trans_start_pos = head_ends[i]
if len(head_starts) > i+1:
trans_end_pos = head_starts[i+1]
else:
trans_end_pos = len(entry.fullentry)
if trans_start_pos > -1:
substr = entry.fullentry[trans_start_pos:trans_end_pos]
start = trans_start_pos
for match in re.finditer(r'(?:, ?|; ?|\d\) )', substr):
mybreak = False
# are we in a bracket?
for m in re.finditer(r'\(.*?\)', substr):
if match.start(0) >= m.start(0) and match.end(0) <= m.end(0):
mybreak = True
if not mybreak:
end = match.start(0) + trans_start_pos
if end > start and not re.match(r' +$', entry.fullentry[start:end]):
functions.insert_translation(entry, start, end)
start = match.end(0) + trans_start_pos
end = trans_end_pos
if end > start and not re.match(r'^ +$', entry.fullentry[start:end]):
functions.insert_translation(entry, start, end)
示例9: main
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [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()
示例10: annotate_everything
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_everything(entry):
# delete annotations
for a in entry.annotations:
if a.value in ['head', 'pos', 'translation', 'crossreference', 'iso-639-3', 'doculect']:
Session.delete(a)
heads = annotate_heads(entry)
h_end = functions.get_last_bold_pos_at_start(entry)
t_start = annotate_pos(entry, h_end)
substr = entry.fullentry[t_start:]
if re.search(u'\(Vea .*?\)', substr): # cross-references
for match_vea in re.finditer(u'\(Vea (.*?)\)', substr):
cref_start = match_vea.start(1) + t_start
cref_end = match_vea.end(1) + t_start
substr = entry.fullentry[cref_start:cref_end]
for match in re.finditer(u', ?', substr):
end = match.start(0) + cref_start
entry.append_annotation(cref_start, end, u'crossreference', u'dictinterpretation')
cref_start = match.end(0) + cref_start
entry.append_annotation(cref_start, cref_end, u'crossreference', u'dictinterpretation')
else: # translations
annotate_translation(entry, t_start)
return heads
示例11: annotate_head
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head(entry):
# delete head annotations
head_annotations = [a for a in entry.annotations if a.value == 'head' or
a.value == "iso-639-3" or a.value == "doculect" or
a.value == 'translation']
for a in head_annotations:
Session.delete(a)
# Delete this code and insert your code
head = None
heads = []
first_italic = functions.get_first_italic_range(entry)
if first_italic != -1:
head_end = first_italic[0]
head = functions.insert_head(entry, 0, head_end)
heads.append(head)
trans_start = head_end
trans_end = len(entry.fullentry)
trans = entry.fullentry[trans_start:]
if trans.startswith(u'“') and trans.endswith(u'”'):
trans_start += 1
trans_end -= 1
functions.insert_translation(entry, trans_start, trans_end)
return heads
示例12: annotate_dialect
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_dialect(entry):
# delete head annotations
dialect_annotations = [ a for a in entry.annotations if a.value=='dialectidentification']
for a in dialect_annotations:
Session.delete(a)
match = re.finditer(u'\((b|p|s|b, p|b, s|p, s|B, P, S)\)', entry.fullentry)
if match:
for x in match:
if x.group(1) == u'b':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los bʉgʉyeri porã')
elif x.group(1) == u'p':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los payatérã porã')
elif x.group(1) == u's':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los sʉ̃meperu porã')
elif x.group(1) == u'b, p':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los bʉgʉyeri porã')
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los payatérã porã')
elif x.group(1) == u'b, s':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los bʉgʉyeri porã')
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los sʉ̃meperu porã')
elif x.group(1) == u'p, s':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los payatérã porã')
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los sʉ̃meperu porã')
elif x.group(1) == u'B, P, S':
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los bʉgʉyeri porã')
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los payatérã porã')
entry.append_annotation(x.start(1), x.end(1), u'dialectidentification', u'dictinterpretation', u'dialecto de los sʉ̃meperu porã')
示例13: annotate_head_and_pos
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head_and_pos(entry):
# delete head annotations
head_annotations = [a for a in entry.annotations if a.value == 'head' or
a.value == 'pos' or
a.value == 'iso-639-3' or a.value == 'doculect']
for a in head_annotations:
Session.delete(a)
heads = []
head_start = 0
first_italic = functions.get_first_italic_range(entry)
if first_italic != -1:
head_end = first_italic[0]
else:
head_end = functions.get_last_bold_pos_at_start(entry)
for h_start, h_end in functions.split_entry_at(entry, r'/|$', head_start, head_end):
match = head_end_pattern.search(entry.fullentry, h_start, h_end)
if match:
h_end = match.start()
h_start, h_end = functions.strip(entry, h_start, h_end, u'\'-–!? ')
head = entry.fullentry[h_start:h_end].translate(head_translate)
if head:
functions.insert_head(entry, h_start, h_end, head)
heads.append(head)
# add pos
if first_italic != -1:
entry.append_annotation(first_italic[0], first_italic[1], u'pos', u'dictinterpretation')
head_end = first_italic[1]
return heads, head_end
示例14: annotate_translations
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_translations(entry):
# delete translation annotations
trans_annotations = [ a for a in entry.annotations if a.value=='translation']
for a in trans_annotations:
Session.delete(a)
in_brackets = functions.get_in_brackets_func(entry)
heads = [x for x in functions.get_list_bold_ranges(entry) if not in_brackets(*x)]
heads += functions.get_list_italic_ranges(entry)
heads = sorted(heads, key=itemgetter(1))
translation_start = -1
translation_end = -1
for i, h in enumerate(heads):
translation_start = h[1]
if i < (len(heads) - 1):
translation_end = heads[i+1][0]
else:
translation_end = len(entry.fullentry)
if not (translation_end > 0 and (translation_end - translation_start) > 1):
continue
for t_start, t_end in functions.split_entry_at(entry, r',|;|$', translation_start, translation_end):
functions.insert_translation(entry, t_start, t_end)
示例15: annotate_head
# 需要导入模块: from quanthistling.model.meta import Session [as 别名]
# 或者: from quanthistling.model.meta.Session import delete [as 别名]
def annotate_head(entry):
# delete head annotations
head_annotations = [ a for a in entry.annotations if a.value=='head' or a.value=="iso-639-3" or a.value=="doculect"]
for a in head_annotations:
Session.delete(a)
# Delete this code and insert your code
head = None
heads = []
bolds = functions.get_list_bold_ranges(entry)
last_bold_end = 0
for b in bolds:
between = entry.fullentry[last_bold_end:b[0]]
# remove italics
italics = functions.get_list_italic_ranges(entry)
for i in reversed(italics):
if i[0] >= last_bold_end and i[1] <= b[0]:
between = re.sub(entry.fullentry[i[0]:i[1]], "", between)
# remove brackets
between = re.sub("\([^)]*\)", "", between)
between = re.sub(",", "", between)
between = re.sub("\s+", "", between)
if between != "":
break
heads += _add_head_with_comma(entry, b[0], b[1])
last_bold_end = b[1]
return heads