本文整理汇总了Python中LTTL.Segmenter.select方法的典型用法代码示例。如果您正苦于以下问题:Python Segmenter.select方法的具体用法?Python Segmenter.select怎么用?Python Segmenter.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LTTL.Segmenter
的用法示例。
在下文中一共展示了Segmenter.select方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_progress
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_progress(self):
"""Does select track progress?"""
def progress_callback():
"""Mock progress callback"""
self.count += 1
Segmenter.select(
self.char_seg,
re.compile(r'.'),
progress_callback=progress_callback,
)
self.assertEqual(
self.count,
len(self.char_seg),
msg="select doesn't track progress!"
)
示例2: test_select_import_annotations_false
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_import_annotations_false(self):
"""Does select skip importing annotations?"""
segmentation, _ = Segmenter.select(
self.word_seg,
re.compile(r'\w+'),
copy_annotations=False,
)
self.assertFalse(
'a' in segmentation[0].annotations,
msg="select doesn't skip importing annotations!"
)
示例3: test_select_select_neg
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_select_neg(self):
"""Does select output complementary segmentation?"""
_, segmentation = Segmenter.select(
self.word_seg,
re.compile(r'\w{3,}'),
)
self.assertEqual(
[s.get_content() for s in segmentation],
['ab'],
msg="select doesn't output complementary segmentation!"
)
示例4: test_select_select
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_select(self):
"""Does select select segments?"""
segmentation, _ = Segmenter.select(
self.word_seg,
re.compile(r'\w{3,}'),
)
self.assertEqual(
[s.get_content() for s in segmentation],
['cde'],
msg="select doesn't select segments!"
)
示例5: test_select_autonumber
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_autonumber(self):
"""Does select autonumber input segments?"""
segmentation, _ = Segmenter.select(
self.char_seg,
re.compile(r'.'),
auto_number_as='num'
)
self.assertEqual(
[s.annotations['num'] for s in segmentation],
[1, 2, 3, 4, 5, 6],
msg="select doesn't autonumber input segments!"
)
示例6: test_select_annotations
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_annotations(self):
"""Does select work with annotations?"""
segmentation, _ = Segmenter.select(
self.word_seg,
re.compile(r'.'),
annotation_key='a'
)
self.assertEqual(
[s.get_content() for s in segmentation],
['ab'],
msg="select doesn't work with annotations!"
)
示例7: test_select_import_annotations
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_import_annotations(self):
"""Does select import annotations?"""
segmentation, _ = Segmenter.select(
self.word_seg,
re.compile(r'\w+'),
copy_annotations=True,
)
self.assertEqual(
segmentation[0].annotations['a'],
'1',
msg="select doesn't import annotations!"
)
示例8: test_select_mode
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def test_select_mode(self):
"""Does select respect mode setting?"""
segmentation, _ = Segmenter.select(
self.word_seg,
re.compile(r'\w{3,}'),
mode="exclude",
)
self.assertEqual(
[s.get_content() for s in segmentation],
['ab'],
msg="select doesn't respect mode setting!"
)
示例9: setUp
# 需要导入模块: from LTTL import Segmenter [as 别名]
# 或者: from LTTL.Segmenter import select [as 别名]
def setUp(self):
input_seg = Input("un texte")
word_seg = Segmenter.tokenize(
input_seg,
[(re.compile(r'\w+'), 'tokenize')],
import_annotations=False,
)
letter_seg = Segmenter.tokenize(
input_seg,
[
(re.compile(r'\w'), 'tokenize', {'type': 'C'}),
(re.compile(r'[aeiouy]'), 'tokenize', {'type': 'V'}),
],
import_annotations=False,
merge_duplicates=True,
)
vowel_seg, consonant_seg = Segmenter.select(
letter_seg,
re.compile(r'V'),
annotation_key='type',
)
# Create the cooccurrence matrix for cooccurrence in window
# with window_size=3 and without annotation (woa):
self.window_woa_row_ids = ['u', 'n', 't', 'e', 'x']
self.window_woa_col_ids = ['u', 'n', 't', 'e', 'x']
self.window_woa_values = {
('u', 'u'): 1,
('u', 'n'): 1,
('u', 't'): 1,
('u', 'e'): 0,
('u', 'x'): 0,
('n', 'u'): 1,
('n', 'n'): 2,
('n', 't'): 2,
('n', 'e'): 1,
('n', 'x'): 0,
('t', 'u'): 1,
('t', 'n'): 2,
('t', 't'): 5,
('t', 'e'): 4,
('t', 'x'): 3,
('e', 'u'): 0,
('e', 'n'): 1,
('e', 't'): 4,
('e', 'e'): 4,
('e', 'x'): 3,
('x', 'u'): 0,
('x', 'n'): 0,
('x', 't'): 3,
('x', 'e'): 3,
('x', 'x'): 3,
}
self.window_woa_header_row_id = '__unit__'
self.window_woa_header_row_type = 'string'
self.window_woa_header_col_id = '__unit2__'
self.window_woa_header_col_type = 'string'
self.window_woa_col_type = {
col_id: 'continuous' for col_id in self.window_woa_col_ids
}
self.window_woa_ref = IntPivotCrosstab(
self.window_woa_row_ids,
self.window_woa_col_ids,
self.window_woa_values,
self.window_woa_header_row_id,
self.window_woa_header_row_type,
self.window_woa_header_col_id,
self.window_woa_header_col_type,
self.window_woa_col_type,
)
# Create the cooccurrence matrix for cooccurrence in window
# with window_size=3 and with annotation (wa):
self.window_wa_row_ids = ['C', 'V']
self.window_wa_col_ids = ['C', 'V']
self.window_wa_values = {
('C', 'C'): 5,
('C', 'V'): 5,
('V', 'C'): 5,
('V', 'V'): 5,
}
self.window_wa_header_row_id = '__unit__'
self.window_wa_header_row_type = 'string'
self.window_wa_header_col_id = '__unit2__'
self.window_wa_header_col_type = 'string'
self.window_wa_col_type = {
col_id: 'continuous' for col_id in self.window_wa_col_ids
}
self.window_wa_ref = IntPivotCrosstab(
self.window_wa_row_ids,
self.window_wa_col_ids,
self.window_wa_values,
self.window_wa_header_row_id,
self.window_wa_header_row_type,
self.window_wa_header_col_id,
self.window_wa_header_col_type,
self.window_wa_col_type,
)
# Create the cooccurrence matrix for cooccurrence in context
# without the secondary unit (wos) and without annotation (woa):
self.context_wos_woa_row_ids = ['u', 'n', 't', 'e', 'x']
#.........这里部分代码省略.........