public virtual void LoadFrom(IItemData itemData, IFieldFormatter[] fieldFormatters) { Id = itemData.Id; DatabaseName = itemData.DatabaseName; ParentId = itemData.ParentId; TemplateId = itemData.TemplateId; Path = itemData.Path; BranchId = itemData.BranchId; foreach (var field in itemData.SharedFields) { var fieldObject = new YamlFieldValue(); fieldObject.LoadFrom(field, fieldFormatters); SharedFields.Add(fieldObject); } var languages = itemData.Versions.GroupBy(x => x.Language.Name); foreach (var language in languages) { var languageObject = new YamlLanguage(); languageObject.LoadFrom(language, fieldFormatters); if (languageObject.Versions.Count > 0) { Languages.Add(languageObject); } } foreach (var unversionedFieldLanguage in itemData.UnversionedFields) { var existing = Languages.FirstOrDefault(language => language.Language == unversionedFieldLanguage.Language.Name); if (existing == null) { existing = new YamlLanguage { Language = unversionedFieldLanguage.Language.Name }; Languages.Add(existing); } foreach (var unversionedField in unversionedFieldLanguage.Fields) { var field = new YamlFieldValue(); field.LoadFrom(unversionedField, fieldFormatters); existing.UnversionedFields.Add(field); } } }
private void RemoveLanguageVersions( [NotNull] ItemDefinition item, [NotNull] Language language, bool removeSharedData) { if (removeSharedData) { SharedFields.Remove(item.ID); } UnversionedFields[item.ID].Delete(r => r.Language == language.ToString()); VersionedFields[item.ID].Delete(r => r.Language == language.ToString()); }
private void RemoveFields([NotNull] ID itemId, [NotNull] Language language, [NotNull] Data.Version version) { SharedFields.Remove(itemId); { var itemFields = UnversionedFields[itemId]; itemFields.Where(r => r.Language == language.ToString()).ToList().Apply(r => itemFields.Remove(r)); } { var itemFields = VersionedFields[itemId]; itemFields.Where(r => (r.Language == language.ToString()) && (r.Version == version.ToInt32())) .ToList() .Apply(r => itemFields.Remove(r)); } }
// Use this for initialization void Start() { //benötigte Map Objekte mapBorder = GameObject.FindGameObjectWithTag("MinimapBorder"); mapBorderRectTransform = mapBorder.GetComponent <RectTransform>(); minimapKamera = GameObject.Find("MiniMapCamera").GetComponent <Camera>(); mapOverlayRect = GameObject.Find("Map").GetComponent <RectTransform>(); //das Overlay, welches die Map enthält mapRect = GameObject.Find("Minimap").GetComponent <RectTransform>(); mapScript = minimapKamera.GetComponent <Minimap>(); playerCarObject = GameObject.Find("Car Prototype v8"); navigationArrow = playerCarObject.transform.Find("navArrow2");//.Find("NavigationArrow"); //benötigte Steuerungsobjekte (Lenkung) sharedData = SharedFields.Instance; }
public override bool DeleteItem([NotNull] ItemDefinition itemDefinition, [NotNull] CallContext context) { lock (this) { var parentId = GetParentID(itemDefinition, context); Items.Remove(itemDefinition.ID); SharedFields.Remove(itemDefinition.ID); UnversionedFields.Remove(itemDefinition.ID); VersionedFields.Remove(itemDefinition.ID); Items[parentId].Children.Remove(itemDefinition.ID); return(true); } }
public virtual void WriteYaml(YamlWriter writer) { writer.WriteMap("ID", Id.ToString("D")); writer.WriteMap("Parent", ParentId.ToString("D")); writer.WriteMap("Template", TemplateId.ToString("D")); writer.WriteMap("Path", Path); writer.WriteMap("DB", DatabaseName); if (BranchId != default(Guid)) { writer.WriteMap("BranchID", BranchId.ToString()); } if (SharedFields.Any()) { writer.WriteMap("SharedFields"); writer.IncreaseIndent(); foreach (var field in SharedFields) { field.WriteYaml(writer); } writer.DecreaseIndent(); } if (Languages.Any()) { writer.WriteMap("Languages"); writer.IncreaseIndent(); foreach (var language in Languages) { language.WriteYaml(writer); } writer.DecreaseIndent(); } }
public SharedFilter(SharedFields sharedFields) { _sharedFields = sharedFields; }
public virtual void ReadYaml(YamlReader reader) { Id = reader.ReadExpectedGuidMap("ID"); ParentId = reader.ReadExpectedGuidMap("Parent"); TemplateId = reader.ReadExpectedGuidMap("Template"); Path = reader.ReadExpectedMap("Path"); var dbName = reader.PeekMap(); if (dbName.HasValue && dbName.Value.Key.Equals("DB")) //could be missing if serialized with 1.0.x { reader.ReadMap(); DatabaseName = dbName.Value.Value; } var branch = reader.PeekMap(); if (branch.HasValue && branch.Value.Key.Equals("BranchID")) { reader.ReadMap(); BranchId = Guid.Parse(branch.Value.Value); } var sharedFields = reader.PeekMap(); if (sharedFields.HasValue && sharedFields.Value.Key.Equals("SharedFields")) { reader.ReadMap(); while (true) { var field = new YamlFieldValue(); if (field.ReadYaml(reader)) { SharedFields.Add(field); } else { break; } } } var languages = reader.PeekMap(); if (languages.HasValue && languages.Value.Key.Equals("Languages")) { reader.ReadMap(); while (true) { var language = new YamlLanguage(); if (language.ReadYaml(reader)) { Languages.Add(language); } else { break; } } } }
//called on every line public IEnumerable <IRow> ParseEvent(IUpdatableRow output, Stream input) { var shared = new SharedFields(output.Schema); output.Set(this.ParserErrorColumn, string.Empty); TextReader inputReader; bool firstPass = true; int slotIdx = 0; inputReader = new StreamReader(input, Encoding.UTF8); shared.SessionId = Guid.NewGuid().ToString(); string errorMessage = null; // this is a optimized version only parsing parts of the data using (var jsonReader = new JsonTextReader(inputReader)) { jsonReader.DateFormatString = "o"; while (SafeJsonReader.Read(jsonReader, ref errorMessage)) { switch (jsonReader.TokenType) { case JsonToken.PropertyName: { var propertyName = (string)jsonReader.Value; switch (propertyName) { case "EventId": Helpers.ExtractPropertyString(jsonReader, output, this.EventIdColumn); break; case "Timestamp": shared.Timestamp = (DateTime)jsonReader.ReadAsDateTime(); break; case "_outcomes": break; case "_id": Helpers.ExtractPropertyString(jsonReader, output, this.EventIdColumn); output.Set(this.SlotIdxColumn, slotIdx++); break; case "_label_cost": if (!firstPass) { yield return(shared.Apply(output)); } firstPass = false; Helpers.ExtractPropertyDouble(jsonReader, output, this.CostColumn); output.Set(this.IsDanglingColumn, false); break; case "EnqueuedTimeUtc": output.Set(this.EnqueuedTimeUtcColumn, (DateTime)jsonReader.ReadAsDateTime()); output.Set(this.IsDanglingColumn, true); break; case "_p": if (this.ProbabilityColumn.IsRequired) { output.Set(this.ProbabilityColumn.Idx, Helpers.EnumerateFloats(jsonReader).First()); } break; case "_a": if (this.ActionColumn.IsRequired || this.NumActionsPerSlotColumn.IsRequired || this.CbActionColumn.IsRequired) { var actions = Helpers.EnumerateInts(jsonReader).ToList(); output.Set(this.NumActionsPerSlotColumn, actions.Count); var chosen = actions[0]; output.Set(this.ActionColumn, chosen); if (this.CbActionColumn.IsRequired) { output.Set(this.CbActionColumn, actions.Count(a => a < chosen)); } } break; case "_o": if (!this.HasObservationsColumn.IsRequired) { jsonReader.Skip(); } else { if (this.HasObservationsColumn.IsRequired) { output.Set(this.HasObservationsColumn.Idx, Helpers.CountObjects(jsonReader) > 0 ? 1 : 0); } } break; case "c": if (!shared.NumActionsColumn.IsRequired) { jsonReader.Skip(); } break; case "_multi": if (shared.NumActionsColumn.IsRequired) { shared.NumActions = Helpers.CountObjects(jsonReader); } break; case "pdrop": shared.pdrop = Helpers.GetPropertyDouble(jsonReader); break; case "RewardValue": Helpers.ExtractPropertyDoubleOpt(jsonReader, output, this.RewardValueColumn); break; default: jsonReader.Skip(); break; } } break; } } if (!string.IsNullOrEmpty(errorMessage)) { output.Set(this.ParserErrorColumn, errorMessage); } } yield return(shared.Apply(output)); }
public void HandleIntent(EventMessageObject nluAnswer) { AIResponse nluResponse = (AIResponse)nluAnswer.MessageBody; Debug.Log("##### Habe folgenden Intent erkannt und möchte ihn jetzt verarbeiten: " + nluResponse.Result.Metadata.IntentName); //Dialog Delegation prüfen Debug.Log("Überprüfe ob noch Slots fehlen: "); //AIOutputContext context = nluResponse.Result.GetContext(); AIOutputContext[] context = nluResponse.Result.Contexts; bool slotsMissing = false; foreach (AIOutputContext con in context) { Debug.Log(con.Name); if (con.Name.Contains("dialog_context")) { slotsMissing = true; } } if (slotsMissing) { wasInDialogDelegationLastRound = true; //damit nächster Intent sieht, ob DialogDelegation zuvor aktiv war slotMissingRounds++; Debug.Log("Es fehlen noch Slotbelegungen. Ich gebe die Kontrolle an TTS"); //Debug.Log("WWE Status " + asr.WakeWordState); //Debug.Log("STT Status " + asr.DictationState); EventManager.TriggerEvent(EventManager.keywordDetectedEvent, new EventMessageObject(EventManager.keywordDetectedEvent, "Slots fehlen")); //actions.DisplayText(debugText, nluResponse.Result.Fulfillment.Speech); string cancelInfo = ""; if (slotMissingRounds > 1) { cancelInfo = "Du kannst ungewollte Anfragen jederzeit beenden, indem du abbrechen sagst."; } WindowsVoice.speak(string.Format("{0} {1}", cancelInfo, nluResponse.Result.Fulfillment.Speech), delay: 0f); } //ansonsten rufe die Handler auf else { slotMissingRounds = 0; Debug.Log("Alle Slots gefüllt:"); Dictionary <String, System.Object> dic = nluResponse.Result.Parameters; foreach (String key in dic.Keys) { Debug.Log(string.Format("Parameter: {0}", key)); } actions.DisplayText(debugText, nluResponse.Result.Fulfillment.Speech); String intent = nluResponse.Result.Metadata.IntentName; Result nluResultObj = nluResponse.Result; //Ausgabe der Dialogflow Response -> Metadata.EndConversation Boolean bestimmt ob als Frage oder Aussage //***Kann in Unity JSON Objekt bisher nicht abgerufen werden -> Parameter: endConversation simuliert ihn bool canceledDialogDelegation = nluResponse.Result.ResolvedQuery.Equals("abbrechen") && wasInDialogDelegationLastRound ? true:false; //Dialogflow eigenes Abbrechen simuliert endConversation nicht if (nluResultObj.Fulfillment.Speech != "") { if (nluResultObj.GetStringParameter("endConversation").Equals("true") || canceledDialogDelegation) //***evtl. muss hier eine Abfrage rein die beim default fallback auch das mikrofon schließt { actions.Speak(nluResultObj.Fulfillment.Speech); } else //ansonsten öffne das Mikrofon wieder { actions.AskQuestion(nluResultObj.Fulfillment.Speech); } } String action = nluResponse.Result.Action; bool noActionIntent = false; //wird true falls der Intent keine Action enthält oder diese nicht implementiert ist switch (action) { /*case IPAAction.askQuestion: * actions.AskQuestion(nluResultObj.GetStringParameter("speak")); * break; * * * case IPAAction.speak: * actions.Speak(nluResultObj.GetStringParameter("speak")); * break;*/ //Intents zur Fahrzeugsteuerung case IPAAction.moveCar: String groesseneinheit = nluResultObj.GetStringParameter("Groesseneinheit"); String direction = nluResultObj.GetStringParameter("MoveDirection"); actions.MoveCar(groesseneinheit, direction); break; case IPAAction.stopCar: actions.StopCarMovement(); break; case IPAAction.takeCarControl: actions.TakeCarControl(); break; case IPAAction.getCarControlBack: actions.GetCarControlBack(); break; case IPAAction.takePlateControl: actions.TakePlateControl(); break; case IPAAction.getPlateControlBack: actions.GetPlateControlBack(); break; //Map Manipulation Intents: case IPAAction.openMap: actions.OpenMap(); break; case IPAAction.closeMap: actions.CloseMap(); actions.SetMinimapFokusOnCar(); break; case IPAAction.saveNavigationPoint: actions.SaveNavigationPoint(minimapLocationIcon); break; case IPAAction.deleteNavigationPoint: int zielNummer2 = Int32.Parse(nluResultObj.GetStringParameter("navigationNumber")); actions.DeleteNavigationPoint(zielNummer2); break; case IPAAction.changeMapFixedStep: groesseneinheit = nluResponse.Result.GetStringParameter("Groesseneinheit"); direction = nluResponse.Result.GetStringParameter("Direction"); if (direction.Length == 0) { direction = nluResponse.Result.GetStringParameter("MoveDirection"); } actions.ChangMapFixedStep(groesseneinheit, direction); break; case IPAAction.focusOnCar: actions.SetMinimapFokusOnCar(); break; //Navigation Intents: case IPAAction.startNavigation: int zielNummer = Int32.Parse(nluResultObj.GetStringParameter("navigationNumber")); if (sharedData.savedPlacesOnMap.Count > zielNummer - 1) { Vector3 target = sharedData.savedPlacesOnMap[zielNummer - 1].transform.position; actions.StartNavigation(target); } else { WindowsVoice.speak(string.Format("Ich konnte keinen Ort mit Nummer {0} finden.", zielNummer), 3); } break; case IPAAction.endNavigation: actions.EndNavigation(); break; //Intents zur Unterstützung der Teststreckenerstellung case IPAAction.restartTraining: SceneManager.LoadScene("Level1Training"); // Todo:Index auf Namen der Szene ändern break; case IPAAction.setCheckpoint: actions.SetTrainingCheckpoint(sharedData.currentFrameCount); actions.Speak("Sicherungspunkt erstellt bei Frame:" + sharedData.currentFrameCount); break; case IPAAction.discardCheckpoint: actions.SetTrainingCheckpoint(0); break; case IPAAction.endTrainingRouteCreation: actions.EndTraining(); /*sharedData.trainingRouteRecordingStopped = true; //Beendet hinzufügen neuer Framestrokes in AlternateCarController * * * //Entferne PlayerControl und Ball * sharedData.SetPlayerControl(false); * GameObject.FindGameObjectWithTag("Ball").SetActive(false); * if (String.IsNullOrEmpty(sharedData.playerName)) * { * Debug.LogError("Fehler bei Namenserfassung. Öffne Texteingabe."); * GameObject.Find("NameQuestionCanvas").GetComponent<Canvas>().enabled = true; * }*/ break; case IPAAction.performanceAndDifficultyMeasured: bool performanceOK = nluResultObj.GetStringParameter("Performance").Equals("gut") ? true : false; if (sharedData.debugMode && performanceOK) { //Debug.LogError(WindowsVoice.statusMessage); sharedData.trainingRouteDifficulty = nluResultObj.GetStringParameter("Difficulty") + "/"; //sobald gesetzt schreibt AlternateCarController die Route entsprechend ca Codezeile 500 //Beende verzögert StartCoroutine(SharedFields.DelayedQuit(10f)); } else { Debug.LogError(nluResultObj.GetStringParameter("Performance")); actions.Speak("Verwerfe Strecke aufgrund schlechter Performance. Beende Programm"); IEnumerator co = SharedFields.DelayedQuit(10f); StartCoroutine(co); //Application.Quit(); } break; case IPAAction.wantToSetContext: int firstFreeContext = context.Length; AIOutputContext[] newContext = new AIOutputContext[firstFreeContext + 1]; AIOutputContext contextToInsert = new AIOutputContext(); contextToInsert.Name = "TestContext"; contextToInsert.Lifespan = 3; newContext[firstFreeContext] = contextToInsert; context = newContext; Debug.Log("So sollte es aussehen:"); foreach (AIOutputContext con in context) { Debug.Log(con.Name); if (con.Name.Contains("dialog_context")) { slotsMissing = true; } } Debug.Log("Trigger SpeechCommandRecognized to send new Context to Dialogflow"); EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, string.Format("Rueckantwort Kontext einfuegen"))); break; case IPAAction.setContext: Debug.Log("Habe Kontext gesetzt."); foreach (AIOutputContext con in context) { Debug.Log(con.Name); if (con.Name.Contains("dialog_context")) { slotsMissing = true; } } break; //PlayerInfo case IPAAction.setPlayerName: //var outText = NewJSon::Newtonsoft.Json.JsonConvert.SerializeObject(nluResultObj.GetJsonParameter("UserName"), jsonSettings); //Debug.LogError(outText); string name = ""; //Sonderbehandlung falls Dialogflow Entitie givenName benutzt -> bekomme neues Dict statt String Dictionary <string, object> parameterDict = nluResultObj.Parameters; Type t = parameterDict["UserName"].GetType(); bool isDict = t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary <,>); Dictionary <string, object> givenNameEntitie; if (isDict) { givenNameEntitie = (Dictionary <string, object>)parameterDict["UserName"]; try { name = (string)givenNameEntitie["given-name"]; } catch (KeyNotFoundException) { name = (string)givenNameEntitie["MapStringsToName"]; } } else { name = nluResultObj.GetStringParameter("UserName"); } //Debug.LogErrorFormat("is dict? {0}", isDict); //Debug.LogError( parameterDict["UserName"].GetType()); Debug.LogError("Haben folgenden Namen erkannt: " + name); if (String.IsNullOrEmpty(name)) { Debug.LogError("******Name konnte nicht gesetzt werden. Baue erneute Nachfrage ein?"); } actions.SetPlayerName(name); Debug.LogError("Der neue Name ist: " + sharedData.playerName); break; case IPAAction.rename: EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, "Spielerwechsel")); break; //Allgemeine Befehle: case IPAAction.repeatAnswer: actions.Speak(lastIPAspeech); break; case IPAAction.repeatLastAction: if (repeatableTasksDict.ContainsKey(lastIPAAction)) { EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, repeatableTasksDict[lastIPAAction])); } break; case IPAAction.undo: string undoAction = ""; Debug.LogError("Last Action was: " + lastIPAAction); if (symmetricTasksDict.ContainsKey(lastIPAAction)) { undoAction = symmetricTasksDict[lastIPAAction]; } else if (symmetricTasksDict.ContainsValue(lastIPAAction)) { foreach (KeyValuePair <string, string> keyValue in symmetricTasksDict) { if (keyValue.Value.Equals(lastIPAAction)) { undoAction = keyValue.Key; } } } else { Debug.LogErrorFormat("Der letzte Task hatte keine Implementierung eines symmetrischen Gegenparts"); WindowsVoice.speak("Der letzte Task hatte keine Implementierung eines symmetrischen Gegenparts", 2); } if (eventTriggerStringForActionDict.ContainsKey(undoAction)) { string voiceCommandForUndoAction = eventTriggerStringForActionDict[undoAction]; EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, voiceCommandForUndoAction)); } else { actions.Speak("Ich kann die letzte Aktion nicht rueckgängig machen. Die eingetragenen Funktionspaare funktionieren nur in die andere Richtung."); } break; case IPAAction.wantMoreHelp: //Ermittle zuletzt thematisierte Kategorie und simuliere eine entsprechende Anfrage an die NLU int navigationHelpSessionCount = 0; int mlTrainingHelpSessionCount = 0; int driveHelpSessionCount = 0; foreach (AIOutputContext currentContext in nluResponse.Result.Contexts) { string contextName = currentContext.Name; if (contextName.Equals("mltraininghelprequested")) { Debug.Log("habe training kontext"); mlTrainingHelpSessionCount += (int)currentContext.Lifespan; } else if (context.Equals("navigationhelprequested")) { Debug.Log("habe navigation kontext"); navigationHelpSessionCount += (int)currentContext.Lifespan; } else if (context.Equals("drivehelprequested")) { Debug.Log("habe drive kontext"); driveHelpSessionCount += (int)currentContext.Lifespan; } } if (navigationHelpSessionCount > Math.Max(mlTrainingHelpSessionCount, driveHelpSessionCount)) { EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, "Ich brauche Hilfe in der Kategorie Fahren.")); } else if (mlTrainingHelpSessionCount > Math.Max(navigationHelpSessionCount, driveHelpSessionCount)) { EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, "Hilf mir beim trainieren")); } else if (driveHelpSessionCount > Math.Max(navigationHelpSessionCount, mlTrainingHelpSessionCount)) { EventManager.TriggerEvent(EventManager.asrRequerstDetectedEvent, new EventMessageObject(EventManager.asrRequerstDetectedEvent, "Hilf mir beim Navigieren")); } else { Debug.LogFormat("Konnte kein Event auslösen: navigationHelpSessionCount {0} mlTrainingHelpSessionCount{1}, driveHelpSessionCount {2}", navigationHelpSessionCount, mlTrainingHelpSessionCount, driveHelpSessionCount); } break; case IPAAction.continueGame: actions.ContinueGame(); break; case IPAAction.pauseGame: actions.PauseGame(); break; case IPAAction.quitGame: Application.Quit(); break; default: Debug.Log(string.Format("Der Intent {0} wurde im IntentHandler nicht registiert.", intent)); noActionIntent = true; //WindowsVoice.speak("Diesen Intent kenne ich nicht", 0f); //wird von Fallback Intent in Block unten gemacht break; } //Die letzte Aktion soll von Intents ohne Action nicht überschrieben werden if (!noActionIntent) { lastIPAAction = action; } } lastIPAspeech = nluResponse.Result.Fulfillment.Speech; Debug.LogError(lastIPAspeech + " ist zuletzt gesagtes"); }