code: def monkey_patch_keywords(layer):
      
      keyword_io = KeywordIO()
      try:
          layer.keywords = keyword_io.read_keywords(layer)
      except (NoKeywordsFoundError, MetadataReadError):
          layer.keywords = {}
  
      if not layer.keywords.get('inasafe_fields'):
          layer.keywords['inasafe_fields'] = {}
      if not layer.keywords.get('layer_purpose'):
          layer.keywords['layer_purpose'] = 'undefined'
docs: In InaSAFE V4, we do monkey patching for keywords.
  
      :param layer: The layer to monkey patch keywords.
      :type layer: QgsMapLayer