How to use the forte.data.ontology.code_generation_exceptions.OntologySpecError function in forte

To help you get started, we’ve selected a few forte examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asyml / forte / forte / data / ontology / ontology_code_generator.py View on Github external
f" ontology."
            )

        if not this_manager.is_imported(parent_entry):
            raise ParentEntryNotDeclaredException(
                f"The parent entry {parent_entry} is not declared. It is "
                f"neither in the base entries nor in custom entries. "
                f"Please check them ontology specification, and make sure the "
                f"entry is defined before this."
            )

        base_entry: Optional[str] = self.find_base_entry(
            entry_name.class_name, parent_entry)

        if base_entry is None:
            raise OntologySpecError(
                f"Cannot find the base entry for entry "
                f"{entry_name.class_name} and {parent_entry}"
            )

        if base_entry not in self.top_init_args:
            raise ParentEntryNotSupportedException(
                f"Cannot add {entry_name.class_name} to the ontology as "
                f"it's parent entry {parent_entry} is not supported. This is "
                f"likely that the entries are not inheriting the allowed types."
            )

        # Take the property definitions of this entry.
        properties: List[Dict] = schema.get(SchemaKeywords.attributes, [])

        this_manager = self.import_managers.get(entry_name.module_name)
github asyml / forte / forte / data / ontology / ontology_code_generator.py View on Github external
Returns:
                Directory path in which the modules are created: either one of
                the temporary directory or `destination_dir`.
        """
        # Update the list of directories to be examined for imported configs
        self.import_dirs.append(os.path.dirname(os.path.realpath(spec_path)))

        merged_schemas: List[Dict] = []

        # Generate ontology classes for the input json config and the configs
        # it is dependent upon.
        try:
            self.parse_ontology_spec(spec_path, destination_dir,
                                     merged_schema=merged_schemas)
        except OntologySpecError:
            logging.error("Error at parsing [%s]", spec_path)
            raise

        # Now generate all data.

        # A temporary directory to save the generated file structure until the
        # generation is completed and verified.
        tempdir = tempfile.mkdtemp()

        # Starting from here, we won't add any more modules to import.
        self.import_managers.fix_all_modules()

        logging.info('Working on %s', spec_path)
        for writer in self.module_writers.writers():
            logging.info('Writing module: %s', writer.module_name)
            writer.write(tempdir, destination_dir, include_init)
github asyml / forte / forte / data / ontology / code_generation_exceptions.py View on Github external
pass


class OntologySourceNotFoundException(OntologySpecError):
    pass


class OntologyAlreadyGeneratedException(OntologySpecError):
    pass


class ParentEntryNotDeclaredException(OntologySpecError):
    pass


class ParentEntryNotSupportedException(OntologySpecError):
    pass


class TypeNotDeclaredException(OntologySpecError):
    pass


class NoDefaultClassAttributeException(OntologySpecError):
    pass


class UnsupportedTypeException(OntologySpecError):
    pass


class InvalidIdentifierException(ValueError):
github asyml / forte / forte / data / ontology / code_generation_exceptions.py View on Github external
pass


class DuplicatedAttributesWarning(OntologyGenerationWarning):
    pass


class OntologySpecError(ValueError):
    pass


class OntologySpecValidationError(OntologySpecError):
    pass


class OntologySourceNotFoundException(OntologySpecError):
    pass


class OntologyAlreadyGeneratedException(OntologySpecError):
    pass


class ParentEntryNotDeclaredException(OntologySpecError):
    pass


class ParentEntryNotSupportedException(OntologySpecError):
    pass


class TypeNotDeclaredException(OntologySpecError):
github asyml / forte / forte / data / ontology / code_generation_exceptions.py View on Github external
pass


class DuplicateEntriesWarning(OntologyGenerationWarning):
    pass


class DuplicatedAttributesWarning(OntologyGenerationWarning):
    pass


class OntologySpecError(ValueError):
    pass


class OntologySpecValidationError(OntologySpecError):
    pass


class OntologySourceNotFoundException(OntologySpecError):
    pass


class OntologyAlreadyGeneratedException(OntologySpecError):
    pass


class ParentEntryNotDeclaredException(OntologySpecError):
    pass


class ParentEntryNotSupportedException(OntologySpecError):
github asyml / forte / forte / data / ontology / code_generation_exceptions.py View on Github external
pass


class ParentEntryNotDeclaredException(OntologySpecError):
    pass


class ParentEntryNotSupportedException(OntologySpecError):
    pass


class TypeNotDeclaredException(OntologySpecError):
    pass


class NoDefaultClassAttributeException(OntologySpecError):
    pass


class UnsupportedTypeException(OntologySpecError):
    pass


class InvalidIdentifierException(ValueError):
    pass


class CodeGenerationException(BaseException):
    pass
github asyml / forte / forte / data / ontology / code_generation_exceptions.py View on Github external
pass


class ParentEntryNotSupportedException(OntologySpecError):
    pass


class TypeNotDeclaredException(OntologySpecError):
    pass


class NoDefaultClassAttributeException(OntologySpecError):
    pass


class UnsupportedTypeException(OntologySpecError):
    pass


class InvalidIdentifierException(ValueError):
    pass


class CodeGenerationException(BaseException):
    pass