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


Python Session.expunge_all方法代码示例

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


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

示例1: process_articles

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import expunge_all [as 别名]
def process_articles(entity_type=Entity, output_filename='output-all.txt',
                     corpus_root='corpus/'):
    terms = select_terms(entity_type)
    Session.expunge_all()
    Session.close()

    # fix search patterns
    for term in terms:
        newpatterns = []
        for pattern in term.searchpatterns:
            if '(' in pattern and ')' in pattern:
                pattern = pattern.replace('( ', '(\\b')
                pattern = pattern.replace(' )', '\\b)')
            else:
                pattern = '\\b%s\\b' % pattern.strip()

            newpatterns.append(pattern)

        term.searchpatterns = newpatterns

    
    articles = Session.query(Entity.sep_dir).filter(Entity.sep_dir!=None)
    articles = articles.filter(Entity.sep_dir!='')
    articles = articles.distinct().all()
    articles = [a[0] for a in articles]
   
    # parallel processing of articles
    p = Pool()
    args = [(title, terms, entity_type, None, corpus_root) for title in articles]
    doc_lines = p.map(process_wrapper, args)
    p.close()

    #serial processing for tests
    '''
    doc_lines = []
    for title in articles:
        lines = process_article(title, terms, entity_type, None, corpus_root)
        doc_lines.append(lines)
    '''

    # write graph output to file
    print output_filename
    with open(output_filename, 'w') as f:
        for lines in doc_lines:
            f.writelines(lines)
开发者ID:camerontt2000,项目名称:inpho,代码行数:47,代码来源:sep.py

示例2: process_articles

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import expunge_all [as 别名]
def process_articles(entity_type=Entity, output_filename='output-all.txt',
                     corpus_root='corpus/'):
    terms = select_terms(entity_type)
    Session.expunge_all()
    Session.close()
    
    articles = Session.query(entity_type).filter(entity_type.sep_dir!='').all()
   
    # parallel processing of articles
    p = Pool()
    args = [(title, terms, entity_type, None, corpus_root) for title in articles]
    doc_lines = p.map(process_wrapper, args)
    p.close()

    # write graph output to file
    with open(output_filename, 'w') as f:
        for lines in doc_lines:
            f.writelines(lines)
开发者ID:etboggs,项目名称:inpho,代码行数:20,代码来源:sep.py


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