private static Dictionary <String, decimal> CalculateConfidence(Node node, Dictionary <string, object> dict) { Dictionary <String, decimal> ret = new Dictionary <string, decimal>(); // Test childs foreach (Node child in node.Nodes) { PredicateResult childPredicate = child.Predicate.Evaluate(dict); if (childPredicate != PredicateResult.False) { foreach (ScoreDistribution sd in child.ScoreDistributions) { if (!ret.ContainsKey(sd.Value)) { ret.Add(sd.Value, 0); } decimal new_val = (Convert.ToDecimal(sd.RecordCount) / child.RecordCount) * (child.RecordCount / node.RecordCount); ret[sd.Value] = ret[sd.Value] + new_val; } } } return(ret); }
public virtual void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; if (item == null) { return; } var existingSitecoreItem = new ItemData(item); PredicateResult matchingPredicate = null; foreach (var configuration in _configurations) { matchingPredicate = configuration.Resolve <IPredicate>().Includes(existingSitecoreItem); if (matchingPredicate.IsIncluded) { var evaluator = configuration.Resolve <IEvaluator>(); var warningObject = evaluator.EvaluateEditorWarning(item, matchingPredicate); if (warningObject != null) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = warningObject.Title; warning.Text = warningObject.Message; } } } }
public PredicateResult Includes(User user) { Assert.ArgumentNotNull(user, nameof(user)); // no entries = include everything if (_includeEntries.Count == 0) { return(new PredicateResult(true)); } var result = new PredicateResult(true); PredicateResult priorityResult = null; foreach (var entry in _includeEntries) { result = Includes(entry, user); if (result.IsIncluded) { return(result); // it's definitely included if anything includes it } if (!string.IsNullOrEmpty(result.Justification)) { priorityResult = result; // a justification means this is probably a more 'important' fail than others } } return(priorityResult ?? result); // return the last failure }
public ForkNode Mount(int nodeIndex, ExecutionPath executionPath, PredicateResult predicateResult) { NodeIndex = nodeIndex; ExecutionPath = executionPath; PredicateResult = predicateResult; var sourceNode = ExecutionPath.Nodes[NodeIndex]; CopyLookup(sourceNode); return(this); }
public override Warning EvaluateEditorWarning(Item item, PredicateResult predicateResult) { bool transparentSync = item.Statistics.UpdatedBy == UnicornDataProvider.TransparentSyncUpdatedByValue; string title = transparentSync ? "This item is included by Unicorn Transparent Sync" : "This item is controlled by Unicorn"; var message = new StringBuilder(); if (IsDevMode) { message.Append("Changes to this item will be written to disk so they can be shared with others."); } else { message.Append("<b style=\"color: red; font-size: 24px;\">You should not change this item because your changes will be overwritten by the next code deployment.</b><br>Ask a developer for help if you need to change this item."); } message.Append($"<br><br><b>Configuration</b>: {_parentConfiguration.Name}"); if (predicateResult.PredicateComponentId != null) { message.Append($"<br><b>Predicate Component</b>: {predicateResult.PredicateComponentId}"); } if (transparentSync) { using (new TransparentSyncDisabler()) { using (new DatabaseCacheDisabler()) { var dbItem = Database.GetItem(item.Uri); if (dbItem != null) { message.Append("<br><b>Transparent Sync</b>: Database + Serialized"); } else { message.Append("<br><b>Transparent Sync</b>: Serialized Only"); } } } } var existingTargetItem = _targetDataStore.GetByPathAndId(item.Paths.Path, item.ID.Guid, item.Database.Name); // check if serialized item ID looks like a filesystem path e.g. c:\ if (IsDevMode && existingTargetItem?.SerializedItemId != null && existingTargetItem.SerializedItemId.Substring(1, 2) == ":\\") { message.Append($"<br><b>Physical path</b>: <span style=\"font-family: consolas, monospace\">{existingTargetItem.SerializedItemId}</span>"); } return(new Warning(title, message.ToString())); }
/// <summary> /// Compute OR operator between 2 predicates. /// </summary> /// <param name="pred1"></param> /// <param name="pred2"></param> /// <returns></returns> protected PredicateResult Or(PredicateResult pred1, PredicateResult pred2) { if (pred1 == PredicateResult.True) return PredicateResult.True; if (pred2 == PredicateResult.True) return PredicateResult.True; if (pred1 == PredicateResult.False && pred2 == PredicateResult.False) return PredicateResult.False; return PredicateResult.Unknown; }
/// <summary> /// Test predicate /// </summary> /// <param name="dict"></param> /// <returns></returns> public override PredicateResult Evaluate(Dictionary <string, object> dict) { //double var_test_double = Convert.ToDouble(dict[field]); //double ref_double = Convert.ToDouble(fvalue); if ("or".Equals(fbooleanOperator.Trim().ToLowerInvariant())) { PredicateResult ret = fpredicates[0].Evaluate(dict); for (int i = 1; i < fpredicates.Count; i++) { ret = Or(ret, fpredicates[i].Evaluate(dict)); if (ret == PredicateResult.True) { return(PredicateResult.True); } } return(ret); } else if ("and".Equals(fbooleanOperator.Trim().ToLowerInvariant())) { foreach (Predicate pred in fpredicates) { if (pred.Evaluate(dict) == PredicateResult.False) { return(PredicateResult.False); } } return(PredicateResult.True); } else if ("surrogate".Equals(fbooleanOperator.Trim().ToLowerInvariant())) { foreach (Predicate pred in fpredicates) { PredicateResult ret = pred.Evaluate(dict); if (ret != PredicateResult.Unknown) { return(ret); } } return(PredicateResult.Unknown); } else { throw new PmmlException(); } }
public PredicateResult Includes(IItemData itemData) { Assert.ArgumentNotNull(itemData, "itemData"); // no entries = include everything if (_preset.FirstOrDefault() == null) return new PredicateResult(true); var result = new PredicateResult(true); PredicateResult priorityResult = null; foreach (var entry in _preset) { result = Includes(entry, itemData); if (result.IsIncluded) return result; // it's definitely included if anything includes it if (!string.IsNullOrEmpty(result.Justification)) priorityResult = result; // a justification means this is probably a more 'important' fail than others } return priorityResult ?? result; // return the last failure }
/// <summary> /// Compute OR operator between 2 predicates. /// </summary> /// <param name="pred1"></param> /// <param name="pred2"></param> /// <returns></returns> protected PredicateResult Or(PredicateResult pred1, PredicateResult pred2) { if (pred1 == PredicateResult.True) { return(PredicateResult.True); } if (pred2 == PredicateResult.True) { return(PredicateResult.True); } if (pred1 == PredicateResult.False && pred2 == PredicateResult.False) { return(PredicateResult.False); } return(PredicateResult.Unknown); }
private void collectFiredRules(OrderedDictionary /*<String, SimpleRule>*/ firedRules, Rule rule, Dictionary <string, object> dict /*, EvaluationContext context*/) { /*Predicate predicate = rule.getPredicate(); * if(predicate == null){ * throw new InvalidFeatureException(rule); * } * * Boolean status = PredicateUtil.evaluate(predicate, context); * if(status == null || !status.booleanValue()){ * return; * } // End if*/ PredicateResult status = rule.Evaluate(dict); if (status == PredicateResult.Unknown || status == PredicateResult.False) { return; } if (rule is SimpleRule) { SimpleRule simpleRule = (SimpleRule)rule; firedRules.Add(simpleRule.Score, simpleRule); } else { if (rule is CompoundRule) { CompoundRule compoundRule = (CompoundRule)rule; foreach (Rule childRule in compoundRule.Rules) { collectFiredRules(firedRules, childRule, dict); } } else { throw new PmmlException("Type of Rule not supported"); } } }
public virtual Warning EvaluateEditorWarning(Item item, PredicateResult predicateResult) { var existingTargetItem = _targetDataStore.GetByPathAndId(item.Paths.Path, item.ID.Guid, item.Database.Name); // if we have no existing serialized item, there's no need for a warning: Unicorn won't touch this item when using NIO if (existingTargetItem == null) { return(null); } var title = "This item is part of a Unicorn deploy once configuration."; var message = new StringBuilder(); // if dev mode is on, we don't need a warning if (IsDevMode) { message.Append("Changes to this item will not be synced to other environments unless the item does not exist yet."); } else { title = "This item was added by developers."; message.Append("You may edit this item, but <b>it will return next time code is deployed</b>. Ask a developer to help if you need to delete this item."); } message.Append($"<br><br><b>Configuration</b>: {_parentConfiguration.Name}"); if (predicateResult.PredicateComponentId != null) { message.Append($"<br><b>Predicate Component</b>: {predicateResult.PredicateComponentId}"); } // check if serialized item ID looks like a filesystem path e.g. c:\ if (IsDevMode && existingTargetItem?.SerializedItemId != null && existingTargetItem.SerializedItemId.Substring(1, 2) == ":\\") { message.Append($"<br><b>Physical path</b>: <span style=\"font-family: consolas, monospace\">{existingTargetItem.SerializedItemId}</span>"); } return(new Warning(title, message.ToString())); }
/// <summary> /// Scoring with Tree Model /// </summary> /// <param name="root">Parent node</param> /// <param name="missingvalueStr">Missing value strategy to evaluate this node.</param> /// <param name="noTrueChildStr">Strategy to evaluate this node if no child are true</param> /// <param name="dict">Values</param> /// <param name="res" >Result to return</param> /// <returns></returns> public static ScoreResult Evaluate(Node root, MissingValueStrategy missingvalueStr, NoTrueChildStrategy noTrueChildStr, Dictionary <string, object> dict, ScoreResult res) { // Test childs foreach (Node child in root.Nodes) { PredicateResult childPredicate = child.Predicate.Evaluate(dict); if (childPredicate == PredicateResult.True) { res.Nodes.Add(child); res.Value = child.Score; foreach (ScoreDistribution sco in child.ScoreDistributions) { if (sco.Value.Equals(child.Score)) { if (sco.Confidence != null) { res.Confidence = Decimal.Parse(sco.Confidence, NumberStyles.Any, CultureInfo.InvariantCulture); } } } return(Evaluate(child, missingvalueStr, noTrueChildStr, dict, res)); } else if (childPredicate == PredicateResult.Unknown) { // Unknow value lead to act with missingvalueStr switch (missingvalueStr) { case MissingValueStrategy.LastPrediction: return(res); case MissingValueStrategy.NullPrediction: res.Value = null; return(res); case MissingValueStrategy.WeightedConfidence: Dictionary <string, decimal> conf = CalculateConfidence(root, dict); string max_conf = null; foreach (string key in conf.Keys) { if (max_conf == null) { max_conf = key; } if (conf[key] > conf[max_conf]) { max_conf = key; } } res.Value = max_conf; res.Confidence = conf[max_conf]; return(res); case MissingValueStrategy.AggregateNodes: return(res); default: throw new NotImplementedException(); } } } // All child nodes are false if (root.Nodes.Count > 0) { if (noTrueChildStr == NoTrueChildStrategy.ReturnNullPrediction) { res.Value = null; } } return(res); }
public void EnqueuePredicateResult(PredicateResult predicateResult) { PredicateResultQueue ??= Parent.PredicateResultQueue.Pool.Get().AddReference(); PredicateResultQueue.Queue.Enqueue(predicateResult); }
internal void EnqueuePredicateResult(PredicateResult predicateResult) { _currentThread.EnqueuePredicateResult(predicateResult); }
private ForkNode BuildForkNode(int nodeIndex, ExecutionPath executionPath, PredicateResult predicateResult) { var forkNode = _processResources.ForkNodePool.Get().Mount(nodeIndex, executionPath, predicateResult); predicateResult.Dispose(); return(forkNode); }