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


Python MarkovChain.dumpdb方法代码示例

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


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

示例1: main

# 需要导入模块: from pymarkovchain import MarkovChain [as 别名]
# 或者: from pymarkovchain.MarkovChain import dumpdb [as 别名]
def main():
    args = parser.parse_args()
    dirname=os.path.split(__file__)[0]
    filename=os.path.join(dirname,"phil.txt")
    title_filename=os.path.join(dirname,"phil_titles.txt")
    dbname1 = "database.pkl"
    dbname2 = "database_title.pkl"
    new_db = not os.path.exists(dbname1)
    body_maker = MarkovChain(dbname1)
    title_maker = MarkovChain(dbname2)
    if new_db:
        title_maker.generateDatabase(open(title_filename).read())
        title_maker.dumpdb()
        body_maker.generateDatabase(open(filename).read())
        body_maker.dumpdb()

    name = title_maker.generateString()
    body = '  '.join([body_maker.generateString()+'.' for i in xrange(3)])

    if args.repo:
        if args.token:
            token = args.token
        else:
            token_filename = os.path.join(dirname, "token.txt")
            if not os.path.exists(token_filename):
                sys.stderr.write("Please either specify --token=XXX on the command line or put a github API token in token.txt\n")
                sys.stderr.write("You can generate a token here: https://github.com/settings/tokens\n")
                sys.exit(1)
            token = open(token_filename).read().strip()

        import github
        gh=github.Github(token)
        user=gh.get_user()
        repo=user.get_repo(args.repo)
        issue = repo.create_issue(title=name, body=body)
        print issue.html_url
    else:
        print 
        print name
        print "-"*len(name)
        print body
开发者ID:joezuntz,项目名称:philsim,代码行数:43,代码来源:philsim.py

示例2: MarkovChain

# 需要导入模块: from pymarkovchain import MarkovChain [as 别名]
# 或者: from pymarkovchain.MarkovChain import dumpdb [as 别名]
if not os.path.isfile(DB_FILE):
    # Handle common user errors
    if not os.path.isfile(SOURCE_FILE):
        if os.path.isfile(DB_FILE + '.7z'):
            sys.exit("NOTICE: Please extract the archive containing the Markov database before use.")
        sys.exit("NOTICE: You can't regenerate the Markov database without the source text.");

    # Moving this in here avoids an annoying warning message if either of the
    # above two sys.exit() calls would be triggered
    mc = MarkovChain(DB_FILE)

    # Generate the database
    with open(SOURCE_FILE, 'r') as f:
        mc.generateDatabase(f.read(), sentenceSep='[.!?"\n]', n=2)
    mc.dumpdb()
else:
    mc = MarkovChain(DB_FILE)

def generate_string(max_length):
    # Generate the string
    # We could be a bit smarter about this, but it works fairly well
    gen_string = ''
    short_counter = 0
    while len(gen_string) < max_length:
        new_str = mc.generateString().strip()
        new_str = re.sub(r' , ?', ', ', new_str)
    
        # Too short or too long to be meaningful
        if len(new_str) < 4 or len(new_str) > 100:
            continue
开发者ID:ConnorKrammer,项目名称:worm-serial-markov,代码行数:32,代码来源:worm-markov-server.py


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