static async Task Main(string[] args) { //Dialogue original data grabbed from //https://github.com/UCSD-AI4H/COVID-Dialogue/blob/master/COVID-Dialogue-Dataset-English.txt Console.WriteLine("Starting!"); TagFound latestFound = TagFound.None; var newDialogue = new Dialogue(); List <Dialogue> dialogueList = new List <Dialogue>(); string line; System.IO.StreamReader file = new System.IO.StreamReader(@"COVID-Dialogue-Dataset-English.txt"); while ((line = file.ReadLine()) != null) { if (line.Contains("id=")) { latestFound = TagFound.Id; dialogueList.Add(newDialogue); newDialogue = new Dialogue(); int Id; bool foundId = int.TryParse(line.Replace("id=", ""), out Id); newDialogue.Id = Id; } else if (line == "Dialogue") { latestFound = TagFound.Dialogue; } else if (line == "Description") { latestFound = TagFound.Description; } else { if (latestFound == TagFound.Description) { newDialogue.Description += line + Environment.NewLine; } else if (latestFound == TagFound.Dialogue) { newDialogue.DialogueText += line + Environment.NewLine; } } } file.Close(); foreach (var item in dialogueList) { using FileStream createStream = File.Create($"dialogue-{item.Id}.txt"); await JsonSerializer.SerializeAsync(createStream, item); } System.Console.ReadLine(); }
private void FoundTag() { // end of data + end tag TagFound?.Invoke(this, EventArgs.Empty); previousLevel = Level; previousTag = Tag; // reset states ResetParseState(false); }
protected void Poller() { SCW.SCARD_READERSTATE[] State = new SCW.SCARD_READERSTATE[1]; State[0].RdrName = this.Name; State[0].UserData = IntPtr.Zero; State[0].RdrCurrState = SCW.SCARD_STATE_UNKNOWN; int retCode; retCode = SCW.SCardGetStatusChange(hContext, 100, State, 1); if (retCode != SCW.SCARD_S_SUCCESS) { throw new Exception("Failed initial get status change: " + SCW.GetScardErrMsg(retCode)); } State[0].RdrCurrState = State[0].RdrEventState; while (!stopPollingSignal) { retCode = SCW.SCardGetStatusChange(hContext, 1000, State, 1); if (retCode == SCW.SCARD_E_TIMEOUT) { continue; } if (retCode != SCW.SCARD_S_SUCCESS) { throw new Exception("Failed cycling get status change: " + SCW.GetScardErrMsg(retCode)); } if (((State[0].RdrEventState & SCW.SCARD_STATE_PRESENT) == SCW.SCARD_STATE_PRESENT) && ((State[0].RdrEventState & SCW.SCARD_STATE_CHANGED) == SCW.SCARD_STATE_CHANGED)) { NFCTag tag = Connect(); foreach (Delegate d in TagFound.GetInvocationList()) { ISynchronizeInvoke syncer = d.Target as ISynchronizeInvoke; if (syncer != null) { syncer.BeginInvoke(d, new NFCTag[] { tag }); } else { d.DynamicInvoke(tag); } } } State[0].RdrCurrState = State[0].RdrEventState; } }