-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from singnet/senna-qe-338-1
[#338] Change get_links() API to use link filters instead of optional parameters
- Loading branch information
Showing
11 changed files
with
160 additions
and
489 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
[#338] Change get_links() API to use link filters instead of optional parameters |
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
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,62 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum, auto | ||
|
||
from hyperon_das_atomdb import WILDCARD | ||
|
||
|
||
class LinkFilterType(int, Enum): | ||
NAMED_TYPE = auto() | ||
FLAT_TYPE_TEMPLATE = auto() | ||
TARGETS = auto() | ||
|
||
|
||
@dataclass | ||
class LinkFilter: | ||
filter_type: LinkFilterType | ||
toplevel_only: bool | ||
link_type: str = None | ||
target_types: list[str] = None | ||
targets: list[str] = None | ||
|
||
|
||
@dataclass | ||
class NamedType(LinkFilter): | ||
""" | ||
All links of a given type. Optionally, only toplevel links are selected. | ||
""" | ||
|
||
def __init__(self, link_type: str, toplevel_only: bool = False): | ||
self.filter_type = LinkFilterType.NAMED_TYPE | ||
self.link_type = link_type | ||
self.toplevel_only = toplevel_only | ||
|
||
|
||
@dataclass | ||
class FlatTypeTemplate(LinkFilter): | ||
""" | ||
All links of a given type whose targets are of given types. Any number of wildcards '*' can | ||
be used as link or target types. | ||
""" | ||
|
||
def __init__( | ||
self, target_types: list[str], link_type: str = WILDCARD, toplevel_only: bool = False | ||
): | ||
|
||
self.filter_type = LinkFilterType.FLAT_TYPE_TEMPLATE | ||
self.link_type = link_type | ||
self.target_types = target_types | ||
self.toplevel_only = toplevel_only | ||
|
||
|
||
@dataclass | ||
class Targets(LinkFilter): | ||
""" | ||
All links of a given type whose targets match a given list of handles. Any number of | ||
wildcards '*' can be used as link type or target handle. | ||
""" | ||
|
||
def __init__(self, targets: list[str], link_type: str = WILDCARD, toplevel_only: bool = False): | ||
self.filter_type = LinkFilterType.TARGETS | ||
self.link_type = link_type | ||
self.targets = targets | ||
self.toplevel_only = toplevel_only |
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
Oops, something went wrong.