Move word counter to analyze submodule

This commit is contained in:
Tim Van Baak 2020-03-05 22:03:04 -08:00
parent e08fcefb5f
commit a7f2a56345
3 changed files with 28 additions and 23 deletions

View File

@ -2,5 +2,6 @@
Module encapsulating all markdown parsing functionality Module encapsulating all markdown parsing functionality
""" """
from amanuensis.parser.analyze import WordCounter
from amanuensis.parser.text import parse_raw_markdown from amanuensis.parser.text import parse_raw_markdown
from amanuensis.parser.render import PreviewHtmlRenderer, WordCounter from amanuensis.parser.render import PreviewHtmlRenderer

View File

@ -0,0 +1,24 @@
"""
Internal module encapsulating visitors that compute metrics on articles
for verification against constraints.
"""
import re
class WordCounter():
def TextSpan(self, span):
return len(re.split('\s+', span.innertext.strip()))
def LineBreak(self, span):
return 0
def ParsedArticle(self, span):
return sum(span.recurse(self))
def BodyParagraph(self, span):
return sum(span.recurse(self))
def SignatureParagraph(self, span):
return sum(span.recurse(self))
def BoldSpan(self, span):
return sum(span.recurse(self))
def ItalicSpan(self, span):
return sum(span.recurse(self))
def CitationSpan(self, span):
return sum(span.recurse(self))

View File

@ -1,10 +1,8 @@
""" """
Internal module encapsulating the render logic for parsed articles. Rendering Internal module encapsulating visitors that render articles into
is done via a rough approximation of the visitor pattern. readable formats.
""" """
import re
class PreviewHtmlRenderer(): class PreviewHtmlRenderer():
def TextSpan(self, span): def TextSpan(self, span):
@ -25,21 +23,3 @@ class PreviewHtmlRenderer():
return f'<i>{"".join(span.recurse(self))}</i>' return f'<i>{"".join(span.recurse(self))}</i>'
def CitationSpan(self, span): def CitationSpan(self, span):
return f'<a href="#">{"".join(span.recurse(self))}</a>' return f'<a href="#">{"".join(span.recurse(self))}</a>'
class WordCounter():
def TextSpan(self, span):
return len(re.split('\s+', span.innertext.strip()))
def LineBreak(self, span):
return 0
def ParsedArticle(self, span):
return sum(span.recurse(self))
def BodyParagraph(self, span):
return sum(span.recurse(self))
def SignatureParagraph(self, span):
return sum(span.recurse(self))
def BoldSpan(self, span):
return sum(span.recurse(self))
def ItalicSpan(self, span):
return sum(span.recurse(self))
def CitationSpan(self, span):
return sum(span.recurse(self))