Repository: redpen-cc/redpen (java)
Issue: Void Section validator
Section should have some contents at least one line.  
Pull request description: Adds VoidSectionValidator
Hello, I've added VoidSectionValidator, a validator looks for void sections.
This PR intends to resolve #606.

Please review and hopefully merge.
Thanks.
-t

Changes:
- src/main/resources/cc/redpen/validator/section/error-messages.properties: Adding the message.
- src/main/resources/cc/redpen/validator/section/error-messages_ja.properties: Adding the message.

Patch:
diff --git a/redpen-core/src/main/java/cc/redpen/validator/section/VoidSectionValidator.java b/redpen-core/src/main/java/cc/redpen/validator/section/VoidSectionValidator.java
new file mode 100644
index 00000000..2cb0e5d1
--- /dev/null
+++ b/redpen-core/src/main/java/cc/redpen/validator/section/VoidSectionValidator.java
@@ -0,0 +1,45 @@
+/**
+ * redpen: a text inspection tool
+ * Copyright (c) 2014-2015 Recruit Technologies Co., Ltd. and contributors
+ * (see CONTRIBUTORS.md)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package cc.redpen.validator.section;
+
+import cc.redpen.model.Paragraph;
+import cc.redpen.model.Section;
+import cc.redpen.model.Sentence;
+import cc.redpen.tokenizer.TokenElement;
+import cc.redpen.validator.Validator;
+
+import java.util.*;
+
+/**
+ * VoidSectionValidator detects sections with no content..
+ */
+final public class VoidSectionValidator extends Validator {
+    @Override
+    public void validate(Section section) {
+        if (section.getNumberOfParagraphs() == 0) {
+            addLocalizedError(section.getJoinedHeaderContents());
+        } else {
+            for (Paragraph p : section.getParagraphs()) {
+                if (p.getNumberOfSentences() == 0) {
+                    addLocalizedError(section.getJoinedHeaderContents());
+                    break;
+                }
+            }
+        }
+    }
+}
diff --git a/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages.properties b/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages.properties
index 32a1be22..b8af5188 100644
--- a/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages.properties
+++ b/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages.properties
@@ -6,3 +6,4 @@ UnexpandedAcronymValidator.UnexpandedAcronym=The expanded form of the acronym {0
 FrequentSentenceStartValidator.SentenceStartTooFrequent={0}% of sentences start with "{1}".
 WordFrequencyValidator.WordUsedTooFrequently=The word "{0}" comprises {1}% of all words. Expected around {2}%.
 SectionLevelValidator=The section "{0}" is too deep.
+VoidSectionValidator=The section "{0}" is void.
\ No newline at end of file
diff --git a/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages_ja.properties b/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages_ja.properties
index 2b2aef8c..2d075688 100644
--- a/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages_ja.properties
+++ b/redpen-core/src/main/resources/cc/redpen/validator/section/error-messages_ja.properties
@@ -3,3 +3,4 @@ ParagraphNumberValidator=\u30BB\u30AF\u30B7\u30E7\u30F3\u5185\u306E\u30D1\u30E9\
 ParagraphStartWithValidator=\u30D1\u30E9\u30B0\u30E9\u30D5\u306E\u958B\u59CB\u90E8\u5206\u304C\u4E0D\u6B63\u3067\u3059 "{0}"
 DuplicatedSectionValidator=\u985E\u4F3C\u3059\u308B\u7BC0\uFF08"{0}"\u884C\u76EE\u304B\u3089\u958B\u59CB\uFF09\u304C\u898B\u3064\u304B\u308A\u307E\u3057\u305F
 SectionLevelValidator=\u7BC0"{0}"\u306E\u30EC\u30D9\u30EB\u304C\u6DF1\u3059\u304E\u307E\u3059
+VoidSectionValidator=\u7BC0"{0}"\u306E\u5185\u5BB9\u304C\u7A7A\u3067\u3059\u3002


Test patch:
diff --git a/redpen-core/src/test/java/cc/redpen/validator/section/VoidSectionValidatorTest.java b/redpen-core/src/test/java/cc/redpen/validator/section/VoidSectionValidatorTest.java
new file mode 100644
index 00000000..07293be8
--- /dev/null
+++ b/redpen-core/src/test/java/cc/redpen/validator/section/VoidSectionValidatorTest.java
@@ -0,0 +1,85 @@
+/**
+ * redpen: a text inspection tool
+ * Copyright (c) 2014-2015 Recruit Technologies Co., Ltd. and contributors
+ * (see CONTRIBUTORS.md)
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package cc.redpen.validator.section;
+
+import cc.redpen.RedPenException;
+import cc.redpen.config.Configuration;
+import cc.redpen.config.ValidatorConfiguration;
+import cc.redpen.model.Document;
+import cc.redpen.model.Section;
+import cc.redpen.model.Sentence;
+import cc.redpen.validator.ValidationError;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class VoidSectionValidatorTest {
+    private VoidSectionValidator validator = new VoidSectionValidator();
+
+    @Test
+    public void testInvalid() {
+        Document document =
+                Document.builder()
+                        .addSection(1)
+                        .addSectionHeader("Abstract")
+                        .build();
+
+        List<ValidationError> errors = new ArrayList<>();
+        validator.setErrorList(errors);
+        validator.validate(document.getSection(0));
+
+        assertEquals(1, errors.size());
+    }
+
+    @Test
+    public void testInvalidWithVoidSentence() {
+        Document document =
+                Document.builder()
+                        .addSection(1)
+                        .addSectionHeader("Abstract")
+                        .addParagraph()
+                        .build();
+
+        List<ValidationError> errors = new ArrayList<>();
+        validator.setErrorList(errors);
+        validator.validate(document.getSection(0));
+
+        assertEquals(1, errors.size());
+    }
+
+    @Test
+    public void testValid() {
+        Document document =
+                Document.builder()
+                        .addSection(1)
+                        .addSectionHeader("Abstract")
+                        .addParagraph()
+                        .addSentence(new Sentence("he is a super man.", 1))
+                        .build();
+
+        List<ValidationError> errors = new ArrayList<>();
+        validator.setErrorList(errors);
+        validator.validate(document.getSection(0));
+
+        assertEquals(0, errors.size());
+    }
+}