mawiesne commented on code in PR #1459:
URL: https://github.com/apache/opennlp/pull/1459#discussion_r4228337322
##########
opennlp-api/src/main/java/opennlp/tools/namefind/NameSample.java:
##########
@@ -266,8 +265,42 @@ private static String errorTokenWithContext(String[]
sentence, int index) {
return errorString.toString();
}
- private static final Pattern START_TAG_PATTERN =
Pattern.compile("<START(:([^:>\\s]*))?>");
+ /**
+ * Tests whether a token is a start tag, either {@code <START>} or {@code
<START:type>}, where
Review Comment:
"Tests" -> "Checks" pls
##########
opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/namefind/NameSampleTest.java:
##########
@@ -302,6 +306,41 @@ public static NameSample createPredSample() {
return createSimpleNameSample(false);
}
+ /**
+ * Reference expression for the start tag syntax; serves as the oracle for
+ * {@link #testStartTagMatchesRegexOracle(String)}.
+ */
+ private static final Pattern START_TAG_ORACLE =
Pattern.compile("<START(:([^:>\\s]*))?>");
+
+ /**
+ * Parses a single tag followed by one word and checks the result against
+ * {@link #START_TAG_ORACLE}: a tag the oracle matches opens a name of the
captured type, an
+ * empty captured type is rejected, and any other tag is kept as an ordinary
token.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = {
+ "<START>", "<START:>", "<START:person>", "<START:type-1>",
"<START:NP-SBJ=2>",
+ "<START:a.b_c/d;e,f&g%h$i>", "<START:a\u001Cb>", "<START:\u00E9t\u00E9>",
+ "<START:\uD83D\uDE00>", "<START:a:b>", "<START::>", "<START:a>b>",
"<START:a>>",
+ "<START>>", "<START>a>", "<START", "<START:", "<START:person",
"START:person>",
+ "<start:person>", "<STARTX>", "<START;person>", "x<START>",
"<START:person>x", "<END:x>"})
Review Comment:
`<START;person>` looks _sus_ to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]