public void SyncWatsonConversation(LexiconWorkspace workspace, WorkspaceSyncData syncData)
        {
            workspace.WatsonConversationManager.IsSyncing  = true;
            workspace.WatsonConversationManager.SyncStatus = "Syncing";

            WatsonSyncQueue syncQueue = ScriptableObject.CreateInstance <WatsonSyncQueue>();

            syncQueue.workspace = workspace;
            syncQueue.syncData  = syncData;

            if (string.IsNullOrEmpty(workspace.WatsonConversationManager.WorkspaceId))
            {
                syncQueue.Enqueue(WatsonWorkspaceCreate.CreateInstance(workspace));
            }

            syncQueue.Enqueue(WatsonIntentSyncAll.CreateInstance(workspace));
            syncQueue.Enqueue(WatsonEntitySyncAll.CreateInstance(workspace));

            syncQueue.OnCompleteAction = WatsonCompleteConversationSync.CreateInstance(workspace);
            syncQueue.OnQueueFinished += CleanUp;

            syncQueue.Process();

            watsonConversationSyncQueues.Add(syncQueue);
        }
        public void SyncWatsonSpeechToText(LexiconWorkspace workspace, WorkspaceSyncData syncData)
        {
            workspace.WatsonSpeechToTextManager.IsSyncing  = true;
            workspace.WatsonSpeechToTextManager.SyncStatus = "Syncing";

            WatsonSyncQueue syncQueue = ScriptableObject.CreateInstance <WatsonSyncQueue>();

            syncQueue.workspace = workspace;
            syncQueue.syncData  = syncData;

            if (string.IsNullOrEmpty(workspace.WatsonSpeechToTextManager.CustomizationId))
            {
                syncQueue.Enqueue(WatsonCustomModelCreate.CreateInstance(workspace));
            }
            else
            {
                syncQueue.Enqueue(WatsonCustomWordsUpdate.CreateInstance(workspace));
                syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));
            }

            syncQueue.Enqueue(WatsonCorpusAddIntents.CreateInstance(workspace));
            syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));
            syncQueue.Enqueue(WatsonCorpusAddEntities.CreateInstance(workspace));
            syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));
            syncQueue.Enqueue(WatsonCustomModelTrain.CreateInstance(workspace));
            syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));

            syncQueue.OnCompleteAction = WatsonCompleteSpeechToTextSync.CreateInstance(workspace);
            syncQueue.OnQueueFinished += CleanUp;

            syncQueue.Process();

            watsonSpeechToTextSyncQueues.Add(syncQueue);
        }
예제 #3
0
        private string CreateCorpusData(WorkspaceSyncData syncData)
        {
            StringBuilder builder = new StringBuilder();

            foreach (IntentData intent in syncData.intentData.Values)
            {
                foreach (string phrase in intent.phrases)
                {
                    builder.AppendLine(phrase);
                }
            }

            return(builder.ToString());
        }
        public void SyncWatson(LexiconWorkspace workspace)
        {
            WorkspaceSyncData syncData = WorkspaceSyncData.Create(workspace);

            if (workspace.UseWatsonSpeechToText)
            {
                SyncWatsonSpeechToText(workspace, syncData);
            }

            if (workspace.UseWatsonConversation)
            {
                SyncWatsonConversation(workspace, syncData);
            }
        }
예제 #5
0
        private Words GetCustomWords(WorkspaceSyncData syncData)
        {
            Words       words    = new Words();
            List <Word> wordList = new List <Word>();

            foreach (LexiconCustomWord customWord in syncData.customWords)
            {
                Word w0 = new Word();
                w0.word        = customWord.Word;
                w0.display_as  = customWord.DisplayAs;
                w0.sounds_like = customWord.GetPronunciationList().ToArray();
                wordList.Add(w0);
            }

            words.words = wordList.ToArray();

            return(words);
        }
        private string CreateCorpusData(WorkspaceSyncData syncData)
        {
            StringBuilder builder = new StringBuilder();

            foreach (EntityData entity in syncData.entityData.Values)
            {
                foreach (EntityValueData entityValue in entity.values)
                {
                    builder.AppendLine(entityValue.name);

                    foreach (string synonym in entityValue.synonyms)
                    {
                        builder.AppendLine(synonym);
                    }
                }
            }

            return(builder.ToString());
        }
        public static WorkspaceSyncData Create(LexiconWorkspace workspace)
        {
            WorkspaceSyncData syncData = new WorkspaceSyncData();

            foreach (LexiconIntent intent in workspace.Intents)
            {
                if (string.IsNullOrEmpty(intent.IntentName))
                {
                    Debug.LogError("Found intent with empty name, skipping");
                    continue;
                }

                IntentData intentData;
                if (syncData.intentData.TryGetValue(intent.IntentName, out intentData))
                {
                    // Intent exists, add any new phrases
                    foreach (string phrase in intent.Phrases)
                    {
                        if (intentData.phrases.FindIndex(x => x.Equals(phrase, StringComparison.OrdinalIgnoreCase)) < 0)
                        {
                            // Phrase does not exist, add it
                            intentData.phrases.Add(phrase);
                        }
                    }
                }
                else
                {
                    // Intent does not exist, add it
                    intentData      = new IntentData();
                    intentData.name = intent.IntentName;
                    intentData.phrases.AddRange(intent.Phrases);
                    syncData.intentData.Add(intent.IntentName, intentData);
                }
            }

            foreach (LexiconEntity entity in workspace.GetUniqueEntities())
            {
                if (entity == null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(entity.EntityName))
                {
                    Debug.LogError("Found entity with empty name, skipping");
                    continue;
                }

                EntityData entityData;
                if (syncData.entityData.TryGetValue(entity.EntityName, out entityData))
                {
                    // Entity exists, add any new values
                    foreach (LexiconEntityValue entityValue in entity.Values)
                    {
                        List <string> synonyms   = entityValue.GetSynonymList();
                        int           valueIndex = entityData.values.FindIndex(x => x.name.Equals(entityValue.ValueName, StringComparison.OrdinalIgnoreCase));
                        if (valueIndex < 0)
                        {
                            // Value does not exist, add it
                            EntityValueData entityValueData = new EntityValueData();
                            entityValueData.name = entityValue.ValueName;
                            entityValueData.synonyms.AddRange(synonyms);
                            entityData.values.Add(entityValueData);
                        }
                        else
                        {
                            // Value exists, add any new synonyms
                            EntityValueData entityValueData = entityData.values[valueIndex];
                            foreach (string synonym in synonyms)
                            {
                                if (entityValueData.synonyms.FindIndex(x => x.Equals(synonym, StringComparison.OrdinalIgnoreCase)) < 0)
                                {
                                    // Synonym does not exist, add it
                                    entityValueData.synonyms.Add(synonym);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Entity does not exist, add it
                    entityData      = new EntityData();
                    entityData.name = entity.EntityName;
                    if (entity.Values != null)
                    {
                        foreach (LexiconEntityValue entityValue in entity.Values)
                        {
                            List <string>   synonyms        = entityValue.GetSynonymList();
                            EntityValueData entityValueData = new EntityValueData();
                            entityValueData.name = entityValue.ValueName;
                            entityValueData.synonyms.AddRange(synonyms);
                            entityData.values.Add(entityValueData);
                        }
                    }
                    syncData.entityData.Add(entity.EntityName, entityData);
                }
            }

            syncData.customWords.AddRange(workspace.CustomWords);

            //foreach (LexiconCustomWord customWord in workspace.customWords)
            //{
            //    syncData.customWords.Add(customWord.word, customWord);
            //}

            syncData.dataIsDirty = true;

            return(syncData);
        }
예제 #8
0
        void HandleSuccessCallback(ListIntentsResp intentsResp, Dictionary <string, object> customData)
        {
            if (intentsResp == null)
            {
                succeeded = false;
                isDone    = true;
                return;
            }

            WorkspaceSyncData syncData = queue.syncData;

            HashSet <string> watsonIntentNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (Intent watsonIntent in intentsResp.intents)
            {
                string     intentName = watsonIntent.intent;
                IntentData localIntent;

                if (syncData.intentData.TryGetValue(intentName, out localIntent))
                {
                    string localTimestamp = workspace.WatsonConversationManager.Timestamps.GetIntentTimestamp(intentName);
                    bool   needsUpdate    = true;

                    if (watsonIntent.updated.Equals(localTimestamp, StringComparison.OrdinalIgnoreCase))
                    {
                        // No remote changes

                        if (workspace.WatsonConversationManager.LastSyncData != null)
                        {
                            IntentData lastSync;
                            if (workspace.WatsonConversationManager.LastSyncData.intentData.TryGetValue(intentName, out lastSync))
                            {
                                if (WorkspaceSyncData.CompareIntentData(localIntent, lastSync))
                                {
                                    // No local changes
                                    needsUpdate = false;
                                }
                            }
                        }
                    }

                    if (needsUpdate)
                    {
                        queue.Enqueue(WatsonIntentUpdate.CreateInstance(workspace, localIntent));
                    }
                }
                else
                {
                    // Intent deleted locally
                    queue.Enqueue(WatsonIntentDelete.CreateInstance(workspace, intentName));
                }

                watsonIntentNames.Add(intentName);
            }

            foreach (IntentData localIntent in syncData.intentData.Values)
            {
                if (!watsonIntentNames.Contains(localIntent.name))
                {
                    // Intent does not exist on server
                    queue.Enqueue(WatsonIntentCreate.CreateInstance(workspace, localIntent));
                }
            }

            succeeded = true;
            isDone    = true;
        }
        void HandleSuccessCallback(ListEntitiesResp entitiesResp, Dictionary <string, object> customData)
        {
            if (entitiesResp == null)
            {
                succeeded = false;
                isDone    = true;
                return;
            }

            WorkspaceSyncData syncData = queue.syncData;

            HashSet <string> watsonEntityNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (Entity watsonEntity in entitiesResp.entities)
            {
                string     entityName = watsonEntity.entity;
                EntityData localEntity;

                if (syncData.entityData.TryGetValue(entityName, out localEntity))
                {
                    string localTimestamp = workspace.WatsonConversationManager.Timestamps.GetEntityTimestamp(entityName);
                    bool   needsUpdate    = true;

                    if (watsonEntity.updated.Equals(localTimestamp, StringComparison.OrdinalIgnoreCase))
                    {
                        // No remote changes

                        if (workspace.WatsonConversationManager.LastSyncData != null)
                        {
                            EntityData lastSync;
                            if (workspace.WatsonConversationManager.LastSyncData.entityData.TryGetValue(entityName, out lastSync))
                            {
                                if (WorkspaceSyncData.CompareEntityData(localEntity, lastSync))
                                {
                                    // No local changes
                                    needsUpdate = false;
                                }
                            }
                        }
                    }

                    if (needsUpdate)
                    {
                        queue.Enqueue(WatsonEntityUpdate.CreateInstance(workspace, localEntity));
                    }
                }
                else
                {
                    // Entity deleted locally
                    queue.Enqueue(WatsonEntityDelete.CreateInstance(workspace, entityName));
                }

                watsonEntityNames.Add(entityName);
            }

            foreach (EntityData localEntity in syncData.entityData.Values)
            {
                if (!watsonEntityNames.Contains(localEntity.name))
                {
                    // Entity does not exist on server
                    queue.Enqueue(WatsonEntityCreate.CreateInstance(workspace, localEntity));
                }
            }

            succeeded = true;
            isDone    = true;
        }
예제 #10
0
        public void SyncWatsonConversation(LexiconWorkspace workspace)
        {
            WorkspaceSyncData syncData = WorkspaceSyncData.Create(workspace);

            SyncWatsonConversation(workspace, syncData);
        }
예제 #11
0
        public void SyncWatsonSpeechToText(LexiconWorkspace workspace)
        {
            WorkspaceSyncData syncData = WorkspaceSyncData.Create(workspace);

            SyncWatsonSpeechToText(workspace, syncData);
        }