def BuildUniverse():
    """Generates the ontology universe.

  Returns:
    Generated universe object.
  """

    ontology_validator_exists = path.exists(
        path.join('..', 'ontology_validator'))
    ontology_exists = path.exists(path.join('..', '..', '..', 'ontology'))

    if not (ontology_validator_exists and ontology_exists):
        print('ERROR: ontology validator or ontology have changed locations')
        return None

    yaml_files = external_file_lib.RecursiveDirWalk(
        path.join('..', '..', '..', 'ontology', 'yaml', 'resources'))
    config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
    universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe
Ejemplo n.º 2
0
def BuildUniverse(
    use_simplified_universe: bool = False,
    modified_types_filepath: str = None,
) -> presubmit_validate_types_lib.ConfigUniverse:
    """Generates the ontology universe.

  Args:
    use_simplified_universe: boolean to quick load minimal universe instead of
      full ontology
    modified_types_filepath: filepath to the modified ontology types

  Returns:
    Generated universe object.
  """
    if use_simplified_universe:
        yaml_files = None
        universe = universe_helper.create_simplified_universe()
    elif modified_types_filepath:
        modified_ontology_exists = path.exists(modified_types_filepath)
        if not modified_ontology_exists:
            print(f'Specified filepath [{modified_types_filepath}] '
                  'modified ontology does not exist')
            return None

        modified_types_filepath = path.expanduser(modified_types_filepath)

        external_file_lib.Validate(filter_text=None,
                                   changed_directory=modified_types_filepath,
                                   original_directory=constants.ONTOLOGY_ROOT,
                                   interactive=False)
        yaml_files = external_file_lib.RecursiveDirWalk(
            modified_types_filepath)
    else:
        default_ontology_exists = path.exists(constants.ONTOLOGY_ROOT)
        if not default_ontology_exists:
            print(f'Specified filepath [{constants.ONTOLOGY_ROOT}] '
                  'for default ontology does not exist')
            return None
        # use default location for ontology files
        yaml_files = external_file_lib.RecursiveDirWalk(
            constants.ONTOLOGY_ROOT)

    if yaml_files:
        config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
        universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe
def BuildUniverse(
    modified_types_filepath: str = None
) -> presubmit_validate_types_lib.ConfigUniverse:
    """Generates the ontology universe.

  Args:
    modified_types_filepath: filepath to the modified ontology types

  Returns:
    Generated universe object.
  """
    if modified_types_filepath:
        modified_ontology_exists = path.exists(modified_types_filepath)
        if not modified_ontology_exists:
            print('Specified filepath [{0}] modified ontology does not exist'.
                  format(modified_types_filepath))
            return None

        modified_types_filepath = path.expanduser(modified_types_filepath)

        external_file_lib.Validate(filter_text=None,
                                   changed_directory=modified_types_filepath,
                                   original_directory=constants.ONTOLOGY_ROOT,
                                   interactive=False)
        yaml_files = external_file_lib.RecursiveDirWalk(
            modified_types_filepath)
    else:
        default_ontology_exists = path.exists(constants.ONTOLOGY_ROOT)
        if not default_ontology_exists:
            print(
                'Specified filepath [{0}] for default ontology does not exist'.
                format(constants.ONTOLOGY_ROOT))
            return None
        # use default location for ontology files
        yaml_files = external_file_lib.RecursiveDirWalk(
            constants.ONTOLOGY_ROOT)

    config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
    universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe
Ejemplo n.º 4
0
 def setUp(self):
   super(ModelTest).setUp()
   self.yaml = RecursiveDirWalk(test_constants.ONTOLOGY_ROOT)
   self.config = presubmit_validate_types_lib.SeparateConfigFiles(self.yaml)
   self.universe = presubmit_validate_types_lib.BuildUniverse(self.config)
   nv.NamespaceValidator(self.universe.GetEntityTypeNamespaces())
   test_entity_type = self.universe.entity_type_universe.GetEntityType(
       namespace_name='HVAC', typename='ZONE_HVAC')
   test_field_list = [
       EntityTypeField(optwrapper.field.namespace, optwrapper.field.field[0:],
                       optwrapper.optional, optwrapper.field.increment)
       for optwrapper in test_entity_type.GetAllFields().values()
   ]
   self.test_match = Match(
       field_list=test_field_list,
       entity_type=test_entity_type,
       match_type='EXACT')
Ejemplo n.º 5
0
def Build(ontology_path: str) -> OntologyWrapper:
    """A constructor for the ontology explorer.

  Args:
    ontology_path: A path for an alternative ontology extended from DBO.

  Returns:
    ontology: An instance of the OntologyWrapper class.
  """
    if ontology_path is not None:
        yaml_file_path = ontology_path
    else:
        yaml_file_path = constants.ONTOLOGY_ROOT
    yaml_files = external_file_lib.RecursiveDirWalk(yaml_file_path)
    config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
    universe = presubmit_validate_types_lib.BuildUniverse(config)
    nv.NamespaceValidator(universe.GetEntityTypeNamespaces())
    ontology = OntologyWrapper(universe)
    return ontology
def BuildUniverse(modified_types_filepath=None):
    """Generates the ontology universe.

  Args:
    modified_types_filepath: filepath to the modified ontology types

  Returns:
    Generated universe object.
  """

    if modified_types_filepath:
        modified_ontology_exists = path.exists(modified_types_filepath)
        if not modified_ontology_exists:
            print('Specified filepath for modified ontology does not exist')
            return None

        modified_types_filepath = path.expanduser(modified_types_filepath)

        external_file_lib.Validate(filter_text=None,
                                   changed_directory=modified_types_filepath,
                                   original_directory=path.join(
                                       '..', '..', '..', 'ontology', 'yaml',
                                       'resources'),
                                   interactive=False)
        yaml_files = external_file_lib.RecursiveDirWalk(
            modified_types_filepath)
    else:
        # use default location for ontology files
        yaml_files = external_file_lib.RecursiveDirWalk(
            path.join('..', '..', '..', 'ontology', 'yaml', 'resources'))

    config = presubmit_validate_types_lib.SeparateConfigFiles(yaml_files)
    universe = presubmit_validate_types_lib.BuildUniverse(config)

    namespace_validation = namespace_validator.NamespaceValidator(
        universe.GetEntityTypeNamespaces())

    if not namespace_validation.IsValid():
        print('Universe is not valid')
        return None

    return universe