Package com.tnsai.rag

Class IngestionPathSelector

java.lang.Object
com.tnsai.rag.IngestionPathSelector

public final class IngestionPathSelector extends Object
Portable include/exclude globs for FILE knowledge-source candidates.

Patterns match the entire root-relative path, using / separators and no leading slash. * and ? do not cross directories; ** matches zero or more path segments. A brace group such as {md,pdf} matches any one of its comma-separated alternatives; each alternative is literal text and the same tokens, and the group may not be nested or hold an empty alternative. [, ] and \ are refused. include is evaluated first; a match in exclude always wins. An empty include list admits every path; an empty exclude list admits every include match.

matches(String, List, List) ignores case: it lower-cases the selector and the path one code point at a time (see foldCase(String)) before matching, so **/*.pdf admits B.PDF, and a Turkish default locale changes nothing. Under that rule I, i and İ match one another, the dotless ı matches only itself, and the final ς matches σ and Σ.

Since:
0.13.0
  • Method Details

    • compile

      public static Pattern compile(String glob)
      Compiles one glob or throws with the offending selector.
      Parameters:
      glob - selector text
      Returns:
      anchored regex
    • compileIgnoreFileSelector

      public static Pattern compileIgnoreFileSelector(String glob)
      Compiles one selector read from a .gitignore or .tnsignore line, or throws with the offending selector.

      Ignore-file lines keep the *, **, ? contract alone: unlike compile(String), a brace is refused rather than read as a group. They also match the raw key case-sensitively: unlike compileIgnoringCase(String), secret.md does not drop SECRET.md.

      Parameters:
      glob - selector text
      Returns:
      anchored regex
      Since:
      0.18.7
    • compileIgnoringCase

      public static Pattern compileIgnoringCase(String glob)
      Compiles one glob for case-insensitive matching, or throws with the offending selector as written.

      The pattern matches a key passed through foldCase(String): compileIgnoringCase("**/*.PDF") matches foldCase("docs/B.pdf").

      Parameters:
      glob - selector text
      Returns:
      anchored regex over a lower-cased key
      Since:
      0.18.7
    • foldCase

      public static String foldCase(String text)
      Lower-cases a selector or a /-normalized relative key one code point at a time with Character.toLowerCase(int), which no locale changes, and maps the final ς to σ.

      Each code point folds to exactly one code point, whatever surrounds it, so a selector and a path fold alike and ? still matches one character. Folding never yields *, ?, /, a brace or a comma, so a folded selector keeps its glob tokens and brace groups.

      Parameters:
      text - selector or relative key
      Returns:
      the folded text
      Since:
      0.18.7
    • matches

      public static boolean matches(Path relativePath, List<String> include, List<String> exclude)
      Whether relativePath is admitted by the two selector lists.
    • matches

      public static boolean matches(String relativeKey, List<String> include, List<String> exclude)
      Whether a /-normalized relative path is admitted. Selectors and path are compared after foldCase(String).
    • relativeKey

      public static String relativeKey(Path relativePath)
      Renders a relative path with / separators, independent of the host filesystem.