Skip to content
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

Add to_list() analogous to to_tree() #79

Merged
merged 29 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e94735a
add `to_list()` for `TokenTree`
peterr-s May 5, 2023
193fd22
Merge branch 'tree-to-list'
peterr-s Jul 6, 2023
3d80a2a
Bump cryptography from 41.0.0 to 41.0.2
dependabot[bot] Jul 15, 2023
67e2432
Bump pygments from 2.13.0 to 2.15.0
dependabot[bot] Jul 20, 2023
4d51d48
Bump certifi from 2022.12.7 to 2023.7.22
dependabot[bot] Jul 25, 2023
b524d02
Bump cryptography from 41.0.2 to 41.0.3
dependabot[bot] Aug 2, 2023
41a48e1
Bump cryptography from 41.0.3 to 41.0.4
dependabot[bot] Sep 21, 2023
2fdca06
Bump urllib3 from 1.26.13 to 1.26.17
dependabot[bot] Oct 3, 2023
537e304
Bump urllib3 from 1.26.17 to 1.26.18
dependabot[bot] Oct 18, 2023
3f7a0e9
Bump cryptography from 41.0.4 to 41.0.6
dependabot[bot] Nov 29, 2023
0a1c9d4
Bump cryptography from 41.0.6 to 42.0.0
dependabot[bot] Feb 6, 2024
065c5b8
Bump cryptography from 42.0.0 to 42.0.2
dependabot[bot] Feb 17, 2024
b565c08
Bump cryptography from 42.0.2 to 42.0.4
dependabot[bot] Feb 21, 2024
a1474c5
Bump idna from 3.4 to 3.7
dependabot[bot] Apr 12, 2024
1feaac9
---
dependabot[bot] May 21, 2024
e0d5bb0
Bump urllib3 from 1.26.18 to 1.26.19
dependabot[bot] Jun 18, 2024
bd6d3f1
Bump zipp from 3.11.0 to 3.19.1
dependabot[bot] Jul 9, 2024
bbd7e2e
Bump certifi from 2023.7.22 to 2024.7.4
dependabot[bot] Jul 6, 2024
2be49b9
Add .python-version to gitignore.
EmilStenstrom Jul 12, 2024
44fcd39
Downgrade virtualenv for python 3.6 support.
EmilStenstrom Jul 12, 2024
fba0d14
Upgrade all dev the dependencies.
EmilStenstrom Jul 12, 2024
afcbb2f
Test in 3.11 and 3.12 too.
EmilStenstrom Jul 12, 2024
5c1e9f8
Upgrade to latest versions of github actions.
EmilStenstrom Jul 12, 2024
c09fbb3
Convert to pyproject.toml instead of setup.py.
EmilStenstrom Jul 12, 2024
1225e0d
Seems I need isolated build for pyproject.
EmilStenstrom Jul 12, 2024
a4995ec
Add py310 and fail on no env.
EmilStenstrom Jul 12, 2024
bac045f
Don't move isolated build.
EmilStenstrom Jul 12, 2024
1493d6c
Put envs on separate lines and match GHA versions.
EmilStenstrom Jul 12, 2024
73ae932
Replace custom test runner with pytest.
EmilStenstrom Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
python -m pip install tox tox-gh-actions
- name: Run tests
run: |
tox
run: tox
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.tox
/build
/dist
.python-version
23 changes: 13 additions & 10 deletions conllu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,26 @@ def __eq__(self, other: T.Any) -> bool:
and self.metadata == other.metadata
return False

def serialize(self) -> str:
if not self.token or "id" not in self.token:
raise ParseException("Could not serialize tree, missing 'id' field.")

def flatten_tree(root_token: TokenTree, token_list: T.List[Token] = []) -> T.List[Token]:
def to_list(self):
def _to_list(root_token: TokenTree, token_list: T.List[Token] = []) -> T.List[Token]:
token_list.append(root_token.token)

for child_token in root_token.children:
flatten_tree(child_token, token_list)
_to_list(child_token, token_list)

return token_list

tokens = flatten_tree(self)
tokens = sorted(tokens, key=lambda t: t['id'])
tokenlist = TokenList(tokens, self.metadata)
if not self.token or "id" not in self.token:
raise ParseException("Could not flatten tree; missing 'id' field.")

return serialize(tokenlist)
token_list = _to_list(self)
token_list = sorted(token_list, key=lambda t: t['id'])
token_list = TokenList(token_list, self.metadata)

return token_list

def serialize(self) -> str:
return serialize(self.to_list())

def print_tree(self, depth: int = 0, indent: int = 4,
exclude_fields: T.Sequence[str] = DEFAULT_EXCLUDE_FIELDS) -> None:
Expand Down
67 changes: 67 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "conllu"
version = "4.5.3"
description = "CoNLL-U Parser parses a CoNLL-U formatted string into a nested python dictionary"
readme = "README.md"
requires-python = ">=3.6"
authors = [{name = "Emil Stenström", email = "emil@emilstenstrom.se"}]
license = {file = "LICENSE"}
keywords = ["conllu", "conll", "conll-u", "parser", "nlp"]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://github.com/EmilStenstrom/conllu/"

[project.optional-dependencies]
test = ["tox"]

[tool.setuptools.packages.find]
where = ["conllu"]
include = ["conllu"]

[tool.setuptools.package-data]
"conllu" = ["py.typed"]

[tool.pytest.ini_options]
markers = [
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
]
[tool.flake8]
ignore = "E302, W503"
max-line-length = 119

[tool.coverage.report]
fail_under = 100
exclude_lines = [
"pragma: no cover",
"def __repr__",
'if T\.TYPE_CHECKING',
'TT\.Protocol',
]

[tool.coverage.run]
branch = true
source = ["conllu"]
omit = [
"conllu/__init__.py",
]

[tool.isort]
line_length = 119
multi_line_output = 5
include_trailing_comma = true
known_first_party = ["conllu", "tests"]
1 change: 1 addition & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage
flake8
flake8-pyproject
isort
mypy
pip-tools
Expand Down
130 changes: 68 additions & 62 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,140 +1,146 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements-dev.in
#
attrs==22.2.0
# via pytest
bleach==5.0.1
# via readme-renderer
build==0.9.0
build==1.2.1
# via pip-tools
cachetools==5.2.0
cachetools==5.3.3
# via tox
certifi==2022.12.7
certifi==2024.7.4
# via requests
cffi==1.15.1
cffi==1.16.0
# via cryptography
chardet==5.1.0
chardet==5.2.0
# via tox
charset-normalizer==2.1.1
charset-normalizer==3.3.2
# via requests
click==8.1.3
click==8.1.7
# via pip-tools
colorama==0.4.6
# via tox
commonmark==0.9.1
# via rich
coverage==7.0.1
coverage==7.6.0
# via -r requirements-dev.in
cryptography==41.0.0
cryptography==42.0.8
# via secretstorage
distlib==0.3.6
distlib==0.3.8
# via virtualenv
docutils==0.19
docutils==0.21.2
# via readme-renderer
filelock==3.8.2
filelock==3.15.4
# via
# tox
# virtualenv
flake8==6.0.0
flake8==7.1.0
# via
# -r requirements-dev.in
# flake8-pyproject
flake8-pyproject==1.2.3
# via -r requirements-dev.in
idna==3.4
idna==3.7
# via requests
importlib-metadata==5.2.0
# via
# keyring
# twine
iniconfig==1.1.1
importlib-metadata==8.0.0
# via twine
iniconfig==2.0.0
# via pytest
isort==5.11.4
isort==5.13.2
# via -r requirements-dev.in
jaraco-classes==3.2.3
jaraco-classes==3.4.0
# via keyring
jaraco-context==5.3.0
# via keyring
jaraco-functools==4.0.1
# via keyring
jeepney==0.8.0
# via
# keyring
# secretstorage
keyring==23.13.1
keyring==25.2.1
# via twine
markdown-it-py==3.0.0
# via rich
mccabe==0.7.0
# via flake8
more-itertools==9.0.0
# via jaraco-classes
mypy==0.991
mdurl==0.1.2
# via markdown-it-py
more-itertools==10.3.0
# via
# jaraco-classes
# jaraco-functools
mypy==1.10.1
# via -r requirements-dev.in
mypy-extensions==0.4.3
mypy-extensions==1.0.0
# via mypy
packaging==22.0
nh3==0.2.18
# via readme-renderer
packaging==24.1
# via
# build
# pyproject-api
# pytest
# tox
pep517==0.13.0
# via build
pip-tools==6.12.1
pip-tools==7.4.1
# via -r requirements-dev.in
pkginfo==1.9.2
pkginfo==1.10.0
# via twine
platformdirs==2.6.0
platformdirs==4.2.2
# via
# tox
# virtualenv
pluggy==1.0.0
pluggy==1.5.0
# via
# pytest
# tox
pycodestyle==2.10.0
pycodestyle==2.12.0
# via flake8
pycparser==2.21
pycparser==2.22
# via cffi
pyflakes==3.0.1
pyflakes==3.2.0
# via flake8
pygments==2.13.0
pygments==2.18.0
# via
# readme-renderer
# rich
pyproject-api==1.2.1
pyproject-api==1.7.1
# via tox
pytest==7.2.0
pyproject-hooks==1.1.0
# via
# build
# pip-tools
pytest==8.2.2
# via -r requirements-dev.in
readme-renderer==37.3
readme-renderer==44.0
# via twine
requests==2.31.0
requests==2.32.3
# via
# requests-toolbelt
# twine
requests-toolbelt==0.10.1
requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==12.6.0
rich==13.7.1
# via twine
secretstorage==3.3.3
# via keyring
six==1.16.0
# via bleach
tox==4.0.17
tox==4.16.0
# via -r requirements-dev.in
twine==4.0.2
twine==5.1.1
# via -r requirements-dev.in
typing-extensions==4.4.0
typing-extensions==4.12.2
# via mypy
urllib3==1.26.13
urllib3==2.2.2
# via
# requests
# twine
virtualenv==20.17.1
virtualenv==20.26.3
# via tox
webencodings==0.5.1
# via bleach
wheel==0.38.4
wheel==0.43.0
# via
# -r requirements-dev.in
# pip-tools
zipp==3.11.0
zipp==3.19.2
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
Expand Down
Loading