@Test void testDetectDuplicatedSection() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("DuplicatedSection")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addSectionHeader("this is header") .addParagraph() .addSentence(new Sentence("he is a super man.", 1)) .addSection(1) .addSectionHeader("this is header 2") .addParagraph() .addSentence(new Sentence("he is a super man.", 2)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(2, errors.get(documents.get(0)).size()); }
@Override public void validate(Section section) { Map<String, Integer> targetVector = extractWordFrequency(section); for (SectionVector sectionVector : sectionVectors) { Map<String, Integer> candidateVector = sectionVector.sectionVector; if (sectionVector.header != section.getHeaderContent(0) && calcCosine(targetVector, candidateVector) > getFloat("threshold")) { Optional<Sentence> header = Optional.ofNullable(section.getHeaderContent(0)); if (section.getNumberOfParagraphs() == 0 || sectionVector.header == null) { continue; } addLocalizedError(header.orElse(section.getParagraph(0).getSentence(0)), sectionVector.header.getLineNumber()); } } }
DuplicatedSectionValidator extends Validator { @Override public void validate(Section section) { Map<String, Integer> targetVector = extractWordFrequency(section); for (SectionVector sectionVector : sectionVectors) { Map<String, Integer> candidateVector = sectionVector.sectionVector; if (sectionVector.header != section.getHeaderContent(0) && calcCosine(targetVector, candidateVector) > getFloat("threshold")) { Optional<Sentence> header = Optional.ofNullable(section.getHeaderContent(0)); if (section.getNumberOfParagraphs() == 0 || sectionVector.header == null) { continue; } addLocalizedError(header.orElse(section.getParagraph(0).getSentence(0)), sectionVector.header.getLineNumber()); } } } }
DuplicatedSectionValidator extends Validator { @Override public void validate(Section section) { Map<String, Integer> targetVector = extractWordFrequency(section); for (SectionVector sectionVector : sectionVectors) { Map<String, Integer> candidateVector = sectionVector.sectionVector; if (sectionVector.header != section.getHeaderContent(0) && calcCosine(targetVector, candidateVector) > getFloat("threshold")) { Optional<Sentence> header = Optional.ofNullable(section.getHeaderContent(0)); if (section.getNumberOfParagraphs() == 0 || sectionVector.header == null) { continue; } addLocalizedError(header.orElse(section.getParagraph(0).getSentence(0)), sectionVector.header.getLineNumber()); } } } DuplicatedSectionValidator(); }
DuplicatedSectionValidator extends Validator { @Override public void validate(Section section) { Map<String, Integer> targetVector = extractWordFrequency(section); for (SectionVector sectionVector : sectionVectors) { Map<String, Integer> candidateVector = sectionVector.sectionVector; if (sectionVector.header != section.getHeaderContent(0) && calcCosine(targetVector, candidateVector) > getFloat("threshold")) { Optional<Sentence> header = Optional.ofNullable(section.getHeaderContent(0)); if (section.getNumberOfParagraphs() == 0 || sectionVector.header == null) { continue; } addLocalizedError(header.orElse(section.getParagraph(0).getSentence(0)), sectionVector.header.getLineNumber()); } } } DuplicatedSectionValidator(); @Override void preValidate(Section section); @Override void validate(Section section); }
DuplicatedSectionValidator extends Validator { @Override public void validate(Section section) { Map<String, Integer> targetVector = extractWordFrequency(section); for (SectionVector sectionVector : sectionVectors) { Map<String, Integer> candidateVector = sectionVector.sectionVector; if (sectionVector.header != section.getHeaderContent(0) && calcCosine(targetVector, candidateVector) > getFloat("threshold")) { Optional<Sentence> header = Optional.ofNullable(section.getHeaderContent(0)); if (section.getNumberOfParagraphs() == 0 || sectionVector.header == null) { continue; } addLocalizedError(header.orElse(section.getParagraph(0).getSentence(0)), sectionVector.header.getLineNumber()); } } } DuplicatedSectionValidator(); @Override void preValidate(Section section); @Override void validate(Section section);  }