本文整理汇总了Python中regex.U属性的典型用法代码示例。如果您正苦于以下问题:Python regex.U属性的具体用法?Python regex.U怎么用?Python regex.U使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类regex
的用法示例。
在下文中一共展示了regex.U属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_empty_node_empty_vals
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def validate_empty_node_empty_vals(cols):
"""
Checks that an empty node has _ empty values in HEAD and DEPREL. This is
required by UD guidelines but not necessarily by CoNLL-U, therefore
a level 2 test.
"""
assert is_empty_node(cols), 'internal error'
for col_idx in (HEAD, DEPREL):
if cols[col_idx]!= '_':
testlevel = 2
testclass = 'Format'
testid = 'mwt-nonempty-field'
testmessage = "An empty node must have '_' in the column %s. Now: '%s'." % (COLNAMES[col_idx], cols[col_idx])
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
# Ll ... lowercase Unicode letters
# Lm ... modifier Unicode letters (e.g., superscript h)
# Lo ... other Unicode letters (all caseless scripts, e.g., Arabic)
# M .... combining diacritical marks
# Underscore is allowed between letters but not at beginning, end, or next to another underscore.
示例2: __init__
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def __init__(self, arpabet='arpabet', ligatures=False, cedict_file=None):
"""Construct a Flite "wrapper"
Args:
arpabet (str): file containing ARPAbet to IPA mapping
ligatures (bool): if True, use non-standard ligatures instead of
standard IPA
cedict_filename (str): path to CC-CEDict dictionary (included for
compatibility)
"""
arpabet = pkg_resources.resource_filename(__name__, os.path.join('data', arpabet + '.csv'))
self.arpa_map = self._read_arpabet(arpabet)
self.chunk_re = re.compile(r"([A-Za-z'’]+|[^A-Za-z'’]+)", re.U)
self.letter_re = re.compile(r"[A-Za-z'’]+")
self.regexp = re.compile(r'[A-Za-z]')
self.puncnorm = PuncNorm()
self.ligatures = ligatures
self.ft = panphon.FeatureTable()
self.num_panphon_fts = len(self.ft.names)
示例3: _get_simplifications
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def _get_simplifications(self, settings=None):
no_word_spacing = eval(self.info.get('no_word_spacing', 'False'))
if settings.NORMALIZE:
if self._normalized_simplifications is None:
self._normalized_simplifications = []
simplifications = self._generate_simplifications(normalize=True)
for simplification in simplifications:
pattern, replacement = list(simplification.items())[0]
if not no_word_spacing:
pattern = r'(?<=\A|\W|_)%s(?=\Z|\W|_)' % pattern
pattern = re.compile(pattern, flags=re.I | re.U)
self._normalized_simplifications.append({pattern: replacement})
return self._normalized_simplifications
else:
if self._simplifications is None:
self._simplifications = []
simplifications = self._generate_simplifications(normalize=False)
for simplification in simplifications:
pattern, replacement = list(simplification.items())[0]
if not no_word_spacing:
pattern = r'(?<=\A|\W|_)%s(?=\Z|\W|_)' % pattern
pattern = re.compile(pattern, flags=re.I | re.U)
self._simplifications.append({pattern: replacement})
return self._simplifications
示例4: lspec2ud
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def lspec2ud(deprel):
return deprel.split(':', 1)[0]
#==============================================================================
# Level 1 tests. Only CoNLL-U backbone. Values can be empty or non-UD.
#==============================================================================
示例5: shape
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def shape(word: str) -> str: # TODO zredukowac czas
word = regex.sub(r'(?V1)\p{Lowercase}', 'l', word, flags=regex.U) # 80%
word = regex.sub(r'(?V1)\p{Uppercase}', 'u', word, flags=regex.U)
word = regex.sub(r'\p{gc=Decimal_Number}', 'd', word, flags=regex.U)
word = regex.sub(r'[^A-Za-z0-9]', 'x', word, flags=regex.LOCALE)
return unix_uniq(word)
示例6: _fields_to_function_metathesis
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def _fields_to_function_metathesis(self, a, X, Y):
left = r'(?P<X>{}){}(?P<Y>{})'.format(X, a, Y)
regexp = re.compile(left)
def rewrite(m):
d = {k: none2str(v) for k, v in m.groupdict().items()}
return '{}{}{}{}'.format(d['X'], d['sw2'], d['sw1'], d['Y'])
return lambda w: regexp.sub(rewrite, w, re.U)
示例7: _fields_to_function
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def _fields_to_function(self, a, b, X, Y):
left = r'(?P<X>{})(?P<a>{})(?P<Y>{})'.format(X, a, Y)
regexp = re.compile(left)
def rewrite(m):
d = {k: none2str(v) for k, v in m.groupdict().items()}
return '{}{}{}'.format(d['X'], b, d['Y'])
return lambda w: regexp.sub(rewrite, w, re.U)
示例8: __init__
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def __init__(self, infile=sys.stdin):
"""Validate Unicode IPA from file relative to panphon database.
infile -- File from which input is taken; by default, STDIN.
"""
self.ws_punc_regex = re.compile(r'[," \t\n]', re.V1 | re.U)
self.ft = panphon.FeatureTable()
self._validate_file(infile)
示例9: add_rule
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def add_rule(self, pattern, css_class):
"""Add a new rule.
Parameters
----------
pattern: str
Pattern that is compiled to a regular expression.
css_class: str
The class that will corresponds to given pattern.
"""
#print('adding rule <{0}> <{1}>'.format(pattern, css_class))
self.__patterns.append(re.compile(pattern, flags=re.U | re.M))
self.__css_classes.append(css_class)
示例10: validate_cols_level1
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def validate_cols_level1(cols):
"""
Tests that can run on a single line and pertain only to the CoNLL-U file
format, not to predefined sets of UD tags.
"""
testlevel = 1
testclass = 'Format'
# Some whitespace may be permitted in FORM, LEMMA and MISC but not elsewhere.
for col_idx in range(MISC+1):
if col_idx >= len(cols):
break # this has been already reported in trees()
# Must never be empty
if not cols[col_idx]:
testid = 'empty-column'
testmessage = 'Empty value in column %s.' % (COLNAMES[col_idx])
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
else:
# Must never have leading/trailing whitespace
if cols[col_idx][0].isspace():
testid = 'leading-whitespace'
testmessage = 'Leading whitespace not allowed in column %s.' % (COLNAMES[col_idx])
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
if cols[col_idx][-1].isspace():
testid = 'trailing-whitespace'
testmessage = 'Trailing whitespace not allowed in column %s.' % (COLNAMES[col_idx])
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
# Must never contain two consecutive whitespace characters
if whitespace2_re.match(cols[col_idx]):
testid = 'repeated-whitespace'
testmessage = 'Two or more consecutive whitespace characters not allowed in column %s.' % (COLNAMES[col_idx])
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
# These columns must not have whitespace
for col_idx in (ID,UPOS,XPOS,FEATS,HEAD,DEPREL,DEPS):
if col_idx >= len(cols):
break # this has been already reported in trees()
if whitespace_re.match(cols[col_idx]):
testid = 'invalid-whitespace'
testmessage = "White space not allowed in column %s: '%s'." % (COLNAMES[col_idx], cols[col_idx])
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
# Check for the format of the ID value. (ID must not be empty.)
if not (is_word(cols) or is_empty_node(cols) or is_multiword_token(cols)):
testid = 'invalid-word-id'
testmessage = "Unexpected ID format '%s'." % cols[ID]
warn(testmessage, testclass, testlevel=testlevel, testid=testid)
##### Tests applicable to the whole tree
示例11: split_by_regex
# 需要导入模块: import regex [as 别名]
# 或者: from regex import U [as 别名]
def split_by_regex(self, regex_or_pattern, flags=re.U, gaps=True):
"""Split the text into multiple instances using a regex.
Parameters
----------
regex_or_pattern: str or compiled pattern
The regular expression to use for splitting.
flags: int (default: re.U)
The regular expression flags (only used, when user has not supplied compiled regex).
gaps: boolean (default: True)
If True, then regions matched by the regex are not included in the resulting Text instances, which
is expected behaviour.
If False, then only regions matched by the regex are included in the result.
Returns
-------
list of Text
The Text instances obtained by splitting.
"""
text = self[TEXT]
regex = regex_or_pattern
if isinstance(regex, six.string_types):
regex = re.compile(regex_or_pattern, flags=flags)
# else is assumed pattern
last_end = 0
spans = []
if gaps: # tag cap spans
for mo in regex.finditer(text):
start, end = mo.start(), mo.end()
if start > last_end:
spans.append((last_end, start))
last_end = end
if last_end < len(text):
spans.append((last_end, len(text)))
else: # use matched regions
spans = [(mo.start(), mo.end()) for mo in regex.finditer(text)]
return self.split_given_spans(spans)
# ///////////////////////////////////////////////////////////////////
# DIVIDING
# ///////////////////////////////////////////////////////////////////