def handle_triple(self, document, source_type, prop, target_type): super(CreateStrategy, self).handle_triple(document, source_type, prop, target_type) target_prefix, target_type = split_prefixed_name(target_type) if target_prefix is None: if target_type not in document.type_definitions and target_type not in VALUE_TYPE_NAMES: document.type_definitions[target_type] = odml2.TypeDef(target_type) else: _get_type_definition(document, target_prefix, target_type) prop_prefix, prop = split_prefixed_name(prop) if prop_prefix is None: full_target_type = join_prefixed_name(target_prefix, target_type) if prop not in document.property_definitions: document.property_definitions[prop] = odml2.PropertyDef(prop, types={full_target_type}) else: prop_def = document.property_definitions[prop] prop_def.copy(types=prop_def.types | {full_target_type}) document.property_definitions[prop] = prop_def else: _get_prop_definition(document, prop_prefix, prop) source_prefix, source_type = split_prefixed_name(source_type) if source_prefix is None: full_prop_name = join_prefixed_name(prop_prefix, prop) if source_type not in document.type_definitions: document.type_definitions[source_type] = odml2.TypeDef(source_type, properties={full_prop_name}) else: source_def = document.type_definitions[source_type] source_def = source_def.copy(properties=source_def.properties | {full_prop_name}) document.type_definitions[source_type] = source_def else: _get_type_definition(document, source_prefix, source_type)
def handle_triple(self, document, source_type, prop, target_type): super(StrictStrategy, self).handle_triple(document, source_type, prop, target_type) source_prefix, source_type = split_prefixed_name(source_type) source_def = _get_type_definition(document, source_prefix, source_type) property_prefix, prop = split_prefixed_name(prop) if prop not in source_def.properties: raise ValueError("The property '%s' is not defined for type '%s'" % (prop, join_prefixed_name(source_prefix, source_type))) property_def = _get_prop_definition(document, property_prefix, prop) target_prefix, target_type = split_prefixed_name(target_type) if target_type not in property_def.types: raise ValueError("The type '%s' is not defined for property '%s'" % (target_type, join_prefixed_name(property_prefix, prop)))
def find_section_and_prefix(self, uuid, search_namespaces=False): """ Find a :class:`~.Section` and its namespace within the document and associated documents. :param uuid: The UUID of the section :type uuid: str :param search_namespaces: If True also search in other namespaces. :type search_namespaces: bool :return: The section with its namespace or None """ document, prefix, is_link = None, None, False if uuid in self.back_end.sections: document = self elif search_namespaces: p, uuid = split_prefixed_name(uuid) if p is None: for ns in self.namespaces.values(): tmp = ns.get_document() if uuid in tmp.back_end.sections: document, prefix, is_link = tmp, ns.prefix, True break if p in self.namespaces: tmp = self.namespaces[p].get_document() if uuid in tmp.back_end.sections: document, prefix, is_link = tmp, p, True if document is not None: return odml2.Section(uuid, document), prefix else: return None, None
def handle_type(self, document, type): super(CreateStrategy, self).handle_type(document, type) prefix, type = split_prefixed_name(type) if prefix is None: if type not in document.type_definitions: document.type_definitions[type] = odml2.TypeDef(type) else: _get_type_definition(document, prefix, type)
def handle_type(self, document, type): super(StrictStrategy, self).handle_type(document, type) prefix, type = split_prefixed_name(type) _get_type_definition(document, prefix, type)