Skip to content

Commit

Permalink
Merge pull request #111 from loinc/logging-updates
Browse files Browse the repository at this point in the history
Logging updates
  • Loading branch information
joeflack4 authored Nov 11, 2024
2 parents 0bd8474 + dd14590 commit 16a6a7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions comploinc_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ logging:
level: INFO
handlers: [ console ]
propagate: False
'Module':
level: INFO
handlers: [ console ]
propagate: False
# cli_runtime:
# handlers: [console]
# level: INFO
Expand Down
6 changes: 2 additions & 4 deletions src/comp_loinc/loinc_builder_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,12 @@ def save_to_owl(
] = None,
):
"""Save the current module to an OWL file."""
logger.info(f"Starting save-owl")
logger.info(f"save-owl: Starting")
owl_dumper = OWLDumper()
document = owl_dumper.to_ontology_document(
schema=self.runtime.current_schema_view.schema,
element=list(self.runtime.current_module.get_all_entities()),
)
logger.info(f"save-owl document created.")
document.ontology.iri = funowl.identifiers.IRI(
f"https://comploinc/{self.runtime.current_module.name}"
)
Expand All @@ -808,6 +807,5 @@ def save_to_owl(
owl_file_path.parent.mkdir(parents=True, exist_ok=True)
typer.echo(f"Writing file: {owl_file_path}")
with open(owl_file_path, "w") as f:
logger.info(f"save-owl writing document.")
f.write(str(document))
logger.info(f"save-owl writing document finished.")
logger.info(f"save-owl: Done")
18 changes: 13 additions & 5 deletions src/comp_loinc/module.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""Module: Provided a given builder configuration, set up a module where that build will be encapsulated. """
import logging
import typing as t

import comp_loinc.datamodel.comp_loinc as v2
from comp_loinc.datamodel.comp_loinc import Entity


logger = logging.getLogger("Module")


# class Modules:
# def __init__(self, *,
# graph: nx.MultiDiGraph = nx.MultiDiGraph(),
Expand All @@ -20,41 +25,44 @@


class Module:
"""Module"""
from comp_loinc import Runtime

def __init__(self, *, name: str, runtime: Runtime):
from comp_loinc import Runtime

logger.info(f"Starting: {name}")
self.name = name
self.runtime: Runtime = runtime

self.entities_by_type: t.Dict[t.Type[Entity], t.Dict[str, v2.Entity]] = dict()

# flags for what to include
self._include_loinc_long_common_name = None
self._include_loinc_long_common_name = None # flags for what to include

def get_entity(
self, entity_id: str, entity_class: t.Type[Entity]
) -> t.Optional[Entity]:
"""Get entity"""
return self.entities_by_type.setdefault(entity_class, {}).get(entity_id, None)

def getsert_entity(self, entity_id: str, entity_class: t.Type[Entity]) -> Entity:
"""Get entity, or insert if it doesn't exist"""
entity = self.entities_by_type.setdefault(entity_class, {}).get(entity_id, None)
if entity is None:
entity = entity_class(id=entity_id)
self.add_entity(entity)
return entity

def add_entity(self, entity: Entity, replace: bool = False):
"""Add entity"""
if self.get_entity(entity.id, type(entity)) is not None and not replace:
raise ValueError(f"Replacing entity {entity} not allowed.")
self.entities_by_type.setdefault(type(entity), {})[entity.id] = entity

def get_entities_of_type(self, entity_class: t.Type[Entity]) -> t.Iterator[Entity]:
"""Get entities of type"""
for entity in self.entities_by_type.get(entity_class, {}).values():
yield entity

def get_all_entities(self) -> t.Iterator[Entity]:
"""Get all entities"""
for entity_map in self.entities_by_type.values():
for entity in entity_map.values():
yield entity
Expand Down

0 comments on commit 16a6a7d

Please sign in to comment.