Exemplo n.º 1
0
        static List <String> lstCmdi  = null; // List of .cmdi.xml files in the [sCmdi] directory
        // Command-line entry point + argument handling
        static void Main(string[] args)
        {
            String sLanguage = "";      // Which language to take (two-letter code 'en' or 'nl')
            String sFolia    = "";      // Base directory to take (e.g. /vol/tensusers/ekomen)
            String sSubtiel  = "";      // Base directory for the output (e.g: /vol/tensusers/ekomen/subtiel)
            String sCmdi     = "";      // Base directory for CMDI files
            String sAction   = "combi"; // The particular type of action expected. Default "combi"
            bool   bIsDebug  = false;   // Debugging

            try {
                // Check command-line options
                for (int i = 0; i < args.Length; i++)
                {
                    // get this argument
                    String sArg = args[i];
                    if (sArg.StartsWith("-"))
                    {
                        // Check out the arguments
                        switch (sArg.Substring(1))
                        {
                        case "f": // Root directory under which the .folia.xml.gz files are located
                            sFolia = Path.GetFullPath(args[++i]);
                            break;

                        case "c": // Root directory where the CMDI files are located
                            sCmdi = Path.GetFullPath(args[++i]);
                            break;

                        case "o": // Root directory where the output files are going to be stored
                            sSubtiel = Path.GetFullPath(args[++i]);
                            break;

                        case "d": // Debugging
                            bIsDebug = true;
                            break;

                        case "l": // Language (three letter code)
                            sLanguage = args[++i];
                            break;

                        case "r": // INSTEAD of 'combi', perform 'REPAIR' action
                            sAction = "repair";
                            break;
                        }
                    }
                    else
                    {
                        // Throw syntax error and leave
                        SyntaxError("1 - i=" + i + " args=" + args.Length + " argCurrent=[" + sArg + "]"); return;
                    }
                }
                // Check presence of input/output
                if (sFolia == "" || !Directory.Exists(sFolia))
                {
                    SyntaxError("No (valid) base directory for FoLiA input"); return;
                }

                // Initialise the Treebank Xpath functions, which may make use of tb:matches()
                XPathFunctions.conTb.AddNamespace("tb", XPathFunctions.TREEBANK_EXTENSIONS);

                // Create a new instance of the combination class
                cmbConv oConv = new cmbConv(errHandle);

                // Other directories depend on ACTION
                switch (sAction)
                {
                case "repair":
                    // No further directories need be present
                    oConv.output = sFolia;
                    // Process all the directories with this action
                    WalkDirectoryTree(sFolia, "*.folia.xml.gz", sAction, ref oConv);
                    break;

                default:
                    if (sCmdi == "" || !Directory.Exists(sCmdi))
                    {
                        SyntaxError("No (valid) cmdi directory"); return;
                    }
                    if (sSubtiel == "")
                    {
                        SyntaxError("No subtiel directory"); return;
                    }
                    // If the target directory is not there, create it
                    if (!Directory.Exists(sSubtiel))
                    {
                        Directory.CreateDirectory(sSubtiel);
                    }
                    oConv.output = sSubtiel;
                    // find .cmdi.xml files
                    errHandle.Status("Finding .cmdi.xml files...");
                    lstCmdi = Directory.GetFiles(sCmdi, "*.cmdi.xml", SearchOption.AllDirectories).ToList();

                    // Convert the list of files into a dictionary
                    oConv.cmdi(lstCmdi);

                    // Find .folia.xml.gz files
                    errHandle.Status("Finding directories in " + sFolia);
                    // Walk all directories
                    errHandle.Status("Processing .folia.xml.gz files...");
                    // Output the header
                    oConv.doHeaderCsv();
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(sFolia, "*.folia.xml.gz", sAction, ref oConv);

                    // Save the harvested information to an xml file
                    if (!oConv.harvestSaveXml(sSubtiel + "/harvest.xml"))
                    {
                        errHandle.DoError("Main", "Could not create harvest summary xml file");
                        return;
                    }
                    break;
                }


                // Exit the program
                errHandle.Status("Ready");
            } catch (Exception ex) {
                errHandle.DoError("Main", ex); // Provide standard error message
                throw;
            }
        }
Exemplo n.º 2
0
        static List<String> lstFolia = null; // List of .folia.xml.gz files in the [sFolia] directory

        #endregion Fields

        #region Methods

        // Command-line entry point + argument handling
        static void Main(string[] args)
        {
            String sLanguage = "";    // Which language to take (two-letter code 'en' or 'nl')
              String sFolia = "";       // Base directory to take (e.g. /vol/tensusers/ekomen)
              String sSubtiel = "";     // Base directory for the output (e.g: /vol/tensusers/ekomen/subtiel)
              String sCmdi = "";        // Base directory for CMDI files
              String sAction = "combi"; // The particular type of action expected. Default "combi"
              bool bIsDebug = false;    // Debugging

              try {
            // Check command-line options
            for (int i = 0; i < args.Length; i++) {
              // get this argument
              String sArg = args[i];
              if (sArg.StartsWith("-")) {
            // Check out the arguments
            switch (sArg.Substring(1)) {
              case "f": // Root directory under which the .folia.xml.gz files are located
                sFolia = Path.GetFullPath(args[++i]);
                break;
              case "c": // Root directory where the CMDI files are located
                sCmdi = Path.GetFullPath(args[++i]);
                break;
              case "o": // Root directory where the output files are going to be stored
                sSubtiel = Path.GetFullPath(args[++i]);
                break;
              case "d": // Debugging
                bIsDebug = true;
                break;
              case "l": // Language (three letter code)
                sLanguage = args[++i];
                break;
              case "r": // INSTEAD of 'combi', perform 'REPAIR' action
                sAction = "repair";
                break;
            }
              } else {
            // Throw syntax error and leave
            SyntaxError("1 - i=" + i + " args=" + args.Length + " argCurrent=[" + sArg + "]"); return;
              }
            }
            // Check presence of input/output
            if (sFolia == "" || !Directory.Exists(sFolia)) { SyntaxError("No (valid) base directory for FoLiA input"); return; }

            // Initialise the Treebank Xpath functions, which may make use of tb:matches()
            XPathFunctions.conTb.AddNamespace("tb", XPathFunctions.TREEBANK_EXTENSIONS);

            // Create a new instance of the combination class
            cmbConv oConv = new cmbConv(errHandle);

            // Other directories depend on ACTION
            switch (sAction) {
              case "repair":
            // No further directories need be present
            oConv.output = sFolia;
            // Process all the directories with this action
            WalkDirectoryTree(sFolia, "*.folia.xml.gz", sAction, ref oConv);
            break;
              default:
            if (sCmdi == "" || !Directory.Exists(sCmdi)) { SyntaxError("No (valid) cmdi directory"); return; }
            if (sSubtiel == "") { SyntaxError("No subtiel directory"); return; }
            // If the target directory is not there, create it
            if (!Directory.Exists(sSubtiel)) {
              Directory.CreateDirectory(sSubtiel);
            }
            oConv.output = sSubtiel;
            // find .cmdi.xml files
            errHandle.Status("Finding .cmdi.xml files...");
            lstCmdi = Directory.GetFiles(sCmdi, "*.cmdi.xml", SearchOption.AllDirectories).ToList();

            // Convert the list of files into a dictionary
            oConv.cmdi(lstCmdi);

            // Find .folia.xml.gz files
            errHandle.Status("Finding directories in " + sFolia);
            // Walk all directories
            errHandle.Status("Processing .folia.xml.gz files...");
            // Output the header
            oConv.doHeaderCsv();
            // Resursive call for each subdirectory.
            WalkDirectoryTree(sFolia, "*.folia.xml.gz", sAction, ref oConv);

            // Save the harvested information to an xml file
            if (!oConv.harvestSaveXml(sSubtiel + "/harvest.xml")) {
              errHandle.DoError("Main", "Could not create harvest summary xml file");
              return;
            }
            break;
            }

            // Exit the program
            errHandle.Status("Ready");
              } catch (Exception ex) {
            errHandle.DoError("Main", ex); // Provide standard error message
            throw;
              }
        }
Exemplo n.º 3
0
        /// <summary>
        /// WalkDirectoryTree -- Walk all the folia.xml.gz files in the indicated directory tree and take the given @sAction
        /// </summary>
        /// <param name="sStartDir"></param>
        /// <param name="sFilter"></param>
        /// <param name="sAction"></param>
        /// <param name="objConv"></param>
        static void WalkDirectoryTree(String sStartDir, String sFilter, String sAction, ref cmbConv objConv)
        {
            String[] arFiles   = null;
            String[] arSubDirs = null;

            // First, process all the files directly under this folder
            try {
                arFiles = Directory.GetFiles(sStartDir, sFilter);
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e) {
                // Only give warning
                errHandle.Status(e.Message);
            } catch (System.IO.DirectoryNotFoundException e) {
                errHandle.Status(e.Message);
            }

            // Check if all is valid
            if (arFiles != null)
            {
                // bSkip = true;
                // Walk all files in this directory
                foreach (String sFile in arFiles)
                {
                    // Check the action that needs be taken
                    switch (sAction)
                    {
                    case "repair":
                        // Check and repair this file
                        if (!objConv.repairOneFolia(sFile))
                        {
                            errHandle.DoError("Main", "Could not repair file " + sFile);
                            return;
                        }
                        break;

                    default:
                        // Process this file
                        if (!objConv.harvestOneFolia(sFile))
                        {
                            errHandle.DoError("Main", "Could not harvest file " + sFile);
                            return;
                        }
                        break;
                    }
                }

                // Now find all the subdirectories under this directory.
                arSubDirs = Directory.GetDirectories(sStartDir);
                // Walk all directories
                foreach (String sDirName in arSubDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(sDirName, sFilter, sAction, ref objConv);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// WalkDirectoryTree -- Walk all the folia.xml.gz files in the indicated directory tree and take the given @sAction
        /// </summary>
        /// <param name="sStartDir"></param>
        /// <param name="sFilter"></param>
        /// <param name="sAction"></param>
        /// <param name="objConv"></param>
        static void WalkDirectoryTree(String sStartDir, String sFilter, String sAction, ref cmbConv objConv)
        {
            String[] arFiles = null;
              String[] arSubDirs = null;

              // First, process all the files directly under this folder
              try {
            arFiles = Directory.GetFiles(sStartDir, sFilter);
              }
              // This is thrown if even one of the files requires permissions greater
              // than the application provides.
              catch (UnauthorizedAccessException e) {
            // Only give warning
            errHandle.Status(e.Message);
              } catch (System.IO.DirectoryNotFoundException e) {
            errHandle.Status(e.Message);
              }

              // Check if all is valid
              if (arFiles != null) {
            // bSkip = true;
            // Walk all files in this directory
            foreach (String sFile in arFiles) {
              // Check the action that needs be taken
              switch(sAction) {
            case "repair":
              // Check and repair this file
              if (!objConv.repairOneFolia(sFile)) {
                errHandle.DoError("Main", "Could not repair file " + sFile);
                return;
              }
              break;
            default:
              // Process this file
              if (!objConv.harvestOneFolia(sFile)) {
                errHandle.DoError("Main", "Could not harvest file " + sFile);
                return;
              }
              break;
              }
            }

            // Now find all the subdirectories under this directory.
            arSubDirs = Directory.GetDirectories(sStartDir);
            // Walk all directories
            foreach (String sDirName in arSubDirs) {
              // Resursive call for each subdirectory.
              WalkDirectoryTree(sDirName, sFilter, sAction, ref objConv);
            }
              }
        }