本文整理汇总了Python中model.Article._asdict方法的典型用法代码示例。如果您正苦于以下问题:Python Article._asdict方法的具体用法?Python Article._asdict怎么用?Python Article._asdict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Article
的用法示例。
在下文中一共展示了Article._asdict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import _asdict [as 别名]
def run(input_filename, output_filename):
articles = defaultdict(set)
without_identifiers = set()
reader = csv.reader(open(input_filename, 'r'))
try:
biggest = 0
for i, article in enumerate(reader):
article = Article(*article)
identifiers = [(k,v) for k,v in article._asdict().items() if k in IDENTIFIERS and v]
data = None # dict(identifiers)
if not identifiers:
without_identifiers.add(article.id)
continue
articles[identifiers[0]].add(article.id)
for identifier in identifiers[1:]:
if articles[identifiers[0]] is not articles[identifier]:
articles[identifiers[0]] |= articles[identifier]
articles[identifier] = articles[identifiers[0]]
if len(articles[identifier]) > biggest:
biggest = len(articles[identifier])
if i % 10000 == 0:
print "%7d" % i, resource.getrusage(resource.RUSAGE_SELF)[2], biggest
if resource.getrusage(resource.RUSAGE_SELF)[2] > 1e7:
print "Using too much memory"
raise Exception
except Exception, e:
print e
示例2: defaultdict
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import _asdict [as 别名]
from model import Article
from recluster import recluster
IDENTIFIERS = ('pmid', 'doi')
articles = defaultdict(list)
without_identifiers = 0
reader = csv.reader(open('../parsed/articles.csv', 'r'))
writer = csv.writer(open('../parsed/clustered.csv', 'w'))
try:
for i, article in enumerate(reader):
article = Article(*article)
identifiers = [(k,v) for k,v in article._asdict().items() if k in IDENTIFIERS and v]
data = None # dict(identifiers)
if not identifiers:
without_identifiers += 1
continue
articles[identifiers[0]].append(article)
for identifier in identifiers[1:]:
if articles[identifiers[0]] is not articles[identifier]:
articles[identifiers[0]] += articles[identifier]
articles[identifier] = articles[identifiers[0]]
if i % 10000 == 0:
print "%7d" % i
except:
pass