Beispiel #1
0
        public String Convert(CommandLineParser Parser)
        {
            Console.WriteLine("Converting IRMA codes...");

              String ret = "";

              try
              {
            FileInfo fileInfo = new FileInfo(Parser.ExecutablePath);
            DirectoryInfo di = new DirectoryInfo(fileInfo.DirectoryName);
            IEnumerable<FileInfo> files = di.EnumerateFiles("*.txt");

            String fileGER = "";
            String fileENG = "";

            foreach(FileInfo fi in files)
            {
              if(fi.FullName.Contains("export_ger"))
              {
            fileGER = fi.FullName;
            Console.WriteLine("Found german import File: " + fi.Name);
              }
              else if (fi.FullName.Contains("export_eng"))
              {
            fileENG = fi.FullName;
            Console.WriteLine("Found english import File: " + fi.Name);
              }
            }

            if(string.IsNullOrEmpty(fileGER) && string.IsNullOrEmpty(fileENG))
            {
              Console.WriteLine("Error while converting IRMA codes: no import file found!");
              Console.WriteLine("Either german or english file must exist containing export_eng or export_ger in filename.");

              return "";
            }

            // begin convert
            TermCSV csv = new TermCSV();
            if(string.IsNullOrEmpty(fileGER) == false)
              ParseFile(fileGER, csv, "de");
            if (string.IsNullOrEmpty(fileENG) == false)
              ParseFile(fileENG, csv, "en");

            csv.CreateFile("irma.csv");

              }
              catch(Exception ex)
              {
            ret = "Error while converting IRMA codes: " + ex.Message;
              }

              return ret;
        }
Beispiel #2
0
        public String Convert(CommandLineParser Parser)
        {
            Console.WriteLine("Converting ATC codes...");

              String ret = "";

              try
              {
            FileInfo fileInfo = new FileInfo(Parser.ExecutablePath);
            DirectoryInfo di = new DirectoryInfo(fileInfo.DirectoryName);
            IEnumerable<FileInfo> files = di.EnumerateFiles("*.csv");

            String filename = options.Filename;

            if (string.IsNullOrEmpty(options.Filename))
            {
              foreach (FileInfo fi in files)
              {
            if (fi.FullName.Contains("atc"))
            {
              filename = fi.FullName;
              Console.WriteLine("Found import File: " + fi.Name);
              break;
            }
              }
            }

            if (string.IsNullOrEmpty(filename))
            {
              Console.WriteLine("Error while converting ATC codes: no import file found! Please specify with Filename.");
              return "";
            }

            // begin convert
            TermCSV csv = new TermCSV();
            if (string.IsNullOrEmpty(filename) == false)
              ParseFile(filename, csv, "de");

            csv.CreateFile("atc_termserver.csv");
              }
              catch (Exception ex)
              {
            ret = "Error while converting ATC codes: " + ex.Message;
              }

              return ret;
        }
Beispiel #3
0
        private void ParseFile(String filename, TermCSV csv, String languageCd)
        {
            int countEntries = 0;
              int countAxis = 0;
              String[] lines = File.ReadAllLines(filename, Encoding.Default);

              int currentLevel = 0;
              TermCSVEntry currentAxis = null;
              String upperCode = "", currentCode = "";

              foreach(String line in lines)
              {
            if (string.IsNullOrEmpty(line))
              continue;

            if(line.StartsWith("**"))
            {
              String axisName = line.Replace("*","").Trim();
              currentAxis = new TermCSVEntry();
              currentAxis.Code = axisName[0].ToString().ToUpper();

              TermCSVEntry existingEntry = csv.GetEntry(currentAxis.Code);
              if (existingEntry == null)
              {
            currentAxis.Term = axisName;

            currentAxis.IsAxis = true;
            currentAxis.IsMainclass = false;
            currentAxis.IsPreferred = true;

            currentAxis.Metadata.Add("code", currentAxis.Code);

            csv.Entries.Add(currentAxis);
            countAxis++;
              }
              else
              {
            existingEntry.Translations.Add(languageCd, ExtractTerm(line));
              }
              continue;
            }

            if(currentAxis != null)
            {
              TermCSVEntry entry = new TermCSVEntry();
              String code = ExtractCode(line);
              entry.Code = currentAxis.Code + "-" + code;

              TermCSVEntry existingEntry = csv.GetEntry(entry.Code);
              if (existingEntry == null)
              {

            entry.Term = ExtractTerm(line);

            entry.IsAxis = false;
            entry.IsMainclass = false;
            entry.AssociationKind = "2";
            entry.AssociationType = "is part of";
            entry.AssociationTypeReverse = "is parent of";
            entry.IsPreferred = true;

            int level = GetLevel(line);

            if (level == 0)
            {
              entry.RelationCode = currentAxis.Code;
            }
            else
            {
              entry.RelationCode = entry.Code.Substring(0, entry.Code.Length - 1);
            }

            entry.Metadata.Add("code", code);

            csv.Entries.Add(entry);
            countEntries++;
              }
              else
              {
            existingEntry.Translations.Add(languageCd, ExtractTerm(line));
              }

              //Console.WriteLine("Found code: " + entry.Code + ", Term: " + entry.Term);

            }
            else
            {
              Console.WriteLine("Invalid file format, file must begin with axis information.");
              break;
            }
              }

              Console.WriteLine("File imported. Axis count: " + countAxis + ", Entry count: " + countEntries);
        }
Beispiel #4
0
        private void ParseFile(String filename, TermCSV csv, String languageCd)
        {
            int countEntries = 0;
              int countAxis = 0;

              var engine = new FileHelpers.FileHelperEngine<ATC_Entry>();

              List<ATC_Entry> entries = engine.ReadFileAsList(filename);
              List<String> codeList = new List<string>();

              TermCSVEntry currentAxis = null;

              foreach (ATC_Entry atc_entry in entries)
              {
            if (atc_entry == null || string.IsNullOrEmpty(atc_entry.ATC_CODE))
              continue;

            if (atc_entry.ATC_CODE.Length == 1)
            {
              currentAxis = new TermCSVEntry();
              currentAxis.Code = atc_entry.ATC_CODE;

              currentAxis.Term = atc_entry.BEDEUTUNG;

              currentAxis.IsAxis = true;
              currentAxis.IsMainclass = false;
              currentAxis.IsPreferred = true;

              currentAxis.Metadata.Add("DDD-INFO", atc_entry.DDD_INFO);

              csv.Entries.Add(currentAxis);
              countAxis++;
              codeList.Add(atc_entry.ATC_CODE);

              continue;
            }

            if (currentAxis != null)
            {
              TermCSVEntry entry = new TermCSVEntry();

              entry.Code = atc_entry.ATC_CODE;
              entry.Term = atc_entry.BEDEUTUNG;

              entry.IsAxis = false;
              entry.IsMainclass = false;
              entry.AssociationKind = "2";
              entry.AssociationType = "is part of";
              entry.AssociationTypeReverse = "is parent of";
              entry.IsPreferred = true;

              String code = atc_entry.ATC_CODE;
              while(code.Length > 0)
              {
            code = code.Substring(0, code.Length - 1);

            if(codeList.Contains(code))
            {
              entry.RelationCode = code;
              break;
            }
              }

              entry.Metadata.Add("DDD-INFO", atc_entry.DDD_INFO);

              csv.Entries.Add(entry);
              countEntries++;

              if (codeList.Contains(atc_entry.ATC_CODE))
              {
            // WARNING
            codeList.Add(atc_entry.ATC_CODE);
              }
              else
            codeList.Add(atc_entry.ATC_CODE);

              //Console.WriteLine("Found code: " + entry.Code + ", Term: " + entry.Term);

            }

              }

              Console.WriteLine("File imported. Axis count: " + countAxis + ", Entry count: " + countEntries);
        }