MCPcopy Index your code
hub / github.com/clips/pattern / _parse_article_sections

Method _parse_article_sections

pattern/web/__init__.py:1721–1744  ·  view source on GitHub ↗
(self, article, data)

Source from the content-addressed store, hash-verified

1719 parser = self, **kwargs)
1720
1721 def _parse_article_sections(self, article, data):
1722 # If "References" is a section in the article,
1723 # the HTML will contain a marker <h*><span class="mw-headline" id="References">.
1724 # http://en.wikipedia.org/wiki/Section_editing
1725 t = article.title
1726 d = 0
1727 i = 0
1728 for x in data.get("sections", {}):
1729 a = x.get("anchor")
1730 if a:
1731 p = r"<h.>\s*.*?\s*<span class=\"mw-headline\" id=\"%s\">" % a
1732 p = re.compile(p)
1733 m = p.search(article.source, i)
1734 if m:
1735 j = m.start()
1736 article.sections.append(self.MediaWikiSection(article,
1737 title = t,
1738 start = i,
1739 stop = j,
1740 level = d))
1741 t = x.get("line", "")
1742 d = int(x.get("level", 2)) - 1
1743 i = j
1744 return article
1745
1746 def _parse_article_section_structure(self, article):
1747 # Sections with higher level are children of previous sections with lower level.

Callers 1

searchMethod · 0.95

Calls 5

MediaWikiSectionMethod · 0.95
getMethod · 0.45
searchMethod · 0.45
startMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected