private int countVertices; //menyimpan ada berapa vertice //private Microsoft.Msagl.Drawing.Graph graphMSAGL; //ctor tp langsung aja masukin ada berapa edge dan apa aja public Graph(int countEdges, List <string> rawEdges) { this.countEdges = countEdges; this.countVertices = 0; graphDict = new Dictionary <string, List <string> >(); for (int i = 0; i < rawEdges.Count; i++) { string rawKey = rawEdges[i].Split(" ")[0]; string rawValue = rawEdges[i].Split(" ")[1]; //cek apakah node rawKey sudah ada atau belum if (graphDict.ContainsKey(rawKey)) //node rawKey ada { //cek apakah node rawKey punya edge ke rawValue atau tidak if (!graphDict[rawKey].Contains(rawValue)) { graphDict[rawKey].Add(rawValue); } } else //node rawKey blm ada { //inisialisasi node rawKey dengan edge pertama ke rawValue List <string> temp = new List <string>(); temp.Add(rawValue); graphDict.Add(rawKey, temp); countVertices++; } //cek apakah node rawValue sudah ada atau belum if (graphDict.ContainsKey(rawValue)) { //cek apakah node rawValue punya edge ke rawKey atau tidak if (!graphDict[rawValue].Contains(rawKey)) { graphDict[rawValue].Add(rawKey); } } else { //inisialisasi node rawEdge dengan edge pertama ke rawKey List <string> temp = new List <string>(); temp.Add(rawKey); graphDict.Add(rawValue, temp); countVertices++; } } foreach (List <string> value in graphDict.Values) { CSCompare comparer = new CSCompare(); value.Sort(comparer); } }
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"); }