RDFSharp.Query.RDFAskQuery.ApplyToFederation C# (CSharp) Method

ApplyToFederation() public method

Applies the query to the given federation
public ApplyToFederation ( RDFFederation federation ) : RDFAskQueryResult
federation RDFFederation
return RDFAskQueryResult
        public RDFAskQueryResult ApplyToFederation(RDFFederation federation)
        {
            if (federation != null) {
                this.PatternGroupResultTables.Clear();
                this.PatternResultTables.Clear();

                RDFAskQueryResult askResult    = new RDFAskQueryResult();
                if (this.PatternGroups.Any()) {

                    //Iterate the pattern groups of the query
                    var fedPatternResultTables = new Dictionary<RDFPatternGroup, List<DataTable>>();
                    foreach (RDFPatternGroup patternGroup in this.PatternGroups) {

                        #region TrueFederations
                        foreach (RDFStore store in federation) {

                            //Step 1: Evaluate the patterns of the current pattern group on the current store
                            RDFQueryEngine.EvaluatePatterns(this, patternGroup, store);

                            //Step 2: Federate the patterns of the current pattern group on the current store
                            if (!fedPatternResultTables.ContainsKey(patternGroup)) {
                                 fedPatternResultTables.Add(patternGroup, this.PatternResultTables[patternGroup]);
                            }
                            else {
                                fedPatternResultTables[patternGroup].ForEach(fprt =>
                                    fprt.Merge(this.PatternResultTables[patternGroup].Single(prt => prt.TableName.Equals(fprt.TableName, StringComparison.Ordinal)), true, MissingSchemaAction.Add));
                            }

                        }
                        this.PatternResultTables[patternGroup] = fedPatternResultTables[patternGroup];
                        #endregion

                        //Step 3: Get the result table of the current pattern group
                        RDFQueryEngine.CombinePatterns(this, patternGroup);

                        //Step 4: Apply the filters of the current pattern group to its result table
                        RDFQueryEngine.ApplyFilters(this, patternGroup);

                    }

                    //Step 5: Get the result table of the query
                    DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList(), false);

                    //Step 6: Transform the result into a boolean response
                    askResult.AskResult        = (queryResultTable.Rows.Count > 0);

                }

                return askResult;
            }
            throw new RDFQueryException("Cannot execute ASK query because given \"federation\" parameter is null.");
        }