sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
def MapByteStream(self, byte_stream, **unused_kwargs): # pylint: disable=redundant-returns-doc """Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. Returns: object: mapped value. Raises: MappingError: if the data type definition cannot be mapped on ...
Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. Returns: object: mapped value. Raises: MappingError: if the data type definition cannot be mapped on the byte stream.
entailment
def GetName(self, number): """Retrieves the name of an enumeration value by number. Args: number (int): number. Returns: str: name of the enumeration value or None if no corresponding enumeration value was found. """ value = self._data_type_definition.values_per_number.get(nu...
Retrieves the name of an enumeration value by number. Args: number (int): number. Returns: str: name of the enumeration value or None if no corresponding enumeration value was found.
entailment
def CreateDataTypeMap(self, definition_name): """Creates a specific data type map by name. Args: definition_name (str): name of the data type definition. Returns: DataTypeMap: data type map or None if the date type definition is not available. """ data_type_definition = self....
Creates a specific data type map by name. Args: definition_name (str): name of the data type definition. Returns: DataTypeMap: data type map or None if the date type definition is not available.
entailment
def CreateDataTypeMapByType(cls, data_type_definition): """Creates a specific data type map by type indicator. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: DataTypeMap: data type map or None if the date type definition is not available. """ ...
Creates a specific data type map by type indicator. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: DataTypeMap: data type map or None if the date type definition is not available.
entailment
def GetByteSize(self): """Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. """ if self.size == definitions.SIZE_NATIVE or self.units != 'bytes': return None return self.size
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined.
entailment
def GetByteSize(self): """Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. """ if not self.element_data_type_definition: return None if self.elements_data_size: return self.elements_data_size if ...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined.
entailment
def AddMemberDefinition(self, member_definition): """Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition. """ self._byte_size = None self.members.append(member_definition) if self.sections: section_definition = self.sections[-1] ...
Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition.
entailment
def IsComposite(self): """Determines if the data type is composite. A composite data type consists of other data types. Returns: bool: True if the data type is composite, False otherwise. """ return bool(self.condition) or ( self.member_data_type_definition and self.member_da...
Determines if the data type is composite. A composite data type consists of other data types. Returns: bool: True if the data type is composite, False otherwise.
entailment
def GetByteSize(self): """Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. """ if self._byte_size is None and self.members: self._byte_size = 0 for member_definition in self.members: if isinstance(...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined.
entailment
def GetByteSize(self): """Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. """ if self._byte_size is None and self.members: self._byte_size = 0 for member_definition in self.members: byte_size = me...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined.
entailment
def AddValue(self, name, number, aliases=None, description=None): """Adds an enumeration value. Args: name (str): name. number (int): number. aliases (Optional[list[str]]): aliases. description (Optional[str]): description. Raises: KeyError: if the enumeration value already e...
Adds an enumeration value. Args: name (str): name. number (int): number. aliases (Optional[list[str]]): aliases. description (Optional[str]): description. Raises: KeyError: if the enumeration value already exists.
entailment
def AddMemberDefinition(self, member_definition): """Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition. """ self.members.append(member_definition) member_definition.family_definition = self
Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition.
entailment
def parse_series(s): """ Parses things like '1n+2', or 'an+b' generally, returning (a, b) """ if isinstance(s, Element): s = s._format_element() if not s or s == '*': # Happens when there's nothing, which the CSS parser thinks of as * return (0, 0) if isinstance(s, int): ...
Parses things like '1n+2', or 'an+b' generally, returning (a, b)
entailment
def add_star_prefix(self): """ Adds a /* prefix if there is no prefix. This is when you need to keep context's constrained to a single parent. """ if self.path: self.path += '*/' else: self.path = '*/' self.star_prefix = True
Adds a /* prefix if there is no prefix. This is when you need to keep context's constrained to a single parent.
entailment
def _ReadBooleanDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a boolean data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str,...
Reads a boolean data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data typ...
entailment
def _ReadCharacterDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a character data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[...
Reads a character data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data t...
entailment
def _ReadConstantDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a constant data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[st...
Reads a constant data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data ty...
entailment
def _ReadDataTypeDefinition( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supported_definition_values): """Reads a data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. def...
Reads a data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): name of the defini...
entailment
def _ReadDataTypeDefinitionWithMembers( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supports_conditions=False): """Reads a data type definition with members. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions ...
Reads a data type definition with members. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): name ...
entailment
def _ReadEnumerationDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads an enumeration data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (...
Reads an enumeration data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the dat...
entailment
def _ReadElementSequenceDataTypeDefinition( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supported_definition_values): """Reads an element sequence data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definiti...
Reads an element sequence data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): ...
entailment
def _ReadFixedSizeDataTypeDefinition( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supported_attributes, default_size=definitions.SIZE_NATIVE, default_units='bytes', is_member=False, supported_size_values=None): """Reads a fixed-size data type d...
Reads a fixed-size data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): name of...
entailment
def _ReadFloatingPointDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a floating-point data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_valu...
Reads a floating-point data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the d...
entailment
def _ReadFormatDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a format data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, o...
Reads a format data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data type...
entailment
def _ReadIntegerDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads an integer data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str...
Reads an integer data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data ty...
entailment
def _ReadLayoutDataTypeDefinition( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supported_definition_values): """Reads a layout data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions regist...
Reads a layout data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): name of the...
entailment
def _ReadMemberDataTypeDefinitionMember( self, definitions_registry, definition_values, definition_name, supports_conditions=False): """Reads a member data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_val...
Reads a member data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. supports_conditions (Optional[bool]): True if con...
entailment
def _ReadPaddingDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a padding data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str,...
Reads a padding data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data typ...
entailment
def _ReadSemanticDataTypeDefinition( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supported_definition_values): """Reads a semantic data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions re...
Reads a semantic data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): name of t...
entailment
def _ReadSequenceDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a sequence data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[st...
Reads a sequence data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data ty...
entailment
def _ReadStorageDataTypeDefinition( self, definitions_registry, definition_values, data_type_definition_class, definition_name, supported_attributes, is_member=False): """Reads a storage data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions ...
Reads a storage data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. data_type_definition_class (str): data type definition class. definition_name (str): name of th...
entailment
def _ReadStreamDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a stream data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, o...
Reads a stream data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data type...
entailment
def _ReadStringDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a string data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, o...
Reads a string data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data type...
entailment
def _ReadStructureDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a structure data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[...
Reads a structure data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data t...
entailment
def _ReadStructureFamilyDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads a structure family data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_...
Reads a structure family data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the...
entailment
def _ReadUnionDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads an union data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, ob...
Reads an union data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data type...
entailment
def _ReadUUIDDataTypeDefinition( self, definitions_registry, definition_values, definition_name, is_member=False): """Reads an UUID data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, obje...
Reads an UUID data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. is_member (Optional[bool]): True if the data type ...
entailment
def _ReadDefinition(self, definitions_registry, definition_values): """Reads a data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. Returns: DataTypeDefinition: ...
Reads a data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. Returns: DataTypeDefinition: data type definition or None. Raises: DefinitionReaderError: if ...
entailment
def ReadFile(self, definitions_registry, path): """Reads data type definitions from a file into the registry. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. path (str): path of the file to read from. """ with open(path, 'r') as file_objec...
Reads data type definitions from a file into the registry. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. path (str): path of the file to read from.
entailment
def _GetFormatErrorLocation( self, yaml_definition, last_definition_object): """Retrieves a format error location. Args: yaml_definition (dict[str, object]): current YAML definition. last_definition_object (DataTypeDefinition): previous data type definition. Returns: str:...
Retrieves a format error location. Args: yaml_definition (dict[str, object]): current YAML definition. last_definition_object (DataTypeDefinition): previous data type definition. Returns: str: format error location.
entailment
def ReadFileObject(self, definitions_registry, file_object): """Reads data type definitions from a file-like object into the registry. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. file_object (file): file-like object to read from. Raises: ...
Reads data type definitions from a file-like object into the registry. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. file_object (file): file-like object to read from. Raises: FormatError: if the definitions values are missing or if the f...
entailment
def find_files(path, filter="*.md"): """ Finds files with an (optional) given extension in a given path. """ if os.path.isfile(path): return [path] if os.path.isdir(path): matches = [] for root, dirnames, filenames in os.walk(path): for filena...
Finds files with an (optional) given extension in a given path.
entailment
def read_from_hdx(identifier, configuration=None): # type: (str, Optional[Configuration]) -> Optional['Organization'] """Reads the organization given by identifier from HDX and returns Organization object Args: identifier (str): Identifier of organization configuration (...
Reads the organization given by identifier from HDX and returns Organization object Args: identifier (str): Identifier of organization configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[Organization]: Orga...
entailment
def get_users(self, capacity=None): # type: (Optional[str]) -> List[User] """Returns the organization's users. Args: capacity (Optional[str]): Filter by capacity eg. member, admin. Defaults to None. Returns: List[User]: Organization's users. """ u...
Returns the organization's users. Args: capacity (Optional[str]): Filter by capacity eg. member, admin. Defaults to None. Returns: List[User]: Organization's users.
entailment
def add_update_user(self, user, capacity=None): # type: (Union[hdx.data.user.User,Dict,str],Optional[str]) -> None """Add new or update existing user in organization with new metadata. Capacity eg. member, admin must be supplied either within the User object or dictionary or using the capacity a...
Add new or update existing user in organization with new metadata. Capacity eg. member, admin must be supplied either within the User object or dictionary or using the capacity argument (which takes precedence). Args: user (Union[User,Dict,str]): Either a user id or user metadata ei...
entailment
def add_update_users(self, users, capacity=None): # type: (List[Union[hdx.data.user.User,Dict,str]],Optional[str]) -> None """Add new or update existing users in organization with new metadata. Capacity eg. member, admin must be supplied either within the User object or dictionary or using the c...
Add new or update existing users in organization with new metadata. Capacity eg. member, admin must be supplied either within the User object or dictionary or using the capacity argument (which takes precedence). Args: users (List[Union[User,Dict,str]]): A list of either user ids or...
entailment
def get_datasets(self, query='*:*', **kwargs): # type: (str, Any) -> List[hdx.data.dataset.Dataset] """Get list of datasets in organization Args: query (str): Restrict datasets returned to this query (in Solr format). Defaults to '*:*'. **kwargs: See below so...
Get list of datasets in organization Args: query (str): Restrict datasets returned to this query (in Solr format). Defaults to '*:*'. **kwargs: See below sort (string): Sorting of the search results. Defaults to 'relevance asc, metadata_modified desc'. rows (int)...
entailment
def get_all_organization_names(configuration=None, **kwargs): # type: (Optional[Configuration], Any) -> List[str] """Get all organization names in HDX Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. **kwargs: See below ...
Get all organization names in HDX Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. **kwargs: See below sort (str): Sort the search results according to field name and sort-order. Allowed fields are ‘name’, ‘package_count’ an...
entailment
def _read_from_hdx(self, object_type, value, fieldname='id', action=None, **kwargs): # type: (str, str, str, Optional[str], Any) -> Tuple[bool, Union[Dict, str]] """Makes a read call to HDX passing in given parameter. Args: object_type (str): Description of HD...
Makes a read call to HDX passing in given parameter. Args: object_type (str): Description of HDX object type (for messages) value (str): Value of HDX field fieldname (str): HDX field name. Defaults to id. action (Optional[str]): Replacement CKAN action url to use...
entailment
def _load_from_hdx(self, object_type, id_field): # type: (str, str) -> bool """Helper method to load the HDX object given by identifier from HDX Args: object_type (str): Description of HDX object type (for messages) id_field (str): HDX object identifier Returns:...
Helper method to load the HDX object given by identifier from HDX Args: object_type (str): Description of HDX object type (for messages) id_field (str): HDX object identifier Returns: bool: True if loaded, False if not
entailment
def _check_load_existing_object(self, object_type, id_field_name, operation='update'): # type: (str, str, str) -> None """Check metadata exists and contains HDX object identifier, and if so load HDX object Args: object_type (str): Description of HDX object type (for messages) ...
Check metadata exists and contains HDX object identifier, and if so load HDX object Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier operation (str): Operation to report if error. Defau...
entailment
def _check_required_fields(self, object_type, ignore_fields): # type: (str, List[str]) -> None """Helper method to check that metadata for HDX object is complete Args: ignore_fields (List[str]): Any fields to ignore in the check Returns: None """ ...
Helper method to check that metadata for HDX object is complete Args: ignore_fields (List[str]): Any fields to ignore in the check Returns: None
entailment
def _merge_hdx_update(self, object_type, id_field_name, file_to_upload=None, **kwargs): # type: (str, str, Optional[str], Any) -> None """Helper method to check if HDX object exists and update it Args: object_type (str): Description of HDX object type (for messages) id_f...
Helper method to check if HDX object exists and update it Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier file_to_upload (Optional[str]): File to upload to HDX **kwargs: Se...
entailment
def _update_in_hdx(self, object_type, id_field_name, file_to_upload=None, **kwargs): # type: (str, str, Optional[str], Any) -> None """Helper method to check if HDX object exists in HDX and if so, update it Args: object_type (str): Description of HDX object type (for messages) ...
Helper method to check if HDX object exists in HDX and if so, update it Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier file_to_upload (Optional[str]): File to upload to HDX ...
entailment
def _write_to_hdx(self, action, data, id_field_name, file_to_upload=None): # type: (str, Dict, str, Optional[str]) -> Dict """Creates or updates an HDX object in HDX and return HDX object metadata dict Args: action (str): Action to perform eg. 'create', 'update' data (Di...
Creates or updates an HDX object in HDX and return HDX object metadata dict Args: action (str): Action to perform eg. 'create', 'update' data (Dict): Data to write to HDX id_field_name (str): Name of field containing HDX object identifier or None file_to_upload (...
entailment
def _save_to_hdx(self, action, id_field_name, file_to_upload=None): # type: (str, str, Optional[str]) -> None """Creates or updates an HDX object in HDX, saving current data and replacing with returned HDX object data from HDX Args: action (str): Action to perform: 'create' ...
Creates or updates an HDX object in HDX, saving current data and replacing with returned HDX object data from HDX Args: action (str): Action to perform: 'create' or 'update' id_field_name (str): Name of field containing HDX object identifier file_to_upload (Optional[...
entailment
def _create_in_hdx(self, object_type, id_field_name, name_field_name, file_to_upload=None): # type: (str, str, str, Optional[str]) -> None """Helper method to check if resource exists in HDX and if so, update it, otherwise create it Args: object_type (str): D...
Helper method to check if resource exists in HDX and if so, update it, otherwise create it Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier name_field_name (str): Name of field contain...
entailment
def _delete_from_hdx(self, object_type, id_field_name): # type: (str, str) -> None """Helper method to deletes a resource from HDX Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier ...
Helper method to deletes a resource from HDX Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier Returns: None
entailment
def _addupdate_hdxobject(self, hdxobjects, id_field, new_hdxobject): # type: (List[HDXObjectUpperBound], str, HDXObjectUpperBound) -> HDXObjectUpperBound """Helper function to add a new HDX object to a supplied list of HDX objects or update existing metadata if the object already exists in the l...
Helper function to add a new HDX object to a supplied list of HDX objects or update existing metadata if the object already exists in the list Args: hdxobjects (List[T <= HDXObject]): list of HDX objects to which to add new objects or update existing ones id_field (str): Field o...
entailment
def _remove_hdxobject(self, objlist, obj, matchon='id', delete=False): # type: (List[Union[HDXObjectUpperBound,Dict]], Union[HDXObjectUpperBound,Dict,str], str, bool) -> bool """Remove an HDX object from a list within the parent HDX object Args: objlist (List[Union[T <= HDXObject,Di...
Remove an HDX object from a list within the parent HDX object Args: objlist (List[Union[T <= HDXObject,Dict]]): list of HDX objects obj (Union[T <= HDXObject,Dict,str]): Either an id or hdx object metadata either from an HDX object or a dictionary matchon (str): Field to mat...
entailment
def _convert_hdxobjects(self, hdxobjects): # type: (List[HDXObjectUpperBound]) -> List[HDXObjectUpperBound] """Helper function to convert supplied list of HDX objects to a list of dict Args: hdxobjects (List[T <= HDXObject]): List of HDX objects to convert Returns: ...
Helper function to convert supplied list of HDX objects to a list of dict Args: hdxobjects (List[T <= HDXObject]): List of HDX objects to convert Returns: List[Dict]: List of HDX objects converted to simple dictionaries
entailment
def _copy_hdxobjects(self, hdxobjects, hdxobjectclass, attribute_to_copy=None): # type: (List[HDXObjectUpperBound], type, Optional[str]) -> List[HDXObjectUpperBound] """Helper function to make a deep copy of a supplied list of HDX objects Args: hdxobjects (List[T <= HDXObject]): lis...
Helper function to make a deep copy of a supplied list of HDX objects Args: hdxobjects (List[T <= HDXObject]): list of HDX objects to copy hdxobjectclass (type): Type of the HDX Objects to be copied attribute_to_copy (Optional[str]): An attribute to copy over from the HDX ob...
entailment
def _separate_hdxobjects(self, hdxobjects, hdxobjects_name, id_field, hdxobjectclass): # type: (List[HDXObjectUpperBound], str, str, type) -> None """Helper function to take a list of HDX objects contained in the internal dictionary and add them to a supplied list of HDX objects or update existi...
Helper function to take a list of HDX objects contained in the internal dictionary and add them to a supplied list of HDX objects or update existing metadata if any objects already exist in the list. The list in the internal dictionary is then deleted. Args: hdxobjects (List[T <= HD...
entailment
def _get_tags(self): # type: () -> List[str] """Return the dataset's list of tags Returns: List[str]: list of tags or [] if there are none """ tags = self.data.get('tags', None) if not tags: return list() return [x['name'] for x in tags]
Return the dataset's list of tags Returns: List[str]: list of tags or [] if there are none
entailment
def _add_tag(self, tag): # type: (str) -> bool """Add a tag Args: tag (str): Tag to add Returns: bool: True if tag added or False if tag already present """ tags = self.data.get('tags', None) if tags: if tag in [x['name'] for ...
Add a tag Args: tag (str): Tag to add Returns: bool: True if tag added or False if tag already present
entailment
def _add_tags(self, tags): # type: (List[str]) -> bool """Add a list of tag Args: tags (List[str]): list of tags to add Returns: bool: True if all tags added or False if any already present. """ alltagsadded = True for tag in tags: ...
Add a list of tag Args: tags (List[str]): list of tags to add Returns: bool: True if all tags added or False if any already present.
entailment
def _get_stringlist_from_commastring(self, field): # type: (str) -> List[str] """Return list of strings from comma separated list Args: field (str): Field containing comma separated list Returns: List[str]: List of strings """ strings = self.data...
Return list of strings from comma separated list Args: field (str): Field containing comma separated list Returns: List[str]: List of strings
entailment
def _add_string_to_commastring(self, field, string): # type: (str, str) -> bool """Add a string to a comma separated list of strings Args: field (str): Field containing comma separated list string (str): String to add Returns: bool: True if string ad...
Add a string to a comma separated list of strings Args: field (str): Field containing comma separated list string (str): String to add Returns: bool: True if string added or False if string already present
entailment
def _add_strings_to_commastring(self, field, strings): # type: (str, List[str]) -> bool """Add a list of strings to a comma separated list of strings Args: field (str): Field containing comma separated list strings (List[str]): list of strings to add Returns: ...
Add a list of strings to a comma separated list of strings Args: field (str): Field containing comma separated list strings (List[str]): list of strings to add Returns: bool: True if all strings added or False if any already present.
entailment
def _remove_string_from_commastring(self, field, string): # type: (str, str) -> bool """Remove a string from a comma separated list of strings Args: field (str): Field containing comma separated list string (str): String to remove Returns: bool: True...
Remove a string from a comma separated list of strings Args: field (str): Field containing comma separated list string (str): String to remove Returns: bool: True if string removed or False if not
entailment
def read_from_hdx(identifier, configuration=None): # type: (str, Optional[Configuration]) -> Optional['Resource'] """Reads the resource given by identifier from HDX and returns Resource object Args: identifier (str): Identifier of resource configuration (Optional[Configu...
Reads the resource given by identifier from HDX and returns Resource object Args: identifier (str): Identifier of resource configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[Resource]: Resource object if s...
entailment
def set_file_to_upload(self, file_to_upload): # type: (str) -> None """Delete any existing url and set the file uploaded to the local path provided Args: file_to_upload (str): Local path to file to upload Returns: None """ if 'url' in self.data: ...
Delete any existing url and set the file uploaded to the local path provided Args: file_to_upload (str): Local path to file to upload Returns: None
entailment
def check_url_filetoupload(self): # type: () -> None """Check if url or file to upload provided for resource and add resource_type and url_type if not supplied Returns: None """ if self.file_to_upload is None: if 'url' in self.data: if 're...
Check if url or file to upload provided for resource and add resource_type and url_type if not supplied Returns: None
entailment
def update_in_hdx(self, **kwargs): # type: (Any) -> None """Check if resource exists in HDX and if so, update it Args: **kwargs: See below operation (string): Operation to perform eg. patch. Defaults to update. Returns: None """ self....
Check if resource exists in HDX and if so, update it Args: **kwargs: See below operation (string): Operation to perform eg. patch. Defaults to update. Returns: None
entailment
def create_in_hdx(self): # type: () -> None """Check if resource exists in HDX and if so, update it, otherwise create it Returns: None """ self.check_required_fields() id = self.data.get('id') if id and self._load_from_hdx('resource', id): ...
Check if resource exists in HDX and if so, update it, otherwise create it Returns: None
entailment
def get_dataset(self): # type: () -> hdx.data.dataset.Dataset """Return dataset containing this resource Returns: hdx.data.dataset.Dataset: Dataset containing this resource """ package_id = self.data.get('package_id') if package_id is None: raise ...
Return dataset containing this resource Returns: hdx.data.dataset.Dataset: Dataset containing this resource
entailment
def search_in_hdx(query, configuration=None, **kwargs): # type: (str, Optional[Configuration], Any) -> List['Resource'] """Searches for resources in HDX. NOTE: Does not search dataset metadata! Args: query (str): Query configuration (Optional[Configuration]): HDX configu...
Searches for resources in HDX. NOTE: Does not search dataset metadata! Args: query (str): Query configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. **kwargs: See below order_by (str): A field on the Resource model that or...
entailment
def download(self, folder=None): # type: (Optional[str]) -> Tuple[str, str] """Download resource store to provided folder or temporary folder if no folder supplied Args: folder (Optional[str]): Folder to download resource to. Defaults to None. Returns: Tuple[str...
Download resource store to provided folder or temporary folder if no folder supplied Args: folder (Optional[str]): Folder to download resource to. Defaults to None. Returns: Tuple[str, str]: (URL downloaded, Path to downloaded file)
entailment
def get_all_resource_ids_in_datastore(configuration=None): # type: (Optional[Configuration]) -> List[str] """Get list of resources that have a datastore returning their ids. Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. ...
Get list of resources that have a datastore returning their ids. Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: List[str]: List of resource ids that are in the datastore
entailment
def has_datastore(self): # type: () -> bool """Check if the resource has a datastore. Returns: bool: Whether the resource has a datastore or not """ success, result = self._read_from_hdx('datastore', self.data['id'], 'resource_id', ...
Check if the resource has a datastore. Returns: bool: Whether the resource has a datastore or not
entailment
def delete_datastore(self): # type: () -> None """Delete a resource from the HDX datastore Returns: None """ success, result = self._read_from_hdx('datastore', self.data['id'], 'resource_id', self.actions()['datastore_del...
Delete a resource from the HDX datastore Returns: None
entailment
def create_datastore(self, schema=None, primary_key=None, delete_first=0, path=None): # type: (Optional[List[Dict]], Optional[str], int, Optional[str]) -> None """For tabular data, create a resource in the HDX datastore which enables data preview in HDX. If no schema is provided...
For tabular data, create a resource in the HDX datastore which enables data preview in HDX. If no schema is provided all fields are assumed to be text. If path is not supplied, the file is first downloaded from HDX. Args: schema (List[Dict]): List of fields and types of form {'id': 'FIELD',...
entailment
def create_datastore_from_dict_schema(self, data, delete_first=0, path=None): # type: (dict, int, Optional[str]) -> None """For tabular data, create a resource in the HDX datastore which enables data preview in HDX from a dictionary containing a list of fields and types of form {'id': 'FIELD', '...
For tabular data, create a resource in the HDX datastore which enables data preview in HDX from a dictionary containing a list of fields and types of form {'id': 'FIELD', 'type': 'TYPE'} and optionally a primary key. If path is not supplied, the file is first downloaded from HDX. Args: ...
entailment
def create_datastore_from_yaml_schema(self, yaml_path, delete_first=0, path=None): # type: (str, Optional[int], Optional[str]) -> None """For tabular data, create a resource in the HDX datastore which enables data preview in HDX from a YAML file containi...
For tabular data, create a resource in the HDX datastore which enables data preview in HDX from a YAML file containing a list of fields and types of form {'id': 'FIELD', 'type': 'TYPE'} and optionally a primary key. If path is not supplied, the file is first downloaded from HDX. Args: ...
entailment
def create_datastore_from_json_schema(self, json_path, delete_first=0, path=None): # type: (str, int, Optional[str]) -> None """For tabular data, create a resource in the HDX datastore which enables data preview in HDX from a JSON file containing a list of fields and types of form {'id': 'FIELD'...
For tabular data, create a resource in the HDX datastore which enables data preview in HDX from a JSON file containing a list of fields and types of form {'id': 'FIELD', 'type': 'TYPE'} and optionally a primary key. If path is not supplied, the file is first downloaded from HDX. Args: ...
entailment
def create_datastore_for_topline(self, delete_first=0, path=None): # type: (int, Optional[str]) -> None """For tabular data, create a resource in the HDX datastore which enables data preview in HDX using the built in YAML definition for a topline. If path is not supplied, the file is first downl...
For tabular data, create a resource in the HDX datastore which enables data preview in HDX using the built in YAML definition for a topline. If path is not supplied, the file is first downloaded from HDX. Args: delete_first (int): Delete datastore before creation. 0 = No, 1 = Yes, 2 = If no...
entailment
def update_datastore(self, schema=None, primary_key=None, path=None): # type: (Optional[List[Dict]], Optional[str], Optional[str]) -> None """For tabular data, update a resource in the HDX datastore which enables data preview in HDX. If no schema is provided all fields a...
For tabular data, update a resource in the HDX datastore which enables data preview in HDX. If no schema is provided all fields are assumed to be text. If path is not supplied, the file is first downloaded from HDX. Args: schema (List[Dict]): List of fields and types of form {'id': 'FIELD',...
entailment
def _get_resource_view(self, resource_view): # type: (Union[ResourceView,Dict]) -> ResourceView """Get resource view id Args: resource_view (Union[ResourceView,Dict]): ResourceView metadata from a ResourceView object or dictionary Returns: ResourceView: Resource...
Get resource view id Args: resource_view (Union[ResourceView,Dict]): ResourceView metadata from a ResourceView object or dictionary Returns: ResourceView: ResourceView object
entailment
def add_update_resource_views(self, resource_views): # type: (List[Union[ResourceView,Dict]]) -> None """Add new or update existing resource views in resource with new metadata. Args: resource_views (List[Union[ResourceView,Dict]]): A list of resource views metadata from ResourceVie...
Add new or update existing resource views in resource with new metadata. Args: resource_views (List[Union[ResourceView,Dict]]): A list of resource views metadata from ResourceView objects or dictionaries Returns: None
entailment
def reorder_resource_views(self, resource_views): # type: (List[Union[ResourceView,Dict,str]]) -> None """Order resource views in resource. Args: resource_views (List[Union[ResourceView,Dict,str]]): A list of either resource view ids or resource views metadata from ResourceView obje...
Order resource views in resource. Args: resource_views (List[Union[ResourceView,Dict,str]]): A list of either resource view ids or resource views metadata from ResourceView objects or dictionaries Returns: None
entailment
def delete_resource_view(self, resource_view): # type: (Union[ResourceView,Dict,str]) -> None """Delete a resource view from the resource and HDX Args: resource_view (Union[ResourceView,Dict,str]): Either a resource view id or resource view metadata either from a ResourceView object...
Delete a resource view from the resource and HDX Args: resource_view (Union[ResourceView,Dict,str]): Either a resource view id or resource view metadata either from a ResourceView object or a dictionary Returns: None
entailment
def parse_for_simple_stems(output, skip_empty=False, skip_same_stems=True): """ Parses the output stem lines to produce a list with possible stems for each word in the output. :param skip_empty: set True to skip lines without stems (default is False) :returns: a list of tuples, each containing an o...
Parses the output stem lines to produce a list with possible stems for each word in the output. :param skip_empty: set True to skip lines without stems (default is False) :returns: a list of tuples, each containing an original text word and a list of stems for the given word
entailment
def _CreateClassTemplate(cls, data_type_definition): """Creates the class template. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: str: class template. """ type_name = data_type_definition.name type_description = data_type_definition.description or...
Creates the class template. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: str: class template.
entailment
def _IsIdentifier(cls, string): """Checks if a string contains an identifier. Args: string (str): string to check. Returns: bool: True if the string contains an identifier, False otherwise. """ return ( string and not string[0].isdigit() and all(character.isalnum() or c...
Checks if a string contains an identifier. Args: string (str): string to check. Returns: bool: True if the string contains an identifier, False otherwise.
entailment
def _ValidateDataTypeDefinition(cls, data_type_definition): """Validates the data type definition. Args: data_type_definition (DataTypeDefinition): data type definition. Raises: ValueError: if the data type definition is not considered valid. """ if not cls._IsIdentifier(data_type_defi...
Validates the data type definition. Args: data_type_definition (DataTypeDefinition): data type definition. Raises: ValueError: if the data type definition is not considered valid.
entailment
def CreateClass(cls, data_type_definition): """Creates a new structure values class. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: class: structure values class. """ cls._ValidateDataTypeDefinition(data_type_definition) class_definition = cls._Cre...
Creates a new structure values class. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: class: structure values class.
entailment
def DeregisterDefinition(self, data_type_definition): """Deregisters a data type definition. The data type definitions are identified based on their lower case name. Args: data_type_definition (DataTypeDefinition): data type definition. Raises: KeyError: if a data type definition is not s...
Deregisters a data type definition. The data type definitions are identified based on their lower case name. Args: data_type_definition (DataTypeDefinition): data type definition. Raises: KeyError: if a data type definition is not set for the corresponding name.
entailment
def GetDefinitionByName(self, name): """Retrieves a specific data type definition by name. Args: name (str): name of the data type definition. Returns: DataTypeDefinition: data type definition or None if not available. """ lookup_name = name.lower() if lookup_name not in self._defi...
Retrieves a specific data type definition by name. Args: name (str): name of the data type definition. Returns: DataTypeDefinition: data type definition or None if not available.
entailment
def RegisterDefinition(self, data_type_definition): """Registers a data type definition. The data type definitions are identified based on their lower case name. Args: data_type_definition (DataTypeDefinition): data type definitions. Raises: KeyError: if data type definition is already se...
Registers a data type definition. The data type definitions are identified based on their lower case name. Args: data_type_definition (DataTypeDefinition): data type definitions. Raises: KeyError: if data type definition is already set for the corresponding name.
entailment
def apply_on_csv_string(rules_str, func): """ Splits a given string by comma, trims whitespace on the resulting strings and applies a given ```func``` to each item. """ splitted = rules_str.split(",") for str in splitted: func(str.strip())
Splits a given string by comma, trims whitespace on the resulting strings and applies a given ```func``` to each item.
entailment