textflint.generation_layer.transformation.ABSA.rev_non

Reverse the polarity of non-target in ABSA task

class textflint.generation_layer.transformation.ABSA.rev_non.RevNon(language='eng')[source]

Bases: textflint.generation_layer.transformation.ABSA.absa_transformation.ABSATransformation

Transforms the polarity of non-target by replacing its opinion words

with antonyms provided by WordNet or adding the negation that pre-defined in our negative word list.

Example:

Original sentence: "BEST spicy tuna roll, great asian salad.
(Target: spicy tuna roll)"
Transformed sentence: "BEST spicy tuna roll, not great asian salad."
class textflint.generation_layer.transformation.ABSA.rev_non.ABSATransformation[source]

Bases: textflint.generation_layer.transformation.transformation.Transformation, abc.ABC

An class that supply methods for ABSA task data transformation.

reverse(words_list, opinion_position)[source]

Reverse the polarity of opinions.

Parameters
  • words_list (list) – tokenized words of original sentence

  • opinion_position (list) – opinion position

Returns

transformed sentence and transformed opinion words

exaggerate(words_list, opinions)[source]

Exaggerate the opinion words.

Parameters
  • words_list (list) – tokenized words of original sentence

  • opinions (list) – opinion words and their positions

Returns

transformed sentence and opinion words

get_postag(sentence, start, end)[source]

Get the postag.

Parameters
  • sentence (list|str) – sentence

  • start (int) – start index

  • end (int) – end index

Return list

postag

refine_candidate(trans_words, opi_from, opi_to, candidate_list)[source]

Refine the candidate opinion words.

Parameters
  • trans_words (list) – tokenized words of transformed sentence

  • opi_from (int) – start position of opinion words

  • opi_to (int) – end position of opinion words

  • candidate_list (set) – candidate antonyms word list

Return list

refined candidate word list

static get_word2id(text, lower=True)[source]

Get the index of words in sentence.

Parameters
  • text (str) – input text

  • lower (bool) – whether text is lowercase or not

Return dict

index of words

static add_degree_words(word_list, from_idx, to_idx)[source]

Add the degree words to sentence.

Parameters
  • word_list (list) – tokenized words of original sentence

  • from_idx (int) – index of start

  • to_idx (int) – index of end

Returns

transformed sentence and opinion words

static get_conjunction_idx(trans_words, aspect_term, conjunction_list)[source]

Get the index of conjunction words in conjunction_list.

Parameters
  • trans_words (list) – tokenized words of transformed sentence

  • aspect_term (dict) – aspect term

  • conjunction_list (list) – conjunction list

Return list

index of transformed conjunction word

get_sentence(trans_words, sentence)[source]

Untokenize and uppercase to get an output sentence.

Parameters
  • trans_words (list) – transformed sentence

  • sentence (list) – original sentence

Return list

transformed sentence

get_term_span(trans_sentence, term)[source]

Get the span of term in trans_sentence.

Parameters
  • trans_sentence (list) – transformed sentence

  • term (list) – target term

Returns

start and end index of target term

get_candidate(candidate_list, words_list, postag_list, opi_from, opi_to)[source]

Get the candidate opinion words from words_list.

Parameters
  • candidate_list (set) – candidate words

  • words_list (list) – tokenized words of original sentence

  • postag_list (list) – postag

  • opi_from (int) – start index of opinion

  • opi_to (int) – end index of opinion

Return list

refined candidate words

check_negation(trans_words, opinion_from, opinion_to)[source]

Check the negation words in trans_words and delete them.

Parameters
  • trans_words (list) – tokenized words of transformed sentence

  • opinion_from (int) – start index of opinion

  • opinion_to (int) – end index of opinion

Returns

transformed words, opinion words, position of opinion, and

whether exist negation in transformed sentence

reverse_opinion(trans_words, trans_opinion_words, opinion_from, opinion_to, has_neg)[source]

Reverse the polarity of original opinion and return the new transformed opinion words.

Parameters
  • trans_words (list) – tokenized words of transformed sentence

  • trans_opinion_words (list) – transformed opinion words

  • opinion_from (int) – start index of opinion

  • opinion_to (int) – end index of opinion

  • has_neg (bool) – whether exist negation in transformed sentence

update_sentence_terms(trans_words, trans_terms, trans_opinion_words, opinion_position)[source]

Update the terms and sentence.

Parameters
  • trans_words (list) – tokenized words of transformed sentence

  • trans_terms (dict) – transformed terms

  • trans_opinion_words (list) – transformed opinion words

  • opinion_position (list) – opinion position

Returns

transformed sentence and transformed terms

textflint.generation_layer.transformation.ABSA.rev_non.deepcopy(x, memo=None, _nil=[])[source]

Deep copy operation on arbitrary Python objects.

See the module’s __doc__ string for more info.