private void WriteEntities(List <Takenet.Iris.Messaging.Resources.ArtificialIntelligence.Entity> entities) { var csv = new Chilkat.Csv { Delimiter = ";" }; csv.SetCell(0, 0, "Entity"); csv.SetCell(0, 1, "Value"); csv.SetCell(0, 2, "Synonymous"); var i = 1; foreach (var entity in entities) { if (entity.Values == null) { continue; } foreach (var value in entity.Values) { csv.SetCell(i, 0, entity.Name); csv.SetCell(i, 1, value.Name); csv.SetCell(i, 2, string.Join('/', value.Synonymous)); i++; } } csv.SaveFile(Path.Combine(OutputFilePath.Value, "entities.csv")); }
private void WriteAnswers(List <Takenet.Iris.Messaging.Resources.ArtificialIntelligence.Intention> intentions) { var csv = new Chilkat.Csv { Delimiter = ";", }; csv.SetCell(0, 0, "Intent"); csv.SetCell(0, 1, "Answer"); var i = 1; foreach (var intent in intentions) { if (intent.Answers == null) { continue; } foreach (var answers in intent.Answers) { csv.SetCell(i, 0, intent.Name); csv.SetCell(i, 1, answers.Value.ToString()); i++; } } csv.SaveFile(Path.Combine(OutputFilePath.Value, "answers.csv")); }
private void WriteIntention(List <Takenet.Iris.Messaging.Resources.ArtificialIntelligence.Intention> intentions) { var csv = new Chilkat.Csv { Delimiter = ";", }; csv.SetCell(0, 0, "Intent"); csv.SetCell(0, 1, "Question"); var i = 1; foreach (var intent in intentions) { if (intent.Questions == null) { continue; } foreach (var question in intent.Questions) { csv.SetCell(i, 0, intent.Name); csv.SetCell(i, 1, question.Text); i++; } } var path = Path.Combine(OutputFilePath.Value, "intentions.csv"); csv.SaveFile(path); }
private async Task ImportEntities(CancellationToken cancellationToken) { var entitiesMap = new Dictionary <string, List <EntityValues> >(); //Get intentions on file var csv = new Chilkat.Csv { // Prior to loading the CSV file, indicate that the 1st row // should be treated as column names: HasColumnNames = true }; // Load the CSV records from the entites file: var success = csv.LoadFile(_settings.EntitiesFilePath); if (!success) { Console.WriteLine(csv.LastErrorText); return; } //Get entities on file // Display the contents of the 3rd column (i.e. the country names) for (int row = 0; row <= csv.NumRows - 1; row++) { var entityName = csv.GetCell(row, 0); var value = csv.GetCell(row, 1); var synonymous = csv.GetCell(row, 2); var synonymousList = synonymous.Split(';'); var entitiesValuesList = entitiesMap.ContainsKey(entityName) ? entitiesMap[entityName] : new List <EntityValues>(); var entity = new EntityValues { Name = value, Synonymous = synonymousList.ToArray() }; entitiesValuesList.Add(entity); entitiesMap[entityName] = entitiesValuesList; } //Add each intention on BLiP IA model foreach (var entityKey in entitiesMap.Keys) { var entity = new Entity { Name = entityKey, Values = entitiesMap[entityKey].ToArray() }; var result = await _artificialIntelligenceExtension.SetEntityAsync(entity, cancellationToken); entity.Id = result.Id; } }
private async Task <List <Intention> > ImportIntentions() { var intentionsMap = new Dictionary <string, List <string> >(); //Get intentions on file var csv = new Chilkat.Csv { // Prior to loading the CSV file, indicate that the 1st row // should be treated as column names: HasColumnNames = true }; // Load the CSV records from intentions the file: bool success = csv.LoadFile(IntentsFilePath.Value); if (!success) { Console.WriteLine(csv.LastErrorText); return(null); } // Display the contents of the 3rd column (i.e. the country names) for (int row = 0; row <= csv.NumRows - 1; row++) { var intentionName = csv.GetCell(row, 0); var question = csv.GetCell(row, 1); var questionsList = intentionsMap.ContainsKey(intentionName) ? intentionsMap[intentionName] : new List <string>(); questionsList.Add(question); intentionsMap[intentionName] = questionsList; } var intents = new List <Intention>(); //Add each intention on BLiP IA model foreach (var intentionKey in intentionsMap.Keys) { var id = await _blipAIClient.AddIntent(intentionKey); var questionsList = intentionsMap[intentionKey]; var questionsArray = questionsList.Select(q => new Question { Text = q }).ToArray(); await _blipAIClient.AddQuestions(id, questionsArray); intents.Add(new Intention { Id = id, Questions = questionsArray, Name = intentionKey }); } return(intents); }
private async Task ImportEntities() { var entitiesMap = new Dictionary <string, List <EntityValues> >(); //Get intentions on file var csv = new Chilkat.Csv { // Prior to loading the CSV file, indicate that the 1st row // should be treated as column names: HasColumnNames = true, }; // Load the CSV records from the entites file: var success = csv.LoadFile2(EntitiesFilePath.Value, "utf-8"); if (!success) { Console.WriteLine(csv.LastErrorText); return; } //Get entities on file // Display the contents of the 3rd column (i.e. the country names) for (int row = 0; row <= csv.NumRows - 1; row++) { var entityName = csv.GetCell(row, 0); var value = csv.GetCell(row, 1); var synonymous = csv.GetCell(row, 2); var synonymousList = synonymous.Split('/').Where(s => s.Length > 0).ToArray(); var entitiesValuesList = entitiesMap.ContainsKey(entityName) ? entitiesMap[entityName] : new List <EntityValues>(); var entity = new EntityValues { Name = value, Synonymous = synonymousList.Length == 0 ? null : synonymousList.ToArray() }; entitiesValuesList.Add(entity); entitiesMap[entityName] = entitiesValuesList; } //Add each intention on BLiP IA model foreach (var entityKey in entitiesMap.Keys) { var entity = new Entity { Name = entityKey, Values = entitiesMap[entityKey].ToArray() }; await _blipAIClient.AddEntity(entity); } }
private async Task ImportAnswers(List <Intention> intentions) { var answersMap = new Dictionary <string, List <string> >(); //Get intentions on file var csv = new Chilkat.Csv { // Prior to loading the CSV file, indicate that the 1st row // should be treated as column names: HasColumnNames = true }; // Load the CSV records from intentions the file: bool success = csv.LoadFile(AnswersFilePath.Value); if (!success) { Console.WriteLine(csv.LastErrorText); return; } // Display the contents of the 3rd column (i.e. the country names) for (int row = 0; row <= csv.NumRows - 1; row++) { var intentionName = csv.GetCell(row, 0); var answer = csv.GetCell(row, 1); var answersList = answersMap.ContainsKey(intentionName) ? answersMap[intentionName] : new List <string>(); answersList.Add(answer); answersMap[intentionName] = answersList; } var intents = new List <Intention>(); //Add each intention on BLiP IA model foreach (var intentionKey in answersMap.Keys) { var intention = intentions.FirstOrDefault(i => i.Name == intentionKey); if (intention == null) { Console.WriteLine($"{intentionKey} not present in intentions list."); continue; } var answersList = answersMap[intentionKey]; var answersArray = answersList.Select(q => new Answer { RawValue = q, Type = PlainText.MediaType, Value = PlainText.Parse(q) }).ToArray(); await _blipAIClient.AddAnswers(intention.Id, answersArray); } }
public async Task <FileResult> Get(string address, bool includeTokens = false) { Chilkat.Csv csv = new Chilkat.Csv { HasColumnNames = true }; csv.SetColumnName(0, "Hash"); csv.SetColumnName(1, "From"); csv.SetColumnName(2, "To"); csv.SetColumnName(3, "Value"); csv.SetColumnName(4, "Symbol"); csv.SetColumnName(5, "Timestamp"); csv.SetColumnName(6, "Date"); var builder = Builders <Caladan.Models.Transaction> .Filter; var filter = builder.Where(x => x.From == address || x.To == address); var sort = Builders <Caladan.Models.Transaction> .Sort.Descending("block_number"); var transactions = await _transactionRepository.FindAsync(filter, sort); var i = 0; foreach (var transaction in transactions) { if (!string.IsNullOrEmpty(transaction.Symbol) && !includeTokens) { continue; } csv.SetCell(i, 0, transaction.TransactionHash); csv.SetCell(i, 1, transaction.From); csv.SetCell(i, 2, transaction.To); csv.SetCell(i, 3, transaction.To.ToLower() == address.ToLower() ? transaction.Value.FromHexWei(transaction.Decimals).ToString() : (transaction.Value.FromHexWei(transaction.Decimals) * -1).ToString()); csv.SetCell(i, 4, string.IsNullOrEmpty(transaction.Symbol) ? _configuration["AppSettings:MainCurrencySymbol"] : transaction.Symbol); csv.SetCell(i, 5, transaction.Timestamp.ToString()); csv.SetCell(i, 6, transaction.Created.ToString()); i++; } string csvDoc = csv.SaveToString(); var bytes = Encoding.ASCII.GetBytes(csvDoc); if (includeTokens) { return(File(bytes, "text/csv", $"{address}-withtokens.csv")); } return(File(bytes, "text/csv", $"{address}.csv")); }
private async Task ImportIntentions(CancellationToken cancellationToken) { var intentionsMap = new Dictionary <string, List <string> >(); //Get intentions on file var csv = new Chilkat.Csv { // Prior to loading the CSV file, indicate that the 1st row // should be treated as column names: HasColumnNames = true }; // Load the CSV records from intentions the file: bool success = csv.LoadFile(_settings.IntentionsFilePath); if (!success) { Console.WriteLine(csv.LastErrorText); return; } // Display the contents of the 3rd column (i.e. the country names) for (int row = 0; row <= csv.NumRows - 1; row++) { var question = csv.GetCell(row, 0); var intentionName = csv.GetCell(row, 1); var questionsList = intentionsMap.ContainsKey(intentionName) ? intentionsMap[intentionName] : new List <string>(); questionsList.Add(question); intentionsMap[intentionName] = questionsList; } //Add each intention on BLiP IA model foreach (var intentionKey in intentionsMap.Keys) { var intention = new Intention { Name = intentionKey, }; var result = await _artificialIntelligenceExtension.SetIntentionAsync(intention, cancellationToken); intention.Id = result.Id; var questionsList = intentionsMap[intentionKey]; var questionsArray = questionsList.Select(q => new Question { Text = q }).ToArray(); await _artificialIntelligenceExtension.SetQuestionsAsync(result.Id, questionsArray, cancellationToken); } }
public void WriteContentOnCSV(List <NLPExportModel> models, string outputPath) { foreach (var model in models) { var csv = new Chilkat.Csv { Delimiter = ";" }; for (int i = 0; i < model.Values.GetLength(1); i++) { csv.SetCell(0, i, model.Columns[i]); for (int j = 1; j < model.Values.GetLength(0); j++) { csv.SetCell(j, i, model.Values[j - 1, i]); } } csv.SaveFile(Path.Combine(outputPath, model.Name)); } }
IEnumerable <long> TweetIds() { const string Path = @"./tweets.csv"; var firstDate = new DateTime(2014, 1, 1); var endDate = new DateTime(2015, 1, 31); var csv = new Chilkat.Csv(); csv.HasColumnNames = true; csv.LoadFile(Path); for (var i = 0; i < csv.NumRows; i++) { var id = long.Parse(csv.GetCellByName(i, "tweet_id")); var timestamp = DateTime.Parse(csv.GetCellByName(i, "timestamp")); if (firstDate <= timestamp && timestamp < endDate) { yield return(id); } } }
private void ReadCsv(string t) { // StorageFile sampleFile = await StorageFile.GetFileFromPathAsync("ms-appx:///index.csv"); FileInfo myFile = new FileInfo("index.csv"); var countries = new CountryList().Countries(); var cb = new AutoSuggestBox(); var lv = new ListView(); if (t == "1") { cb = cboxFrom1; lv = lvFrom1; } else if (t == "2") { cb = cboxFrom2; lv = lvFrom2; } else if (t == "3") { cb = cboxFrom3; lv = lvFrom3; } else if (t == "4") { cb = cboxFrom4; lv = lvFrom4; } else if (t == "5") { cb = cboxFrom5; lv = lvFrom5; } // Open Excel File (Roaming) if (myFile != null && cb != null && lv != null) { Chilkat.Csv csv = new Chilkat.Csv(); csv.HasColumnNames = false; bool success; success = csv.LoadFile(myFile.FullName); if (success != true) { return; } Debug.WriteLine($"CSV success"); var results = new List <string>(); int row = countries.IndexOf(countries.Where(x => x.Name == cb.Text).FirstOrDefault()) + 1; int n = csv.NumColumns; for (int col = 1; col < n; col++) { results.Add(ConvertToDescriptiveText(csv.GetCell(row, col))); } lv.ItemsSource = results; lv.Header = CountVisaFreeCountries(results); } }
private void Control() { textBox3.Enabled = false; textBox4.Enabled = false; convert = false; if (data == false) { DateTime past = DateTime.Now; // int y = past.Year; // int m = past.Month; // int d = past.Day -2; // if(d == 0) // { // m = past.Month - 1; // d = past. // } // int h = past.Hour; // int min = past.Minute; // int s = past.Second; // int mill = past.Millisecond; TimeSpan a = new TimeSpan(2, 0, 0, 0); dateTimePicker1.Value = past.Subtract(a);//new System.DateTime(y, m, d, h, min, s, mill); dateTimePicker1.Update(); checkedListBox1.Enabled = false; checkedListBox1.BackColor = Color.DarkGray; checkedListBox1.Update(); label4.Text = "Enter SRC Folder"; label4.Update(); button1.Enabled = false; button1.Update(); button5.Enabled = false; button5.Update(); string history = @"\\video-01\Operations\SBETs\Apps\BaseStationManager\dbpath.txt"; string init; if (File.Exists(history)) { using (StreamReader sr = new StreamReader(history)) { // Read the stream to a string, and write the string to the console. init = sr.ReadToEnd(); } textBox2.Text = init; textBox2.Update(); } all.Enabled = false; none.Enabled = false; } else if (data == true) { checkedListBox1.Enabled = true; checkedListBox1.BackColor = Color.White; all.Enabled = true; none.Enabled = true; Chilkat.Csv csv = new Chilkat.Csv(); csv.HasColumnNames = true; csv.LoadFile(datasrc); int row; int n = csv.NumRows; string[] list = new string[n]; string[] defa = new string[n]; for (row = 0; row <= n - 1; row++) { list[row] = csv.GetCell(row, 1); defa[row] = csv.GetCell(row, 2); } checkedListBox1.Items.AddRange(list); checkedListBox1.CheckOnClick = true; for (int x = 0; x < list.Length; x++) { if (defa[x] == "Y") { checkedListBox1.SetItemChecked(x, true); } } } }