• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rex.rex函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rex.rex函数的典型用法代码示例。如果您正苦于以下问题:Python rex函数的具体用法?Python rex怎么用?Python rex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_m_value_orthodox

 def test_m_value_orthodox(self):
     self.assertEqual('88',
                      rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[
                          't'])
     self.assertEqual('88',
                      rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[2])
     self.assertEqual(None,
                      rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")[
                          'tttt'])
开发者ID:aglenis,项目名称:python-rex,代码行数:9,代码来源:tests.py


示例2: test_m_value

 def test_m_value(self):
     self.assertEqual('88',
                      ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[
                          't'])
     self.assertEqual('88',
                      ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[
                          2])
     self.assertEqual(None,
                      ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))[
                          'tttt'])
开发者ID:aglenis,项目名称:python-rex,代码行数:10,代码来源:tests.py


示例3: arpa

def arpa(fp, gram=None, header_start = None, header_end = None, section_start = None, section_end = None, file_end = None):
    section = None
    lm_info = {}
    max_gram = 0
    for l in fp:
        #print(l)
        if l.startswith("\\"):
            if l == "\\data\\\n":
                section = 0
                print("loading header", file=sys.stderr)
                if header_start and header_start() == False:
                    break
            elif l=="\\end\\\n":
                if file_end:
                    file_end(lm_info)
                break
            else:
                res = (l == rex("/^\\\\(\\d+)-grams/"))
                if res is not None:
                    section = int(res[1])
                    print("loading %d-grams" % section, file=sys.stderr)
                    if section_start and section_start(lm_info,section) == False:
                        break
            continue
        if l == "\n":
            if section == 0 and header_end and header_end(lm_info)== False:
                break
            elif section is not None and section > 0 and section_end and section_end(lm_info,section) == False:
                break
            section = None
            continue
        if section == 0:
            res = (l == rex("/^ngram (\d+)=(\d+)/"))
            lm_info[int(res[1])] = int(res[2])
            print("ngram %d=%d"%(int(res[1]), int(res[2])), file=sys.stderr)
            max_gram = max(max_gram, int(res[1]))
        else:
            larr = l.strip("\n").split("\t")
            bow = None
            if len(larr) == 3:
                bow = float(larr[-1])
            elif len(larr) < 2:
                continue
            if bow is None:
                bow = 0
            prob = float(larr[0])
            words = larr[1].split(" ")
            if gram and gram(lm_info, section, words, prob, bow) == False:
                break
开发者ID:chenkovsky,项目名称:pyngram,代码行数:49,代码来源:arpa.py


示例4: test_m_action_ex

def test_m_action_ex():
    r = rex('m!test!')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == 0
开发者ID:dex4er,项目名称:python-rex,代码行数:5,代码来源:test_rex.py


示例5: test_m_action_ex

 def test_m_action_ex(self):
     r = rex("m!test!")
     self.assertEqual(r.action, "m")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.flags, 0)
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:5,代码来源:tests.py


示例6: test_cache_2

 def test_cache_2(self):
     a = rex("s/cache/test/")
     b = rex("s/cache/test/")
     self.assertEqual(a is b, True)
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:4,代码来源:tests.py


示例7: test_not_cache

 def test_not_cache(self):
     rex("s/cache/test1/", cache=False)
     self.assertNotIn("s/cache/test1/", rex_module.REX_CACHE)
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:3,代码来源:tests.py


示例8: test_m_value

 def test_m_value(self):
     self.assertEqual("88", ("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))["t"])
     self.assertEqual("88", ("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))[2])
     self.assertEqual(None, ("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))["tttt"])
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:4,代码来源:tests.py


示例9: test_s_multi

 def test_s_multi(self):
     self.assertEqual("This is a dog dog dog dog", "This is a cat cat cat cat" == rex("s/cat/dog/"))
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:2,代码来源:tests.py


示例10: test_m_false

def test_m_false():
    assert not ("Aa 9-9  xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))
开发者ID:dex4er,项目名称:python-rex,代码行数:2,代码来源:test_rex.py


示例11: test_m_true

 def test_m_true(self):
     self.assertTrue("Aa 9-9 88 xx" == rex("/([0-9-]+) (?P<t>[0-9-]+)/"))
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:2,代码来源:tests.py


示例12: test_m_true_orthodox

def test_m_true_orthodox():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx")
开发者ID:dex4er,项目名称:python-rex,代码行数:2,代码来源:test_rex.py


示例13: test_m_false_noncache

def test_m_false_noncache():
    assert rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9 88 xx", cache=False)
    assert not rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa bb cc xx", cache=False)
开发者ID:dex4er,项目名称:python-rex,代码行数:3,代码来源:test_rex.py


示例14: test_m_true

def test_m_true():
    assert ("Aa 9-9 88 xx" == rex('/([0-9-]+) (?P<t>[0-9-]+)/'))
开发者ID:dex4er,项目名称:python-rex,代码行数:2,代码来源:test_rex.py


示例15: test_s_action_flags

def test_s_action_flags():
    r = rex('/test/im')
    assert r.action == 'm'
    assert r.pattern == 'test'
    assert r.flags == re.I | re.M
开发者ID:dex4er,项目名称:python-rex,代码行数:5,代码来源:test_rex.py


示例16: test_s_action

def test_s_action():
    r = rex('s/test/ohh/')
    assert r.action == 's'
    assert r.pattern == 'test'
    assert r.replacement == 'ohh'
    assert r.flags == 0
开发者ID:dex4er,项目名称:python-rex,代码行数:6,代码来源:test_rex.py


示例17: test_s_action

 def test_s_action(self):
     r = rex("s/test/ohh/")
     self.assertEqual(r.action, "s")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.replacement, "ohh")
     self.assertEqual(r.flags, 0)
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:6,代码来源:tests.py


示例18: test_m_false_orthodox

def test_m_false_orthodox():
    assert not rex('/([0-9-]+) (?P<t>[0-9-]+)/', "Aa 9-9  xx")
开发者ID:dex4er,项目名称:python-rex,代码行数:2,代码来源:test_rex.py


示例19: test_s_action_flags

 def test_s_action_flags(self):
     r = rex("/test/im")
     self.assertEqual(r.action, "m")
     self.assertEqual(r.pattern, "test")
     self.assertEqual(r.flags, re.I | re.M)
开发者ID:BigData-Tools,项目名称:python-rex,代码行数:5,代码来源:tests.py


示例20: rex

import importlib
import inspect
from textwrap import dedent, indent
from collections import namedtuple
from pathlib import Path

import jinja2
import sass
import click
import markdown
from rex import rex


CONTENT_MODULE_PATH = "tests.test_content"

OUTPUT_RE = rex(r"""s/^.*?assert .*? == ['"](.*)['"].*?# output$\n/\1/""")

Example = namedtuple("Example", ('name', 'title', 'details', 'setup', 'old', 'new', 'output'))


def compile_sass(source_path, target_path_pattern):
    # First generate the content from which we can generate the hashname
    output = sass.compile(
        filename=str(source_path),
        output_style='compressed')
    hash = hashlib.sha512(output.encode('utf-8')).hexdigest()[:8]
    target_path = str(target_path_pattern).format(hash)
    source_map_target_path = target_path + '.map'
    output = sass.compile(
        filename=str(source_path),
        output_style='compressed',
开发者ID:tjguk,项目名称:pyformat.info,代码行数:31,代码来源:main.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rexviewer.logInfo函数代码示例发布时间:2022-05-26
下一篇:
Python rewrite.load函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap