/// <summary> /// Get the result table of the given pattern group /// </summary> internal static void CombinePatterns(RDFConstructQuery query, RDFPatternGroup patternGroup) { if (patternGroup.Patterns.Any()) { //Populate pattern group result table DataTable patternGroupResultTable = RDFQueryEngine.CombineTables(query.PatternResultTables[patternGroup], false); //Add it to the list of pattern group result tables query.PatternGroupResultTables.Add(patternGroup, patternGroupResultTable); //Populate its metadata query.PatternGroupResultTables[patternGroup].TableName = patternGroup.ToString(); if (!query.PatternGroupResultTables[patternGroup].ExtendedProperties.ContainsKey("IsOptional")) { query.PatternGroupResultTables[patternGroup].ExtendedProperties.Add("IsOptional", patternGroup.IsOptional); } else { query.PatternGroupResultTables[patternGroup].ExtendedProperties["IsOptional"] = patternGroup.IsOptional; } if (!query.PatternGroupResultTables[patternGroup].ExtendedProperties.ContainsKey("JoinAsUnion")) { query.PatternGroupResultTables[patternGroup].ExtendedProperties.Add("JoinAsUnion", patternGroup.JoinAsUnion); } else { query.PatternGroupResultTables[patternGroup].ExtendedProperties["JoinAsUnion"] = patternGroup.JoinAsUnion; } } }
/// <summary> /// Applies the query to the given store /// </summary> public RDFAskQueryResult ApplyToStore(RDFStore store) { if (store != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFAskQueryResult askResult = new RDFAskQueryResult(); if (!this.IsEmpty) { //Iterate the pattern groups of the query foreach (RDFPatternGroup patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group RDFAskQueryEngine.EvaluatePatterns(this, patternGroup, store); //Step 2: Get the result table of the current pattern group RDFAskQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFAskQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false); //Step 5: Transform the result into a boolean response askResult.AskResult = (queryResultTable.Rows.Count > 0); } return(askResult); } throw new RDFQueryException("Cannot execute ASK query because given \"store\" parameter is null."); }
/// <summary> /// Applies the query to the given store /// </summary> public RDFSelectQueryResult ApplyToStore(RDFStore store) { if (store != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFSelectQueryResult selectResult = new RDFSelectQueryResult(this.ToString()); if (!this.IsEmpty) { //Iterate the pattern groups of the query foreach (RDFPatternGroup patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group RDFSelectQueryEngine.EvaluatePatterns(this, patternGroup, store); //Step 2: Get the result table of the current pattern group RDFSelectQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFSelectQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false); //Step 5: Apply the modifiers of the query to the result table selectResult.SelectResults = RDFSelectQueryEngine.ApplyModifiers(this, queryResultTable); } return(selectResult); } throw new RDFQueryException("Cannot execute SELECT query because given \"store\" parameter is null."); }
/// <summary> /// Applies the query to the given datasource /// </summary> internal RDFConstructQueryResult ApplyToDataSource(RDFDataSource datasource) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFConstructQueryResult constructResult = new RDFConstructQueryResult(this.ToString()); if (this.PatternGroups.Any()) { //Iterate the pattern groups of the query var fedPatternResultTables = new Dictionary <RDFPatternGroup, List <DataTable> >(); foreach (var patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group if (datasource.IsFederation()) { #region TrueFederations foreach (var store in (RDFFederation)datasource) { //Step FED.1: Evaluate the patterns of the current pattern group on the current store RDFQueryEngine.EvaluatePatterns(this, patternGroup, store); //Step FED.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 } else { RDFQueryEngine.EvaluatePatterns(this, patternGroup, datasource); } //Step 2: Get the result table of the current pattern group RDFQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList(), false); //Step 5: Fill the templates from the result table DataTable filledResultTable = RDFQueryEngine.FillTemplates(this, queryResultTable); //Step 6: Apply the modifiers of the query to the result table constructResult.ConstructResults = RDFQueryEngine.ApplyModifiers(this, filledResultTable); } return(constructResult); }
/// <summary> /// Applies the query to the given federation /// </summary> public RDFConstructQueryResult ApplyToFederation(RDFFederation federation) { if (federation != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFConstructQueryResult constructResult = new RDFConstructQueryResult(this.ToString()); if (!this.IsEmpty) { //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.Stores.Values) { //Step 1: Evaluate the patterns of the current pattern group on the current store RDFConstructQueryEngine.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 RDFConstructQueryEngine.CombinePatterns(this, patternGroup); //Step 4: Apply the filters of the current pattern group to its result table RDFConstructQueryEngine.ApplyFilters(this, patternGroup); } //Step 5: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false); //Step 6: Fill the templates from the result table DataTable filledResultTable = RDFConstructQueryEngine.FillTemplates(this, queryResultTable); //Step 7: Apply the modifiers of the query to the result table constructResult.ConstructResults = RDFConstructQueryEngine.ApplyModifiers(this, filledResultTable); } return(constructResult); } throw new RDFQueryException("Cannot execute CONSTRUCT query because given \"federation\" parameter is null."); }
/// <summary> /// Applies the query to the given federation /// </summary> public RDFAskQueryResult ApplyToFederation(RDFFederation federation) { if (federation != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFAskQueryResult askResult = new RDFAskQueryResult(); if (!this.IsEmpty) { //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.Stores.Values) { //Step 1: Evaluate the patterns of the current pattern group on the current store RDFAskQueryEngine.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 RDFAskQueryEngine.CombinePatterns(this, patternGroup); //Step 4: Apply the filters of the current pattern group to its result table RDFAskQueryEngine.ApplyFilters(this, patternGroup); } //Step 5: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), 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."); }
/// <summary> /// Applies the query to the given store /// </summary> public RDFDescribeQueryResult ApplyToStore(RDFStore store) { if (store != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFDescribeQueryResult describeResult = new RDFDescribeQueryResult(this.ToString()); if (!this.IsEmpty) { //Iterate the pattern groups of the query foreach (RDFPatternGroup patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group RDFDescribeQueryEngine.EvaluatePatterns(this, patternGroup, store); //Step 2: Get the result table of the current pattern group RDFDescribeQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFDescribeQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false); //Step 5: Describe the terms from the result table DataTable describeResultTable = RDFDescribeQueryEngine.DescribeTerms(this, store, queryResultTable); //Step 6: Apply the modifiers of the query to the result table describeResult.DescribeResults = RDFDescribeQueryEngine.ApplyModifiers(this, describeResultTable); } else { //In this case the only chance to proceed is to have resources in the describe terms, //which will be used to search for S-P-O data. Variables are omitted in this scenario. if (this.DescribeTerms.Any(dt => dt is RDFResource)) { //Step 1: Describe the terms from the result table DataTable describeResultTable = RDFDescribeQueryEngine.DescribeTerms(this, store, new DataTable()); //Step 2: Apply the modifiers of the query to the result table describeResult.DescribeResults = RDFDescribeQueryEngine.ApplyModifiers(this, describeResultTable); } } return(describeResult); } throw new RDFQueryException("Cannot execute DESCRIBE query because given \"store\" parameter is null."); }
/// <summary> /// Applies the query to the given graph /// </summary> public RDFConstructQueryResult ApplyToGraph(RDFGraph graph) { if (graph != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFConstructQueryResult constructResult = new RDFConstructQueryResult(this.ToString()); if (!this.IsEmpty) { //Iterate the pattern groups of the query foreach (RDFPatternGroup patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group RDFConstructQueryEngine.EvaluatePatterns(this, patternGroup, graph); //Step 2: Get the result table of the current pattern group RDFConstructQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFConstructQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false); //Step 5: Fill the templates from the result table DataTable filledResultTable = RDFConstructQueryEngine.FillTemplates(this, queryResultTable); //Step 6: Apply the modifiers of the query to the result table constructResult.ConstructResults = RDFConstructQueryEngine.ApplyModifiers(this, filledResultTable); } return(constructResult); } throw new RDFQueryException("Cannot execute CONSTRUCT query because given \"graph\" parameter is null."); }
/// <summary> /// Applies the query to the given federation /// </summary> public RDFDescribeQueryResult ApplyToFederation(RDFFederation federation) { if (federation != null) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFDescribeQueryResult describeResult = new RDFDescribeQueryResult(this.ToString()); if (!this.IsEmpty) { //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.Stores.Values) { //Step 1: Evaluate the patterns of the current pattern group on the current store RDFDescribeQueryEngine.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 RDFDescribeQueryEngine.CombinePatterns(this, patternGroup); //Step 4: Apply the filters of the current pattern group to its result table RDFDescribeQueryEngine.ApplyFilters(this, patternGroup); } //Step 5: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false); //Step 6: Describe the terms on each store and merge them in the federated result table DataTable describeResultTable = new DataTable(this.ToString()); foreach (RDFStore store in federation.Stores.Values) { describeResultTable.Merge(RDFDescribeQueryEngine.DescribeTerms(this, store, queryResultTable), true, MissingSchemaAction.Add); } //Step 7: Apply the modifiers of the query to the result table describeResult.DescribeResults = RDFDescribeQueryEngine.ApplyModifiers(this, describeResultTable); } else { //In this case the only chance to proceed is to have resources in the describe terms, //which will be used to search for S-P-O data. Variables are ignored in this scenario. if (this.DescribeTerms.Any(dt => dt is RDFResource)) { //Step 1: Describe the terms on each store and merge them in the federated result table DataTable describeResultTable = new DataTable(this.ToString()); foreach (RDFStore store in federation.Stores.Values) { describeResultTable.Merge(RDFDescribeQueryEngine.DescribeTerms(this, store, new DataTable()), true, MissingSchemaAction.Add); } //Step 2: Apply the modifiers of the query to the result table describeResult.DescribeResults = RDFDescribeQueryEngine.ApplyModifiers(this, describeResultTable); } } return(describeResult); } throw new RDFQueryException("Cannot execute DESCRIBE query because given \"federation\" parameter is null."); }
/// <summary> /// Applies the query to the given datasource /// </summary> internal RDFDescribeQueryResult ApplyToDataSource(RDFDataSource datasource) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFDescribeQueryResult describeResult = new RDFDescribeQueryResult(this.ToString()); if (this.PatternGroups.Any()) { //Iterate the pattern groups of the query var fedPatternResultTables = new Dictionary <RDFPatternGroup, List <DataTable> >(); foreach (var patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group if (datasource.IsFederation()) { #region TrueFederations foreach (var store in (RDFFederation)datasource) { //Step FED.1: Evaluate the patterns of the current pattern group on the current store RDFQueryEngine.EvaluatePatterns(this, patternGroup, store); //Step FED.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 } else { RDFQueryEngine.EvaluatePatterns(this, patternGroup, datasource); } //Step 2: Get the result table of the current pattern group RDFQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList(), false); //Step 5: Describe the terms from the result table DataTable describeResultTable = new DataTable(this.ToString()); if (datasource.IsFederation()) { #region TrueFederations foreach (var store in (RDFFederation)datasource) { describeResultTable.Merge(RDFQueryEngine.DescribeTerms(this, store, queryResultTable), true, MissingSchemaAction.Add); } #endregion } else { describeResultTable = RDFQueryEngine.DescribeTerms(this, datasource, queryResultTable); } //Step 6: Apply the modifiers of the query to the result table describeResult.DescribeResults = RDFQueryEngine.ApplyModifiers(this, describeResultTable); } else { //In this case the only chance to proceed is to have resources in the describe terms, //which will be used to search for S-P-O data. Variables are ignored in this scenario. if (this.DescribeTerms.Any(dt => dt is RDFResource)) { //Step 1: Describe the terms from the result table DataTable describeResultTable = new DataTable(this.ToString()); if (datasource.IsFederation()) { #region TrueFederations foreach (var store in (RDFFederation)datasource) { describeResultTable.Merge(RDFQueryEngine.DescribeTerms(this, store, new DataTable()), true, MissingSchemaAction.Add); } #endregion } else { describeResultTable = RDFQueryEngine.DescribeTerms(this, datasource, new DataTable()); } //Step 2: Apply the modifiers of the query to the result table describeResult.DescribeResults = RDFQueryEngine.ApplyModifiers(this, describeResultTable); } } return(describeResult); }