/// <summary> /// Get answer from knowledgebase for a given question. /// </summary> /// <param name="question">Question text.</param> /// <param name="isTestKnowledgeBase">Prod or test.</param> /// <param name="previousQnAId">Id of previous question.</param> /// <param name="previousUserQuery">Previous question information.</param> /// <param name="QnAID">Prompts should carry its QnAID</param> /// <returns>QnaSearchResultList result as response.</returns> public async Task <QnASearchResultList> GenerateAnswerAsync(string question, bool isTestKnowledgeBase, string previousQnAId = null, string previousUserQuery = null, string QnAID = null) { var knowledgeBaseId = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.KnowledgeBaseId).ConfigureAwait(false); QueryDTO queryDTO = new QueryDTO() { QnaId = QnAID, IsTest = isTestKnowledgeBase, Question = question?.Trim(), ScoreThreshold = Convert.ToDouble(this.options.ScoreThreshold), RankerType = "QuestionOnly", }; if (previousQnAId != null && previousUserQuery != null) { queryDTO.RankerType = null; queryDTO.Context = new QueryDTOContext { PreviousQnaId = previousQnAId, PreviousUserQuery = previousUserQuery, }; } return(await this.qnaMakerRuntimeClient.Runtime.GenerateAnswerAsync(knowledgeBaseId, queryDTO).ConfigureAwait(false)); }
public void CantCreateObjectOfInterfaceTest() { NewObject newObjectStatement = new NewObject(); Mock <ClassName> className = new Mock <ClassName>(); QueryDTO dto = new QueryDTO { QueryClass = new Class { ClassId = new ClassId { Id = 1, Name = "Test" }, Name = "Test", Interface = true }, }; className.Setup(cn => cn.Execute(It.IsAny <QueryParameters>())).Returns(dto); newObjectStatement.Add(className.Object); QueryParameters parameters = new QueryParameters(); var result = newObjectStatement.Execute(parameters); Assert.AreEqual(ResultType.StringResult, result.Result.QueryResultType); Assert.AreEqual(NewObject.cantCreateObjectLabel, result.Result.StringOutput); }
public void NoClassToCreateObjectTest() { String noClassLabel = "No class: Test"; NewObject newObjectStatement = new NewObject(); Mock <ClassName> className = new Mock <ClassName>(); QueryDTO dto = new QueryDTO { Result = new DTOQueryResult { QueryResultType = ResultType.StringResult, StringOutput = noClassLabel }, QueryClass = new Class { ClassId = new ClassId { Id = 1, Name = "Test" }, Name = "Test" } }; className.Setup(cn => cn.Execute(It.IsAny <QueryParameters>())).Returns(dto); newObjectStatement.Add(className.Object); QueryParameters parameters = new QueryParameters(); var result = newObjectStatement.Execute(parameters); Assert.AreEqual(ResultType.StringResult, result.Result.QueryResultType); Assert.AreEqual(noClassLabel, result.Result.StringOutput); }
public override QueryDTO Execute(QueryParameters parameters) { ISet <IStorable> resultObjects = new HashSet <IStorable>(); var operations = AllElements(ElementType.WHERE_OPERATION); var left = operations.ElementAt(0); var right = operations.ElementAt(1); var leftResult = left.Execute(parameters); if (leftResult.Result?.QueryResultType == ResultType.StringResult) { return(leftResult); } var rightResult = right.Execute(parameters); if (rightResult.Result?.QueryResultType == ResultType.StringResult) { return(rightResult); } QueryDTO query = new QueryDTO() { QueryClass = parameters.Subquery.QueryClass, QueryObjects = leftResult.QueryObjects.Intersect(rightResult.QueryObjects) }; return(query); }
/// <summary> /// Executes the given query using given connection string. /// </summary> /// <param name="args">Query parameters.</param> /// <returns>Selected rows if a SELECT statement was given in form of a <seealso cref="DataSet"/> object, /// number of rows affected if other statements are given, or exception if any was thrown.</returns> public static object ExecuteQuery(QueryDTO args) { using (var sqlConn = new SqlConnection(args.ConnectionString)) { object result = null; string[] queries = args.QueryText.Split(';'); foreach (string singleQuery in queries) { _sqlCmd = new SqlCommand(singleQuery, sqlConn); if (singleQuery.Trim().ToLower().StartsWith("select ")) { SqlDataAdapter adapter = new SqlDataAdapter(_sqlCmd); DataSet dataSet = new DataSet(); adapter.Fill(dataSet); result = dataSet; } else { _sqlCmd.Connection.Open(); try { result = _sqlCmd.ExecuteNonQuery(); } catch (Exception exc) { _sqlCmd.Connection.Close(); throw exc; } _sqlCmd.Connection.Close(); } } _sqlCmd = null; return(result); } }
private async Task CognitiveServices_QnA_MigrationGuide_Runtime() { #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateRuntimeClient var credential = new EndpointKeyServiceClientCredentials("{api-key}"); var client = new QnAMakerRuntimeClient(credential) { RuntimeEndpoint = "{endpoint}" }; #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateRuntimeClient #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_QueryKnowledgeBase var queryDTO = new QueryDTO(); queryDTO.Question = "{question}"; var response = await client.Runtime.GenerateAnswerAsync("{knowladgebase-id}", queryDTO); #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_QueryKnowledgeBase #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_Chat var queryDTOFollowUp = new QueryDTO(); queryDTOFollowUp.Context = new QueryDTOContext(previousQnaId: 1); var responseFollowUp = await client.Runtime.GenerateAnswerAsync("{knowladgebase-id}", queryDTO); #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_Chat }
/// <summary> /// Get answer from knowledgebase for a given question. /// </summary> /// <param name="question">Question text.</param> /// <param name="isTestKnowledgeBase">Prod or test.</param> /// <param name="previousQnAId">Id of previous question.</param> /// <param name="previousUserQuery">Previous question information.</param> /// <returns>QnaSearchResultList result as response.</returns> public async Task<QnASearchResultList> GenerateAnswerAsync(string question, bool isTestKnowledgeBase, string previousQnAId = null, string previousUserQuery = null, IList<QueryTag> tags = null) { var knowledgeBaseId = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.KnowledgeBaseId).ConfigureAwait(false); QueryDTO queryDTO = new QueryDTO() { IsTest = isTestKnowledgeBase, Question = question?.Trim(), ScoreThreshold = Convert.ToDouble(this.options.ScoreThreshold, CultureInfo.InvariantCulture), }; // if metadata tags are provided, add those to the query if (tags != null) { queryDTO.StrictFilters = tags.Select(x => new MetadataDTO(x.Name, x.Value)).ToList(); queryDTO.StrictFiltersCompoundOperationType = StrictFiltersCompoundOperationType.AND; } if (previousQnAId != null && previousUserQuery != null) { queryDTO.Context = new QueryDTOContext { PreviousQnaId = Convert.ToInt32(previousQnAId), PreviousUserQuery = previousUserQuery, }; } QnASearchResultList qnASearchResultList = await this.qnaMakerClient.Knowledgebase.GenerateAnswerAsync(knowledgeBaseId, queryDTO).ConfigureAwait(false); return qnASearchResultList; }
public override QueryDTO Execute(QueryParameters parameters) { var literalDto = new QueryDTO { Value = Value }; return(literalDto); }
/*private async Task<StandardQueryCM> ExtractUpstreamQuery(UpstreamCrateChooser queryPicker) * { * var upstreamQueryCrateLabel = queryPicker.SelectedCrates[0].Label.Value; * if (string.IsNullOrEmpty(upstreamQueryCrateLabel)) * { * return null; * } * var upstreamQueryCrate = (await HubCommunicator.GetCratesByDirection<StandardQueryCM>(ActivityId, CrateDirection.Upstream)) * .FirstOrDefault(x => x.Label == upstreamQueryCrateLabel); * * return upstreamQueryCrate?.Content; * }*/ // This is weird to use query's name as the way to address MT type. // MT type has unique ID that should be used for this reason. Query name is something that is displayed to user. It should not contain any internal data. private Guid?ExtractUpstreamTypeId(QueryDTO query) { using (var uow = _container.GetInstance <IUnitOfWork>()) { var type = uow.MultiTenantObjectRepository.ListTypeReferences().FirstOrDefault(x => x.Alias == query.Name); return(type?.Id); } }
public override QueryDTO Execute(QueryParameters parameters) { var dataTypeDto = new QueryDTO { Value = PropertyType(), AdditionalValue = true }; return(dataTypeDto); }
public override QueryDTO Execute(QueryParameters parameters) { var nullDto = new QueryDTO { Value = null, AdditionalValue = null }; return(nullDto); }
public override QueryDTO Execute(QueryParameters parameters) { var dataTypeDto = new QueryDTO { Value = ClassName, AdditionalValue = false }; return(dataTypeDto); }
public override QueryDTO Execute(QueryParameters parameters) { var literalDto = new QueryDTO { Value = Value, AdditionalValue = Property.STRING }; return(literalDto); }
public override QueryDTO Execute(QueryParameters parameters) { Boolean convertedValue = ConvertValue(Value); var literalDto = new QueryDTO { Value = convertedValue }; return(literalDto); }
public override QueryDTO Execute(QueryParameters parameters) { Boolean convertedValue = ConvertValue(Value); var literalDto = new QueryDTO { Value = convertedValue, AdditionalValue = Property.BOOL }; return(literalDto); }
public async Task DeleteFromWarehouse <TManifest>(List <FilterConditionDTO> query) where TManifest : Manifest { var url = $"{GetHubUrlWithApiVersion()}/warehouses/delete"; var uri = new Uri(url); var payload = new QueryDTO(ManifestDiscovery.Default.GetManifestType <TManifest>().Type, query); await _restfulServiceClient.PostAsync(uri, payload); }
private void InitPageSearch() { qdto = new TextQueryDTO(Dn, LdapScope.SCOPE_ONE_LEVEL, VMDirConstants.SEARCH_ALL_OC, new string[] { VMDirConstants.ATTR_DN, VMDirConstants.ATTR_OBJECT_CLASS }, 0, IntPtr.Zero, 0); cookie = IntPtr.Zero; totalCount = 0; pageNumber = 1; morePages = true; }
public override QueryDTO Execute(QueryParameters parameters) { float floatValue = float.Parse(Value, CultureInfo.InvariantCulture); var literalDto = new QueryDTO { Value = floatValue, AdditionalValue = Property.FLOAT }; return(literalDto); }
/// <summary> /// 分页 新版. /// </summary> /// <param name="models">.</param> /// <returns>.</returns> public async Task <BaseResult <FoodEntity> > GetList(QueryDTO models) { string tableName = "tbFood"; string where = " IsDelete=0"; string orderby = "id "; if (models.sortRule == 1) { orderby += " DESC"; } else { orderby += " ASC"; } int skip = (models.pageIndex - 1) * models.pageSize + 1; if (models.name != null) { where = where + "AND name LIKE '%" + models.name + "%'"; } StringBuilder sb = new StringBuilder(); sb.AppendFormat("SELECT COUNT(1) FROM {0} WHERE {1};", tableName, where); sb.AppendFormat(@"SELECT * FROM(SELECT ROW_NUMBER() OVER(ORDER BY {2}) AS RowNum,* FROM {0} WHERE {1} ) AS result WHERE RowNum >= {3} AND RowNum <= {4} ORDER BY {2}", tableName, where, orderby, skip, models.pageIndex * models.pageSize); var result = new BaseResult <FoodEntity>(); try { var pageData = await GetPageList(sb.ToString()); if (pageData.total > -1) { result.code = ResultKey.RETURN_SUCCESS_CODE; result.data = pageData; result.desc = ResultKey.RETURN_SUCCESS_DESC; } else { result.code = ResultKey.RETURN_FAIL_CODE; result.desc = ResultKey.RETURN_FAIL_DESC; } } catch (Exception ex) { NlogHelper.InfoLog(ex.Message); throw new Exception(ex.Message); } return(result); }
public override QueryDTO Execute(QueryParameters parameters) { int integerValue = Int32.Parse(Value, NumberStyles.Number, CultureInfo.InvariantCulture); var literalDto = new QueryDTO { Value = integerValue }; return(literalDto); }
public static PageableDTO <T> ToPageable <T>(this IQueryable <T> source, QueryDTO q) where T : class { var total = source.Count(); return(new PageableDTO <T> { total = total, rows = source.OrderBy(q.OrderBy, q.Ascending.Value).Skip(q.Skip).Take(q.rows.Value).ToList(), }); }
public override QueryDTO Execute(QueryParameters parameters) { IStorable databaseObject = parameters.Subquery.QueryObjects.Single(); var objectProperty = databaseObject.Properties.Where(p => p.Key.Name == Name); if (!objectProperty.Any()) { var parentClass = parameters.Subquery.QueryClass; var classProperties = parameters.Database.Schema.ClassProperties(parentClass); var classProperty = classProperties.Where(p => p.Name == Name); if (!classProperty.Any()) { throw new NoClassPropertyException { PropertyName = Name }; } return(new QueryDTO { Value = null }); } var propertyValue = objectProperty.Single().Value; if (!objectProperty.Single().Key.IsValueType) { var propertyObject = parameters.Storage.Get(parameters.Database.DatabaseId, (Guid)propertyValue); parameters.Subquery.QueryObjects = new List <IStorable> { propertyObject }; if (TryGetElement(ElementType.CLASS_PROPERTY, out IQueryElement childProperty)) { return(childProperty.Execute(parameters)); } var result = parameters.Subquery; result.Result = new DTOQueryResult { QueryResultType = ResultType.ReferencesOnly }; return(result); } var propertyDto = new QueryDTO { Result = new DTOQueryResult { QueryResultType = ResultType.StringResult, StringOutput = "Property " + Name + ": " + propertyValue }, Value = propertyValue }; return(propertyDto); }
public override QueryDTO Execute(QueryParameters parameters) { IQueryElement classNameElement = Element(ElementType.CLASS_NAME); QueryDTO classResult = classNameElement.Execute(parameters); if (classResult.Result != null) { return(classResult); } var objectClass = classResult.QueryClass; if (objectClass.Interface) { return(new QueryDTO { Result = new DTOQueryResult() { QueryResultType = ResultType.StringResult, StringOutput = cantCreateObjectLabel } }); } List <Property> propeteries = parameters.Database.Schema.ClassProperties(objectClass); var oid = new Oid(Guid.NewGuid(), parameters.Database.DatabaseId.Dli); var toStore = new Storable { Oid = oid }; foreach (var attrToSet in AllElements(ElementType.OBJECT_INITIALIZATION_ELEMENT)) { parameters.Subquery = new QueryDTO { Value = toStore, AdditionalValue = propeteries }; var attributeResult = attrToSet.Execute(parameters); if (attributeResult.Result != null) { return(attributeResult); } } parameters.Storage.Save(parameters.Database.DatabaseId, toStore); parameters.Log("New object saved with id: " + oid, MessageLevel.QueryExecution); return(new QueryDTO() { Result = new DTOQueryResult { NextResult = null, QueryResultType = ResultType.StringResult, StringOutput = "New object saved with id: " + oid } }); }
public async Task <ActionResult <QueryDTO> > GetQueryData(QueryDTO query) { var toReturn = await LinkmirLinkModel.QueryLinks(_context, query); if (toReturn == null) { return(NotFound()); } return(toReturn); }
public async Task <ReturnVal <QueryCollabratorVO> > EnableAll(QueryDTO dto) { var school = await this._query.EnableAsync(/*dto.Type*/ CollabratorType.School, dto.CourseId); var community = await this._query.EnableAsync(/*dto.Type*/ CollabratorType.Community, dto.CourseId); return(RetOk(new QueryCollabratorVO { SchoolObj = school, CommunityObj = community })); }
private SelectQuery BuildQuery(string connectionString, QueryDTO query, Dictionary <string, DbType> columnTypes) { var tableInfo = new TableInfo(query.Name); var tableColumns = columnTypes.Keys.Where(x => x.StartsWith(query.Name)).ToList(); var columns = tableColumns.Select(x => CreateColumnInfo(x, columnTypes)).ToList(); var returnedQuery = new SelectQuery(connectionString, tableInfo, columns, query.Criteria); return(returnedQuery); }
public override QueryDTO Execute(QueryParameters parameters) { IQueryElement leftElement = Element(ElementType.LEFT_OPERAND); IQueryElement rightElement = Element(ElementType.RIGHT_OPERAND); IQueryElement operation = Element(ElementType.OPERATOR); Func <IStorable, bool> expression = delegate(IStorable databaseObject) { QueryDTO subquery = new QueryDTO { QueryClass = parameters.Subquery.QueryClass, QueryObjects = new List <IStorable> { databaseObject } }; QueryParameters singleParameter = new QueryParameters { Database = parameters.Database, Storage = parameters.Storage, Subquery = subquery }; var left = leftElement.Execute(singleParameter).Value; var right = rightElement.Execute(singleParameter).Value; QueryDTO comparisionSubquery = new QueryDTO { Value = left, AdditionalValue = right }; QueryParameters comparisionParameter = new QueryParameters { Subquery = comparisionSubquery }; return((Boolean)operation.Execute(comparisionParameter).Value); }; try { IEnumerable <IStorable> objects = parameters.Subquery.QueryObjects; QueryDTO query = new QueryDTO() { QueryClass = parameters.Subquery.QueryClass, QueryObjects = objects.Where(obj => expression(obj)).ToList() }; return(query); } catch (NoClassPropertyException exc) { new DTOQueryResult { }; DTOQueryResult errorResult = new DTOQueryResult { NextResult = null, QueryResultType = ResultType.StringResult, StringOutput = "Unknown propertyName: " + exc.PropertyName }; return(new QueryDTO { Result = errorResult }); } }
public override int Cost(QueryParameters parameters) { IQueryElement classNameElement = Element(ElementType.CLASS_NAME); QueryDTO classResult = classNameElement.Execute(parameters); if (classResult.QueryClass.ClassId == null) { throw new ApplicationException("Unknow Class"); } return(Index.Value == null?parameters.ServerSchemaStats.GetClassObjectNumber(parameters.Database.DatabaseId, classResult.QueryClass.ClassId) : parameters.IndexMechanism.GetAvarageObjectFindCost(Index.Key, parameters.ServerSchemaStats.GetClassObjectNumber(parameters.Database.DatabaseId, classResult.QueryClass.ClassId))); }
public override QueryDTO Execute(QueryParameters parameters) { IQueryElement classNameElement = Element(ElementType.CLASS_NAME); QueryDTO classResult = classNameElement.Execute(parameters); if (classResult.Result != null) { return(classResult); } var classToGet = classResult.QueryClass; var classParameter = parameters.Database.Schema.ClassProperties(classToGet); var objs = parameters.Storage.GetAll(parameters.Database.DatabaseId); objs = objs.Where(s => s.Properties.All(p => classParameter.Any(cp => cp.PropertyId.Id == p.Key.PropertyId.Id))); var selectDto = new QueryDTO { QueryClass = classToGet, QueryObjects = objs }; parameters.Subquery = selectDto; if (TryGetElement(ElementType.WHERE, out IQueryElement searchCriteria)) { QueryDTO whereDto = searchCriteria.Execute(parameters); if (whereDto.Result?.QueryResultType == ResultType.StringResult) { return(whereDto); } objs = whereDto.QueryObjects; parameters.Subquery.QueryObjects = objs; } if (TryGetElement(ElementType.CLASS_PROPERTY, out IQueryElement property)) { var propertyValueDto = property.Execute(parameters); if (propertyValueDto.Result?.QueryResultType == ResultType.StringResult) { return(propertyValueDto); } objs = propertyValueDto.QueryObjects; } var getDto = new DTOQueryResult { NextResult = null, QueryResultType = ResultType.ReferencesOnly, QueryResults = objs.Select(o => o.Oid).ToList() }; selectDto.Result = getDto; selectDto.QueryClass = classToGet; selectDto.QueryObjects = objs; return(selectDto); }
public async Task <QnASearchResultList> Post(QueryDTO data) { var endpointKey = _configuration["QnAMakerEndpointKey"]; var endpoint = Environment.GetEnvironmentVariable("QnAMakerEndpoint"); var kbId = Environment.GetEnvironmentVariable("QnAMakerKbId"); var client = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(endpointKey)) { RuntimeEndpoint = endpoint }; var response = await client.Runtime.GenerateAnswerAsync(kbId, data); return(response); }
public HttpResponseMessage GetDailyLogPostEx(QueryDTO dto) { Type objectType = Type.GetType("Keywin.DNN.Modules.Fleetmgm.fleetSetting_Company.ServicesController, Keywin.DNN.Modules.Fleetmgm.fleetSetting_Company", true, true); Object objComponent = Activator.CreateInstance(objectType); MethodInfo mi = objectType.GetMethod("GetPortalDeviceIdInternal"); int pID = PortalSettings.PortalId; object[] param = { pID }; List<string> deviceIdList = (List<string>)mi.Invoke(objComponent, param); string deviceIds = string.Empty; foreach(string deviceId in deviceIdList) { deviceIds += ",'" + deviceId + "'"; } return GetDailyLog(dto.page, dto.UTCOffset, dto.rows, dto.sidx, dto.sord, dto.filters, "", deviceIds.TrimStart(',')); }
public HttpResponseMessage GetDailyLogPost(QueryDTO dto) { return GetDailyLog(dto.page, dto.UTCOffset, dto.rows, dto.sidx, dto.sord, dto.filters, dto.devicefilters); }