本文整理汇总了Python中asciitree.LeftAligned方法的典型用法代码示例。如果您正苦于以下问题:Python asciitree.LeftAligned方法的具体用法?Python asciitree.LeftAligned怎么用?Python asciitree.LeftAligned使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asciitree
的用法示例。
在下文中一共展示了asciitree.LeftAligned方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def main(unused_argv):
logging.set_verbosity(logging.INFO)
with tf.Session() as sess:
src = gen_parser_ops.document_source(batch_size=32,
corpus_name=FLAGS.corpus_name,
task_context=FLAGS.task_context)
sentence = sentence_pb2.Sentence()
while True:
documents, finished = sess.run(src)
logging.info('Read %d documents', len(documents))
for d in documents:
sentence.ParseFromString(d)
tr = asciitree.LeftAligned()
d = to_dict(sentence)
print 'Input: %s' % sentence.text
print 'Parse:'
tr_str = tr(d)
pat = re.compile(r'\s*@\d+$')
for tr_ln in tr_str.splitlines():
print pat.sub('', tr_ln)
if finished:
break
示例2: main
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def main(unused_argv):
logging.set_verbosity(logging.INFO)
with tf.Session() as sess:
src = gen_parser_ops.document_source(batch_size=32,
corpus_name=FLAGS.corpus_name,
task_context=FLAGS.task_context)
sentence = sentence_pb2.Sentence()
while True:
documents, finished = sess.run(src)
logging.info('Read %d documents', len(documents))
for d in documents:
sentence.ParseFromString(d)
tr = asciitree.LeftAligned()
d = to_dict(sentence)
print('Input: %s' % sentence.text)
print('Parse:')
tr_str = tr(d)
pat = re.compile(r'\s*@\d+$')
for tr_ln in tr_str.splitlines():
print(pat.sub('', tr_ln))
if finished:
break
示例3: formatted_tree
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def formatted_tree(params, folder):
def tree_node(node):
name = node.name
sfs = [params.folder_cache[sfuid] for sfuid in node.subfolders]
if len(sfs) == 0:
return name, {}
sfs.sort(key=lambda f: f.name.lower(), reverse=False)
tns = [tree_node(sf) for sf in sfs]
return name, OD(tns)
t = tree_node(folder)
tree = {
t[0]: t[1]
}
tr = LeftAligned()
print(tr(tree))
print('')
示例4: main
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def main(unused_argv):
logging.set_verbosity(logging.INFO)
with tf.Session() as sess:
src = gen_parser_ops.document_source(batch_size=32,
corpus_name=FLAGS.corpus_name,
task_context=FLAGS.task_context)
sentence = sentence_pb2.Sentence()
while True:
documents, finished = sess.run(src)
logging.info('Read %d documents', len(documents))
for d in documents:
sentence.ParseFromString(d)
tr = asciitree.LeftAligned()
d = to_dict(sentence)
print 'Input: %s' % sentence.text
print 'Parse:'
print tr(d)
if finished:
break
示例5: print_tree
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def print_tree(token, colors=True):
label, children = _token2label_tree(token, colors=colors)
tr = LeftAligned()
print(tr({label: children}))
示例6: __bytes__
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def __bytes__(self):
drawer = LeftAligned(
traverse=TreeTraversal(),
draw=BoxStyle(gfx=self.bytes_kwargs, **self.text_kwargs),
)
root = self.node_cls(self.group, level=self.level)
result = drawer(root)
# Unicode characters slip in on Python 3.
# So we need to straighten that out first.
if not PY2:
result = result.encode()
return result
示例7: __unicode__
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def __unicode__(self):
drawer = LeftAligned(
traverse=TreeTraversal(),
draw=BoxStyle(gfx=self.unicode_kwargs, **self.text_kwargs),
)
root = self.node_cls(self.group, level=self.level)
return drawer(root)
示例8: process
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def process(irr_host, afi, db, as_set, search):
import datetime
now = datetime.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M")
print "IRRTree (%s) report for '%s' (IPv%i), using %s at %s" \
% (irrtree.__version__, as_set, afi, irr_host, now)
if search and "-" not in db.keys():
if not search in db.keys():
print "NOT_FOUND: %s not present in %s or any of its members" % (search, as_set)
sys.exit()
def print_member(as_set, db, search):
if not "-" in as_set:
res = "%s (%s pfxs)" % (as_set, resolve_prefixes(db, as_set))
elif search:
res = "%s (%s ASNs)" % (as_set, len(db[as_set]['origin_asns']))
else:
res = "%s (%s ASNs, %s pfxs)" % (as_set,
len(db[as_set]['origin_asns']),
resolve_prefixes(db, as_set))
return res
def getasncount(db, item):
v = db[item]
if type(v) == set:
ret = (0, len(v))
else:
ret = (len(v['origin_asns']), resolve_prefixes(db, item))
return ret
def resolve_tree(as_set, db, tree=OD(), seen=set()):
seen.add(as_set)
for member in sorted(db[as_set]['members'], key=lambda x:
getasncount(db, x), reverse=True):
if member in seen:
tree["%s - already expanded" % print_member(member, db, search)] = {}
continue
if "-" in member:
seen.add(member)
tree["%s" % print_member(member, db, search)] = resolve_tree(member, db, OD(), seen)
else:
if not search or search == member:
tree["%s" % print_member(member, db, search)] = {}
else:
continue
return tree
tree = OD()
tree["%s" % print_member(as_set, db, search)] = resolve_tree(as_set, db)
tr = asciitree.LeftAligned()
print tr(tree)
示例9: create_tree
# 需要导入模块: import asciitree [as 别名]
# 或者: from asciitree import LeftAligned [as 别名]
def create_tree(table: dict,
root: str,
mark: str,
f_pid: str = "pid",
f_id: str = "id",
f_label: str = "item",
f_ctime: str = "ctime",
v_none: str = "null") -> str:
"""
Creates the ascii checkpoint tree.
Args:
table: List of checkpoints as a table.
root: Root label of the tree.
mark: Current snapshot name. Mark the element with an '*'
f_pid: Field of the table that contains the parent id of the node.
f_id: Field of the table that contains the id of the node.
f_label: Field with the label of the node.
f_ctime: Field with the timestamp creation date.
v_none: Value to be used for empty fields.
Returns:
A string containing the tree of snapshots
"""
items = [(c[f_pid], c[f_id]) for c in table]
tree = {root: OD()}
inserted = []
while [x[1] for x in items if x[1] not in inserted]:
for parent, item in items:
if parent == v_none:
parent = root
inserts = walk(tree, parent, item)
inserted.extend(list(inserts))
tr = LeftAligned()
tr_tree = tr(tree)
for cell in table:
if cell[f_label] == mark:
cell[f_label] = "{}*".format(cell[f_label])
tr_tree = tr_tree.replace(cell[f_id],
"{} ({})".format(
cell[f_label],
convert_dt(cell[f_ctime])))
return tr_tree