-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clinton/ed 448/sdk html and text #820
Changes from all commits
8047030
53fa0d8
6debbe8
d726863
4830734
a9fc54f
e0ba8d1
8690215
b3047d2
c5d32c4
b27a0f0
c7826e7
3a9aa3a
e86bdc0
100ed74
913f4cc
a46e751
362f166
510b9aa
973bc1a
3143c2b
c349686
93c68e2
97583a2
ccfeffd
93e3754
a358161
3a10a64
dfd120a
d692729
dd233f8
4add650
8550067
1511203
ea71694
32348fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
--- | ||
title: "Objects - HTML Node" | ||
slug: "sdk-ref-objects-html-node" | ||
hidden: false | ||
metadata: | ||
title: "Objects - HTML Node" | ||
description: "Encord SDK Objects - HTML Node." | ||
category: "64e481b57b6027003f20aaa0" | ||
--- | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Collection, List, Union, cast | ||
|
||
from encord.orm.base_dto import BaseDTO | ||
|
||
|
||
class HtmlNode(BaseDTO): | ||
""" | ||
A class representing a single HTML node, with the node and offset. | ||
|
||
Attributes: | ||
node (str): The xpath of the node | ||
offset (int): The offset of the content from the xpath | ||
""" | ||
|
||
node: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the actual Worried it might be confusing to have it called "node" in the exports and in our DB, but then have it called "xpath" here in this one place. |
||
offset: int | ||
|
||
def __repr__(self): | ||
return f"(Node: {self.node} Offset: {self.offset})" | ||
|
||
|
||
class HtmlRange(BaseDTO): | ||
""" | ||
A class representing a section of HTML with a start and end node. | ||
|
||
Attributes: | ||
start (HtmlNode): The starting node of the range. | ||
end (HtmlNode): The ending node of the range. | ||
""" | ||
|
||
start: HtmlNode | ||
end: HtmlNode | ||
|
||
def __repr__(self): | ||
return f"({self.start} - {self.end})" | ||
|
||
def to_dict(self): | ||
return { | ||
"start": {"node": self.start.node, "offset": self.start.offset}, | ||
"end": {"node": self.end.node, "offset": self.end.offset}, | ||
} | ||
|
||
def __hash__(self): | ||
return f"{self.start.node}-{self.start.offset}-{self.end.node}-{self.end.offset}" | ||
|
||
@classmethod | ||
def from_dict(cls, d: dict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can use this method to be able to construct TextCoordinates.range_html from a dict rather than having to import HtmlRange & HtmlNode? |
||
return HtmlRange( | ||
start=HtmlNode(node=d["start"]["node"], offset=d["start"]["offset"]), | ||
end=HtmlNode(node=d["end"]["node"], offset=d["end"]["offset"]), | ||
) | ||
|
||
|
||
HtmlRanges = List[HtmlRange] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be reasonable to expect
label_row.add_classification_instance(cls_instance)
to work for text/html/audio without having to callcls_instance.set_for_frames
, given that we only support global classifications for these?