From 10b9703064b75975461225b728a1dfbf517516ac Mon Sep 17 00:00:00 2001 From: GeorgeBasiev Date: Thu, 30 May 2024 17:39:34 +0300 Subject: [PATCH 1/4] 1 --- .../mundaneassignmentpolice/rules/Rules.kt | 72 +++++++++++++------ 1 file changed, 49 insertions(+), 23 deletions(-) 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 229296d0..94150566 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt @@ -15,6 +15,7 @@ import com.github.darderion.mundaneassignmentpolice.checker.rule.url.then import com.github.darderion.mundaneassignmentpolice.checker.rule.word.WordRule import com.github.darderion.mundaneassignmentpolice.checker.rule.word.WordRuleBuilder import com.github.darderion.mundaneassignmentpolice.checker.rule.word.or +import com.github.darderion.mundaneassignmentpolice.checker.rule.word.and import com.github.darderion.mundaneassignmentpolice.checker.rule.word.splitToWordsAndPunctuations import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument @@ -92,11 +93,23 @@ val RULE_LONG_DASH = SymbolRuleBuilder() .called("Неправильное использование длинного тире") .setDescription("В русском языке оно ставится вместо отсутствующего члена предложения, для указания маршрутов и в ряде других случаев. Подробнее написано тут https://www.vgsa.ru/blogs/mos/80/index.php?special=Y и https://theoryandpractice.ru/posts/18471-dlinnoe-ili-korotkoe-kak-stavit-tire") .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) - .getRule() and SymbolRuleBuilder() + .getRule() and (SymbolRuleBuilder() .symbol(longDash) .shouldHaveNeighbor(' ') .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) + .getRule() or + (SymbolRuleBuilder() + .symbol(longDash) + .fromLeft() + .shouldHaveNeighbor(' ') + .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) .getRule() + and SymbolRuleBuilder() + .symbol(longDash) + .fromRight() + .shouldHaveNeighbor('\n') + .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) + .getRule())) val closingQuote = '”' val openingQuote = '“' @@ -130,26 +143,39 @@ val RULE_MULTIPLE_LITLINKS = SymbolRuleBuilder() .setDescription("Несколько ссылок подряд следует оформлять так [0,1], а не [0] [1]") .getRule() -const val bracket = '(' - -val RULE_BRACKETS_LETTERS = List(2) { - SymbolRuleBuilder() - .symbol(bracket) - .ignoringAdjusting(' ') - .called("Большая русская буква после скобки") - .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") - .type(RuleViolationType.Warning) -}.apply { - first() - .fromLeft() - .shouldNotHaveNeighbor('.') - last() - .fromRight() - .shouldNotHaveNeighbor(*rusCapitalLetters.toCharArray()) -}.map { it.getRule() } - .reduce { acc, symbolRule -> - acc and symbolRule - } +const val bracket = "(" + +val ruleBracketsLettersBuilder1 = WordRuleBuilder() + .word(bracket) + .ignoringAdjusting(Regex("""\s""")) + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) + .fromLeft() + .shouldNotHaveNeighbor(Regex("""\.""")) + +val ruleBracketsLettersBuilder2 = WordRuleBuilder() + .word(bracket) + .ignoringAdjusting(Regex("""\s""")) + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) + .fromRight() + .shouldNotHaveNeighbor(Regex("""[А-Я][а-я]*""")) + +val ruleBracketsLettersBuilder3 = WordRuleBuilder() + .word(bracket) + .ignoringAdjusting(Regex("""\s""")) + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) + .fromRight() + .shouldHaveNeighbor(Regex("""[А-Я][а-я]*[А-Я]+[А-Яа-я]*""")) + +val RULE_BRACKETS_LETTERS = (ruleBracketsLettersBuilder1.getRule() and + ruleBracketsLettersBuilder2.getRule()) or + (ruleBracketsLettersBuilder1.getRule() and + ruleBracketsLettersBuilder3.getRule()) private const val openingBrackets = "([{<" private const val closingBrackets = ")]}>" @@ -475,12 +501,12 @@ val RULE_ORDER_OF_REFERENCES = RegexRuleBuilder() }.map { it.second } }.getRule() -val exclusionsForAbbreviations = arrayOf(Regex("или", RegexOption.IGNORE_CASE), Regex("по", RegexOption.IGNORE_CASE)) +val exclusionsForAbbreviations = arrayOf(Regex("или", RegexOption.IGNORE_CASE), Regex("по", RegexOption.IGNORE_CASE), Regex("не", RegexOption.IGNORE_CASE)) val RULE_VARIOUS_ABBREVIATIONS = RegexRuleBuilder() .called("Использованы различные версии сокращения") .setDescription("Тексте работ (не в ссылках!) часто пишут github, Github и GitHub. При этом, во-первых правильное написание — это GitHub, а во-вторых, в общем случае подобная разнородность смотрится некрасиво. Сейчас правило часто захватывает web-ссылки и потому возможны ложные срабатывания, однако следует проверить все ли из них — ложные (практика показывает что нет)") - .regex(Regex("""[a-zA-Zа-яА-Я]+""")) + .regex(Regex("""(? val abbreviations = hashSetOf() From c7361f2390058cf669205fc7edcef3762c1cc9d4 Mon Sep 17 00:00:00 2001 From: GeorgeBasiev Date: Fri, 31 May 2024 01:28:19 +0300 Subject: [PATCH 2/4] original repo state --- .../mundaneassignmentpolice/rules/Rules.kt | 72 ++++++------------- 1 file changed, 23 insertions(+), 49 deletions(-) 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 00469b3a..27181349 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt @@ -15,7 +15,6 @@ import com.github.darderion.mundaneassignmentpolice.checker.rule.url.then import com.github.darderion.mundaneassignmentpolice.checker.rule.word.WordRule import com.github.darderion.mundaneassignmentpolice.checker.rule.word.WordRuleBuilder import com.github.darderion.mundaneassignmentpolice.checker.rule.word.or -import com.github.darderion.mundaneassignmentpolice.checker.rule.word.and import com.github.darderion.mundaneassignmentpolice.checker.rule.word.splitToWordsAndPunctuations import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument @@ -93,23 +92,11 @@ val RULE_LONG_DASH = SymbolRuleBuilder() .called("Неправильное использование длинного тире") .setDescription("В русском языке оно ставится вместо отсутствующего члена предложения, для указания маршрутов и в ряде других случаев. Подробнее написано тут https://www.vgsa.ru/blogs/mos/80/index.php?special=Y и https://theoryandpractice.ru/posts/18471-dlinnoe-ili-korotkoe-kak-stavit-tire") .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) - .getRule() and (SymbolRuleBuilder() + .getRule() and SymbolRuleBuilder() .symbol(longDash) .shouldHaveNeighbor(' ') .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) - .getRule() or - (SymbolRuleBuilder() - .symbol(longDash) - .fromLeft() - .shouldHaveNeighbor(' ') - .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) .getRule() - and SymbolRuleBuilder() - .symbol(longDash) - .fromRight() - .shouldHaveNeighbor('\n') - .inArea(PDFRegion.EVERYWHERE.except(PDFArea.BIBLIOGRAPHY, PDFArea.FOOTNOTE)) - .getRule())) val closingQuote = '”' val openingQuote = '“' @@ -143,39 +130,26 @@ val RULE_MULTIPLE_LITLINKS = SymbolRuleBuilder() .setDescription("Несколько ссылок подряд следует оформлять так [0,1], а не [0] [1]") .getRule() -const val bracket = "(" - -val ruleBracketsLettersBuilder1 = WordRuleBuilder() - .word(bracket) - .ignoringAdjusting(Regex("""\s""")) - .called("Большая русская буква после скобки") - .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") - .type(RuleViolationType.Warning) - .fromLeft() - .shouldNotHaveNeighbor(Regex("""\.""")) - -val ruleBracketsLettersBuilder2 = WordRuleBuilder() - .word(bracket) - .ignoringAdjusting(Regex("""\s""")) - .called("Большая русская буква после скобки") - .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") - .type(RuleViolationType.Warning) - .fromRight() - .shouldNotHaveNeighbor(Regex("""[А-Я][а-я]*""")) - -val ruleBracketsLettersBuilder3 = WordRuleBuilder() - .word(bracket) - .ignoringAdjusting(Regex("""\s""")) - .called("Большая русская буква после скобки") - .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") - .type(RuleViolationType.Warning) - .fromRight() - .shouldHaveNeighbor(Regex("""[А-Я][а-я]*[А-Я]+[А-Яа-я]*""")) - -val RULE_BRACKETS_LETTERS = (ruleBracketsLettersBuilder1.getRule() and - ruleBracketsLettersBuilder2.getRule()) or - (ruleBracketsLettersBuilder1.getRule() and - ruleBracketsLettersBuilder3.getRule()) +const val bracket = '(' + +val RULE_BRACKETS_LETTERS = List(2) { + SymbolRuleBuilder() + .symbol(bracket) + .ignoringAdjusting(' ') + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) +}.apply { + first() + .fromLeft() + .shouldNotHaveNeighbor('.') + last() + .fromRight() + .shouldNotHaveNeighbor(*rusCapitalLetters.toCharArray()) +}.map { it.getRule() } + .reduce { acc, symbolRule -> + acc and symbolRule + } private const val openingBrackets = "([{<" private const val closingBrackets = ")]}>" @@ -556,12 +530,12 @@ val RULE_ORDER_OF_REFERENCES = RegexRuleBuilder() }.map { it.second } }.getRule() -val exclusionsForAbbreviations = arrayOf(Regex("или", RegexOption.IGNORE_CASE), Regex("по", RegexOption.IGNORE_CASE), Regex("не", RegexOption.IGNORE_CASE)) +val exclusionsForAbbreviations = arrayOf(Regex("или", RegexOption.IGNORE_CASE), Regex("по", RegexOption.IGNORE_CASE)) val RULE_VARIOUS_ABBREVIATIONS = RegexRuleBuilder() .called("Использованы различные версии сокращения") .setDescription("Тексте работ (не в ссылках!) часто пишут github, Github и GitHub. При этом, во-первых правильное написание — это GitHub, а во-вторых, в общем случае подобная разнородность смотрится некрасиво. Сейчас правило часто захватывает web-ссылки и потому возможны ложные срабатывания, однако следует проверить все ли из них — ложные (практика показывает что нет)") - .regex(Regex("""(? val abbreviations = hashSetOf() From af0a532c2d554055751aee49e3eef751e6479de0 Mon Sep 17 00:00:00 2001 From: GeorgeBasiev Date: Fri, 31 May 2024 01:30:42 +0300 Subject: [PATCH 3/4] RuleSet original repo state --- .../github/darderion/mundaneassignmentpolice/rules/RuleSet.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 17e8fbd1..59a47d13 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/RuleSet.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/RuleSet.kt @@ -28,7 +28,7 @@ val RULE_SET_RU = RuleSet( RULE_VARIOUS_ABBREVIATIONS, RULE_SECTIONS_ORDER, RULE_LOW_QUALITY_CONFERENCES, - RULE_DOUBLE_SPACE + RULE_DOUBLE_SPACE, RULE_NUMBER_OF_BRACKETS, RULE_TEXT_IN_BRACKETS, ) From 750ae9d18e72051626b272c0dde6ebe0fce5b093 Mon Sep 17 00:00:00 2001 From: GeorgeBasiev Date: Fri, 31 May 2024 01:49:49 +0300 Subject: [PATCH 4/4] RULE_BRACKETS_LETTERS fix --- .../mundaneassignmentpolice/rules/Rules.kt | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) 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 27181349..24ee9de4 100644 --- a/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt +++ b/src/main/kotlin/com/github/darderion/mundaneassignmentpolice/rules/Rules.kt @@ -132,24 +132,37 @@ val RULE_MULTIPLE_LITLINKS = SymbolRuleBuilder() const val bracket = '(' -val RULE_BRACKETS_LETTERS = List(2) { - SymbolRuleBuilder() - .symbol(bracket) - .ignoringAdjusting(' ') - .called("Большая русская буква после скобки") - .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") - .type(RuleViolationType.Warning) -}.apply { - first() - .fromLeft() - .shouldNotHaveNeighbor('.') - last() - .fromRight() - .shouldNotHaveNeighbor(*rusCapitalLetters.toCharArray()) -}.map { it.getRule() } - .reduce { acc, symbolRule -> - acc and symbolRule - } +val ruleBracketsLettersBuilder1 = WordRuleBuilder() + .word(bracket) + .ignoringAdjusting(Regex("""\s""")) + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) + .fromLeft() + .shouldNotHaveNeighbor(Regex("""\.""")) + +val ruleBracketsLettersBuilder2 = WordRuleBuilder() + .word(bracket) + .ignoringAdjusting(Regex("""\s""")) + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) + .fromRight() + .shouldNotHaveNeighbor(Regex("""[А-Я][а-я]*""")) + +val ruleBracketsLettersBuilder3 = WordRuleBuilder() + .word(bracket) + .ignoringAdjusting(Regex("""\s""")) + .called("Большая русская буква после скобки") + .setDescription("После открывающей круглой скобки следует ставить маленькую букву, если речь идет не о названиях и других сложных случаев") + .type(RuleViolationType.Warning) + .fromRight() + .shouldHaveNeighbor(Regex("""[А-Я][а-я]*[А-Я]+[А-Яа-я]*""")) + +val RULE_BRACKETS_LETTERS = (ruleBracketsLettersBuilder1.getRule() and + ruleBracketsLettersBuilder2.getRule()) or + (ruleBracketsLettersBuilder1.getRule() and + ruleBracketsLettersBuilder3.getRule()) private const val openingBrackets = "([{<" private const val closingBrackets = ")]}>"