/// <summary>
        /// Construct V3 recognizer options from the current dialog context.
        /// </summary>
        /// <param name="dialogContext">Context.</param>
        /// <returns>LUIS Recognizer options.</returns>
        public LuisRecognizerOptionsV3 RecognizerOptions(DialogContext dialogContext)
        {
            var options = PredictionOptions;
            var dcState = dialogContext.GetState();

            if (DynamicLists != null)
            {
                options = new AI.LuisV3.LuisPredictionOptions(options);
                var list = new List <AI.LuisV3.DynamicList>();
                foreach (var listEntity in DynamicLists.GetValue(dcState))
                {
                    list.Add(new AI.LuisV3.DynamicList(listEntity.Entity, listEntity.List));
                }

                options.DynamicLists = list;
            }

            var application = new LuisApplication(ApplicationId.GetValue(dcState), EndpointKey.GetValue(dcState), Endpoint.GetValue(dcState));

            return(new LuisRecognizerOptionsV3(application)
            {
                ExternalEntityRecognizer = ExternalEntityRecognizer,
                PredictionOptions = options,
                TelemetryClient = TelemetryClient
            });
        }
        /// <summary>
        /// Gets an instance of <see cref="IQnAMakerClient"/>.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> used to access state.</param>
        /// <returns>An instance of <see cref="IQnAMakerClient"/>.</returns>
        protected virtual Task <IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
        {
            var qnaClient = dc.Context.TurnState.Get <IQnAMakerClient>();

            if (qnaClient != null)
            {
                // return mock client
                return(Task.FromResult(qnaClient));
            }

            var(epKey, error)            = EndpointKey.TryGetValue(dc.State);
            var(hn, error2)              = HostName.TryGetValue(dc.State);
            var(kbId, error3)            = KnowledgeBaseId.TryGetValue(dc.State);
            var(logPersonalInfo, error4) = LogPersonalInformation.TryGetValue(dc.State);

            var endpoint = new QnAMakerEndpoint
            {
                EndpointKey = epKey ?? throw new InvalidOperationException($"Unable to get a value for {nameof(EndpointKey)} from state. {error}"),
                                    Host = hn ?? throw new InvalidOperationException($"Unable to a get value for {nameof(HostName)} from state. {error2}"),
                                                 KnowledgeBaseId = kbId ?? throw new InvalidOperationException($"Unable to get a value for {nameof(KnowledgeBaseId)} from state. {error3}")
            };

            return(Task.FromResult <IQnAMakerClient>(new QnAMaker(endpoint, new QnAMakerOptions(), HttpClient, TelemetryClient, logPersonalInfo)));
        }
    }
Ejemplo n.º 3
0
 public LinkTypeFailure(EndpointKey fromEP, signals.EType fromType, EndpointKey toEP, signals.EType toType)
 {
     this.fromEP   = fromEP;
     this.fromType = fromType;
     this.toEP     = toEP;
     this.toType   = toType;
     this.HResult  = unchecked ((int)0x80020005);
 }
Ejemplo n.º 4
0
        private bool AddImplicitConversion(EndpointKey fromEP, EndpointKey toEP, signals.IFunctionSpec convFunc)
        {
            Element newElm = new Element(convFunc);

            add(newElm);
            this.connections[fromEP] = new EndpointKey(newElm, 0);
            this.connections[new EndpointKey(newElm, 0)] = toEP;
            return(true);
        }
Ejemplo n.º 5
0
 private void connect(EndpointKey fromEp, EndpointKey toEp)
 {
     if (connections.ContainsKey(fromEp))
     {
         throw new ArgumentException("This connection source is already in use", "fromEp");
     }
     if (connections.ContainsValue(toEp))
     {
         throw new ArgumentException("This connection sink is already in use", "toEp");
     }
     if (!this.contents.ContainsValue(fromEp.elem))
     {
         add(fromEp.elem);
     }
     if (!this.contents.ContainsValue(toEp.elem))
     {
         add(toEp.elem);
     }
     connections.Add(fromEp, toEp);
 }
Ejemplo n.º 6
0
 private void isFullyConnectedImpl(Dictionary <Element, bool> seen, Element elm)
 {
     if (seen.ContainsKey(elm))
     {
         return;
     }
     seen.Add(elm, true);
     foreach (KeyValuePair <EndpointKey, EndpointKey> entry in this.connections)
     {
         EndpointKey key   = entry.Key;
         EndpointKey value = entry.Value;
         if (key.elem == elm)
         {
             isFullyConnectedImpl(seen, value.elem);
         }
         else if (value.elem == elm)
         {
             isFullyConnectedImpl(seen, key.elem);
         }
     }
 }
Ejemplo n.º 7
0
        public Schematic Clone()
        {
            Dictionary <Element, Element> elmMap = new Dictionary <Element, Element>();
            Schematic newOb = new Schematic();

            newOb.genericID = this.genericID;
            foreach (Element elm in this.contents.Values)
            {
                Element newElm = elm.Clone();
                newOb.add(newElm);
                elmMap.Add(elm, newElm);
            }
            foreach (KeyValuePair <EndpointKey, EndpointKey> entry in this.connections)
            {
                EndpointKey key    = entry.Key;
                EndpointKey value  = entry.Value;
                EndpointKey newKey = key.epString == null ?
                                     new EndpointKey(elmMap[key.elem], key.epIdx) : new EndpointKey(elmMap[key.elem], key.epString);
                EndpointKey newValue = value.epString == null ?
                                       new EndpointKey(elmMap[value.elem], value.epIdx) : new EndpointKey(elmMap[value.elem], value.epString);
                newOb.connections.Add(newKey, newValue);
            }
            return(newOb);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Construct V3 recognizer options from the current dialog context.
        /// </summary>
        /// <param name="dialogContext">Context.</param>
        /// <returns>LUIS Recognizer options.</returns>
        public LuisRecognizerOptionsV3 RecognizerOptions(DialogContext dialogContext)
        {
            AI.LuisV3.LuisPredictionOptions options = new LuisV3.LuisPredictionOptions();
            if (this.PredictionOptions != null)
            {
                options = new LuisV3.LuisPredictionOptions(this.PredictionOptions);
            }
            else if (this.Options != null)
            {
                options.DateTimeReference   = this.Options.DateTimeReference?.GetValue(dialogContext);
                options.ExternalEntities    = this.Options.ExternalEntities?.GetValue(dialogContext);
                options.IncludeAllIntents   = this.Options.IncludeAllIntents?.GetValue(dialogContext) ?? false;
                options.IncludeInstanceData = this.Options.IncludeInstanceData?.GetValue(dialogContext) ?? true;
                options.IncludeAPIResults   = this.Options.IncludeAPIResults?.GetValue(dialogContext) ?? false;
                options.Log = this.Options.Log?.GetValue(dialogContext) ?? true;
                options.PreferExternalEntities = this.Options.PreferExternalEntities?.GetValue(dialogContext) ?? true;
                options.Slot = this.Options.Slot?.GetValue(dialogContext);
            }

            if (this.Version != null)
            {
                options.Version = this.Version?.GetValue(dialogContext.State);
            }

            if (DynamicLists != null)
            {
                var list = new List <AI.LuisV3.DynamicList>();
                foreach (var listEntity in DynamicLists.GetValue(dialogContext.State))
                {
                    list.Add(new AI.LuisV3.DynamicList(listEntity.Entity, listEntity.List));
                }

                options.DynamicLists = list;
            }

            var application = new LuisApplication(ApplicationId.GetValue(dialogContext.State), EndpointKey.GetValue(dialogContext.State), Endpoint.GetValue(dialogContext.State));

            return(new LuisRecognizerOptionsV3(application)
            {
                ExternalEntityRecognizer = ExternalEntityRecognizer,
                PredictionOptions = options,
                TelemetryClient = TelemetryClient,
                IncludeAPIResults = options.IncludeAPIResults,
            });
        }
Ejemplo n.º 9
0
 void Start()
 {
     endpoint = GameObject.Find("KeyBox").GetComponent <EndpointKey>();
 }
Ejemplo n.º 10
0
        private static List <Schematic> resolveImpl(sharptest.ModLibrary library, Schematic here, Dictionary <int, bool> seen, int elmKey)
        {
            if (seen.ContainsKey(elmKey))
            {
                return new List <Schematic> {
                           here
                }
            }
            ;
            if (!here.contents.ContainsKey(elmKey))
            {
                throw new ApplicationException("couldn't kind elmKey in contents");
            }
            Element elm = here.contents[elmKey];

            seen.Add(elmKey, true);
            try
            {
                List <Schematic> answers = new List <Schematic>();
                ResolveFailure   failure = new ResolveFailure();
                if (elm.availObjects.Count == 0)
                {
                    failure.Add(new CannotResolveElement(elm));
                }
                foreach (signals.ICircuitConnectible avail in elm.availObjects)
                {
                    Schematic newSchem = here.Clone();
                    Element   newElem  = newSchem.contents[elmKey];
                    newElem.availObjects.Clear();
                    newElem.availObjects.Add(avail);

                    try
                    {
                        newSchem.resolveNeighbors(library, newElem);
                    }
                    catch (ResolveFailureReason fault)
                    {
                        failure.Add(fault);
                        continue;
                    }

                    Dictionary <int, bool> recurseList = new Dictionary <int, bool>();
                    foreach (KeyValuePair <EndpointKey, EndpointKey> entry in newSchem.connections)
                    {
                        EndpointKey key   = entry.Key;
                        EndpointKey value = entry.Value;
                        if (key.elem == newElem)
                        {
                            if (!seen.ContainsKey(value.elem.circuitId))
                            {
                                recurseList.Add(value.elem.circuitId, true);
                            }
                        }
                        else if (value.elem == newElem)
                        {
                            if (!seen.ContainsKey(key.elem.circuitId))
                            {
                                recurseList.Add(key.elem.circuitId, true);
                            }
                        }
                    }
                    List <Schematic> possibles = new List <Schematic>();
                    possibles.Add(newSchem);
                    foreach (KeyValuePair <int, bool> entry in recurseList)
                    {
                        List <Schematic> prevPass = possibles;
                        possibles = new List <Schematic>();
                        foreach (Schematic possible in prevPass)
                        {
                            try
                            {
                                possibles.AddRange(resolveImpl(library, possible, seen, entry.Key));
                            }
                            catch (ResolveFailure fail)
                            {
                                failure.Add(fail);
                            }
                        }
                    }
                    answers.AddRange(possibles);
                }
                if (answers.Count == 0 && failure.reasons.Count > 0)
                {
                    throw failure;
                }
                return(answers);
            }
            finally
            {
                seen.Remove(elmKey);
            }
        }
Ejemplo n.º 11
0
        public Circuit construct()
        {
            Dictionary <int, Circuit.Element> result    = new Dictionary <int, Circuit.Element>();
            Dictionary <Element, object>      elmResult = new Dictionary <Element, object>();

            foreach (KeyValuePair <int, Element> here in contents)
            {
                Element elm = here.Value;
                if (elm.availObjects.Count != 1)
                {
                    throw new ApplicationException("expecting all elements to have exactly one solution");
                }
                signals.ICircuitConnectible avail = elm.availObjects[0];
                signals.ICircuitElement     newOb = null;
                switch (elm.type)
                {
                case ElementType.Module:
                {
                    signals.IBlockDriver drv = avail as signals.IBlockDriver;
                    if (drv != null)
                    {
                        newOb = drv.Create();
                    }
                    else
                    {
                        newOb = (signals.IBlock)avail;
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                case ElementType.FunctionOnOut:
                    newOb = ((signals.IFunctionSpec)avail).Create();
                    break;
                }
                result.Add(elm.circuitId, new Circuit.Element(new ElemKey(elm), elm.circuitId, newOb));
                elmResult.Add(elm, newOb);
            }

            foreach (KeyValuePair <EndpointKey, EndpointKey> conn in connections)
            {
                EndpointKey from    = conn.Key;
                EndpointKey to      = conn.Value;
                object      fromObj = elmResult[from.elem];
                object      toObj   = elmResult[to.elem];
                switch (from.elem.type)
                {
                case ElementType.Module:
                {
                    signals.IOutEndpoint outEP = from.OutputEP((signals.IBlock)fromObj);
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IEPSendTo inEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(inEP);
                        break;
                    }
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                {
                    signals.IInputFunction func = ((signals.IFunction)fromObj).Input;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                        throw new ApplicationException("incompatible connection types");
                    }
                    break;
                }

                case ElementType.FunctionOnOut:
                {
                    signals.IOutputFunction func = ((signals.IFunction)fromObj).Output;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IOutEndpoint outEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(func);
                        break;
                    }
                    }
                    break;
                }
                }
            }
            return(new Circuit(result));
        }
Ejemplo n.º 12
0
        private void resolveNeighbors(sharptest.ModLibrary library, Element elm)
        {
            if (elm.availObjects.Count != 1)
            {
                throw new ApplicationException("elm should contain a single availObject by this point");
            }
            signals.ICircuitConnectible avail       = elm.availObjects[0];
            Dictionary <Element, bool>  recurseList = new Dictionary <Element, bool>();
            List <KeyValuePair <EndpointKey, EndpointKey> > tempCollect = new List <KeyValuePair <EndpointKey, EndpointKey> >();

            tempCollect.AddRange(connections);
            foreach (KeyValuePair <EndpointKey, EndpointKey> entry in tempCollect)
            {
                EndpointKey key   = entry.Key;
                EndpointKey value = entry.Value;
                if (key.elem == elm)
                {
                    Element       otherElm = value.elem;
                    signals.EType ourType  = key.OutputType(avail);
                    bool          changed  = false;
                    if (otherElm.availObjects.Count > 1)
                    {
                        // if we have more than one option here, just look for possible compatibility
                        List <signals.ICircuitConnectible> newAvail = new List <signals.ICircuitConnectible>();
                        foreach (signals.ICircuitConnectible otherAvail in otherElm.availObjects)
                        {
                            signals.EType otherType = value.InputType(otherAvail);
                            if (ourType != otherType && findImplicitConversion(library, ourType, otherType) == null)
                            {
                                changed = true;
                            }
                            else
                            {
                                newAvail.Add(otherAvail);
                            }
                        }
                        otherElm.availObjects = newAvail;
                    }
                    if (otherElm.availObjects.Count == 1)
                    {
                        // if we're on one-to-one terms, we might add compat connections
                        signals.ICircuitConnectible otherAvail = otherElm.availObjects[0];
                        signals.EType otherType = value.InputType(otherAvail);
                        if (ourType != otherType)
                        {
                            signals.IFunctionSpec func = findImplicitConversion(library, ourType, otherType);
                            if (func == null)
                            {
                                // only option isn't type-compatible? Looks like we broke a connection
                                throw new LinkTypeFailure(entry.Key, ourType, entry.Value, otherType);
                            }
                            else
                            {
                                AddImplicitConversion(key, value, func);
                            }
                        }
                    }
                    else if (otherElm.availObjects.Count == 0)
                    {
                        // ran out of possible connections? Looks like we broke a connection
                        throw new CannotResolveElement(otherElm);
                    }
                    if (changed)
                    {
                        recurseList.Add(value.elem, true);
                    }
                }
                if (value.elem == elm)
                {
                    Element       otherElm = key.elem;
                    signals.EType ourType  = value.InputType(avail);
                    bool          changed  = false;
                    if (otherElm.availObjects.Count > 1)
                    {
                        // if we have more than one option here, just look for possible compatibility
                        List <signals.ICircuitConnectible> newAvail = new List <signals.ICircuitConnectible>();
                        foreach (signals.ICircuitConnectible otherAvail in otherElm.availObjects)
                        {
                            signals.EType otherType = key.OutputType(otherAvail);
                            if (ourType != otherType && findImplicitConversion(library, otherType, ourType) == null)
                            {
                                changed = true;
                            }
                            else
                            {
                                newAvail.Add(otherAvail);
                            }
                        }
                        otherElm.availObjects = newAvail;
                    }
                    if (otherElm.availObjects.Count == 1)
                    {
                        // if we're on one-to-one terms, we might add compat connections
                        signals.ICircuitConnectible otherAvail = otherElm.availObjects[0];
                        signals.EType otherType = key.OutputType(otherAvail);
                        if (ourType != otherType)
                        {
                            signals.IFunctionSpec func = findImplicitConversion(library, otherType, ourType);
                            if (func == null)
                            {
                                // only option isn't type-compatible? Looks like we broke a connection
                                throw new LinkTypeFailure(entry.Key, otherType, entry.Value, ourType);
                            }
                            else
                            {
                                AddImplicitConversion(key, value, func);
                            }
                        }
                    }
                    else if (otherElm.availObjects.Count == 0)
                    {
                        // ran out of possible connections? Looks like we broke a connection
                        throw new CannotResolveElement(otherElm);
                    }
                    if (changed)
                    {
                        recurseList.Add(value.elem, true);
                    }
                }
            }
            foreach (KeyValuePair <Element, bool> entry in recurseList)
            {
                if (entry.Key.availObjects.Count == 1)
                {
                    resolveNeighbors(library, entry.Key);
                }
            }
        }
Ejemplo n.º 13
0
 public string GetEndpoint(EndpointKey key) => _endpoints.ContainsKey(key) ? _endpoints[key] : throw new ArgumentOutOfRangeException(key.ToString());