text
stringlengths
81
112k
Returns: dict: A dictionary that maps occurrence counts to the terms that appear that many times in the text. def term_count_buckets(self): """ Returns: dict: A dictionary that maps occurrence counts to the terms that appear that many times in the text. ...
Get the X most frequent terms in the text, and then probe down to get any other terms that have the same count as the last term. Args: depth (int): The number of terms. Returns: set: The set of frequent terms. def most_frequent_terms(self, depth): """ ...
Given a stemmed term, get the most common unstemmed variant. Args: term (str): A stemmed term. Returns: str: The unstemmed token. def unstem(self, term): """ Given a stemmed term, get the most common unstemmed variant. Args: term (str): A ...
Estimate the kernel density of the instances of term in the text. Args: term (str): A stemmed term. bandwidth (int): The kernel bandwidth. samples (int): The number of evenly-spaced sample points. kernel (str): The kernel function. Returns: n...
Compute the geometric area of the overlap between the kernel density estimates of two terms. Args: term1 (str) term2 (str) Returns: float def score_intersect(self, term1, term2, **kwargs): """ Compute the geometric area of the overlap between the kerne...
Compute a weighting score based on the cosine distance between the kernel density estimates of two terms. Args: term1 (str) term2 (str) Returns: float def score_cosine(self, term1, term2, **kwargs): """ Compute a weighting score based on the cosine dis...
Compute a weighting score based on the "City Block" distance between the kernel density estimates of two terms. Args: term1 (str) term2 (str) Returns: float def score_braycurtis(self, term1, term2, **kwargs): """ Compute a weighting score based on the ...
Plot kernel density estimates for multiple words. Args: words (list): A list of unstemmed terms. def plot_term_kdes(self, words, **kwargs): """ Plot kernel density estimates for multiple words. Args: words (list): A list of unstemmed terms. """ ...
Tries to lookup a matching formfield generator (lowercase field-classname) and raises a NotImplementedError of no generator can be found. def generate(self, field_name, field): """Tries to lookup a matching formfield generator (lowercase field-classname) and raises a NotImplementedError...
@param truncate: If true, negative indices which go past the beginning of the list will be evaluated as zero. For example:: >>> L = List([1,2,3,4,5]) >>> len(L) 5 >>> L....
Return an L{axiom.iaxiom.IComparison} (an object that can be passed as the 'comparison' argument to Store.query/.sum/.count) which will constrain a query against 2 attributes for ranges which overlap with the given arguments. For a database with Items of class O which represent values in this confi...
Compare two 'in-database tuples'. Useful when sorting by a compound key and slicing into the middle of that query. def _tupleCompare(tuple1, ineq, tuple2, eq=lambda a,b: (a==b), ander=AND, orer=OR): """ Compare two 'in-database tuples'. Useful when sorti...
Truncates the rationale for analytics event emission if necessary Args: rationale (string): the string value of the rationale max_length (int): the max length for truncation Returns: truncated_value (string): the possibly truncated version of the rationale was_truncated (bool):...
Validate the options that course author set up and return errors in a dict if there is any def validate_options(options): """ Validate the options that course author set up and return errors in a dict if there is any """ errors = [] if int(options['rationale_size']['min']) < 1: errors.appe...
Create a student_item_dict from our surrounding context. See also: submissions.api for details. Args: anonymous_user_id(str): A unique anonymous_user_id for (user, course) pair. Returns: (dict): The student item associated with this XBlock instance. This ...
Retrieve answers from backend for a student and question Args: student_item (dict): The location of the problem this submission is associated with, as defined by a course, student, and item. Returns: Answers: answers for the student def get_answers_for_student(student_item): "...
Add an answer for a student to the backend Args: student_item (dict): The location of the problem this submission is associated with, as defined by a course, student, and item. vote (int): the option that student voted for rationale (str): the reason why the student vote for the...
Get an answer data (vote or rationale) by revision Args: revision (int): the revision number for student answer, could be 0 (original) or 1 (revised) key (str); key for retrieve answer data, could be VOTE_KEY or RATIONALE_KEY Returns: ...
Add an answer Args: vote (int): the option that student voted for rationale (str): the reason why the student vote for the option def add_answer(self, vote, rationale): """ Add an answer Args: vote (int): the option that student voted for ...
when you "except Exception as e", give me the e and I'll give you a string. def exceptionToString(e,silent=False): """when you "except Exception as e", give me the e and I'll give you a string.""" exc_type, exc_obj, exc_tb = sys.exc_info() s=("\n"+"="*50+"\n") s+="EXCEPTION THROWN UNEXPECTEDLY\n" s...
Create a new SubStore, allocating a new file space for it. def createNew(cls, store, pathSegments): """ Create a new SubStore, allocating a new file space for it. """ if isinstance(pathSegments, basestring): raise ValueError( 'Received %r instead of a sequenc...
Create the actual Store this Substore represents. def createStore(self, debug, journalMode=None): """ Create the actual Store this Substore represents. """ if self.storepath is None: self.store._memorySubstores.append(self) # don't fall out of cache if self.store...
Create _TagName instances which version 2 of Catalog automatically creates for use in determining the tagNames result, but which version 1 of Catalog did not create. def upgradeCatalog1to2(oldCatalog): """ Create _TagName instances which version 2 of Catalog automatically creates for use in determi...
Return an iterator of unicode strings - the unique tag names which have been applied objects in this catalog. def tagNames(self): """ Return an iterator of unicode strings - the unique tag names which have been applied objects in this catalog. """ return self.store.query...
Return an iterator of unicode strings - the tag names which apply to the given object. def tagsOf(self, obj): """ Return an iterator of unicode strings - the tag names which apply to the given object. """ return self.store.query( Tag, AND(Tag.cata...
This method is invoked when the item is loaded from the database, and when a transaction is reverted which restores this attribute's value. @param oself: an instance of an item which has this attribute. @param dbval: the underlying database value which was retrieved. def loaded(self, oself, d...
Convert a Python value to a value suitable for inserting into the database. @param oself: The object on which this descriptor is an attribute. @param pyval: The value to be converted. @return: A value legal for this column in the database. def _convertPyval(self, oself, pyval): ...
Generate and cache the subselect SQL and its arguments. Return the subselect SQL. def _queryContainer(self, store): """ Generate and cache the subselect SQL and its arguments. Return the subselect SQL. """ if self._subselectSQL is None: sql, args = self.con...
Smash whatever we got into a list and save the result in case we are executed multiple times. This keeps us from tripping up over generators and the like. def _sequenceContainer(self, store): """ Smash whatever we got into a list and save the result in case we are executed mult...
Filter each element of the data using the attribute type being tested for containment and hand back the resulting list. def _sequenceArgs(self, store): """ Filter each element of the data using the attribute type being tested for containment and hand back the resulting list. """...
Prepare for insertion into the database by making the dbunderlying attribute of the item a relative pathname with respect to the store rather than an absolute pathname. def prepareInsert(self, oself, store): """ Prepare for insertion into the database by making the dbunderlying ...
Undeletes the object. Returns True if undeleted, False if it was already not deleted def restore(self, time=None): """ Undeletes the object. Returns True if undeleted, False if it was already not deleted """ if self.deleted: time = time if time else self.deleted_at ...
Restores itself, as well as objects that might have been deleted along with it if cascade is the deletion strategy def full_restore(self, using=None): using = using or router.db_for_write(self.__class__, instance=self) restore_counter = Counter() if self.deleted: time = self.deleted...
Connect to AWS ec2 :type region: str :param region: AWS region to connect to :type access_key: str :param access_key: AWS access key id :type secret_key: str :param secret_key: AWS secret access key :returns: boto.ec2.connection.EC2Connection -- EC2 connection def connect_to_ec2(region='us...
Find stems for a given text. def parse(self, output): """ Find stems for a given text. """ output = self._get_lines_with_stems(output) words = self._make_unique(output) return self._parse_for_simple_stems(words)
Read valid locations from HDX Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: List[Dict]: A list of valid locations def validlocations(configuration=None): # type: () -> List[Dict] """ Read va...
Get location from HDX location code Args: code (str): code for which to get location name locations (Optional[List[Dict]]): Valid locations list. Defaults to list downloaded from HDX. configuration (Optional[Configuration]): HDX configuration. Defaults to global configuratio...
Get HDX code for location Args: location (str): Location for which to get HDX code locations (Optional[List[Dict]]): Valid locations list. Defaults to list downloaded from HDX. configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. ...
Get HDX code for location Args: location (str): Location for which to get HDX code locations (Optional[List[Dict]]): Valid locations list. Defaults to list downloaded from HDX. configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. ...
The main program function. Returns: bool: True if successful or False if not. def Main(): """The main program function. Returns: bool: True if successful or False if not. """ argument_parser = argparse.ArgumentParser( description='Validates dtFabric format definitions.') argument_parser.ad...
Validates definition files in a directory. Args: path (str): path of the definition file. extension (Optional[str]): extension of the filenames to read. Returns: bool: True if the directory contains valid definitions. def CheckDirectory(self, path, extension='yaml'): """Validates defini...
Validates the definition in a file. Args: path (str): path of the definition file. Returns: bool: True if the file contains valid definitions. def CheckFile(self, path): """Validates the definition in a file. Args: path (str): path of the definition file. Returns: bool: ...
returns css.CSSStyleDeclaration of inline styles, for html: @style def styleattribute(self, element): """ returns css.CSSStyleDeclaration of inline styles, for html: @style """ css_text = element.get('style') if css_text: return cssutils.css.CSSStyleDeclaration(c...
Read configuration file :type filename: str :param filename: Path to the configuration file def get_configuration(filename): """ Read configuration file :type filename: str :param filename: Path to the configuration file """ logger.debug('Reading configuration from {}'.format(filename)) ...
Inlines all CSS in an HTML string Given an HTML document with CSS declared in the HEAD, inlines it into the applicable elements. Used primarily in the preparation of styled emails. Arguments: html_message -- a string of HTML, including CSS def inline_css(html_message, encoding='unicode'): """...
Checks if the byte stream is large enough for the data type. Args: byte_stream (bytes): byte stream. byte_offset (int): offset into the byte stream where to start. data_type_size (int): data type size. Raises: ByteStreamTooSmallError: if the byte stream is too small. MappingError...
Retrieves the byte stream operation. Returns: ByteStreamOperation: byte stream operation or None if unable to determine. def _GetByteStreamOperation(self): """Retrieves the byte stream operation. Returns: ByteStreamOperation: byte stream operation or None if unable to determine. """ b...
Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None if format string cannot be determined. def GetStructByteOrderString(self): """Retrieves the Python struct format string. Returns: str: format string as used by Python struct or No...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def FoldByteStream(self, mapped_value, **unused_kwargs): """Folds the d...
Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: object: mapped value. Raises: MappingError: if the da...
Folds the data type into a value. Args: value (object): value. Returns: object: folded value. Raises: ValueError: if the data type definition cannot be folded into the value. def FoldValue(self, value): """Folds the data type into a value. Args: value (object): value. ...
Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None if format string cannot be determined. def GetStructFormatString(self): """Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None ...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def FoldByteStream(self, mapped_value, **unused_kwargs): """Folds the d...
Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: uuid.UUID: mapped value. Raises: MappingError: if the...
Calculates the elements data size. Args: context (Optional[DataTypeMapContext]): data type map context, used to determine the size hint. Returns: int: the elements data size or None if not available. def _CalculateElementsDataSize(self, context): """Calculates the elements data size...
Evaluates elements data size. Args: context (DataTypeMapContext): data type map context. Returns: int: elements data size. Raises: MappingError: if the elements data size cannot be determined. def _EvaluateElementsDataSize(self, context): """Evaluates elements data size. Args:...
Evaluates number of elements. Args: context (DataTypeMapContext): data type map context. Returns: int: number of elements. Raises: MappingError: if the number of elements cannot be determined. def _EvaluateNumberOfElements(self, context): """Evaluates number of elements. Args:...
Retrieves the element data type definition. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: DataTypeDefinition: element data type definition. Raises: FormatError: if the element data type cannot be determined from the data type definition. def ...
Retrieves a hint about the size. Args: context (Optional[DataTypeMapContext]): data type map context, used to determine the size hint. Returns: int: hint of the number of bytes needed from the byte stream or None. def GetSizeHint(self, context=None, **unused_kwargs): """Retrieves a ...
Maps a sequence of composite data types on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: tuple[object, ...]: mapped values. Rai...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def _LinearFoldByteStream(self, mapped_value, **unused_kwargs): """Fold...
Maps a data type sequence on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: tuple[object, ...]: mapped values. Raises: Map...
Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None if format string cannot be determined. def GetStructFormatString(self): """Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None ...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. context (Optional[DataTypeMapContext]): data type map context. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def Fo...
Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: tuple[object, ...]: mapped values. Raises: MappingErr...
Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. Returns: object: mapped value. Raises: MappingError: if the data type definition cannot be mapped on the byte stream. de...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def FoldByteStream(self, mapped_value, **kwargs): """Folds the data typ...
Maps the data type on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. Returns: str: mapped values. Raises: MappingError: if the data type definition cannot be mapped on the byte stream. def ...
Determines if the data type definition needs a composite map. Args: data_type_definition (DataTypeDefinition): structure data type definition. Returns: bool: True if a composite map is needed, False otherwise. Raises: FormatError: if a composite map is needed cannot be determined from t...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. context (Optional[DataTypeMapContext]): data type map context. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def _C...
Maps a sequence of composite data types on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: object: mapped value. Raises: Ma...
Determines the attribute (or field) names of the members. Args: data_type_definition (DataTypeDefinition): data type definition. Returns: list[str]: attribute names. Raises: FormatError: if the attribute names cannot be determined from the data type definition. def _GetAttrib...
Retrieves the member data type maps. Args: data_type_definition (DataTypeDefinition): data type definition. data_type_map_cache (dict[str, DataTypeMap]): cached data type maps. Returns: list[DataTypeMap]: member data type maps. Raises: FormatError: if the data type maps cannot be ...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def _LinearFoldByteStream(self, mapped_value, **unused_kwargs): """Fold...
Maps a data type sequence on a byte stream. Args: byte_stream (bytes): byte stream. byte_offset (Optional[int]): offset into the byte stream where to start. context (Optional[DataTypeMapContext]): data type map context. Returns: object: mapped value. Raises: MappingError: if...
Retrieves a hint about the size. Args: context (Optional[DataTypeMapContext]): data type map context, used to determine the size hint. Returns: int: hint of the number of bytes needed from the byte stream or None. def GetSizeHint(self, context=None, **unused_kwargs): """Retrieves a ...
Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None if format string cannot be determined. def GetStructFormatString(self): """Retrieves the Python struct format string. Returns: str: format string as used by Python struct or None ...
Folds the data type into a byte stream. Args: mapped_value (object): mapped value. Returns: bytes: byte stream. Raises: FoldingError: if the data type definition cannot be folded into the byte stream. def FoldByteStream(self, mapped_value, **unused_kwargs): # pylint: disable...
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. def MapByteStream(self, byte_stream, **unused_kwargs): # pylint: disable=redunda...
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. def GetName(self, number): """Retrieves the name of an enumeration value by number. Args: ...
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. def CreateDataTypeMap(self, definition_name): """Creates a specific data type map by nam...
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. def CreateDataTypeMapByType(cls, data_type_definition): """Creates a s...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. 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. """ ...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. 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. """ ...
Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition. def AddMemberDefinition(self, member_definition): """Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition. """ self._byte_size = None ...
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. def IsComposite(self): """Determines if the data type is composite. A composite data type consists of other data types. Returns...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. 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. """ ...
Retrieves the byte size of the data type definition. Returns: int: data type size in bytes or None if size cannot be determined. 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. """ ...
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. def AddValue(self, name, number, aliases=None, description=None):...
Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition. def AddMemberDefinition(self, member_definition): """Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition. """ self.members.append(member...
Parses things like '1n+2', or 'an+b' generally, returning (a, b) 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 parse...
Adds a /* prefix if there is no prefix. This is when you need to keep context's constrained to a single parent. 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.pa...
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...
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...
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...
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...
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 ...
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...
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): ...
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...