本文整理匯總了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)