本文整理汇总了Python中util.ElementHelper.is_element_has_child方法的典型用法代码示例。如果您正苦于以下问题:Python ElementHelper.is_element_has_child方法的具体用法?Python ElementHelper.is_element_has_child怎么用?Python ElementHelper.is_element_has_child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.ElementHelper
的用法示例。
在下文中一共展示了ElementHelper.is_element_has_child方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CountTag
# 需要导入模块: from util import ElementHelper [as 别名]
# 或者: from util.ElementHelper import is_element_has_child [as 别名]
def CountTag(element):
tag_num = 0
l2s_tag_num = str(tag_num)
if ElementHelper.is_element_has_child(element):
for child in element:
CountTag(child)
for child in element:
tag_num += long(child.attrib.get(kg_tag_num))+1
l2s_tag_num = str(tag_num)
element.set(kg_tag_num, l2s_tag_num)
else:
element.set(kg_tag_num, l2s_tag_num)
示例2: ComputeDensitySum
# 需要导入模块: from util import ElementHelper [as 别名]
# 或者: from util.ElementHelper import is_element_has_child [as 别名]
def ComputeDensitySum(element, ratio):
density_sum, char_num_sum = 0.0, 0
_from, index, length = 0, 0, 0
content = ElementHelper.element_text_content(element)
if ElementHelper.is_element_has_child(element):
for child in element:
ComputeDensitySum(child, ratio)
for child in element:
density_sum += float(child.attrib.get(kg_text_density))
char_num_sum += long(child.attrib.get(kg_char_num))
#text before tag
child_content = ElementHelper.element_text_content(child)
index = -1
if child_content != '':
index = StringHelper.index_of(content, child_content, _from)
if index > -1:
length = index - _from
if length > 0:
try:
tmp = length * qLn(1.0 * length) / qLn(qLn(ratio * length + qExp(1.0))) #此处的计算结果都为0
density_sum += tmp
except ZeroDivisionError:
pass
_from = index + len(child_content)
#text after tag
length = len(ElementHelper.element_text_content(element)) - _from
if length>0:
try:
density_sum += length * qLn(1.0 * length) / qLn(qLn(ratio * length + qExp(1.0)))
except ZeroDivisionError:
pass
else:
density_sum = float(element.attrib.get(kg_text_density))
d2s_density_sum = str(density_sum)
element.set(kg_density_sum, d2s_density_sum)