Exemplo n.º 1
0
        /// <summary>
        /// Generates the code that processes each incoming document, in order to gather information for features.
        /// </summary>
        /// <param name="script"></param>
        /// <returns></returns>
        private string ProcessFeaturePrepContent(string donutfileContent, DonutScript script)
        {
            string aggregateKeyContent = GetAggregateKeyExtraction(script, "aggKeyBuff");
            var    placeholder         = "$ExtractionBody";
            var    donutCV             = new DonutFeatureGeneratingExpressionVisitor(script);
            var    donutFeatureGen     = new DonutFeatureCodeGenerator(script, donutCV);
            var    donutFeatures       = script.Features.Where(x => x.IsDonutNativeFeature());

            donutFeatureGen.AddAll(donutFeatures);
            var donutFeatureCode = donutFeatureGen.GetScriptContent(donutfileContent);

            donutFeatureCode.PrepareScript = aggregateKeyContent + donutFeatureCode.PrepareScript;
            donutfileContent = donutfileContent.Replace(placeholder, donutFeatureCode.PrepareScript);
            return(donutfileContent);
        }
Exemplo n.º 2
0
        public DonutCodeFeatureDefinition GetTemplate(CallExpression exp, DonutCodeContext ctx)
        {
            var rootIgn         = ctx.Script.GetRootIntegration();
            var expVisitor      = new DonutFeatureGeneratingExpressionVisitor(ctx.Script);
            var callParam       = exp.Parameters.FirstOrDefault();
            var parameterTarget = expVisitor.Visit(callParam);

            if (parameterTarget.ToString() == "document[\"\"]")
            {
                return(DonutCodeFeatureDefinition.Empty);
            }
            var    buffGather     = new StringBuilder();
            var    buffExtract    = new StringBuilder();
            var    paramHash      = HashAlgos.Adler32(callParam.ToString());
            string featureKey     = $"nu_{rootIgn.Name}_{paramHash}";
            var    categoryValue  = "groupKey"; //Use the group key generated from DonutScriptCodeGenerator..
            string ordered        = "true";
            string varCategory    = $"{featureKey}_cat";
            string varValue       = $"{featureKey}_val";
            string varCategoryVal = $"var {varCategory} = {categoryValue};";
            string varValueVal    = $"var {varValue} = {parameterTarget}.ToString();";

            buffGather.AppendLine(varCategoryVal);
            buffGather.AppendLine(varValueVal);
            buffGather.AppendLine($"Context.AddEntityMetaCategory(\"{featureKey}\", {varCategory}, {varValue}, {ordered});");

            buffExtract.AppendLine($"Context.GetSetSize(\"{featureKey}\")");
            var featureDef = new DonutCodeFeatureDefinition()
            {
                PrepareScript    = buffGather.ToString(),
                ExtractionScript = buffExtract.ToString()
            };

            //Feature value:
            //Context.GetSetSize()
            //
            //Define a nameOfTheResultCache, category, value
            //Set the value in the cache
            return(featureDef);

            /**
             * Example
             * //Extraction goes in here
             * var nuRomanianpm25Category = 1;
             * var nuRomanianpm25Value = intDoc["pm25"].ToString();
             * Context.AddEntityMetaCategory("nu_Romanian.pm25", nuRomanianpm25Category, nuRomanianpm25Value, true);
             */
        }
Exemplo n.º 3
0
 public DonutFeatureCodeGenerator(DonutScript script, DonutFeatureGeneratingExpressionVisitor expVisitor) : base(script)
 {
     _donutFnResolver = new DonutFunctions();
     _rootIntegration = script.Integrations.FirstOrDefault();
     if (_rootIntegration == null)
     {
         throw new InvalidIntegrationException("Script has no integrations");
     }
     if (_rootIntegration.Fields == null || _rootIntegration.Fields.Count == 0)
     {
         throw new InvalidIntegrationException("Integration has no fields");
     }
     _rootDataMember   = script.GetDatasetMember(_rootIntegration.Name);
     _outputCollection = _rootIntegration.FeaturesCollection;
     if (string.IsNullOrEmpty(_outputCollection))
     {
         throw new InvalidOperationException("Root integration must have a features collection set.");
     }
     _expVisitor = expVisitor ?? throw new ArgumentNullException(nameof(expVisitor));
     _functions  = new List <IDonutFunction>();
 }