Package com.tnsai.rag

Class KnowledgePaths

java.lang.Object
com.tnsai.rag.KnowledgePaths

public final class KnowledgePaths extends Object
Where the FILE path of a knowledge source points, the one rule every reader of the source follows.
Since:
0.18.6
  • Method Details

    • resolve

      public static Path resolve(String path)
      Resolves the FILE path of a knowledge source, written in Knowledge.path(), given by a @Config or run file, or built in code. A relative path resolves against the base directory ClassConfig.useBaseDirectory(java.nio.file.Path) set, when one is set, and against the working directory otherwise; an absolute path is kept. It resolves against the base directory current when it is called, so a reader calls it when it reads the source. The base is one per process: two runs in one JVM with different bases are not told apart, and a source read while another thread calls ClassConfig.useBaseDirectory(java.nio.file.Path) reads whichever base was current at that moment.

      The result is lexical. Neither the base nor the path is turned into its real path, so a base reached through a symbolic link keeps that spelling, and the same folder spelt through and around the link gives two different paths. The loader then applies its own symbolic-link rules to the path it reads.

      Parameters:
      path - a FILE path; an empty one resolves to the base or working directory itself, so a reader that treats an empty or blank path as unconfigured checks it first
      Returns:
      the path, absolute and normalized
      Throws:
      NullPointerException - when path is null
      InvalidPathException - when path does not parse
    • resolve

      public static Path resolve(String path, Path base)
      Resolves a FILE path as resolve(String) does, against a base the caller read once, so a reader that compares two paths resolves both against the same base.
      Parameters:
      path - a FILE path, as resolve(String) takes it
      base - the base directory, or null for the working directory
      Returns:
      the path, absolute and normalized
      Throws:
      NullPointerException - when path is null
      InvalidPathException - when path does not parse