private void DoExtractPatterns(IDecisionTreeNode node, List <SelectorContext> contexts, InstanceModel model, Action <EmergingPattern> patternFound, Feature classFeature) { if (node.IsLeaf) { EmergingPattern newPattern = Create(contexts, model, classFeature); newPattern.Counts = node.Data; newPattern.Supports = CalculateSupports(node.Data, classFeature); newPattern.ClassValue = newPattern.Supports.ArgMax(); if (patternFound != null) { patternFound(newPattern); } } else { for (int i = 0; i < node.Children.Length; i++) { SelectorContext context = new SelectorContext { Index = i, Selector = node.ChildSelector, }; contexts.Add(context); DoExtractPatterns(node.Children[i], contexts, model, patternFound, classFeature); contexts.Remove(context); } } }
private bool selector_sempred(SelectorContext _localctx, int predIndex) { switch (predIndex) { case 0: return(Precpred(Context, 2)); case 1: return(Precpred(Context, 1)); } return(true); }
public SelectorContext selector() { SelectorContext _localctx = new SelectorContext(Context, State); EnterRule(_localctx, 0, RULE_selector); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 21; ErrorHandler.Sync(this); _alt = 1; do { switch (_alt) { case 1: { { State = 20; _la = TokenStream.LA(1); if (_la <= 0 || ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__1) | (1L << T__2) | (1L << T__3) | (1L << T__4) | (1L << T__5) | (1L << T__6) | (1L << T__7) | (1L << GROUP_START) | (1L << GROUP_END))) != 0))) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } } } break; default: throw new NoViableAltException(this); } State = 23; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 0, Context); } while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
/// <summary> /// Saw everything. Set axis limits, finish up render process. /// </summary> /// <param name="state"></param> void IDataSourceRenderer.RenderComplete(object state) { var st = state as State; var labels = new List <ICategoryLabelState>(st.itemstate); // materialize current state var sc = new SelectorContext(this, st.icrc.SeriesArea, labels); // configure axis limits; just based on count-of-elements UpdateLimits(0); UpdateLimits(st.itemstate.Count); // finish up layout process by checking with selector/formatter foreach (var ist in st.itemstate) { ElementPipeline(sc, ist, st.recycler); } }
void IRequireDataSourceUpdates.Add(IChartRenderContext icrc, int startAt, IList items) { // mimic the DSRP sequence var widx = LabelStyle?.Find(FrameworkElement.WidthProperty); var bl = new BindingEvaluator(LabelPath); // keep a separate list; easier at the end var reproc = new List <ItemState>(); for (int ix = 0; ix < items.Count; ix++) { // add requested item var label = bl.For(items[ix]); var istate = makeit(startAt + ix, label, widx == null); AxisLabels.Insert(startAt + ix, istate); reproc.Add(istate); } // re-sequence remaining items for (int ix = startAt + reproc.Count; ix < AxisLabels.Count; ix++) { AxisLabels[ix].index = ix; AxisLabels[ix].value = ix; } // render new items // run the element pipeline on the added items var recycler = new Recycler <FrameworkElement, ItemState>(CreateElement); var labels = new List <ICategoryLabelState>(AxisLabels); var sc = new SelectorContext(this, icrc.SeriesArea, labels); foreach (var istate in reproc) { ElementPipeline(sc, istate, recycler); } // configure axis limits; just based on count-of-elements UpdateLimits(0); UpdateLimits(AxisLabels.Count); // finish up Layer.Add(recycler.Created); RebuildAxisGeometry(); Dirty = false; }
private void FillNode(ref Dictionary <IDecisionTreeNode, double> validityIndexByNode, InstanceModel model, ref Dictionary <IDecisionTreeNode, IEnumerable <Tuple <Instance, double> > > instancesByNode, Feature classFeature, ref Dictionary <IDecisionTreeNode, int> levelByNode, List <SelectorContext> currentContext, ref int leafCount) { IDecisionTreeNode node = null; double bestIndexValue = Double.MinValue; foreach (var currentNode in validityIndexByNode.Keys) { if (bestIndexValue < validityIndexByNode[currentNode]) { bestIndexValue = validityIndexByNode[currentNode]; node = currentNode; } } if (node != null) { int level = levelByNode[node]; var instances = instancesByNode[node]; int whichBetterToFind = 1; if (OnSelectingWhichBetterSplit != null) { whichBetterToFind = OnSelectingWhichBetterSplit(node, level); } WiningSplitSelector winingSplitSelector = new WiningSplitSelector(whichBetterToFind) { CanAcceptChildSelector = this.CanAcceptChildSelector, }; foreach (var feature in OnSelectingFeaturesToConsider(model.Features, level)) { if (feature != classFeature) { ISplitIterator splitIterator = SplitIteratorProvider.GetSplitIterator(model, feature, classFeature); if (splitIterator == null) { throw new InvalidOperationException(string.Format("Undefined iterator for feature {0}", feature)); } splitIterator.Initialize(feature, instances); while (splitIterator.FindNext()) { double currentGain = DistributionEvaluator.Evaluate(node.Data, splitIterator.CurrentDistribution); if (currentGain > MinimalSplitGain || leafCount < ClusterCount) { if (OnSplitEvaluation != null) { OnSplitEvaluation(node, splitIterator, currentContext); } winingSplitSelector.EvaluateThis(currentGain, splitIterator, level); } } } } if (winingSplitSelector.IsWinner()) { IChildSelector maxSelector = winingSplitSelector.WinningSelector; node.ChildSelector = maxSelector; node.Children = new IDecisionTreeNode[maxSelector.ChildrenCount]; var instancesPerChildNode = childrenInstanceCreator.CreateChildrenInstances(instances, maxSelector, double.MinValue); for (int i = 0; i < maxSelector.ChildrenCount; i++) { var childNode = new DecisionTreeNode { Parent = node }; node.Children[i] = childNode; childNode.Data = winingSplitSelector.WinningDistribution[i]; SelectorContext context = null; if (OnSplitEvaluation != null) { context = new SelectorContext { Index = i, Selector = node.ChildSelector, }; currentContext.Add(context); } double currentBestValidityIndex = double.MinValue; foreach (var feature in OnSelectingFeaturesToConsider(model.Features, level)) { if (feature != classFeature) { ISplitIterator splitIterator = SplitIteratorProvider.GetSplitIterator(model, feature, classFeature); if (splitIterator == null) { throw new InvalidOperationException(string.Format("Undefined iterator for feature {0}", feature)); } splitIterator.Initialize(feature, instancesPerChildNode[i]); while (splitIterator.FindNext()) { double currentGain = DistributionEvaluator.Evaluate(node.Data, splitIterator.CurrentDistribution); if (currentGain > currentBestValidityIndex) { if (OnSplitEvaluation != null) { OnSplitEvaluation(node, splitIterator, currentContext); } currentBestValidityIndex = currentGain; } } } } if (currentBestValidityIndex > validityIndexByNode[node] || leafCount < ClusterCount) { validityIndexByNode.Add(childNode, currentBestValidityIndex); instancesByNode.Add(childNode, instancesPerChildNode[i]); levelByNode.Add(childNode, level + 1); } if (OnSplitEvaluation != null) { currentContext.Remove(context); } } validityIndexByNode.Remove(node); instancesByNode.Remove(node); levelByNode.Remove(node); leafCount++; if (leafCount < 4 * ClusterCount) { FillNode(ref validityIndexByNode, model, ref instancesByNode, classFeature, ref levelByNode, currentContext, ref leafCount); } } } }
public override Resultset Get(QueryContext queryContext, object[] parameters) { // Prepare bindings Resultset source = ChildNodes[0].Get(queryContext, parameters); List<ColumnBinding> bindings = new List<ColumnBinding>(); ExpressionTransformer transformer = new ExpressionTransformer(bindings); foreach (RowType.TypeInfo ti in source.RowType.Fields) foreach (RowType.TypeInfo nested_ti in ti.NestedType.Fields) if (!nested_ti.IsHidden && nested_ti.IsNatural) { ColumnBinding b = new ColumnBinding(); b.typecode = Type.GetTypeCode(nested_ti.DataType); b.rnum = ti.Ordinal; b.TableName = ti.Name; b.Name = nested_ti.Name; b.fieldType = nested_ti; b.natural = nested_ti.IsNatural; b.container = nested_ti.IsContainer; b.caseSensitive = nested_ti.IsCaseSensitive; b.data = new SymbolLink(nested_ti.DataType); bindings.Add(b); if (nested_ti.IsContainer) transformer.NeedTransform = true; } foreach (RowType.TypeInfo ti in source.RowType.Fields) foreach (RowType.TypeInfo nested_ti in ti.NestedType.Fields) if (!nested_ti.IsHidden && !nested_ti.IsNatural) { ColumnBinding b = new ColumnBinding(); b.typecode = Type.GetTypeCode(nested_ti.DataType); b.rnum = ti.Ordinal; b.TableName = ti.Name; b.Name = nested_ti.Name; b.fieldType = nested_ti; b.natural = nested_ti.IsNatural; b.container = nested_ti.IsContainer; b.caseSensitive = nested_ti.IsCaseSensitive; b.data = new SymbolLink(nested_ti.DataType); bindings.Add(b); if (nested_ti.IsContainer) transformer.NeedTransform = true; } // Expand columns. // On this step we transform select table.* and select * to select field1,... List<Column> columns = new List<Column>(); if (_targets == null) // Select fields from all selected tables { foreach (ColumnBinding b in bindings) columns.Add(new Column(ATOM.Create(null, new string[] { b.TableName, b.Name }, false))); } else foreach (Column col in _targets) { if (Lisp.IsFunctor(col.Expr, Table)) // Select fields from specified table { bool found = false; String name = (String)Lisp.Second(col.Expr); var tableBindings = from b in bindings where b.TableName == name select b; foreach (ColumnBinding b in tableBindings) { columns.Add(new Column(ATOM.Create(null, new string[] { b.TableName, b.Name }, false))); found = true; } if (!found) throw new ESQLException(Properties.Resources.InvalidIdentifier, name); } else // Select expression specified if (transformer.NeedTransform) { Column c = new Column(); c.Alias = col.Alias; c.Expr = transformer.Process(col.Expr); columns.Add(c); } else columns.Add(col); } // Create demand context FunctionLink[] compiledBody = new FunctionLink[columns.Count]; SelectorResolver resolver = new SelectorResolver(new Binder(bindings)); SelectorContext context = new SelectorContext(this, _distinct, columns.ToArray(), resolver, source, queryContext, parameters, compiledBody); // Create columns type info and generate unique column names by field name and alias RowType.TypeInfo[] fields = new RowType.TypeInfo[columns.Count]; List<String> fieldNames = new List<string>(); int p = 1; for (int k = 0; k < fields.Length; k++) { String name; RowType.TypeInfo fieldType = null; object expr = columns[k].Expr; compiledBody[k] = new FunctionLink(); Type resType = context.LispExecutive.Compile(null, expr, compiledBody[k]); if (Lisp.IsAtom(expr)) { ColumnBinding b = resolver.GetBinding(expr); if (b != null) fieldType = b.fieldType; } else if (Lisp.IsNode(expr) && expr is String) { fieldType = new RowType.TypeInfo(null, typeof(String), TypeConverter.GetValueSize(expr)); } else if (Lisp.IsFunctor(expr, ID.ParamRef)) { object value = parameters[(int)Lisp.Arg1(expr)]; fieldType = new RowType.TypeInfo(null, value.GetType(), TypeConverter.GetValueSize(value)); } else if (Lisp.IsFunctor(expr, ID.ToString)) { if (Lisp.Length(expr) == 3) fieldType = new RowType.TypeInfo(null, typeof(String), (int)Lisp.Arg2(expr)); else fieldType = new RowType.TypeInfo(null, typeof(String), 0); } else if (Lisp.IsFunctor(expr, ID.ToInt16)) fieldType = new RowType.TypeInfo(null, typeof(Int16), 0); else if (Lisp.IsFunctor(expr, ID.ToInt32)) fieldType = new RowType.TypeInfo(null, typeof(Int32), 0); else if (Lisp.IsFunctor(expr, ID.ToInt64)) fieldType = new RowType.TypeInfo(null, typeof(Int64), 0); else if (Lisp.IsFunctor(expr, ID.ToSingle)) fieldType = new RowType.TypeInfo(null, typeof(Single), 0); else if (Lisp.IsFunctor(expr, ID.ToDouble)) fieldType = new RowType.TypeInfo(null, typeof(Double), 0); else if (Lisp.IsFunctor(expr, ID.ToDecimal)) fieldType = new RowType.TypeInfo(null, typeof(Decimal), 0); else if (Lisp.IsFunctor(expr, ID.ToDateTime)) fieldType = new RowType.TypeInfo(null, typeof(DateTime), 0); else fieldType = new RowType.TypeInfo(null, resType, 0); if (!String.IsNullOrEmpty(columns[k].Alias)) name = columns[k].Alias; else if (fieldType.Name == null) name = String.Format("Expr{0}", p++); else name = fieldType.Name; fields[k] = new RowType.TypeInfo(k, Util.CreateUniqueName(fieldNames, name), fieldType); } ScanDynatableAccessors(ChildNodes[0], resolver); return new Resultset(new RowType(fields), context); }
/// <summary> /// Main flow of the render pipeline. /// </summary> /// <param name="sc"></param> /// <param name="ist"></param> /// <param name="recycler"></param> void ElementPipeline(SelectorContext sc, ItemState ist, Recycler <FrameworkElement, ItemState> recycler) { sc.SetTick(ist.index); var createit = true; if (LabelSelector != null) { var ox = LabelSelector.Convert(sc, typeof(bool), null, System.Globalization.CultureInfo.CurrentUICulture.Name); if (ox is bool bx) { createit = bx; } else { createit = ox != null; } } if (!createit) { return; } var current = recycler.Next(ist); if (current == null) { return; } if (!current.Item1) { // recycled: restore binding if we are using a LabelFormatter if (LabelFormatter != null && LabelStyle != null) { BindTo(this, nameof(LabelStyle), current.Item2, FrameworkElement.StyleProperty); } } // default text var text = ist.label == null ? String.Empty : (String.IsNullOrEmpty(LabelFormatString) ? ist.label.ToString() : String.Format(LabelFormatString, ist.label) ); if (LabelFormatter != null) { // call for Style, String override var format = LabelFormatter.Convert(sc, typeof(Tuple <Style, String>), null, System.Globalization.CultureInfo.CurrentUICulture.Name); if (format is Tuple <Style, String> ovx) { if (ovx.Item1 != null) { current.Item2.Style = ovx.Item1; } if (ovx.Item2 != null) { text = ovx.Item2; } } } // back-fill values var shim = new TextShim() { Text = text }; current.Item2.DataContext = shim; BindTo(shim, nameof(Visibility), current.Item2, UIElement.VisibilityProperty); ist.element = current.Item2; sc.Generated(ist); }
public SelectorContext selector() { SelectorContext _localctx = new SelectorContext(Context, State); EnterRule(_localctx, 8, RULE_selector); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 59; selectableElement(); State = 63; ErrorHandler.Sync(this); _la = TokenStream.La(1); while (_la == LEFT_SQUARE_BRACKET) { { { State = 60; selectorAttribute(); } } State = 65; ErrorHandler.Sync(this); _la = TokenStream.La(1); } State = 72; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 10, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber) { if (_alt == 1) { { { State = 67; _la = TokenStream.La(1); if (_la == SELECTOR_OPERATOR) { { State = 66; Match(SELECTOR_OPERATOR); } } State = 69; selectableElement(); } } } State = 74; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 10, Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public UserRepository(SelectorContext selectorContext) { this.selectorContext = selectorContext; }
public FilmRepository(SelectorContext selectorContext) { this.selectorContext = selectorContext; }
public SeriesRepository(SelectorContext selectorContext) { this.selectorContext = selectorContext; }
public MockComparisonContext(SelectorContext selectorContext, ArgumentsContext argumentsContext) : base(null, 0) { _selectorContext = selectorContext; _argumentsContext = argumentsContext; }
private SelectorContext selector(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; SelectorContext _localctx = new SelectorContext(Context, _parentState); SelectorContext _prevctx = _localctx; int _startState = 12; EnterRecursionRule(_localctx, 12, RULE_selector, _p); try { int _alt; EnterOuterAlt(_localctx, 1); { State = 64; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 5, Context)) { case 1: { State = 62; identifier(); } break; case 2: { State = 63; functionInvoke(); } break; } Context.Stop = TokenStream.LT(-1); State = 76; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 7, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 74; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 6, Context)) { case 1: { _localctx = new SelectorContext(_parentctx, _parentState); PushNewRecursionContext(_localctx, _startState, RULE_selector); State = 66; if (!(Precpred(Context, 2))) { throw new FailedPredicateException(this, "Precpred(Context, 2)"); } State = 67; Match(DOT); State = 68; identifier(); } break; case 2: { _localctx = new SelectorContext(_parentctx, _parentState); PushNewRecursionContext(_localctx, _startState, RULE_selector); State = 69; if (!(Precpred(Context, 1))) { throw new FailedPredicateException(this, "Precpred(Context, 1)"); } State = 70; Match(LBRACKET); State = 71; simple(); State = 72; Match(RBRACKET); } break; } } } State = 78; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 7, Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }
public SelectorContext selector() { SelectorContext _localctx = new SelectorContext(_ctx, State); EnterRule(_localctx, 66, RULE_selector); try { EnterOuterAlt(_localctx, 1); { State = 528; Match(IDENTIFIER); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }