sner.classes package

Submodules

sner.classes.display module

Display Class

class sner.classes.display.Display

Bases: object

Display the progress of a process.

Will print a progress bar updated by function calls made off of an instance of this type. Will also estimate time to completion via naieve averaging.
start_time

float – Seconds since epoch to when progress starts.

elapsed_time

float – Seconds since progress started.

last_updated

float – Seconds since epoch to when progress was last updated.

finish()
Displays elapsed time of the tracked process. Clears attributes.
Call upon the completion of whatever it is you are tracking.
Parameters:None
Returns:None
Raises:None
start(message=None)
Used to denote the beginning of whatever process you are displaying
the progress of. Will mark down the current time for purposes of estimating the time remaining. May display an initial message that you can pass in.
Parameters:message (string) – Optional start message.
Returns:None
Raises:None
update_progress_bar(step, end)
Call at the end of each ‘iteration’, whatever that happens to mean
in the current context. Will update the progress bar and estimated time remaining accordingly.
Parameters:
  • step (float) – Current iteration of process.
  • end (float) – Final iteration of process.
Returns:

None

Raises:

None

sner.classes.rule module

Rule

class sner.classes.rule.Rule(ruletype, rule, strength)

Bases: object

Object representing a rule that is used to identify names within the
corpus. This object is used in the ner model, rather than the sner model.
type

Enum – What variety of rule is this (spelling, context, etc)

contents

str – Data that defines the rule

strength

float – Percent chance that any token this rule applies to is a name

occurrences

int – Number of tokens this rule applies to iteration (int): The iteration in which this rule was generated

Type

alias of Types

classmethod find_type(rule_type)
Parse a string representation and return an equivalent Rule.Type
enumeration value. A string representation is used in the input data files, however the enumeration allows for faster comparisons. This function is a convenience to make it easier to scan the appropriate input files.
Parameters:rule_type (string) – String representation of a type of rule.
Returns:Enumeration value representing the type of rule.
Return type:type (Rule.Type)
Raises:TypeError – If the string represents some unrecognized type of rule, then freak out. You should probably respond to this by adding said rule to the enumeration above as well as to the code here.
key()
Define what constitutes an identifying key for a Rule type object.
The Rule’s type as a string concatenated with the Rule’s contents was considered to be uniquely identifying.
Parameters:None
Returns:Uniquely identifying key for this Rule object.
Return type:key (string)
Raises:None

sner.classes.token module

Token

class sner.classes.token.Token(left_context, word, right_context, token_type)

Bases: object

This represents a given ‘token’ in the corpus. It represents a combination of left context, right context, and the word itself. Any identical tokens will be combined into pre-existing ones.

Attributes: left_context (str): contents of token to the left of this token word (str): this token as a string right_context (str): contents of token to the right of this token

type (Enum): what kind of data does this token represent? (personal name, date, etc) rules (set): set of Rule objects that apply to this token

name_probability (float): percent chance that this token represents a name

Type

alias of Types

classmethod find_type(token_type)
Parse a string representation and return an equivalent Token.Type
enumeration value. A string representation is used in the input data files, however the enumeration allows for faster comparisons. This function is a convenience to make it easier to scan the appropriate input files.
Parameters:token_type (string) – String representation of a type of token.
Returns:Enumeration value representing the type of token.
Return type:type (Token.Type)
Raises:TypeError – If the string represents some unrecognized type of token, then freak out. You should probably respond to this by adding said rule to the enumeration above as well as to the code here.

Module contents