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

Fix bug with unknown_conforms_to message when running tutorial. #43

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion linkml_owl/dumpers/owl_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
OP_KEY = Tuple[LEVEL, OPERAND, AXIOM_TYPE_NAME]


def _skip_key_in_element(k: str, element: YAMLRoot) -> bool:
return k.startswith("unknown_") and k.replace("unknown_", "") in vars(element)

@dataclass
class EntityAxiomIndex:
"""
Expand Down Expand Up @@ -248,10 +251,12 @@ def transform(self, element: YAMLRoot, schema: SchemaDefinition, is_element_an_o
unprocessed_parents = []
# set subj = IRI for element
for k, v in vars(element).items():
if _skip_key_in_element(k, element):
continue
slot: SlotDefinition
slot = self._lookup_slot(c, k)
if slot is None:
raise ValueError(f'Lookup slot in {c.name} failed for {k} // element={element}')
raise ValueError(f'Cannot find slot {c.name}.{k} // {vars(element)} element={element}')
if slot.identifier:
subj = URIRef(self._get_IRI_str(v))
logging.debug(f"set subj from {slot.name}={v} asURI: {subj}")
Expand All @@ -275,6 +280,8 @@ def transform(self, element: YAMLRoot, schema: SchemaDefinition, is_element_an_o
# iterate through all slot-value assignments for element;
# generate axioms or add axioms to EntityAxiomIndex for each
for k, v in vars(element).items():
if _skip_key_in_element(k, element):
continue
slot: SlotDefinition
# TODO: unify slot/schema_level_slot
slot = self._lookup_slot(c, k)
Expand Down Expand Up @@ -518,6 +525,9 @@ def _instance_of_linkml_class(self, v) -> bool:
return False

def _lookup_slot(self, cls: ClassDefinition, field: str) -> SlotDefinition:
"""
Lookup a slot in a class by name
"""
matching_slot = None
for s in self.schemaview.class_induced_slots(cls.name):
if underscore(s.name) == field:
Expand Down Expand Up @@ -798,6 +808,13 @@ def cli(inputfile: str, schema: str, target_class, module, output, output_type,
https://linkml.io/linkml-owl/
"""
logger = logging.getLogger()
# Set handler for the root logger to output to the console
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
# Clear existing handlers to avoid duplicate messages if function runs multiple times
logger.handlers = []
# Add the newly created console handler to the logger
logger.addHandler(console_handler)
if verbose >= 2:
logger.setLevel(level=logging.DEBUG)
elif verbose == 1:
Expand All @@ -806,6 +823,7 @@ def cli(inputfile: str, schema: str, target_class, module, output, output_type,
logger.setLevel(level=logging.WARNING)
if quiet:
logger.setLevel(level=logging.ERROR)
logger.info(f"Loading and compiling schema {schema}")
if module is None:
if schema is None:
raise Exception('must pass one of module OR schema')
Expand All @@ -814,6 +832,7 @@ def cli(inputfile: str, schema: str, target_class, module, output, output_type,
else:
python_module = compile_python(module)
sv = SchemaView(schema)
logger.info(f"Loading {inputfile} into schema {sv.schema.name}")
element = load_structured_file(inputfile, target_class=target_class, python_module=python_module, schemaview=sv, fmt=format)

dumper = OWLDumper()
Expand Down
Loading