@Test void testDetectJapaneseAmbiguousNounConjunction() throws Exception { List<Document> documents = new ArrayList<>(); documents.add(Document.builder(new NeologdJapaneseTokenizer()) .addSection(1) .addParagraph() .addSentence(new Sentence("弊社の経営方針の説明を受けた。", 1)) .build()); Configuration config = Configuration.builder("ja") .addValidatorConfig(new ValidatorConfiguration("JapaneseAmbiguousNounConjunction")) .build(); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Override public void validate(Sentence sentence) { int stackSize = 0; final List<String> surfaces = new LinkedList<>(); for (TokenElement tokenElement : sentence.getTokens()) { final List<String> tags = tokenElement.getTags(); switch (stackSize) { case 0: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); stackSize = 1; } case 1: if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 2; } break; case 2: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 3; } else { surfaces.clear(); stackSize = 0; } } break; case 3: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { String surface = String.join("", surfaces); if (!inDictionary(surface)) { addLocalizedError(sentence, surface); } stackSize = 0; } break; } } }
JapaneseAmbiguousNounConjunctionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { int stackSize = 0; final List<String> surfaces = new LinkedList<>(); for (TokenElement tokenElement : sentence.getTokens()) { final List<String> tags = tokenElement.getTags(); switch (stackSize) { case 0: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); stackSize = 1; } case 1: if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 2; } break; case 2: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 3; } else { surfaces.clear(); stackSize = 0; } } break; case 3: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { String surface = String.join("", surfaces); if (!inDictionary(surface)) { addLocalizedError(sentence, surface); } stackSize = 0; } break; } } } }
JapaneseAmbiguousNounConjunctionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { int stackSize = 0; final List<String> surfaces = new LinkedList<>(); for (TokenElement tokenElement : sentence.getTokens()) { final List<String> tags = tokenElement.getTags(); switch (stackSize) { case 0: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); stackSize = 1; } case 1: if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 2; } break; case 2: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 3; } else { surfaces.clear(); stackSize = 0; } } break; case 3: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { String surface = String.join("", surfaces); if (!inDictionary(surface)) { addLocalizedError(sentence, surface); } stackSize = 0; } break; } } } JapaneseAmbiguousNounConjunctionValidator(); }
JapaneseAmbiguousNounConjunctionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { int stackSize = 0; final List<String> surfaces = new LinkedList<>(); for (TokenElement tokenElement : sentence.getTokens()) { final List<String> tags = tokenElement.getTags(); switch (stackSize) { case 0: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); stackSize = 1; } case 1: if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 2; } break; case 2: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 3; } else { surfaces.clear(); stackSize = 0; } } break; case 3: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { String surface = String.join("", surfaces); if (!inDictionary(surface)) { addLocalizedError(sentence, surface); } stackSize = 0; } break; } } } JapaneseAmbiguousNounConjunctionValidator(); @Override void validate(Sentence sentence); @Override List<String> getSupportedLanguages(); }
JapaneseAmbiguousNounConjunctionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { int stackSize = 0; final List<String> surfaces = new LinkedList<>(); for (TokenElement tokenElement : sentence.getTokens()) { final List<String> tags = tokenElement.getTags(); switch (stackSize) { case 0: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); stackSize = 1; } case 1: if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 2; } break; case 2: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { if (tags.get(0).equals("助詞") && tokenElement.getSurface().equals("の")) { surfaces.add(tokenElement.getSurface()); stackSize = 3; } else { surfaces.clear(); stackSize = 0; } } break; case 3: if (tags.get(0).equals("名詞")) { surfaces.add(tokenElement.getSurface()); } else { String surface = String.join("", surfaces); if (!inDictionary(surface)) { addLocalizedError(sentence, surface); } stackSize = 0; } break; } } } JapaneseAmbiguousNounConjunctionValidator(); @Override void validate(Sentence sentence); @Override List<String> getSupportedLanguages();  }