本文整理汇总了Python中core.model.DataSource.license_sources_for方法的典型用法代码示例。如果您正苦于以下问题:Python DataSource.license_sources_for方法的具体用法?Python DataSource.license_sources_for怎么用?Python DataSource.license_sources_for使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.model.DataSource
的用法示例。
在下文中一共展示了DataSource.license_sources_for方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lookup_equivalent_isbns
# 需要导入模块: from core.model import DataSource [as 别名]
# 或者: from core.model.DataSource import license_sources_for [as 别名]
def lookup_equivalent_isbns(self, identifier):
"""Finds NoveList data for all ISBNs equivalent to an identifier.
:return: Metadata object or None
"""
lookup_metadata = []
license_sources = DataSource.license_sources_for(self._db, identifier)
# Look up strong ISBN equivalents.
for license_source in license_sources:
lookup_metadata += [self.lookup(eq.output)
for eq in identifier.equivalencies
if (eq.data_source==license_source and eq.strength==1
and eq.output.type==Identifier.ISBN)]
if not lookup_metadata:
self.log.error(
"Identifiers without an ISBN equivalent can't \
be looked up with NoveList: %r", identifier
)
return None
# Remove None values.
lookup_metadata = [metadata for metadata in lookup_metadata if metadata]
if not lookup_metadata:
return None
best_metadata = self.choose_best_metadata(lookup_metadata, identifier)
if not best_metadata:
metadata, confidence = best_metadata
if round(confidence, 2) < 0.5:
self.log.warn(self.NO_ISBN_EQUIVALENCY, identifier)
return None
return metadata
示例2: lookup_equivalent_isbns
# 需要导入模块: from core.model import DataSource [as 别名]
# 或者: from core.model.DataSource import license_sources_for [as 别名]
def lookup_equivalent_isbns(self, identifier):
"""Finds NoveList data for all ISBNs equivalent to an identifier.
:return: Metadata object or None
"""
lookup_metadata = []
license_sources = DataSource.license_sources_for(self._db, identifier)
# Find strong ISBN equivalents.
isbns = list()
for license_source in license_sources:
isbns += [eq.output for eq in identifier.equivalencies if (
eq.data_source==license_source and
eq.strength==1 and
eq.output.type==Identifier.ISBN
)]
if not isbns:
self.log.warn(
("Identifiers without an ISBN equivalent can't"
"be looked up with NoveList: %r"), identifier
)
return None
# Look up metadata for all equivalent ISBNs.
lookup_metadata = list()
for isbn in isbns:
metadata = self.lookup(isbn)
if metadata:
lookup_metadata.append(metadata)
if not lookup_metadata:
self.log.warn(
("No NoveList metadata found for Identifiers without an ISBN"
"equivalent can't be looked up with NoveList: %r"), identifier
)
return None
best_metadata, confidence = self.choose_best_metadata(
lookup_metadata, identifier
)
if best_metadata:
if round(confidence, 2) < 0.5:
self.log.warn(self.NO_ISBN_EQUIVALENCY, identifier)
return None
return metadata