Getters#

asent.getters#

asent.getters.allcap_differential_getter(span: Union[Span, Doc]) bool[source]#

Check whether just some words in the span are ALL CAPS.

Parameters:

span (Union[Span, Doc]) – A spaCy span

Returns:

True if some but not all items in words are ALL CAPS

Return type:

bool

asent.getters.make_doc_polarity_getter(span_polarity_getter: Optional[Callable[[Span], float]]) Callable[[Doc], DocPolarityOutput][source]#

Creates a function (getter) which for a doc return the aggrated polarities. Including accounting for contrastive conjugations (e.g. ‘but’), exclamationsmarks and questionmarks.

Parameters:

span_polarity_getter – a function which given a span return the polarity (sentiment) of the span. If None it assumes that the the span extention “polarity” is already set. If specified it overwrites the extension. Defaults to None.

Returns:

A function which given a doc return the aggrated polarities. Including accounting for

contrastive conjugations (e.g. ‘but’), exclamationsmarks and questionmarks.

asent.getters.make_intensifier_getter(intensifiers: dict[str, float], lemmatize: bool = True, lowercase: bool = True) Callable[[Token], float][source]#

Creates a token getter which checks it token is an intensifier and return it intensification factor.

Parameters:
  • intensifiers – A dictionary of intensifiers and multiplication factor.

  • lemmatize – Should it look up in the intensifiers using the lemma? Defaults to True.

  • lowercase – Should it look up in the intensifiers using the lowercased word? Defaults to True.

Returns:

The getter function

asent.getters.make_is_contrastive_conj_getter(contrastive_conjugations: Iterable[str], lemmatize: bool = True, lowercase: bool = True) Callable[[Token], bool][source]#

Creates a token getter for whether a token is a constrastive conjugations.

Parameters:
  • contrastive_conjugations – A list of contrastive conjugations.

  • lemmatize – Should you lemmatize before lookup in the contrastive conjugations list? Defaults to True.

  • lowercase – Should you lowercase before lookup in the conjugations list? Defaults to True.

Returns:

A token getter

asent.getters.make_is_negated_getter(lookback: int = 3, is_negation_getter: Optional[Callable[[Token], bool]] = None) Callable[[Token], Optional[Token]][source]#

Creates a getter which checks if a token is negated by checked whether the n previous workds are negations.

Parameters:
  • lookback – How many token should it look backwards for negations? Defaults to 3 which is emperically derived by Hutto and Gilbert (2014).

  • is_negation_getter – A function which given a token return if the token is a negation or not. If None it assumes that the token extention “is_negation” is set. If specified overwrites the extension. Defualts to None.

Returns:

The getter function

asent.getters.make_is_negation_getter(negations: Iterable[str], lemmatize: bool = True, lowercase: bool = True) Callable[[Token], bool][source]#

Creates a token getter which return whether a token is a negation or not.

Parameters:
  • negations – An list of negations

  • lemmatize – Should it look up in negations using the lemma? Defaults to True.

  • lowercase – Should it look up in negations using the lowercased word? Defaults to True.

Returns:

A token getter

asent.getters.make_span_polarity_getter(polarity_getter: Optional[Callable[[Token], float]], contrastive_conj_getter: Optional[Callable[[Token], bool]]) Callable[[Span], SpanPolarityOutput][source]#

Creates a function (getter) which for a span return the aggrated polarities. Including accounting for contrastive conjugations (e.g. ‘but’), exclamationsmarks and questionmarks.

Parameters:
  • polarity_getter (Optional[Callable[[Token], float]]) – A function which given a token return the polarity (sentiment) of the token. If None it assumes that the token extension “polarity” is already set. If given it overwrites the “polarity” extension. Defaults to None.

  • contrastive_conj_getter (Optional[Callable[[Token], bool]]) – A function which given a token return whether the token is a contrastive conjunction. If None it assumes that the token extension “is_contrastive_conj” is already set. If given it overwrites the “is_contrastive_conj” extension. Defaults to None.

Returns:

A function which for a span return the aggrated polarities. Including accounting for contrastive conjugations (e.g. ‘but’), exclamationsmarks and questionmarks.

asent.getters.make_token_polarity_getter(valence_getter: Optional[Callable[[Token], float]] = None, is_negated_getter: Optional[Callable[[Token], Optional[Union[bool, Token]]]] = None, intensifier_getter: Optional[Callable[[Token], float]] = None, negation_scalar: float = -0.74, lookback_intensities: list[float] = [1.0, 0.95, 0.9], **kwargs) Callable[[Token], TokenPolarityOutput][source]#

Creates a function (getter) which takes a token and return the polarity of the token based upon whether the token valence (sentiment) including whether is negated and whether it is intensified using an intensifier.

Parameters:
  • valence_getter – a function which given a token return the valence (sentiment) of the token. If None it assumes that the the token extention “valence” is set. If specified it overwrites the extension. Defualts to None.

  • is_negated_getter – A function which given a token return a boolean indicating whether the token is negated. If None it assumes that the the token extention “is_negated” is set. If specified it overwrites the extension. Defualts to None.

  • intensifier_getter – A getter which for a token return 0 if it is not an intensifier or its intensifcation value if it is an intensifier. E.g. the token ‘especially’ might have an value of 0.293 which increases or decreases the valence of the following word by the specified amount. Defaults to None, intensifiers aren’t included in the analysis of token valence.

  • negation_scalar – Defaults to the emperically derived constant -0.74 (Hutto and Gilbert, 2014).

  • lookback_intensities – How long to look back for intensifiers (length). Intensities indicate the how much to weight each intensifier. Defaults to [1.0, 0.95, 0.90] which is emperically derived (Hutto and Gilbert, 2014).

  • **kwargs – Additional keyword arguments.

Returns:

The getter function

asent.getters.make_txt_getter(lemmatize: bool, lowercase: bool) Callable[[Token], str][source]#

Creates a token getter which return the string of a text string.

Parameters:
  • lemmatize – Should the token be lemmatized?

  • lowercase – Should the token be lowercased?

Returns:

The getter function

asent.getters.make_valance_getter(lexicon: dict[str, float], lemmatize: bool = False, lowercase: bool = True, cap_differential: float = 0.733) Callable[[Token], float][source]#

Creates a token getter which return the valence (sentiment) of a token including the capitalization of the token.

Parameters:
  • lexicon – The valence scores of the tokens.

  • lemmatize – Should it look up in the lexicon (and intensifiers) using the lemma? Defaults to True.

  • lowercase – Should it look up in the lexicon (and intensifiers) using the lowercased word? Defaults to True.

  • cap_differential – Capitalization differential, which is added to the valence of the score it is emphasized using all caps. Defaults to 0.733, an emperically derived constant (Hutto and Gilbert, 2014). If None it will not be used.

Returns:

The getter function