You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by "rzo1 (via GitHub)" <gi...@apache.org> on 2026/10/09 08:44:30 UTC

[PR] GH-1458: Parse name-finder tags and parse-tree strings without regular expressions (opennlp)

rzo1 opened a new pull request, #1459:
URL: https://github.com/apache/opennlp/pull/1459

   NameSample start tags and Parse labels, function tags and tokens are now recognised by character scans that reproduce the former expressions exactly, pinned by parameterized tests that use the old patterns as oracles. The forbiddenapis guard in #1348 depends on this change. Because training-data parsing for the name finder and parser goes through this code, an eval build is advisable before merging.
   
   Fixes #1458


-- 
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: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-1458: Parse name-finder tags and parse-tree strings without regular expressions (opennlp)

Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-1458: Parse name-finder tags and parse-tree strings without regular expressions (opennlp)

Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on code in PR #1459:
URL: https://github.com/apache/opennlp/pull/1459#discussion_r4228463318


##########
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:
   Done in 158e495c4.



-- 
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: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-1458: Parse name-finder tags and parse-tree strings without regular expressions (opennlp)

Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on code in PR #1459:
URL: https://github.com/apache/opennlp/pull/1459#discussion_r4228420474


##########
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:
   Better split the test into three here.



-- 
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: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-1458: Parse name-finder tags and parse-tree strings without regular expressions (opennlp)

Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on code in PR #1459:
URL: https://github.com/apache/opennlp/pull/1459#discussion_r4228420474


##########
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:
   Better split the test into two here.



-- 
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: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-1458: Parse name-finder tags and parse-tree strings without regular expressions (opennlp)

Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 merged PR #1459:
URL: https://github.com/apache/opennlp/pull/1459


-- 
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: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org