-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add abstract base class for scoring methods (#247)
* change staticmethod to classmethod for `setup` method * change `ScoringMethod` to abstract base class and rename it * update the use of the new `ScoringBase` class
- Loading branch information
1 parent
7a96b1c
commit 3de97c1
Showing
7 changed files
with
100 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from .abc import ScoringBase | ||
from .link_collection import LinkCollection | ||
from .metcalf_scoring import MetcalfScoring | ||
from .methods import ScoringMethod | ||
from .object_link import ObjectLink | ||
|
||
|
||
__all__ = ["LinkCollection", "MetcalfScoring", "ScoringMethod", "ObjectLink"] | ||
__all__ = ["LinkCollection", "MetcalfScoring", "ScoringBase", "ObjectLink"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from __future__ import annotations | ||
import logging | ||
from abc import ABC | ||
from abc import abstractmethod | ||
from typing import TYPE_CHECKING | ||
|
||
|
||
if TYPE_CHECKING: | ||
from nplinker import NPLinker | ||
from . import LinkCollection | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ScoringBase(ABC): | ||
"""Abstract base class of scoring methods. | ||
Attributes: | ||
name: The name of the scoring method. | ||
npl: The NPLinker object. | ||
""" | ||
|
||
name: str = "ScoringBase" | ||
|
||
def __init__(self, npl: NPLinker): | ||
"""Initialize the scoring method. | ||
Args: | ||
npl: The NPLinker object. | ||
""" | ||
self.npl = npl | ||
|
||
@classmethod | ||
@abstractmethod | ||
def setup(cls, npl: NPLinker): | ||
"""Setup class level attributes.""" | ||
|
||
@abstractmethod | ||
def get_links(self, *objects, link_collection: LinkCollection) -> LinkCollection: | ||
"""Get links information for the given objects. | ||
Args: | ||
objects: A set of objects. | ||
link_collection: The LinkCollection object. | ||
Returns: | ||
The LinkCollection object. | ||
""" | ||
|
||
@abstractmethod | ||
def format_data(self, data) -> str: | ||
"""Format the scoring data to a string.""" | ||
|
||
@abstractmethod | ||
def sort(self, objects, reverse=True) -> list: | ||
"""Sort the given objects based on the scoring data.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters