Skip to content

Commit

Permalink
Fix transform join subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
dalito committed Mar 4, 2024
1 parent ded5b4e commit 612d245
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Change log

## Release 0.8.4 (2024-03-04)

Bug fixes:

- Fix transform join subcommand to produce vocpub-4.7-conform turtle file. #213

## Release 0.8.3 (2024-02-28)

Bug fixes:

- Fix writing to wrong file location for sub-command "join" with "--outbox" option. #211, #212
- Fix writing to wrong file location for sub-command "join" with "--outbox" option. #211, #212
- Fix clearing of cells with hyperlinks in xlsx by openpyxl. #209, #210

## Release 0.8.2 (2024-02-21)
Expand Down
19 changes: 12 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,19 @@ exclude = [
"*.egg",
".*",
]

# Assume Python 3.8
target-version = "py38"

# Same as Black.
line-length = 88

[tool.ruff.lint]

ignore = [
"B905", # zip() without an explicit strict= parameter set. (requires python >= 3.10)
"E501", # line too long
]
# Same as Black.
line-length = 88

# Avoid trying to fix these violations
unfixable = [
Expand Down Expand Up @@ -218,19 +225,17 @@ select = [
# NumPy-specific rules (NPY)
"RUF", # Ruff-specific rules
]
# Assume Python 3.8
target-version = "py38"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*.py" = [
"S101", # assert in tests is OK
]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
# Flake8-mccabe uses a default level of 7, ruff of 10.
max-complexity = 10

[tool.ruff.pep8-naming]
[tool.ruff.lint.pep8-naming]
# Allow Pydantic's `@validator` decorator to trigger class method treatment.
classmethod-decorators = [
"classmethod",
Expand Down
39 changes: 38 additions & 1 deletion src/voc4cat/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import openpyxl
from openpyxl.styles import Alignment
from rdflib import DCTERMS, OWL, RDF, SKOS, XSD, Graph, Literal
from rdflib import DCTERMS, OWL, RDF, SDO, SKOS, XSD, Graph, Literal, URIRef

from voc4cat import config
from voc4cat.checks import Voc4catError
Expand All @@ -19,6 +19,7 @@
dag_to_node_levels,
get_concept_and_level_from_indented_line,
)
from voc4cat.models import ORGANISATIONS
from voc4cat.utils import (
EXCEL_FILE_ENDINGS,
RDF_FILE_ENDINGS,
Expand Down Expand Up @@ -103,6 +104,42 @@ def join_split_turtle(vocab_dir: Path) -> Graph:
):
graph = autoversion_cs(graph)
cs_graph += graph

# TODO The metadata should also be present in a separate ttl-file and
# joined just like the other.
# Newer for vocpub profile require creator_/publisher for vocabulary:
# Requirement 2.1.6 Each vocabulary MUST have at least one creator,
# indicated using sdo:creator or dcterms:creator predicate and exactly
# one publisher, indicated using sdo:publisher or dcterms:publisher,
# all of which MUST be IRIs indicating instances of sdo:Person,
# or sdo:Organization.
# Get the publisher from the first concept scheme
publisher = next(cs_graph.triples((None, DCTERMS.publisher, None)))[2]
tg = Graph()
org = ORGANISATIONS.get(publisher, URIRef(publisher))
tg.add((org, RDF.type, SDO.Organization))
tg.add(
(
org,
SDO.name,
# should be name but there is no field in the template 0.43
Literal(
ORGANISATIONS.get(publisher, publisher),
),
)
)
tg.add(
(
org,
SDO.url,
Literal(
ORGANISATIONS.get(publisher, publisher),
datatype=URIRef(XSD.anyURI),
),
)
)
cs_graph += tg

cs_graph.serialize(destination=vocab_dir.with_suffix(".ttl"), format="turtle")
return cs_graph

Expand Down

0 comments on commit 612d245

Please sign in to comment.