Skip to content

Proposal: make a new dataclass for ontological validation #257

@liamhuber

Description

@liamhuber

I currently have snippets like this running around:

if (
    len(validation["missing_triples"]) > 0
    or len(validation["incompatible_connections"]) > 0
    or len(validation["distinct_units"]) > 0
):

Or, less egregiously, annoying string references like

self.assertEqual(validate_values(graph)["incompatible_connections"], [])

Also, since #255, they type return on ontology.validate_values is extremely vague:

) -> dict[str, Any]:

Let's make a new dataclass to hold the validation like

@dataclass
class Validation:
    missing_triples: list
    incompatible_connections: list
    distinct_units: dict[URIRef, list[URIRef]]

    def valid():
        return not any([
           self.missing_triples,
           self.incompatible_connections,
           self.distinct_units
       ])  # We could iterate over fields, but no need to get fancy yet

    def report():
        return as_dict(self)  # Or a JSON or whatever

Actually, that's basically it, but I want to make sure @samwaseda doesn't hate it before I bother writing tests and adapting all the existing tests.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions