public string Get([FromQuery] string question) { List <PdfFormatWrapper> results = new List <PdfFormatWrapper>(); string[] filePaths = Directory.GetFiles(@"C:\Users\HP\\source\repos\API Test\API Test\root\"); foreach (var path in filePaths) { string fileName = Path.GetFileName(path); FileStream docStream = new FileStream(path, FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); PdfLoadedPageCollection loadedPages = loadedDocument.Pages; string extractedText = string.Empty; foreach (PdfLoadedPage loadedPage in loadedPages) { extractedText += loadedPage.ExtractText();//.Trim(); } var newString = string.Join(" ", Regex.Split(extractedText, @"(?:\r\n|\n|\r)")); var result = CSCompare.Compute(question, newString); results.Add( new PdfFormatWrapper { nameOfFile = fileName, value = result } ); loadedDocument.Close(true); } // var sendResult ="Text "+" ' "+question+" ' "+" se nalazi u fajlu: "+ results.OrderByDescending(x => x.value).FirstOrDefault().nameOfFile; var sendResult = results.OrderByDescending(x => x.value).FirstOrDefault().nameOfFile; return(sendResult); }
public String Get([FromQuery] string top, [FromQuery] string question) { List <QAFormatWrapper> ExampleDatabase = new List <QAFormatWrapper>() { new QAFormatWrapper { Question = "Koliko košta godina na prvom ciklusu? ", Answer = "Svaka godina na prvom ciklusu košta 1800 KM." }, new QAFormatWrapper { Question = "Koliko košta godina na drugom ciklusu?", Answer = "Svaka godina na drugom ciklusu košta 2000 KM." }, new QAFormatWrapper { Question = "Koliko predmeta mogu da prenesem iz jedne godine u drugu?", Answer = "Moguće je prenijeti maksimalno dva predmeta." }, new QAFormatWrapper { Question = "Koliko košta komisijski izlazak?", Answer = "Komisijski izlazak košta 50 KM" }, new QAFormatWrapper { Question = "Nakon koliko izlazaka moram platiti komisijski?", Answer = "Svaki izlazak poslije treceg izlaska se placa komisijski." } }; if (question != null && top == null) { var A1 = ExampleDatabase .OrderByDescending(x => CSCompare.Compute(question, x.Question)) .FirstOrDefault() .Answer; return("Answer:" + A1); } else if (question != null && top != null) { string result = ""; var possibleMatches = ExampleDatabase .OrderByDescending(x => CSCompare.Compute(question, x.Question)) .ToList() .Select(x => x.Answer).Take(Int32.Parse(top)); foreach (var match in possibleMatches) { result += match + "\n"; } return(result); } return("You need to provide answer"); }