private Dictionary <string, List <RecognitionResult> > importResultData(string fileName) { Dictionary <string, List <RecognitionResult> > eventList = new Dictionary <string, List <RecognitionResult> >(); string line; double startTime = 0; StreamReader reader = new StreamReader(fileName); RecognitionResult recEvent = null; List <RecognitionResult> tempList = new List <RecognitionResult>(); while ((line = reader.ReadLine()) != null) { string[] sp = line.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); if (line.StartsWith("start:")) { string[] sp2 = sp[0].Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries); startTime = Convert.ToDouble(sp2[1]); } else if (line.StartsWith("time:")) { recEvent = new RecognitionResult(); List <KeyValuePair <string, SemanticValue> > semanticList = new List <KeyValuePair <string, SemanticValue> >(); int index = 0; while (sp.Length > index) { string[] sp2 = sp[index].Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries); if (sp2[0].CompareTo(StoryLoggingDevice.time_tag) == 0) { double time = Convert.ToDouble(sp2[1]); time -= startTime; recEvent.startTime = time; } else if (sp2[0].CompareTo(StoryLoggingDevice.confidence_tag) == 0) { recEvent.confidence = float.Parse(sp2[1]); } else if (sp2[0].CompareTo(StoryLoggingDevice.textResult_tag) == 0) { recEvent.textResult = sp2[1]; } else if (sp2[0].CompareTo(StoryLoggingDevice.isHyp_tag) == 0) { recEvent.isHypothesis = Convert.ToBoolean(sp2[1]); } else if (sp2[0].CompareTo(StoryLoggingDevice.grammarName_tag) == 0) { if (sp2.Length > 1) { recEvent.grammarName = sp2[1]; } else { recEvent.grammarName = ""; } } else if (sp2[0].CompareTo(StoryLoggingDevice.ruleName_tag) == 0) { if (sp2.Length > 1) { recEvent.ruleName = sp2[1]; } } else if (sp2[0].CompareTo(StoryLoggingDevice.duration_tag) == 0) { if (sp2.Length > 1) { recEvent.audioDuration = Convert.ToDouble(sp2[1]); } } else if (sp2[0].CompareTo(StoryLoggingDevice.wavePath_tag) == 0) { if (sp2.Length > 1) { recEvent.wavPath = sp2[1]; } } else if (sp2[0].CompareTo(StoryLoggingDevice.key_tag) == 0) { string key = sp2[1]; index++; string[] spx = sp[index].Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries); if (spx[0].CompareTo(StoryLoggingDevice.value_tag) == 0 && spx.Length == 2) { string value = spx[1]; KeyValuePair <string, SemanticValue> kvp = new KeyValuePair <string, SemanticValue>(key, new SemanticValue(new String(value.ToCharArray()))); semanticList.Add(kvp); } } index++; } KeyValuePair <string, SemanticValue>[] tmp = new KeyValuePair <string, SemanticValue> [semanticList.Count]; if (semanticList.Count > 0) { for (int i = 0; i < semanticList.Count; i++) { tmp[i] = semanticList.ElementAt(i); } } recEvent.semanticResult = tmp; string path = recEvent.wavPath; if (!recEvent.isHypothesis && path != null) { List <RecognitionResult> list; eventList.TryGetValue(path, out list); if (list == null) { list = new List <RecognitionResult>(); eventList.Add(path, list); } for (int i = 0; i < tempList.Count; i++) { list.Add(tempList.ElementAt(i)); } tempList.Clear(); list.Add(recEvent); } else { //add the event to a temp list tempList.Add(recEvent); } } else if (line.StartsWith("finishPage")) { if (recEvent != null) { recEvent.endPage = true; } } } return(eventList); }
/// <summary> /// The method is currently used in replay mode. The recognitionResult is /// simulated from log file. /// </summary> /// <param name="result">The RecognitionResult ecapsulate the text, confidence, grammars, etc.</param> private void processRecognitionResult(RecognitionResult result) { processRecognitionResult(result.confidence, result.textResult, result.isHypothesis, result.semanticResult, result.grammarName, result.ruleName, result.audioDuration, result.wavPath); }