Ejemplo n.º 1
0
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public void Resolve(LuisMRResult result)
        {
            // Loop through all LUIS entities of the specific type MR.InstanceName
            foreach (Entity entity in result.PredictionResult.Entities["MR.InstanceName"])
            {
                // The Value of this type should be the name in the name table
                GameObject gameObject = nameTable[entity.Value];

                // If it's a valid entity, map it
                if (gameObject != null)
                {
                    result.Map(entity, gameObject, this);
                }
            }
        }
        /// <summary>
        /// Find all the scene GameObjects that have names matching the Entity value
        /// </summary>
        /// <param name="result"></param>
        public void Resolve(LuisMRResult result)
        {
            // Collect any entities that match the entity names we're looking for
            List <Entity> predictionEntities = result.PredictionResult.Entities.Where(x => entityNames.Contains(x.Key)).SelectMany(y => y.Value).ToList();

            // If there are no entities in the prediction that we're looking for, nothing to do
            if (predictionEntities.Count < 1)
            {
                if (debugMessages)
                {
                    Debug.Log("No entities in the prediction match the names configured for the resolver.");
                }
                return;
            }

            // Join the list of scene objects with prediction entities to get matches in the scene
            IEnumerable <EntityMap> meq =
                from entity in predictionEntities
                let entityName = entity.Value.ToLower()
                                 from sceneEntity in GameObject.FindObjectsOfType <EntityMetadata>()
                                 where entityName.Equals(sceneEntity.EntityName.ToLower()) || entityName.Equals(sceneEntity.EntityType.ToLower())
                                 select new EntityMap()
            {
                Entity     = entity,
                GameObject = sceneEntity.gameObject,
                Resolver   = this
            };
            List <EntityMap> matchedEntities = meq.ToList();

            //Add all our found entities to the result's entity map, which maps LUIS entities with scene entities.
            foreach (EntityMap entityMap in matchedEntities)
            {
                // Create map entry
                result.Map(entityMap);

                // Remove the entity from the prediction list to mark it as "mapped"
                predictionEntities.Remove(entityMap.Entity);
            }

            // If any entity is still in the prediction list, it was not matched. Log a warning.
            if (debugMessages)
            {
                foreach (var entity in predictionEntities)
                {
                    Debug.LogWarning($"Warning: {entity.Name} \"{entity.Value}\" could not be mapped to the scene.");
                }
            }
        }