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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.darderion.mundaneassignmentpolice.checker.rule.symbol
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.checker.rulebuilder.symbolbuilder.indicesOf
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.inside
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.darderion.mundaneassignmentpolice.checker.rule.word

import com.github.darderion.mundaneassignmentpolice.checker.Direction
import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.wordbuilder.splitToWordsAndPunctuations
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.darderion.mundaneassignmentpolice.checker.rule.word
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.checker.rulebuilder.wordbuilder.splitToWordsAndPunctuations
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFDocument
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.inside
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder

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.PDFRegion

abstract class NotRegionRuleBuilder<out TBuilder: NotRegionRuleBuilder<TBuilder>>(
var type: RuleViolationType,
var name: String,
var region : PDFRegion
)
{
fun called(name: String) = apply { this.name = name } as TBuilder
fun type(type: RuleViolationType)= apply { this.type = type } as TBuilder
fun inArea(area: PDFArea) = this.also { region = PDFRegion.NOWHERE.except(area) } as TBuilder
fun inArea(region: PDFRegion) = this.also { this.region = region } as TBuilder

abstract fun getRule(): Rule
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.checker.rule.Rule
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion


abstract class RegionRuleBuilder<out TBuilder: RegionRuleBuilder<TBuilder>>(
var type: RuleViolationType,
var name: String,
var region : PDFRegion
)
{
fun called(name: String) = apply { this.name = name } as TBuilder
fun type(type: RuleViolationType)= apply { this.type = type } as TBuilder

abstract fun getRule(): Rule
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.listbuilder

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.checker.rule.list.ListRule
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.NotRegionRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.list.PDFList
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class ListRuleBuilder<out TBuilder: ListRuleBuilder<TBuilder>>(
type: RuleViolationType = RuleViolationType.Error,
name: String = "Rule name",
region: PDFRegion = PDFRegion.EVERYWHERE
) : NotRegionRuleBuilder<TBuilder>(type,name, region){

private var predicates: MutableList<(list: PDFList<Line>) -> List<Line>> = mutableListOf()

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

override fun getRule() = ListRule(predicates, type, region, name)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.github.darderion.mundaneassignmentpolice.checker.rule.regex
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.regexbuilder

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.checker.rule.regex.RegexRule
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.NotRegionRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class RegexRuleBuilder {
class RegexRuleBuilder<out TBuilder: RegexRuleBuilder<TBuilder>>(
type: RuleViolationType = RuleViolationType.Error,
name: String = "Rule name",
region: PDFRegion = PDFRegion.EVERYWHERE
) : NotRegionRuleBuilder<TBuilder>(type,name, region){
private var regex: Regex = Regex("")
private val predicates: MutableList<(matches: List<Pair<String, List<Line>>>) -> List<List<Line>>> = mutableListOf()
private var numberOfNearestLinesToSearch: Int = 0
private var type: RuleViolationType = RuleViolationType.Error
private var region: PDFRegion = PDFRegion.EVERYWHERE
private var name: String = "Rule name"

fun regex(regex: Regex) = this.also { this.regex = regex }

Expand All @@ -20,13 +23,8 @@ class RegexRuleBuilder {
fun searchIn(numberOfNearestLines: Int) =
this.also { this.numberOfNearestLinesToSearch = numberOfNearestLines }

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

fun inArea(region: PDFRegion) = this.also { this.region = region }

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

fun getRule() = RegexRule(
override fun getRule() = RegexRule(
regex,
predicates,
numberOfNearestLinesToSearch,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.darderion.mundaneassignmentpolice.checker.rule.symbol
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.symbolbuilder

import com.github.darderion.mundaneassignmentpolice.checker.Direction
import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea
import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.BasicSymbolRule
import com.github.darderion.mundaneassignmentpolice.checker.rule.symbol.SymbolRule
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.NotRegionRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion.Companion.EVERYWHERE
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion.Companion.NOWHERE
import java.util.regex.Pattern

// Extension method
Expand All @@ -16,7 +16,12 @@ fun CharSequence.indicesOf(input: String): List<Int> =
.map { it.range.first } // get the index
.toCollection(mutableListOf()) // collect the result as list

class SymbolRuleBuilder {
class SymbolRuleBuilder<out TBuilder: SymbolRuleBuilder<TBuilder>>(
type: RuleViolationType = RuleViolationType.Error,
name: String = "Rule name",
region: PDFRegion = PDFRegion.EVERYWHERE
): NotRegionRuleBuilder<TBuilder>(type,name, region){

private var symbol: Char = ' '
private var ignoredNeighbors: MutableList<Char> = mutableListOf()
private var notIgnoredNeighbors: MutableList<Char> = mutableListOf()
Expand All @@ -25,14 +30,9 @@ class SymbolRuleBuilder {
private var requiredNeighbors: MutableList<Char> = mutableListOf()
private var direction: Direction = Direction.BIDIRECTIONAL
private var neighborhoodSize: Int = 1
private var type: RuleViolationType = RuleViolationType.Error
private var name: String = "Rule name"
private var region: PDFRegion = EVERYWHERE

infix fun symbol(symbol: Char) = this.also { this.symbol = symbol }

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

fun ignoringAdjusting(vararg symbols: Char) = this.also { if (notIgnoredNeighbors.isEmpty()) ignoredNeighbors.addAll(symbols.toList())
else throw Exception("Up to one of the following methods can be used:" +
" ignoringAdjusting() or ignoringEveryCharacterExcept().")}
Expand All @@ -55,15 +55,9 @@ class SymbolRuleBuilder {

infix fun from(direction: Direction) = this.also { this.direction = direction }

infix fun inArea(area: PDFArea) = this.also { region = NOWHERE.except(area) }

infix fun inArea(region: PDFRegion) = this.also { this.region = region }

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

fun inNeighborhood(size: Int) = this.also { this.neighborhoodSize = size }

fun getRule() = BasicSymbolRule(
override fun getRule() = BasicSymbolRule(
symbol,
ignoredNeighbors,
notIgnoredNeighbors,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.tableofcontentbuilder

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.checker.rule.tableofcontent.TableOfContentRule
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.RegionRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class TableOfContentRuleBuilder<out TBuilder: TableOfContentRuleBuilder<TBuilder>>(
type: RuleViolationType = RuleViolationType.Error,
name: String = "Rule name"
) : RegionRuleBuilder<TBuilder>(type,name, PDFRegion.NOWHERE.except(PDFArea.TABLE_OF_CONTENT)){

private var predicates: MutableList<(list: List<Line>) -> List<Line>> = mutableListOf()

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

override fun getRule() = TableOfContentRule(predicates, type, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.urlbuilder

import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.checker.rule.url.URLRule
import com.github.darderion.mundaneassignmentpolice.checker.rule.url.Url
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.NotRegionRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion
import com.github.darderion.mundaneassignmentpolice.pdfdocument.text.Line

class URLRuleBuilder<out TBuilder: URLRuleBuilder<TBuilder>>(
type: RuleViolationType = RuleViolationType.Error,
name: String = "Rule name",
region: PDFRegion = PDFRegion.EVERYWHERE
) : NotRegionRuleBuilder<TBuilder>(type,name, region){

private val predicates: MutableList<(urls: List<Url>) -> List<Pair<Url, List<Line>>>> = mutableListOf()

fun disallow(predicate: (urls: List<Url>) -> List<Pair<Url, List<Line>>>) = this.also { predicates.add(predicate) }

override fun getRule() = URLRule(predicates, type, region, name)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.darderion.mundaneassignmentpolice.checker.rule.word
package com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.wordbuilder

import com.github.darderion.mundaneassignmentpolice.checker.Direction
import com.github.darderion.mundaneassignmentpolice.checker.RuleViolationType
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea
import com.github.darderion.mundaneassignmentpolice.checker.rule.word.BasicWordRule
import com.github.darderion.mundaneassignmentpolice.checker.rule.word.WordRule
import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.NotRegionRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion

fun splitToWordsAndPunctuations(str: String): List<String> {
Expand All @@ -20,7 +22,11 @@ fun splitToWordsAndPunctuations(str: String): List<String> {
return wordsAndPunctuations.filter { it != "" }
}

class WordRuleBuilder {
class WordRuleBuilder<out TBuilder: WordRuleBuilder<TBuilder>>(
type: RuleViolationType = RuleViolationType.Error,
name: String = "Rule name",
region: PDFRegion = PDFRegion.EVERYWHERE
) : NotRegionRuleBuilder<TBuilder>(type,name, region){
private var word: String = " "
private var ignoredNeighbors: MutableList<Regex> = mutableListOf()
private var notIgnoredNeighbors: MutableList<Regex> = mutableListOf()
Expand All @@ -32,14 +38,9 @@ class WordRuleBuilder {
private var direction: Direction = Direction.BIDIRECTIONAL
private var neighborhoodSize: Int = 1
private var numberOfNeighbors: Int = 1
private var type: RuleViolationType = RuleViolationType.Error
private var name: String = "Rule name"
private var region: PDFRegion = PDFRegion.EVERYWHERE

infix fun word(word: String) = this.also { this.word = word }

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

fun ignoringAdjusting(vararg words: Regex) = this.also {
if (notIgnoredNeighbors.isEmpty()) ignoredNeighbors.addAll(words.toList())
else throw Exception(
Expand Down Expand Up @@ -86,17 +87,11 @@ class WordRuleBuilder {

fun fromBothSides() = this.also { direction = Direction.BIDIRECTIONAL }

infix fun inArea(area: PDFArea) = this.also { region = PDFRegion.NOWHERE.except(area) }

infix fun inArea(region: PDFRegion) = this.also { this.region = region }

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

fun inNeighborhood(size: Int) = this.also { this.neighborhoodSize = size }

fun shouldHaveNumberOfNeighbors(number: Int) = this.also { this.numberOfNeighbors = number }

fun getRule() = BasicWordRule(
override fun getRule() = BasicWordRule(
word,
ignoredNeighbors,
notIgnoredNeighbors,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.darderion.mundaneassignmentpolice.rules

import com.github.darderion.mundaneassignmentpolice.checker.rulebuilder.listbuilder.ListRuleBuilder
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFArea
import com.github.darderion.mundaneassignmentpolice.pdfdocument.PDFRegion

val RULE_SINGLE_SUBSECTION = ListRuleBuilder<ListRuleBuilder<*>>()
.inArea(PDFRegion.NOWHERE.except(PDFArea.TABLE_OF_CONTENT))
//.called("Only 1 subsection in a section")
.called("Одна подсекция в секции")
.disallow {
if (it.nodes.count() == 1) it.nodes.first().getText() else listOf()
}.getRule()
Loading