Implement more constraint analysis
This commit is contained in:
parent
4e13cdeff6
commit
214136485c
|
@ -66,18 +66,28 @@ def get_draft(
|
||||||
def title_constraint_analysis(
|
def title_constraint_analysis(
|
||||||
lexicon: LexiconModel,
|
lexicon: LexiconModel,
|
||||||
player: UserModel,
|
player: UserModel,
|
||||||
title: str) -> Tuple[List[str], List[str]]:
|
title: str) -> Tuple[List[str], List[str], List[str]]:
|
||||||
"""
|
"""
|
||||||
Checks article constraints for the lexicon against a proposed
|
Checks article constraints for the lexicon against a proposed
|
||||||
draft title.
|
draft title.
|
||||||
"""
|
"""
|
||||||
warnings = []
|
infos: list = []
|
||||||
errors = []
|
warnings: list = []
|
||||||
|
errors: list = []
|
||||||
with lexicon.ctx.read('info') as info:
|
with lexicon.ctx.read('info') as info:
|
||||||
# No title
|
# E: No title
|
||||||
if not title:
|
if not title:
|
||||||
errors.append('Missing title')
|
errors.append('Missing title')
|
||||||
return warnings, errors # No point in further analysis
|
return infos, warnings, errors # No point in further analysis
|
||||||
|
# I: This article is new
|
||||||
|
if title not in info:
|
||||||
|
infos.append('New article')
|
||||||
|
# I: This article is a phantom
|
||||||
|
elif info[title].character is None:
|
||||||
|
infos.append('Phantom article')
|
||||||
|
# E: This article has already been written and addendums are disabled
|
||||||
|
elif not lexicon.cfg.article.addendum.allowed:
|
||||||
|
errors.append('Article already exists')
|
||||||
# The article does not sort under the player's assigned index
|
# The article does not sort under the player's assigned index
|
||||||
pass
|
pass
|
||||||
# The article's title is new, but its index is full
|
# The article's title is new, but its index is full
|
||||||
|
@ -97,7 +107,7 @@ def title_constraint_analysis(
|
||||||
# The article's title matches a character's name
|
# The article's title matches a character's name
|
||||||
pass # warning
|
pass # warning
|
||||||
|
|
||||||
return warnings, errors
|
return infos, warnings, errors
|
||||||
|
|
||||||
|
|
||||||
def content_constraint_analysis(
|
def content_constraint_analysis(
|
||||||
|
@ -109,13 +119,14 @@ def content_constraint_analysis(
|
||||||
Checks article constraints for the lexicon against the content of
|
Checks article constraints for the lexicon against the content of
|
||||||
a draft
|
a draft
|
||||||
"""
|
"""
|
||||||
infos = []
|
infos: list = []
|
||||||
warnings = []
|
warnings: list = []
|
||||||
errors = []
|
errors: list = []
|
||||||
character = lexicon.cfg.character.get(cid)
|
character = lexicon.cfg.character.get(cid)
|
||||||
content_analysis: ConstraintAnalysis = (
|
content_analysis: ConstraintAnalysis = (
|
||||||
parsed.render(ConstraintAnalysis(lexicon)))
|
parsed.render(ConstraintAnalysis(lexicon)))
|
||||||
with lexicon.ctx.read('info') as info:
|
with lexicon.ctx.read('info') as info:
|
||||||
|
# I: Word count
|
||||||
infos.append(f'Word count: {content_analysis.word_count}')
|
infos.append(f'Word count: {content_analysis.word_count}')
|
||||||
# Self-citation when forbidden
|
# Self-citation when forbidden
|
||||||
pass
|
pass
|
||||||
|
@ -130,20 +141,20 @@ def content_constraint_analysis(
|
||||||
# Too many total citations
|
# Too many total citations
|
||||||
# Not enough characters' articles cited
|
# Not enough characters' articles cited
|
||||||
# Too many characters' articles cited
|
# Too many characters' articles cited
|
||||||
# Exceeded hard word limit
|
# E: Exceeded hard word limit
|
||||||
if (lexicon.cfg.article.word_limit.hard is not None
|
if (lexicon.cfg.article.word_limit.hard is not None
|
||||||
and content_analysis.word_count > lexicon.cfg.article.word_limit.hard):
|
and content_analysis.word_count > lexicon.cfg.article.word_limit.hard):
|
||||||
errors.append('Exceeded maximum word count '
|
errors.append('Exceeded maximum word count '
|
||||||
f'({lexicon.cfg.article.word_limit.hard})')
|
f'({lexicon.cfg.article.word_limit.hard})')
|
||||||
# Exceeded soft word limit
|
# W: Exceeded soft word limit
|
||||||
elif (lexicon.cfg.article.word_limit.soft is not None
|
elif (lexicon.cfg.article.word_limit.soft is not None
|
||||||
and content_analysis.word_count > lexicon.cfg.article.word_limit.soft):
|
and content_analysis.word_count > lexicon.cfg.article.word_limit.soft):
|
||||||
warnings.append('Exceeded suggested maximum word count '
|
warnings.append('Exceeded suggested maximum word count '
|
||||||
f'({lexicon.cfg.article.word_limit.soft})')
|
f'({lexicon.cfg.article.word_limit.soft})')
|
||||||
# Missing signature
|
# W: Missing signature
|
||||||
if content_analysis.signatures < 1:
|
if content_analysis.signatures < 1:
|
||||||
warnings.append('Missing signature')
|
warnings.append('Missing signature')
|
||||||
# Multiple signatures
|
# W: Multiple signatures
|
||||||
if content_analysis.signatures > 1:
|
if content_analysis.signatures > 1:
|
||||||
warnings.append('Multiple signatures')
|
warnings.append('Multiple signatures')
|
||||||
# Signature altered from default
|
# Signature altered from default
|
||||||
|
|
|
@ -110,7 +110,7 @@ def update_draft(lexicon: LexiconModel, article_json):
|
||||||
# HTML parsing
|
# HTML parsing
|
||||||
preview = parsed.render(PreviewHtmlRenderer(lexicon))
|
preview = parsed.render(PreviewHtmlRenderer(lexicon))
|
||||||
# Constraint analysis
|
# Constraint analysis
|
||||||
title_warnings, title_errors = title_constraint_analysis(
|
title_infos, title_warnings, title_errors = title_constraint_analysis(
|
||||||
lexicon, current_user, title)
|
lexicon, current_user, title)
|
||||||
content_infos, content_warnings, content_errors = content_constraint_analysis(
|
content_infos, content_warnings, content_errors = content_constraint_analysis(
|
||||||
lexicon, current_user, article.character, parsed)
|
lexicon, current_user, article.character, parsed)
|
||||||
|
@ -133,7 +133,7 @@ def update_draft(lexicon: LexiconModel, article_json):
|
||||||
},
|
},
|
||||||
'rendered': preview.contents,
|
'rendered': preview.contents,
|
||||||
'citations': preview.citations,
|
'citations': preview.citations,
|
||||||
'info': content_infos,
|
'info': title_infos + content_infos,
|
||||||
'warning': title_warnings + content_warnings,
|
'warning': title_warnings + content_warnings,
|
||||||
'error': title_errors + content_errors,
|
'error': title_errors + content_errors,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue