-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
38 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 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,36 +1,36 @@ | ||
from collections import deque | ||
# from collections import deque | ||
|
||
from tekst.models.text import NodeDocument, TextDocument, TextRead | ||
# from tekst.models.text import NodeDocument, TextDocument, TextRead | ||
|
||
|
||
async def import_text(data: dict) -> TextRead | None: | ||
# create and save text object | ||
text = await TextDocument(**data).create() | ||
stack = deque() | ||
positions = [0] | ||
# async def import_text(data: dict) -> TextRead | None: | ||
# # create and save text object | ||
# text = await TextDocument(**data).create() | ||
# stack = deque() | ||
# positions = [0] | ||
|
||
# push nodes of first structure level onto stack | ||
for node in data.get("nodes", []): | ||
node["parentId"] = None | ||
node["textId"] = text.id | ||
node["level"] = 0 | ||
node["position"] = positions[0] | ||
stack.append(node) | ||
positions[0] += 1 | ||
# # push nodes of first structure level onto stack | ||
# for node in data.get("nodes", []): | ||
# node["parentId"] = None | ||
# node["textId"] = text.id | ||
# node["level"] = 0 | ||
# node["position"] = positions[0] | ||
# stack.append(node) | ||
# positions[0] += 1 | ||
|
||
# process stack | ||
while stack: | ||
node_data = stack.pop() | ||
node = await NodeDocument(**node_data).create() | ||
# # process stack | ||
# while stack: | ||
# node_data = stack.pop() | ||
# node = await NodeDocument(**node_data).create() | ||
|
||
for u in node_data.get("nodes", []): | ||
u["parentId"] = node.id | ||
u["textId"] = text.id | ||
u["level"] = node.level + 1 | ||
if len(positions) <= u["level"]: | ||
positions.append(0) | ||
u["position"] = positions[u["level"]] | ||
positions[u["level"]] += 1 | ||
stack.append(u) | ||
# for u in node_data.get("nodes", []): | ||
# u["parentId"] = node.id | ||
# u["textId"] = text.id | ||
# u["level"] = node.level + 1 | ||
# if len(positions) <= u["level"]: | ||
# positions.append(0) | ||
# u["position"] = positions[u["level"]] | ||
# positions[u["level"]] += 1 | ||
# stack.append(u) | ||
|
||
return text | ||
# return text |
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