/// <summary> /// First auxiliary method of the SearchEmployees method /// </summary> /// <param name="file"> /// File to be searched and added to the sql database /// </param> /// <param name="filePath"> /// File path where the file is located /// </param> /// <param name="text"> /// Text of the file /// </param> /// <returns> /// Dictionary with the results found /// </returns> private Dictionary <string, int> SearchEmployeesAux1(D.Models.File file, string filePath, string text) { text = text.Replace(Environment.NewLine, " "); File.Delete(filePath); _fileService.AddFile(file); var doc = NLPAnalysis(text).Result; return(SearchEmployeesAux2(doc)); }
/// <summary> /// Method that searches all the employees in a file /// </summary> /// <param name="file"> /// File to be searched and added to the sql database /// </param> /// <param name="connectionString"> /// Azure blob storage connection string /// </param> /// <param name="containerName"> /// Azure blob storage container name /// </param> /// <returns> /// Dictionary with the results found /// </returns> public Dictionary <string, int> SearchEmployees(D.Models.File file, string connectionString, string containerName) { string filePath = GeneratePath(file.Name); string extension = Path.GetExtension(file.Name).ToLower(); string text; DownloadFile(file.Name, filePath, connectionString, containerName); if (extension == ".pdf") { PdfDocument doc = new PdfDocument(); doc.LoadFromFile(filePath); StringBuilder buffer = new StringBuilder(); foreach (PdfPageBase page in doc.Pages) { buffer.Append(page.ExtractText()); } doc.Close(); text = buffer.ToString(); text = text.Replace(Environment.NewLine, " "); text = DeleteRepeatedSpaces(text); return(SearchEmployeesAux1(file, filePath, text)); } else if (extension == ".docx") { Spire.Doc.Document doc = new Spire.Doc.Document(); doc.LoadFromFile(filePath); text = doc.GetText(); doc.Close(); return(SearchEmployeesAux1(file, filePath, text)); } else { text = File.ReadAllText(filePath); return(SearchEmployeesAux1(file, filePath, text)); } }