Skip to content

Commit

Permalink
feat: introduce workbook row initialization
Browse files Browse the repository at this point in the history
Create a function to initialize an empty workbook row to be subsequently
filled with content. This provides a foundation for independent
annotation operations without relying on an existing workbook,
addressing scenarios where a new workbook row needs to be created from
scratch.

Currently, annotators create rows of annotation data by copying from an
existing workbook then modifying the rows contents.
  • Loading branch information
clnsmth authored Oct 24, 2024
1 parent b06ae95 commit 4cd6858
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/spinneret/workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,35 @@ def get_description(element: etree._Element) -> str:
else:
description = None
return description


def list_workbook_columns() -> list:
"""
:returns: A list of the columns in the workbook.
"""
res = [
"package_id",
"url",
"element",
"element_id",
"element_xpath",
"context",
"description",
"subject",
"predicate",
"predicate_id",
"object",
"object_id",
"author",
"date",
"comment",
]
return res


def initialize_workbook_row() -> pd.core.series.Series:
"""Initialize a row for the annotation workbook
:returns: A pandas Series with the initialized row
"""
row = dict.fromkeys(list_workbook_columns(), "")
return pd.Series(row)
21 changes: 20 additions & 1 deletion tests/test_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from lxml import etree
from spinneret import workbook
from spinneret import datasets
from spinneret.workbook import get_description
from spinneret.workbook import (
get_description,
initialize_workbook_row,
list_workbook_columns,
)


def test_create():
Expand Down Expand Up @@ -73,3 +77,18 @@ def test_get_description_handles_missing_element():
# Test element with missing abstract
description = get_description(element)
assert description == ""


def test_list_workbook_columns():
"""Test the list_workbook_columns function"""
res = list_workbook_columns()
assert isinstance(res, list)
assert len(res) > 0


def test_initialize_workbook_row():
"""Test the initialize_workbook_row function"""
res = initialize_workbook_row()
assert isinstance(res, pd.core.series.Series)
assert res.index.to_list() == list_workbook_columns()
assert res.to_list() == [""] * len(res)

0 comments on commit 4cd6858

Please sign in to comment.