Skip to content

Commit

Permalink
DocMetadataClient can now take instantiated providers and processors (
Browse files Browse the repository at this point in the history
#414)

- [x]  updated clients to work with instantiated providers and processors
- [x] retraction test now looks at a stub csv file instead of downloading
- [x] update RetrationDataPostProcessor -> Retra**c**tionDataPostProcessor
  • Loading branch information
geemi725 committed Sep 16, 2024
1 parent 49273f2 commit 7aa7fda
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
31 changes: 24 additions & 7 deletions paperqa/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .client_models import MetadataPostProcessor, MetadataProvider
from .crossref import CrossrefProvider
from .journal_quality import JournalQualityPostProcessor
from .retractions import RetrationDataPostProcessor
from .retractions import RetractionDataPostProcessor
from .semantic_scholar import SemanticScholarProvider
from .unpaywall import UnpaywallProvider

Expand All @@ -29,7 +29,7 @@
ALL_CLIENTS: Collection[type[MetadataPostProcessor | MetadataProvider]] = {
*DEFAULT_CLIENTS,
UnpaywallProvider,
RetrationDataPostProcessor,
RetractionDataPostProcessor,
}


Expand Down Expand Up @@ -89,22 +89,39 @@ def __init__( # pylint: disable=dangerous-default-value
self.tasks.append(
DocMetadataTask(
providers=[
c() for c in sub_clients if issubclass(c, MetadataProvider)
c if isinstance(c, MetadataProvider) else c()
for c in sub_clients
if (isinstance(c, type) and issubclass(c, MetadataProvider))
or isinstance(c, MetadataProvider)
],
processors=[
c()
c if isinstance(c, MetadataPostProcessor) else c()
for c in sub_clients
if issubclass(c, MetadataPostProcessor)
if (
isinstance(c, type)
and issubclass(c, MetadataPostProcessor)
)
or isinstance(c, MetadataPostProcessor)
],
)
)
# otherwise, we are a flat collection
if not self.tasks and all(not isinstance(c, Collection) for c in clients):
self.tasks.append(
DocMetadataTask(
providers=[c() for c in clients if issubclass(c, MetadataProvider)], # type: ignore[operator, arg-type]
providers=[
c if isinstance(c, MetadataProvider) else c() # type: ignore[redundant-expr]
for c in clients
if (isinstance(c, type) and issubclass(c, MetadataProvider))
or isinstance(c, MetadataProvider)
],
processors=[
c() for c in clients if issubclass(c, MetadataPostProcessor) # type: ignore[operator, arg-type]
c if isinstance(c, MetadataPostProcessor) else c() # type: ignore[redundant-expr]
for c in clients
if (
isinstance(c, type) and issubclass(c, MetadataPostProcessor)
)
or isinstance(c, MetadataPostProcessor)
],
)
)
Expand Down
2 changes: 1 addition & 1 deletion paperqa/clients/retractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logger = logging.getLogger(__name__)


class RetrationDataPostProcessor(MetadataPostProcessor[DOIQuery]):
class RetractionDataPostProcessor(MetadataPostProcessor[DOIQuery]):
def __init__(self, retraction_data_path: os.PathLike | str | None = None) -> None:

if retraction_data_path is None:
Expand Down
Loading

0 comments on commit 7aa7fda

Please sign in to comment.