Class PathLibrary


  • public class PathLibrary
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DATA_DIR  
    • Constructor Summary

      Constructors 
      Constructor Description
      PathLibrary()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static NormalizedPath getSimilarPath​(java.util.List<NormalizedPath> candidates, double targetDistance)
      Selects a NormalizedPath from a provided list of candidate paths that most closely matches a target distance, considering tolerance thresholds and randomization within a subset of viable matches.
      static java.util.List<NormalizedPath> load​(java.lang.String library)
      Loads and normalizes a set of mouse gestures from a specified library file, converting them into NormalizedPath objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DATA_DIR

        public static final java.lang.String DATA_DIR
    • Constructor Detail

      • PathLibrary

        public PathLibrary()
    • Method Detail

      • load

        public static java.util.List<NormalizedPath> load​(java.lang.String library)
        Loads and normalizes a set of mouse gestures from a specified library file, converting them into NormalizedPath objects. The method searches for a corresponding JSON file within the directory defined by DATA_DIR. If the file is found, it parses the content, normalizes valid mouse gestures, and logs the results.

        Mouse gestures are read line-by-line. Invalid or malformed entries are skipped with appropriate warnings logged. Normalization is performed through the PathNormalizer.normalize() method, which filters out gestures that cannot be reliably normalized.

        Parameters:
        library - The name of the library for which to load mouse gestures. This name is used to search for a JSON file in the DATA_DIR. Spaces in the library name are replaced with underscores during the filename matching.
        Returns:
        A List of NormalizedPath objects representing the normalized mouse gestures loaded from the library file. Returns null if no matching file is found or if an error occurs during the loading process.
      • getSimilarPath

        public static NormalizedPath getSimilarPath​(java.util.List<NormalizedPath> candidates,
                                                    double targetDistance)
        Selects a NormalizedPath from a provided list of candidate paths that most closely matches a target distance, considering tolerance thresholds and randomization within a subset of viable matches.

        The method evaluates the "fitness" of each candidate based on the absolute difference between its original distance and the target distance. Viable paths are those whose distance is within a calculated tolerance of the target distance.

        If no viable paths exist, a fallback strategy is employed to select randomly from the top three closest matches. Otherwise, a standard strategy randomly selects a path from the top 50% of the viable matches, ensuring some degree of diversity and non-determinism in the selection.

        Parameters:
        candidates - a list of NormalizedPath objects representing potential matches. This list must not be null but can be empty, in which case the method will log a warning and return null.
        targetDistance - the target distance to match with the candidates' original distance values. This value is used for calculating fitness and tolerance thresholds.
        Returns:
        a NormalizedPath object selected as the best match to the target distance, or null if no candidates are provided in the list.