MCPcopy
hub / github.com/QData/TextAttack / printable_text

Method printable_text

textattack/shared/attacked_text.py:579–609  ·  view source on GitHub ↗

Represents full text input. Adds field descriptions. For example, entailment inputs look like: ``` premise: ... hypothesis: ... ```

(self, key_color="bold", key_color_method=None)

Source from the content-addressed store, hash-verified

577 ]
578
579 def printable_text(self, key_color="bold", key_color_method=None) -> str:
580 """Represents full text input. Adds field descriptions.
581
582 For example, entailment inputs look like:
583 ```
584 premise: ...
585 hypothesis: ...
586 ```
587 """
588 # For single-sequence inputs, don't show a prefix.
589 if len(self._text_input) == 1:
590 return next(iter(self._text_input.values()))
591 # For multiple-sequence inputs, show a prefix and a colon. Optionally,
592 # color the key.
593 else:
594 if key_color_method:
595
596 def ck(k):
597 return textattack.shared.utils.color_text(
598 k, key_color, key_color_method
599 )
600
601 else:
602
603 def ck(k):
604 return k
605
606 return "\n".join(
607 f"{ck(key.capitalize())}: {value}"
608 for key, value in self._text_input.items()
609 )
610
611 def __repr__(self) -> str:
612 return f'<AttackedText "{self.text}">'

Callers 6

runMethod · 0.80
augmentMethod · 0.80
original_textMethod · 0.80
perturbed_textMethod · 0.80
diff_colorMethod · 0.80
test_printable_textMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_printable_textMethod · 0.64