-
Notifications
You must be signed in to change notification settings - Fork 5
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 #30 from Accenture/develop
feat: unify apis for relationships
- Loading branch information
Showing
8 changed files
with
180 additions
and
166 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
Large diffs are not rendered by default.
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
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,51 +1,45 @@ | ||
|
||
|
||
|
||
def related(self, label: str, ref_name: str = None, properties: dict = None, **kwargs): | ||
return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, **kwargs)) | ||
def related(self, label: str, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): | ||
return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, min_hops, max_hops, **kwargs)) | ||
|
||
|
||
def related_to(self, label: str, ref_name: str = None, properties: str = {}, **kwargs): | ||
return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, **kwargs)) | ||
def related_to(self, label: str, ref_name: str = None, properties: str = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): | ||
return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, min_hops, max_hops, **kwargs)) | ||
|
||
|
||
def related_from(self, label: str, ref_name: str = None, properties: str = {}, **kwargs): | ||
return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, **kwargs)) | ||
def related_from(self, label: str, ref_name: str = None, properties: str = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): | ||
return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, min_hops, max_hops, **kwargs)) | ||
|
||
|
||
def related_variable_len(self, label: str, ref_name: str = None, min_hops: int = -1, max_hops: int = -1): | ||
def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: str = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): | ||
min_hops_str = '' if min_hops == -1 else str(min_hops) | ||
max_hops_str = '' if max_hops == -1 else str(max_hops) | ||
|
||
relation_type = '' if label is None else f': {label}' | ||
relation_ref_name = '' if ref_name is None else f'{ref_name}' | ||
|
||
relation_length = '*' if min_hops == -1 and max_hops == -1 else (f'*{min_hops_str}'if min_hops == max_hops else f'*{min_hops_str}..{max_hops_str}') | ||
|
||
if relation_length: | ||
realtion_str = f'[{relation_ref_name}{relation_type}{relation_length}]' | ||
else: | ||
realtion_str = '' | ||
|
||
return RelationAvailable(self.query + f'-{realtion_str}-') | ||
|
||
|
||
def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: str = {}, **kwargs): | ||
relation_type = '' if label is None else f': {label}' | ||
relation_ref_name = '' if ref_name is None else f'{ref_name}' | ||
relation_properties = f' {{{Properties(properties).to_str(**kwargs)}}}' if properties else '' | ||
|
||
if relation_ref_name or relation_type: | ||
realtion_str = f'[{relation_ref_name}{relation_type}{relation_properties}]' | ||
if min_hops == 1 and max_hops == 1: | ||
relation_length = '' | ||
elif min_hops == -1 and max_hops == -1: | ||
relation_length = '*' | ||
elif min_hops == max_hops: | ||
relation_length = f'*{min_hops_str}' | ||
else: | ||
relation_length = f'*{min_hops_str}..{max_hops_str}' | ||
|
||
if relation_ref_name or relation_type or relation_length or relation_properties: | ||
relation_str = f'[{relation_ref_name}{relation_type}{relation_length}{relation_properties}]' | ||
else: | ||
realtion_str = '' | ||
relation_str = '' | ||
|
||
if direction == 'forward': | ||
return f'-{realtion_str}->' | ||
return f'-{relation_str}->' | ||
if direction == 'backward': | ||
return f'<-{realtion_str}-' | ||
return f'<-{relation_str}-' | ||
|
||
return f'-{realtion_str}-' | ||
return f'-{relation_str}-' | ||
|
||
|
||
__all__ = ['related', 'related_to', 'related_from', '_directed_relation'] |
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,3 +1,3 @@ | ||
"""Version information for Cymple""" | ||
|
||
__version__: str = "0.9.0" | ||
__version__: str = "0.10.0" |
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