Browse Source

fix: update Feature.__repr__ & add __eq__

Problems fixed:

 - Feature repr did not include feature_extractor since that API was changed
 - Intervals that were equivalent were not equal, so Features were not properly
   sorted or equal
main
Rob Hallam 3 months ago
parent
commit
eaafb43a35
1 changed files with 10 additions and 1 deletions
  1. +10
    -1
      pipeline/utils.py

+ 10
- 1
pipeline/utils.py View File

@@ -179,6 +179,9 @@ class Interval():
return self.end < other.end return self.end < other.end
return self.start < other.start return self.start < other.start


def __eq__(self, other):
return self.start == other.start and self.end == other.end

def to_json(self): def to_json(self):
"""Return a dict representation of the interval for JSON encoding """Return a dict representation of the interval for JSON encoding


@@ -268,7 +271,7 @@ class Feature():
feature_extractor=feature_extractor, score=score) feature_extractor=feature_extractor, score=score)


def __repr__(self): def __repr__(self):
return f"Feature({self.interval}, {self.source}, {self.score})"
return f"Feature({self.interval}, {self.source}, {self.feature_extractor}, {self.score})"


def __lt__(self, other): def __lt__(self, other):
"""Sort based on interval, then feature_extractor, then score""" """Sort based on interval, then feature_extractor, then score"""
@@ -278,6 +281,12 @@ class Feature():
return self.feature_extractor < other.feature_extractor return self.feature_extractor < other.feature_extractor
return self.interval < other.interval return self.interval < other.interval


def __eq__(self, other):
return self.interval == other.interval \
and self.source == other.source \
and self.feature_extractor == other.feature_extractor \
and self.score == other.score

def to_json(self): def to_json(self):
"""Return a dict representation of the feature for JSON encoding """Return a dict representation of the feature for JSON encoding




Loading…
Cancel
Save