| 1 | from .entity import Entity |
| 2 | |
| 3 | # Represents an ontolegy relation |
| 4 | # A relation is composed of: |
| 5 | # 1. name |
| 6 | # 2. src entity |
| 7 | # 3. destination entity |
| 8 | class Relation(object): |
| 9 | def __init__(self, name:str, src:Entity, dest:Entity): |
| 10 | # Validate arguments |
| 11 | if not isinstance(name, str) or name == "": |
| 12 | raise Exception("Relation name must be a none empty string") |
| 13 | if not isinstance(src, Entity): |
| 14 | raise Exception("src must be am entity") |
| 15 | if not isinstance(dest, Entity): |
| 16 | raise Exception("dest must be am entity") |
| 17 | |
| 18 | self.src = src |
| 19 | self.dest = dest |
| 20 | self.name = name |
| 21 | |
| 22 | def __eq__(self, other) -> bool: |
| 23 | if not isinstance(other, Relation): |
| 24 | return False |
| 25 | |
| 26 | return (self.src == other.src and |
| 27 | self.dest == other.dest and |
| 28 | self.name == other.name) |