HTMLStripNormalizer#
- class scikitplot.corpus.HTMLStripNormalizer(use_beautifulsoup=False, parser='html.parser', decode_entities=True)[source]#
Remove HTML and XML tags from the document text.
Two modes are available:
use_beautifulsoup=False(default): regex-based stripping. Zero additional dependencies; handles well-formed HTML.use_beautifulsoup=True: usesbs4.BeautifulSoupfor robust parsing of malformed or deeply nested HTML. Requirespip install beautifulsoup4.
- Parameters:
- use_beautifulsoupbool, optional
Use BeautifulSoup for parsing. Default:
False.- parserstr, optional
BeautifulSoup parser (
\"html.parser\",\"lxml\",\"html5lib\"). Ignored whenuse_beautifulsoup=False. Default:\"html.parser\"(stdlib, no extra deps).- decode_entitiesbool, optional
Decode HTML entities (e.g.
&→&). Default:True.
- Parameters:
Notes
Regex mode: comments go first (
<!-- ... -->, even holding<), then every<...>holding no other<. So a lone<in text keeps what follows it (x < y and <b>b</b>givesx < y and b), and the cost is linear in the text however many<it holds. A tag whose attribute value holds an unescaped<(title="a < b") is not recognised and leaves a fragment; useuse_beautifulsoup=Truefor markup that needs exact parsing.Examples
>>> norm = HTMLStripNormalizer() >>> doc = CorpusDocument.create("f.txt", 0, "<p>Hello <b>world</b>.</p>") >>> norm.normalize_doc(doc).normalized_text 'Hello world.'
- normalize_doc(doc)[source]#
Apply
normalize_textto the document.- Parameters:
- docCorpusDocument
Input document.
- Returns:
- CorpusDocument
New instance with
normalized_textupdated.textis never modified.
- Parameters:
doc (CorpusDocument)
- Return type: