-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add layer * remove unused vila pred * add layer impl * remove ANnotation; migrate code to Entity * remove all occurrences of Annotation in favor of Entity
- Loading branch information
Showing
18 changed files
with
261 additions
and
245 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 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
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,43 @@ | ||
""" | ||
Layers are collections of Entities. Supports indexing and slicing. | ||
@kylel | ||
""" | ||
|
||
from typing import List | ||
|
||
from .entity import Entity | ||
|
||
|
||
class Layer: | ||
"""Views into a document. Immutable. Lightweight.""" | ||
|
||
__slots__ = ["entities"] | ||
|
||
def __init__(self, entities: List[Entity]): | ||
self.entities = entities | ||
|
||
def __repr__(self): | ||
entity_repr = "\n".join([f"\t{e}" for e in self.entities]) | ||
return f"Layer with {len(self)} Entities:\n{entity_repr}" | ||
|
||
def __getitem__(self, key): | ||
return self.entities[key] | ||
|
||
def __len__(self): | ||
return len(self.entities) | ||
|
||
def __iter__(self): | ||
return iter(self.entities) | ||
|
||
def __contains__(self, item): | ||
return item in self.entities | ||
|
||
def to_json(self): | ||
return [entity.to_json() for entity in self.entities] | ||
|
||
@classmethod | ||
def from_json(cls, layer_json): | ||
return cls(entities=[Entity.from_json(entity_json) for entity_json in layer_json]) |
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
Oops, something went wrong.