Ejemplo n.º 1
0
        public static PublicationsFile Parse(string filePath)
        {
            PublicationsFile parsed = new PublicationsFile();

            parsed.Type = FileType.SCOPUS;

            using (TextReader textReader = new StreamReader(filePath, Encoding.UTF8))
            {
                var csv = new CsvParser(textReader);

                int rowIndex = 0;
                var titleRow = csv.Read();

                while (true)
                {
                    ++rowIndex;
                    var row = csv.Read();
                    if (row == null)
                    {
                        break;
                    }

                    if (row.Length > titleRow.Length)
                    {
                        if (row.Length > 0)
                        {
                            logger.Warn("Invalid CSV row ({0}), ignoring: {1}", rowIndex + 1, row[0]);
                        }
                        else
                        {
                            logger.Warn("Invalid CSV row ({0}), ignoring", rowIndex + 1);
                        }
                        continue;
                    }

                    Publication publication = new Publication();
                    for (int i = 0; i < row.Length; ++i)
                    {
                        PublicationEntry entry = new PublicationEntry();
                        entry.field  = titleRow[i];
                        entry.values = new List <string>();
                        string[] values = row[i].Split(';');
                        foreach (string value in values)
                        {
                            entry.values.Add(value.Trim());
                        }
                        publication.entries.Add(entry.field, entry);
                    }

                    parsed.publications.Add(publication);
                }
            }

            logger.Info("Publications loaded from scopus: {0}", parsed.publications.Count);

            return(parsed);
        }
Ejemplo n.º 2
0
 public void SetInput_Publications_ScopusCsv(string filePath)
 {
     try
     {
         publicationsFile = ScopusFileFormatParser.Parse(filePath);
     }
     catch (Exception e)
     {
         logger.Error(e, "Error while reading Scopus.");
         throw;
     }
 }
Ejemplo n.º 3
0
        public static PublicationsFile Parse(string filePath)
        {
            string[] lines = File.ReadAllLines(filePath, Encoding.UTF8);

            PublicationsFile parsed = new PublicationsFile();

            parsed.Type = FileType.WOS;

            Publication currentPublication = new Publication();

            PublicationEntry currentEntry = null;

            bool wasEndOfFile = false;

            foreach (string line in lines)
            {
                if (wasEndOfFile)
                {
                    throw new Exception("Data after end of file");
                }

                if (line == "")
                {
                    continue;
                }

                if (line == "EF")
                {
                    wasEndOfFile = true;
                    continue;
                }

                if (line == "ER")
                {
                    parsed.publications.Add(currentPublication);
                    currentPublication = new Publication();
                }
                else
                {
                    string tagPart = line.Substring(0, 3).TrimEnd(' ');

                    if (tagPart == "FN" || tagPart == "VR")
                    {
                        continue;
                    }

                    string valuePart = line.Substring(3);

                    if (tagPart != "")
                    {
                        currentEntry       = new PublicationEntry();
                        currentEntry.field = tagPart;
                        currentEntry.values.Add(valuePart);
                        currentPublication.entries.Add(tagPart, currentEntry);
                    }
                    else
                    {
                        currentEntry.values.Add(valuePart);
                    }
                }
            }

            logger.Info("Publications loaded from WOS: {0}", parsed.publications.Count);

            return(parsed);
        }