当前位置: 首页>>代码示例>>Python>>正文


Python Unit.irregular方法代码示例

本文整理汇总了Python中unit.Unit.irregular方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.irregular方法的具体用法?Python Unit.irregular怎么用?Python Unit.irregular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unit.Unit的用法示例。


在下文中一共展示了Unit.irregular方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _find_irregular

# 需要导入模块: from unit import Unit [as 别名]
# 或者: from unit.Unit import irregular [as 别名]
	def _find_irregular(self, common_parent, potential_parents, cluster_units):
		unit = cluster_units[0]
		unit_tags_names = map(lambda x : x.name, unit.tags)
		typ = unit.typ
		unit_length = len(unit.tags) # units in the same cluster are expected to have the same number of tags
		for p in potential_parents:
			units_in_p = filter(lambda x : x.parent == p, cluster_units)
			tags = filter(lambda x : isinstance(x, Tag), p.contents)
			occupied_indices = []
			for un in units_in_p:
				start, stop = un.get_tags_interval()
				occupied_indices.extend(range(start, stop+1))
				if typ == 1:
					count = unit.get_level_one_tags_count()
					occupied_indices.extend(range(start+1, start+count))
			already_checked_instances = []
			for i in range(0, len(tags)):
				if i not in occupied_indices and i not in already_checked_instances:
					new_unit_tags = []
					for j in range(i, i+unit_length):
						if j in occupied_indices or j >= len(tags):
							break
						if tags[j].name in unit_tags_names:
							new_unit_tags.append(tags[j])
							if typ == 1:
								ts = filter(lambda x : isinstance(x, Tag), tags[j].contents)
								new_unit_tags.extend(ts)
						already_checked_instances.append(j)
					new_unit_tags_names = map(lambda x : x.name, new_unit_tags)
					lev = self._levenshtein(unit_tags_names, new_unit_tags_names)
					if abs(len(unit_tags_names) - len(new_unit_tags)) <= 1 and lev <= 1:
						new_unit = Unit(self, p, new_unit_tags, unit.level, typ, unit.pattern, unit.parent_tag_indices)
						new_unit.label = unit.label
						new_unit.irregular = True
						self._logger.info("irregular unit found ---------------------------------")
						self._logger.info("new irregular unit: %s" % new_unit)
						self.units.append(new_unit)
开发者ID:miha-stopar,项目名称:extract-repetitions,代码行数:39,代码来源:extractor.py


注:本文中的unit.Unit.irregular方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。