diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/Checker.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/Checker.kt index 636c4313..68721174 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/Checker.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/Checker.kt @@ -1,18 +1,8 @@ package com.github.darderion.mundaneassignmentpolice.checker import com.github.darderion.mundaneassignmentpolice.checker.rule.Rule -import com.github.darderion.mundaneassignmentpolice.checker.rule.list.ListRuleBuilder -import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.SymbolRule -import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.SymbolRuleBuilder -import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.and -import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.or -import com.github.darderion.mundaneassignmentpolice.checker.rule.tableofcontent.TableOfContentRuleBuilder -import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea.* -import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion.Companion.EVERYWHERE -import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion.Companion.NOWHERE import com.github.darderion.mundaneassignmentpolice.rules.RuleSet import com.github.darderion.mundaneassignmentpolice.wrapper.PDFBox -import java.util.* class Checker { fun getRuleViolations(pdfName: String, ruleSet: RuleSet) = getRuleViolations(pdfName, ruleSet.rules) diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/PunctuationMark.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/PunctuationMark.kt new file mode 100644 index 00000000..bd7d7077 --- /dev/null +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/PunctuationMark.kt @@ -0,0 +1,10 @@ +package com.github.darderion.mundaneassignmentpolice.checker + +enum class PunctuationMark(val value: Char) { + FULL_STOP('.'), + COMMA(',') +} + +fun Char.isPunctuationMark() = PunctuationMark.values().map { it.value }.contains(this) + +fun String.isPunctuationMark() = this.length == 1 && this.single().isPunctuationMark() diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaPunctuationRule.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaPunctuationRule.kt new file mode 100644 index 00000000..0e41e282 --- /dev/null +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaPunctuationRule.kt @@ -0,0 +1,47 @@ +package com.github.darderion.mundaneassignmentpolice.checker.rule.formula + +import com.github.darderion.mundaneassignmentpolice.checker.RuleViolation +import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType +import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument +import com.github.darderion.mundaneassignmentpolice.pdfdocument.inside +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Formula +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Word + +class FormulaPunctuationRule( + type: RuleViolationType, + name: String, + private val ignoredWords: List, + private val ruleBody: + (formula: Formula, filteredText: List, nextFormula: Formula?) -> List +) : FormulaRule(type, name) { + override fun getViolations(document: PDFDocument, formulas: List): List { + val violations = mutableListOf() + + formulas.forEachIndexed { index, formula -> + val textAfterFormula = formula.lines.last().text + .takeLastWhile { it != formula.text.last() } + .toMutableList() + + textAfterFormula.addAll( + document.text.asSequence().drop(formula.lines.last().documentIndex + 1) + .filter { it.area!! inside area && it.isNotEmpty() } + .take(2) // take a line with formula reference and a line with words after the formula + .map { it.text }.flatten() + ) + + val filteredText = textAfterFormula.filterNot { word -> ignoredWords.any { it.matches(word.text) } } + + val nextFormula = formulas.getOrNull(index + 1) + + val violationLines = ruleBody(formula, filteredText, nextFormula) + if (violationLines.isNotEmpty()) { + violations.add( + RuleViolation(violationLines, name, type) + ) + } + } + + return violations + } +} diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaPunctuationRuleBuilder.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaPunctuationRuleBuilder.kt new file mode 100644 index 00000000..cd0aef4b --- /dev/null +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaPunctuationRuleBuilder.kt @@ -0,0 +1,31 @@ +package com.github.darderion.mundaneassignmentpolice.checker.rule.formula + +import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Formula +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Word + +class FormulaPunctuationRuleBuilder { + private var type: RuleViolationType = RuleViolationType.Error + private var name: String = "Rule name" + private var ignoredWords: MutableList = mutableListOf() + private var ruleBody: (formula: Formula, filteredText: List, nextFormula: Formula?) -> List = + { _, _, _ -> emptyList() } + + infix fun called(name: String) = this.also { this.name = name } + + infix fun type(type: RuleViolationType) = this.also { this.type = type } + + fun ignoredWords(vararg regexes: Regex) = this.also { ignoredWords.addAll(regexes) } + + infix fun rule( + ruleBody: (formula: Formula, filteredText: List, nextFormula: Formula?) -> List + ) = this.also { this.ruleBody = ruleBody } + + fun getRule() = FormulaPunctuationRule( + type, + name, + ignoredWords, + ruleBody + ) as FormulaRule +} diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaRule.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaRule.kt new file mode 100644 index 00000000..04a4133b --- /dev/null +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/checker/rule/formula/FormulaRule.kt @@ -0,0 +1,56 @@ +package com.github.darderion.mundaneassignmentpolice.checker.rule.formula + +import com.github.darderion.mundaneassignmentpolice.checker.RuleViolation +import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType +import com.github.darderion.mundaneassignmentpolice.checker.rule.Rule +import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea +import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument +import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion +import com.github.darderion.mundaneassignmentpolice.pdfdocument.inside +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Formula +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.PostScriptFontType +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Word + +abstract class FormulaRule( + type: RuleViolationType, + name: String +) : Rule(PDFRegion.NOWHERE.except(PDFArea.SECTION), name, type) { + abstract fun getViolations(document: PDFDocument, formulas: List): List + + override fun process(document: PDFDocument) = + getViolations(document, getAllFormulas(document)) + + private fun getAllFormulas(document: PDFDocument): List { + val text = document.text.filter { it.area!! inside area && it.isNotEmpty() } + + val formulas = mutableListOf() + val formulaText = mutableListOf() + val formulaLines = mutableSetOf() + + text.forEach { line -> + line.text.forEach { word -> + if (word.font.type == PostScriptFontType.TYPE2 || word.text == " " && formulaText.isNotEmpty()) { + // also captures some records in tables and code listings + formulaText.add(word) + formulaLines.add(line) + } else if (formulaText.isNotEmpty()) { + formulas.add(Formula(formulaText.dropLastWhile { it.text == " " }, formulaLines.toSet())) + formulaText.clear() + formulaLines.clear() + } + } + } + if (formulaText.isNotEmpty()) + formulas.add(Formula(formulaText.dropLastWhile { it.text == " " }, formulaLines.toSet())) + + return filterFormulas(formulas) + } + + private fun filterFormulas(formulas: List) = + formulas.filterNot { + it.text.size == 1 && it.text.first().text == "∗" // remove single special characters + }.filterNot { + it.text.size == 1 && it.text.first().text.toDoubleOrNull() != null // remove numbers + } +} diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/PDFDocument.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/PDFDocument.kt index 280a9ff2..a7c7e71b 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/PDFDocument.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/PDFDocument.kt @@ -2,7 +2,6 @@ package com.github.darderion.mundaneassignmentpolice.pdfdocument import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line import mu.KotlinLogging -import java.lang.Exception class PDFDocument(val name: String = "PDF", val text: List, diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/list/PDFList.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/list/PDFList.kt index c55826eb..bf3592be 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/list/PDFList.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/list/PDFList.kt @@ -1,9 +1,6 @@ package com.github.darderion.mundaneassignmentpolice.pdfdocument.list -import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Coordinate -import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Font -import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line -import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Word +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.* import java.util.* data class PDFList(val value: MutableList = mutableListOf(), val nodes: MutableList> = mutableListOf()) { @@ -54,7 +51,7 @@ data class PDFList(val value: MutableList = mutableListOf(), val nodes: Mu */ fun getLists(lines: List): List> { // Adding a line to process a text that has no lines after a list - val lines = lines + Line(-1, -1, -1, listOf(Word("NOT A LIST ITEM", Font(0.0f), Coordinate(1000, -1)))) + val lines = lines + Line(-1, -1, -1, listOf(Word("NOT A LIST ITEM", Font(), Coordinate(1000, -1)))) val lists: MutableList> = mutableListOf() val stack: Stack> = Stack() diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Font.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Font.kt index 20580b21..1164f35b 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Font.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Font.kt @@ -2,9 +2,15 @@ package com.github.darderion.mundaneassignmentpolice.pdfdocument.text import com.github.darderion.mundaneassignmentpolice.utils.floatEquals -class Font(val size: Float) { +enum class PostScriptFontType { + TYPE0, TYPE1, TYPE2, TYPE3, NONE +} + +class Font(val type: PostScriptFontType, val size: Float) { + constructor(): this(PostScriptFontType.NONE, 0.0f) + override fun equals(other: Any?) = this === other || - (other is Font && floatEquals(size, other.size)) + (other is Font && type == other.type && floatEquals(size, other.size)) - override fun hashCode() = size.hashCode() + override fun hashCode() = (type to size).hashCode() } diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Formula.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Formula.kt new file mode 100644 index 00000000..901f2baa --- /dev/null +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Formula.kt @@ -0,0 +1,3 @@ +package com.github.darderion.mundaneassignmentpolice.pdfdocument.text + +data class Formula(val text: List, val lines: Set) diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Line.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Line.kt index a7003cc6..0c194910 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Line.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Line.kt @@ -20,4 +20,8 @@ data class Line(val index: Int, val page: Int, val documentIndex: Int, override fun toString() = "[$documentIndex -- $index, p.$page, $area, ${position.x}] --> '$content'" fun drop(numberOfItems: Int) = Line(index, page, documentIndex, text.drop(numberOfItems), area) + + fun isEmpty() = text.isEmpty() || text.size == 1 && text.first().text == "" + + fun isNotEmpty() = !isEmpty() } diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Word.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Word.kt index 6663a344..3fb28309 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Word.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/pdfdocument/text/Word.kt @@ -5,6 +5,6 @@ data class Word(val text: String, val font: Font, val position: Coordinate) { companion object { val spaceCharacter: Word - get() = Word(" ", Font(0.0f), Coordinate(0, 0)) + get() = Word(" ", Font(), Coordinate(0, 0)) } } diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/RuleSet.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/RuleSet.kt index eb2fa858..f7bf89eb 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/RuleSet.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/RuleSet.kt @@ -3,7 +3,7 @@ package com.github.darderion.mundaneassignmentpolice.rules import com.github.darderion.mundaneassignmentpolice.checker.rule.Rule val RULE_SET_RU = RuleSet( - mutableListOf( + listOf( RULE_LITLINK, RULE_SHORT_DASH, RULE_MEDIUM_DASH, @@ -21,6 +21,7 @@ val RULE_SET_RU = RuleSet( ) + RULES_SPACE_AROUND_BRACKETS + RULES_SMALL_NUMBERS + + RULES_FORMULA_PUNCTUATION ) -class RuleSet(val rules: List) {} +class RuleSet(val rules: List) diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt index e3ecfa20..b4236f2b 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt @@ -1,8 +1,10 @@ package com.github.darderion.mundaneassignmentpolice.rules +import com.github.darderion.mundaneassignmentpolice.checker.PunctuationMark import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType +import com.github.darderion.mundaneassignmentpolice.checker.isPunctuationMark +import com.github.darderion.mundaneassignmentpolice.checker.rule.formula.FormulaPunctuationRuleBuilder import com.github.darderion.mundaneassignmentpolice.checker.rule.list.ListRuleBuilder -import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.SymbolRule import com.github.darderion.mundaneassignmentpolice.checker.rule.regex.RegexRuleBuilder import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.SymbolRuleBuilder import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.and @@ -265,3 +267,91 @@ val RULE_ORDER_OF_REFERENCES = RegexRuleBuilder() referencesInIntList != referencesInIntList.sorted() }.map { it.second } }.getRule() + +private val ignoringAfterFormula = listOf( + """\s""".toRegex(), + """\([0-9]+\)""".toRegex() // ignore formula reference, e.g. "(1)" +) + +val fullStopAfterFormulaRule = FormulaPunctuationRuleBuilder() + .called("Отсутствует точка после формулы") + .ignoredWords(*ignoringAfterFormula.toTypedArray()) + .rule { formula, filteredText, nextFormula -> + val violationLines = listOf(formula.lines.last()) + val lastFormulaSymbol = formula.text.last().text.last() + + if (filteredText.isEmpty()) { + return@rule if (lastFormulaSymbol != PunctuationMark.FULL_STOP.value) violationLines else emptyList() + } + + // full stop is not required if there is another formula after the formula + val (firstAfterFormula, secondAfterFormula) = filteredText.first() to filteredText.getOrNull(1) + if (nextFormula != null && + (firstAfterFormula == nextFormula.text.first() || + firstAfterFormula.text.isPunctuationMark() && secondAfterFormula == nextFormula.text.first()) + ) { + return@rule emptyList() + } + + val indicator = """[A-ZА-Я].*?""".toRegex() // capitalized word that indicates the beginning of a new sentence + if (indicator.matches(firstAfterFormula.text)) { + return@rule if (lastFormulaSymbol != PunctuationMark.FULL_STOP.value) violationLines else emptyList() + } + + // case when a punctuation mark is after the formula and not the last symbol of the formula + if (firstAfterFormula.text.isPunctuationMark() && + secondAfterFormula != null && indicator.matches(secondAfterFormula.text) + ) { + return@rule if (firstAfterFormula.text.single() != PunctuationMark.FULL_STOP.value) violationLines + else emptyList() + } + + return@rule emptyList() + } + .getRule() + +val commaAfterFormulaRule = FormulaPunctuationRuleBuilder() + .called("Отсутствует запятая после формулы") + .ignoredWords(*ignoringAfterFormula.toTypedArray()) + .rule { formula, filteredText, nextFormula -> + val violationLines = listOf(formula.lines.last()) + val lastFormulaSymbol = formula.text.last().text.last() + + if (filteredText.isEmpty()) return@rule emptyList() + + // comma is required if there is another formula after the formula + val (firstAfterFormula, secondAfterFormula) = filteredText.first() to filteredText.getOrNull(1) + if (nextFormula != null) { + if (firstAfterFormula == nextFormula.text.first()) { + return@rule if (lastFormulaSymbol == PunctuationMark.COMMA.value || + lastFormulaSymbol == PunctuationMark.FULL_STOP.value + ) emptyList() + else violationLines + } + + if (firstAfterFormula.text.isPunctuationMark() && secondAfterFormula == nextFormula.text.first()) { + return@rule if (firstAfterFormula.text.single() == PunctuationMark.COMMA.value || + firstAfterFormula.text.single() == PunctuationMark.FULL_STOP.value + ) emptyList() + else violationLines + } + } + + val indicator = """где""".toRegex() + if (indicator.matches(firstAfterFormula.text)) { + return@rule if (lastFormulaSymbol != PunctuationMark.COMMA.value) violationLines else emptyList() + } + + // case when a punctuation mark is after the formula and not the last symbol of the formula + if (firstAfterFormula.text.isPunctuationMark() && + secondAfterFormula != null && indicator.matches(secondAfterFormula.text) + ) { + return@rule if (firstAfterFormula.text.single() != PunctuationMark.COMMA.value) violationLines + else emptyList() + } + + return@rule emptyList() + } + .getRule() + +val RULES_FORMULA_PUNCTUATION = listOf(fullStopAfterFormulaRule, commaAfterFormulaRule) diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFBox.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFBox.kt index 395b3426..a446d809 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFBox.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFBox.kt @@ -100,8 +100,8 @@ class PDFBox { val strippers = listOf(stripper, textStripper) - var lineIndex = 0 - for(pageIndex in (0..document.pages.count)) { + var lineIndex = -1 + for (pageIndex in (0 until document.pages.count)) { // For each page strippers.forEach { it.startPage = pageIndex + 1 @@ -142,7 +142,7 @@ class PDFBox { contentIndex += contentItem.length if (contentItem == " ") { - words.add(Word(word, font?: Font(0.0f), coordinates)) + words.add(Word(word, font?: Font(), coordinates)) words.add(Word.spaceCharacter) font = null word = "" @@ -163,7 +163,7 @@ class PDFBox { stripperIndex++ } } - if (font == null && word.isEmpty()) font = Font(0.0f) + if (font == null && word.isEmpty()) font = Font() words.add(Word(word, font!!, coordinates)) Line(line, pageIndex, lineIndex, words.toList()) diff --git a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFStripper.kt b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFStripper.kt index 00baf046..bb949539 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFStripper.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/wrapper/PDFStripper.kt @@ -2,8 +2,12 @@ package com.github.darderion.mundaneassignmentpolice.wrapper import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Coordinate import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Font +import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.PostScriptFontType import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Symbol -import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Word +import org.apache.pdfbox.pdmodel.font.PDType0Font +import org.apache.pdfbox.pdmodel.font.PDType1CFont +import org.apache.pdfbox.pdmodel.font.PDType1Font +import org.apache.pdfbox.pdmodel.font.PDType3Font import org.apache.pdfbox.text.PDFTextStripper import org.apache.pdfbox.text.TextPosition @@ -16,10 +20,19 @@ class PDFStripper: PDFTextStripper() { override fun writeString(string: String?, textPositions: List) { for (text: TextPosition in textPositions) { val symbol = text.unicode + + val fontType = when (text.font) { + is PDType0Font -> PostScriptFontType.TYPE0 + is PDType1Font -> PostScriptFontType.TYPE1 + is PDType1CFont -> PostScriptFontType.TYPE2 + is PDType3Font -> PostScriptFontType.TYPE3 + else -> PostScriptFontType.NONE + } + if (symbol != null && symbol != " ") { symbol.forEach { symbols.add( - Symbol(it, Font(text.fontSize), Coordinate(text.xDirAdj to text.yDirAdj)) + Symbol(it, Font(fontType, text.fontSize), Coordinate(text.xDirAdj to text.yDirAdj)) ) } } diff --git a/src/test/kotlin/com/github/darderion/mundaneassignmentpolice/checker/RulesTests.kt b/src/test/kotlin/com/github/darderion/mundaneassignmentpolice/checker/RulesTests.kt index 3c4c908d..31902758 100644 --- a/src/test/kotlin/com/github/darderion/mundaneassignmentpolice/checker/RulesTests.kt +++ b/src/test/kotlin/com/github/darderion/mundaneassignmentpolice/checker/RulesTests.kt @@ -51,6 +51,10 @@ class RulesTests : StringSpec({ "Regex rule should detect incorrect order of literature references"{ RULE_ORDER_OF_REFERENCES.process(PDFBox().getPDF(filePathOrderOfReferences)).count() shouldBeExactly 3 } + "Formula punctuation rules should detect the absence of a full stop or a comma after a formula"{ + fullStopAfterFormulaRule.process(PDFBox().getPDF(filePathFormulaPunctuation)).count() shouldBeExactly 3 + commaAfterFormulaRule.process(PDFBox().getPDF(filePathFormulaPunctuation)).count() shouldBeExactly 4 + } }) { companion object { const val filePathQuestionMarkAndDashes = @@ -63,10 +67,12 @@ class RulesTests : StringSpec({ const val filePathSpaceAroundBrackets = "${TestsConfiguration.resourceFolder}checker/SymbolRuleTestsSpaceAroundBrackets.pdf" const val filePathCitation = "${TestsConfiguration.resourceFolder}checker/SymbolRuleTestsCitation.pdf" - const val filePathShortenedUrls = "${TestsConfiguration.resourceFolder}checker/URLRuleShortenedUrls.pdf" + const val filePathShortenedUrls = "${TestsConfiguration.resourceFolder}checker/URLRuleTestsShortenedUrls.pdf" const val filePathSymbolsInSectionNames = "${TestsConfiguration.resourceFolder}checker/RulesTestsSymbolsInSectionNames.pdf" const val filePathOrderOfReferences = "${TestsConfiguration.resourceFolder}checker/RegexRuleTestsOrderOfReferences.pdf" + const val filePathFormulaPunctuation = + "${TestsConfiguration.resourceFolder}checker/FormulaRuleTestsFormulaPunctuation.pdf" } } diff --git a/src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/FormulaRuleTestsFormulaPunctuation.pdf b/src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/FormulaRuleTestsFormulaPunctuation.pdf new file mode 100644 index 00000000..e70c6c0e Binary files /dev/null and b/src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/FormulaRuleTestsFormulaPunctuation.pdf differ diff --git a/src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/URLRuleShortenedUrls.pdf b/src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/URLRuleTestsShortenedUrls.pdf similarity index 100% rename from src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/URLRuleShortenedUrls.pdf rename to src/test/resources/com/github/darderion/mundaneassignmentpolice/checker/URLRuleTestsShortenedUrls.pdf