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


Python re.L属性代码示例

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


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

示例1: pynlp_build_key_word

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def pynlp_build_key_word(filename):
    d={}
    with open(filename, encoding="utf-8") as fp:
        for line in fp:
            s = line
            p = re.compile(r'http?://.+$')  # 正则表达式,提取URL
            result = p.findall(line)  # 找出所有url
            if len(result):
                for i in result:
                    s = s.replace(i, '')  # 一个一个的删除
            temp = pynlpir.segment(s, pos_tagging=False)  # 分词
            for i in temp:
                if '@' in i:
                    temp.remove(i)  # 删除分词中的名字
                p = re.compile(r'\w', re.L)
                result = p.sub("", i)
                if not result or result == ' ':  # 空字符
                    continue
                if len(i) > 1:  # 避免大量无意义的词语进入统计范围
                    d[i] = d.get(i, 0) + 1
    kw_list = sorted(d, key=lambda x: d[x], reverse=True)
    size = int(len(kw_list) * 0.2)  # 取最前的30%
    mood = set(kw_list[:size])
    return list(mood - set(stop)- set('\u200b') - set(' ') - set('\u3000')) 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:26,代码来源:tool.py

示例2: loadDataSet

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def loadDataSet(path):  # 返回每条微博的分词与标签
    line_cut = []
    label = []
    with open(path, encoding="utf-8") as fp:
        for line in fp:
            temp = line.strip()
            try:
                sentence = temp[2:].lstrip()  # 每条微博
                label.append(int(temp[:2]))  # 获取标注
                word_list = []
                sentence = str(sentence).replace('\u200b', '')
                for word in jieba.cut(sentence.strip()):
                    p = re.compile(r'\w', re.L)
                    result = p.sub("", word)
                    if not result or result == ' ':  # 空字符
                        continue
                    word_list.append(word)
                word_list = list(set(word_list) - set(stop) - set('\u200b')
                                 - set(' ') - set('\u3000') - set('️'))
                line_cut.append(word_list)
            except Exception:
                continue
    return line_cut, label  # 返回每条微博的分词和标注 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:25,代码来源:Bayes.py

示例3: getmatch

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def getmatch(self, haystack):
        if not isinstance(haystack, basestring):
            return None
        flags = 0
        if self.flags is not None:
            if "i" in self.flags or "I" in self.flags:
                flags |= re.I
            if "l" in self.flags or "L" in self.flags:
                flags |= re.L
            if "m" in self.flags or "M" in self.flags:
                flags |= re.M
            if "s" in self.flags or "S" in self.flags:
                flags |= re.S
            if "u" in self.flags or "U" in self.flags:
                flags |= re.U
            if "x" in self.flags or "X" in self.flags:
                flags |= re.X
        if re.match(self.pattern, haystack, flags=flags) is None:
            return None
        elif self.to is None:
            return Match(haystack, haystack)
        else:
            return Match(haystack, re.sub(self.pattern, self.to, haystack, flags=flags)) 
开发者ID:modelop,项目名称:hadrian,代码行数:25,代码来源:tools.py

示例4: loadDataSet

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def loadDataSet(path):  # 返回每条微博的分词与标签
    line_cut = []
    label = []
    with open(path, encoding="utf-8") as fp:
        for line in fp:
            temp = line.strip()
            try:
                sentence = temp[2:].lstrip()  # 每条微博
                label.append(int(temp[:2]))  # 获取标注
                word_list = []
                sentence = str(sentence).replace('\u200b', '')
                for word in jieba.cut(sentence.strip()):
                    p = re.compile(b'\w', re.L)
                    result = p.sub(b"", bytes(word, encoding="utf-8")).decode("utf-8")
                    if not result or result == ' ':  # 空字符
                        continue
                    word_list.append(word)
                word_list = list(set(word_list) - set(stop) - set('\u200b')
                                 - set(' ') - set('\u3000') - set('️'))
                line_cut.append(word_list)
            except Exception:
                continue
    return line_cut, label  # 返回每条微博的分词和标注 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:25,代码来源:Bayes.py

示例5: preprocessing

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def preprocessing(content):
    remove_punc = ('。 ; 。 、 」 「 , ( ) —').split(' ')
    ## preprocessing #1 : remove XXenglishXX and numbers
    preprocessing_1 = re.compile(r'\d*',re.L)  ## only substitute numbers
    #preprocessing_1 = re.compile(r'\w*',re.L)  ## substitute number & English
    content = preprocessing_1.sub("",content)
    ## preprocessing #2 : remove punctuation
    preprocessing_2 = re.compile('[%s]' % re.escape(string.punctuation))
    content = preprocessing_2.sub("",content)
    ## preprocessing #3 : remove Chinese punctuation and multiple whitspaces
    content = content.replace('\n','')
    for punc in remove_punc:
        content = content.replace(punc,'')
    try:
        content = parsing.strip_multiple_whitespaces(content)
    except:
        print 'Warning : failed to strip whitespaces @ '   
    
    return content 
开发者ID:easonchan1213,项目名称:LDA_RecEngine,代码行数:21,代码来源:utils.py

示例6: _branch_flags

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def _branch_flags(flags):
        flagsbyte = 0
        for flag in flags:
            if flag == "i":
                flagsbyte += re.I
            elif flag == "L":
                flagsbyte += re.L
            elif flag == "m":
                flagsbyte += re.M
            elif flag == "s":
                flagsbyte += re.S
            elif flag == "u":
                flagsbyte += re.U
            elif flag == "x":
                flagsbyte += re.X
        return flagsbyte 
开发者ID:scikit-hep,项目名称:uproot,代码行数:18,代码来源:tree.py

示例7: build_key_word

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def build_key_word(path):  # 通过词频产生key word
    d = {}
    with open(path, encoding="utf-8") as fp:
        for line in fp:
            for word in jieba.cut(line.strip()):
                p = re.compile(r'\w', re.L)
                result = p.sub("", word)
                if not result or result == ' ':  # 空字符
                    continue
                if len(word) > 1:  # 避免大量无意义的词语进入统计范围
                    d[word] = d.get(word, 0) + 1
    kw_list = sorted(d, key=lambda x: d[x], reverse=True)
    size = int(len(kw_list) * 0.15)  # 取最前的30%
    mood = set(kw_list[:size])
    return list(mood - set(stop)) 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:17,代码来源:tool.py

示例8: get_word_feature

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def get_word_feature(sentence):
    wordlist = []
    sentence = str(sentence).replace('\u200b', '')
    for word in jieba.cut(sentence.strip()):
        p = re.compile(r'\w', re.L)
        result = p.sub("", word)
        if not result or result == ' ':  # 空字符
            continue
        wordlist.append(word)
    return list(set(wordlist) - set(stop) - set(' ')) 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:12,代码来源:tool.py

示例9: build_key_word

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def build_key_word(path):  # 通过词频产生特征
    d = {}
    with open(path, encoding="utf-8") as fp:
        for line in fp:
            for word in jieba.cut(line.strip()):
                p = re.compile(r'\w', re.L)
                result = p.sub("", word)
                if not result or result == ' ':  # 空字符
                    continue
                if len(word) > 1:  # 避免大量无意义的词语进入统计范围
                    d[word] = d.get(word, 0) + 1
    kw_list = sorted(d, key=lambda x: d[x], reverse=True)
    size = int(len(kw_list) * 0.2)  # 取最前的30%
    mood = set(kw_list[:size])
    return list(mood - set(stop)) 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:17,代码来源:Bayes.py

示例10: loadDataSet

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def loadDataSet(path):  # 返回每条微博的分词与标签
    line_cut = []
    label = []
    with open(path, encoding="utf-8") as fp:
        for line in fp:
            temp = line.strip()
            try:
                sentence = temp[2:].lstrip()  # 每条微博
                first_label = int(temp[:2])
                if first_label == 3:
                    continue
                label.append(first_label)  # 获取标注
                word_list = []
                sentence = str(sentence).replace('\u200b', '')
                for word in jieba.cut(sentence.strip()):
                    p = re.compile(r'\w', re.L)
                    result = p.sub("", word)
                    if not result or result == ' ':  # 空字符
                        continue
                    word_list.append(word)
                word_list = list(set(word_list) - set(stop) - set('\u200b')
                                 - set(' ') - set('\u3000') - set('️'))
                line_cut.append(word_list)
            except Exception:
                continue
    return line_cut, label  # 返回每条微博的分词和标注 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:28,代码来源:two_nb.py

示例11: build_key_word

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def build_key_word(path):  # 通过词频产生特征
    d = {}
    with open(path, encoding="utf-8") as fp:
        for line in fp:
            for word in jieba.cut(line.strip()):
                p = re.compile(b'\w', re.L)
                result = p.sub(b"", bytes(word, encoding="utf-8")).decode("utf-8")
                if not result or result == ' ':  # 空字符
                    continue
                if len(word) > 1:  # 避免大量无意义的词语进入统计范围
                    d[word] = d.get(word, 0) + 1
    kw_list = sorted(d, key=lambda x: d[x], reverse=True)
    size = int(len(kw_list) * 0.2)  # 取最前的30%
    mood = set(kw_list[:size])
    return list(mood - set(stop)) 
开发者ID:Zephery,项目名称:weiboanalysis,代码行数:17,代码来源:Bayes.py

示例12: test_constants

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def test_constants(self):
        self.assertEqual(re.I, re.IGNORECASE)
        self.assertEqual(re.L, re.LOCALE)
        self.assertEqual(re.M, re.MULTILINE)
        self.assertEqual(re.S, re.DOTALL)
        self.assertEqual(re.X, re.VERBOSE) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:test_re.py

示例13: test_flags

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def test_flags(self):
        for flag in [re.I, re.M, re.X, re.S, re.L]:
            self.assertNotEqual(re.compile('^pattern$', flag), None) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:5,代码来源:test_re.py

示例14: testParseErrors

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def testParseErrors(self):
        self.assertRaises(sre_yield.ParseError, sre_yield.AllStrings, 'a', re.I)
        self.assertRaises(sre_yield.ParseError, sre_yield.AllStrings, 'a', re.U)
        self.assertRaises(sre_yield.ParseError, sre_yield.AllStrings, 'a', re.L) 
开发者ID:girishramnani,项目名称:hacking-tools,代码行数:6,代码来源:test_sre_yield.py

示例15: test_flags

# 需要导入模块: import re [as 别名]
# 或者: from re import L [as 别名]
def test_flags(self):
        for flag in [re.I, re.M, re.X, re.S, re.L]:
            self.assertTrue(re.compile('^pattern$', flag)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_re.py


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