Class CommandLineInterface


  • public class CommandLineInterface
    extends java.lang.Object
    LangDetect Command Line Interface.

    This is a command line interface of Language Detection Library "LangDetect".

    Renamed: this class was previously known as "Command".

    TODO after my recent changes switching to the new Detector this code is untested. -Fabian

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> arglist  
      private static double DEFAULT_ALPHA
      smoothing default parameter (ELE)
      private java.util.Map<java.lang.String,​java.lang.String> opt_with_value
      for Command line easy parser
      private java.util.Set<java.lang.String> opt_without_value  
      private java.util.Map<java.lang.String,​java.lang.String> values  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addOpt​(java.lang.String opt, java.lang.String key, java.lang.String value)  
      void batchTest()
      Batch Test of Language Detection (--batchtest option)
      void detectLang()
      Language detection test for each file (--detectlang option)
      void generateProfile()
      Generate Language Profile from a text file.
      private double getParamDouble​(java.lang.String key, double defaultValue)
      Returns the double, or the default is absent.
      private @Nullable java.lang.Long getParamLongOrNull​(java.lang.String key)  
      private boolean hasParam​(java.lang.String opt)  
      static void main​(java.lang.String[] args)
      Command Line Interface
      private LanguageDetector makeDetector()
      Using all language profiles from the given directory.
      private void parse​(java.lang.String[] args)
      Command line easy parser
      private @NotNull java.lang.String requireParamString​(@NotNull java.lang.String key)  
      private java.io.File searchFile​(java.io.File directory, java.lang.String pattern)
      File search (easy glob)
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_ALPHA

        private static final double DEFAULT_ALPHA
        smoothing default parameter (ELE)
        See Also:
        Constant Field Values
      • opt_with_value

        private final java.util.Map<java.lang.String,​java.lang.String> opt_with_value
        for Command line easy parser
      • values

        private final java.util.Map<java.lang.String,​java.lang.String> values
      • opt_without_value

        private final java.util.Set<java.lang.String> opt_without_value
      • arglist

        private final java.util.List<java.lang.String> arglist
    • Constructor Detail

      • CommandLineInterface

        public CommandLineInterface()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Command Line Interface
        Parameters:
        args - command line arguments
        Throws:
        java.io.IOException
      • parse

        private void parse​(java.lang.String[] args)
        Command line easy parser
        Parameters:
        args - command line arguments
      • addOpt

        private void addOpt​(java.lang.String opt,
                            java.lang.String key,
                            java.lang.String value)
      • requireParamString

        @NotNull
        private @NotNull java.lang.String requireParamString​(@NotNull
                                                             @NotNull java.lang.String key)
      • getParamDouble

        private double getParamDouble​(java.lang.String key,
                                      double defaultValue)
        Returns the double, or the default is absent. Throws if the double is specified but invalid.
      • getParamLongOrNull

        @Nullable
        private @Nullable java.lang.Long getParamLongOrNull​(java.lang.String key)
      • hasParam

        private boolean hasParam​(java.lang.String opt)
      • searchFile

        private java.io.File searchFile​(java.io.File directory,
                                        java.lang.String pattern)
        File search (easy glob)
        Parameters:
        directory - directory path
        pattern - searching file pattern with regular representation
        Returns:
        matched file
      • generateProfile

        public void generateProfile()
        Generate Language Profile from a text file.
         usage: --genprofile [text file] [language name]
         
      • detectLang

        public void detectLang()
                        throws java.io.IOException
        Language detection test for each file (--detectlang option)
         usage: --detectlang -d [profile directory] -a [alpha] -s [seed] [test file(s)]
         
        Throws:
        java.io.IOException
      • batchTest

        public void batchTest()
                       throws java.io.IOException
        Batch Test of Language Detection (--batchtest option)
         usage: --batchtest -d [profile directory] -a [alpha] -s [seed] [test data(s)]
         
        The format of test data(s):
           [correct language name]\t[text body for test]\n
         
        Throws:
        java.io.IOException
      • makeDetector

        private LanguageDetector makeDetector()
                                       throws java.io.IOException
        Using all language profiles from the given directory.
        Throws:
        java.io.IOException