Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.darderion.mundaneassignmentpolice.checker

import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument

fun getPages(document: PDFDocument, word : String): Pair<Int,Int>
{
var pages = -1 to -1
var linesIndexes = -1 to -1
val lines = document.text.filter {
var isFirstSectionWithWord = true
document.areas!!.sections.forEachIndexed { index , section ->
if (isFirstSectionWithWord) {
if (section.title.contains(word) && word != "Заключение") {
linesIndexes = section.contentIndex to document.areas.sections[index + 1].contentIndex
isFirstSectionWithWord = false
}
else if (section.title.contains(word)) {
linesIndexes = section.contentIndex to -1
isFirstSectionWithWord = false
}
}

}
if (word!="Заключение")
linesIndexes.first <= it.documentIndex && it.documentIndex < linesIndexes.second
else linesIndexes.first <= it.documentIndex
}

if (lines.isNotEmpty() && word!="Заключение")
pages = lines[0].page to lines.last().page
else if (lines.isNotEmpty())
pages = lines[0].page to -1
return pages
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.darderion.mundaneassignmentpolice.checker.rule.line

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.PDFDocument
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class LineRule (
val singleLinePredicates: MutableList<(line: Line) -> List<Line>> = mutableListOf(),
val multipleLinesPredicates : MutableList<(lines: List<Line>, document: PDFDocument) -> List<Line>>,
val linesFilters : MutableList <(lines: List<Line>, document: PDFDocument) -> List<Line>>,
type: RuleViolationType,
area: PDFRegion,
name: String
): Rule(area, name, type) {

override fun process(document: PDFDocument): List<RuleViolation> {
val rulesViolations: MutableSet<RuleViolation> = mutableSetOf()

var lines = document.text
linesFilters.map { lines = it(lines, document) }

if (lines.isNotEmpty()) {
singleLinePredicates.map { predicate ->
rulesViolations.addAll(
lines.map { predicate(it) }
.filter { it.isNotEmpty() }.map {
RuleViolation(it, name, type)
}
)
}
multipleLinesPredicates.map { predicate ->
if (predicate(lines, document).isNotEmpty())
rulesViolations.add(RuleViolation(predicate(lines, document), name, type))
}
}
return rulesViolations.toList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.darderion.mundaneassignmentpolice.checker.rule.line

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class LineRuleBuilder {
private var region: PDFRegion = PDFRegion.EVERYWHERE
private val singleLinePredicates: MutableList<(line: Line) -> List<Line>> = mutableListOf()
private val multipleLinesPredicates : MutableList<(lines: List<Line>, document: PDFDocument) -> List<Line>> = mutableListOf()
private val linesFilters : MutableList <(lines: List<Line>, document: PDFDocument) -> List<Line>> = mutableListOf()
private var type: RuleViolationType = RuleViolationType.Error
private var name: String = "Rule name"


fun disallowInSingleLine(predicate: (line: Line) -> List<Line>) = this.also { singleLinePredicates.add(predicate) }

fun disallowInMultipleLines(predicate: (lines: List<Line>, document: PDFDocument) -> List<Line> ) = this.also { multipleLinesPredicates.add(predicate) }

fun addLinesFilter (predicate: (lines: List<Line>, document: PDFDocument) -> List<Line>) = this.also { linesFilters.add(predicate) }

fun called(name: String) = this.also { this.name = name }

infix fun type(type: RuleViolationType) = this.also { this.type = type }

fun getRule() = LineRule(
singleLinePredicates,
multipleLinesPredicates,
linesFilters,
type,
region,
name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.list.PDFList
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line


class ListRule(
val predicates: List<(list: PDFList<Line>) -> List<Line>>,
val singleListPredicates: MutableList<(list: PDFList<Line>) -> List<Line>> = mutableListOf(),
val multipleListsPredicates : MutableList<(lists: List<PDFList<Line>>)->List<Line>> = mutableListOf(),
val multipleListsPredicatesWithDocument : MutableList<(lists: List<PDFList<Line>>, document: PDFDocument) -> List<Line>> = mutableListOf(),
val listsFilter : MutableList<(lists: List<PDFList<Line>>,document: PDFDocument) -> MutableList<PDFList<Line>>> ,
type: RuleViolationType,
area: PDFRegion,
name: String
Expand All @@ -32,9 +36,11 @@ class ListRule(

if (area.contains(SECTION)) lists.addAll(document.areas!!.lists)

val pdfLists = lists.map { it.getSublists() }.flatten()
var pdfLists = lists.map { it.getSublists() }.flatten()

listsFilter.forEach { pdfLists = it(pdfLists, document) }

predicates.forEach { predicate ->
singleListPredicates.forEach { predicate ->
rulesViolations.addAll(
pdfLists.map {
predicate(it)
Expand All @@ -43,7 +49,13 @@ class ListRule(
}
)
}

multipleListsPredicates.forEach { predicate ->
if (predicate(pdfLists).isNotEmpty()) rulesViolations.add(RuleViolation(predicate(pdfLists),name,type))
}
multipleListsPredicatesWithDocument.forEach { predicate ->
if (predicate(pdfLists,document).isNotEmpty())
rulesViolations.add(RuleViolation(predicate(pdfLists,document),name,type))
}
return rulesViolations.toList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package com.github.darderion.mundaneassignmentpolice.checker.rule.list

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument
import com.github.darderion.mundaneassignmentpolice.pdfdocument.list.PDFList
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class ListRuleBuilder {
private var region: PDFRegion = PDFRegion.EVERYWHERE
private val predicates: MutableList<(list: PDFList<Line>) -> List<Line>> = mutableListOf()
private val singleListPredicates: MutableList<(list: PDFList<Line>) -> List<Line>> = mutableListOf()
private val multipleListsPredicates : MutableList<(lists: List<PDFList<Line>>)->List<Line>> = mutableListOf()
private val multipleListsPredicatesWithDocument : MutableList<(lists: List<PDFList<Line>>, document: PDFDocument) -> List<Line>> = mutableListOf()
private val listsFilter : MutableList <(lists: List<PDFList<Line>>,document: PDFDocument) -> MutableList<PDFList<Line>>> = mutableListOf()
private var type: RuleViolationType = RuleViolationType.Error
private var name: String = "Rule name"

fun disallow(predicate: (list: PDFList<Line>) -> List<Line>) = this.also { predicates.add(predicate) }

fun disallowInSingleList(predicate: (list: PDFList<Line>) -> List<Line>) = this.also { singleListPredicates.add(predicate) }
fun disallowInMultipleLists(predicate: (lists: List<PDFList<Line>>) -> List<Line>) = this.also { multipleListsPredicates.add(predicate) }
fun disallowInMultipleListsWithDocument(predicate: (lists: List<PDFList<Line>>, document: PDFDocument) -> List<Line> ) = this.also { multipleListsPredicatesWithDocument.add(predicate) }
fun addListsFilter (predicate: (lists: List<PDFList<Line>>, document: PDFDocument) -> MutableList<PDFList<Line>>) = this.also { listsFilter.add(predicate) }
infix fun inArea(area: PDFArea) = this.also { region = PDFRegion.NOWHERE.except(area) }

infix fun inArea(region: PDFRegion) = this.also { this.region = region }
Expand All @@ -22,5 +28,11 @@ class ListRuleBuilder {

infix fun type(type: RuleViolationType) = this.also { this.type = type }

fun getRule() = ListRule(predicates, type, region, name)
fun getRule() = ListRule(singleListPredicates,
multipleListsPredicates,
multipleListsPredicatesWithDocument,
listsFilter,
type,
region,
name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ val RULE_SET_RU = RuleSet(
RULE_MULTIPLE_LITLINKS,
RULE_BRACKETS_LETTERS,
RULE_CITATION,
RULE_NO_TASKS,
RULE_TASKS_MAPPING,
RULE_SINGLE_SUBSECTION,
RULE_TABLE_OF_CONTENT_NUMBERS,
RULE_SYMBOLS_IN_SECTION_NAMES,
Expand All @@ -23,6 +25,7 @@ val RULE_SET_RU = RuleSet(
RULE_SECTIONS_ORDER,
RULE_LOW_QUALITY_CONFERENCES,
)
+ RULE_CONFIGURATION_IN_EXPERIMENTS
+ RULES_SPACE_AROUND_BRACKETS
+ RULES_SMALL_NUMBERS
)
Expand Down
Loading