public static FromRDFGraph ( RDFGraph graph ) : |
||
graph | RDFGraph | |
return |
/// <summary> /// Applies the query to the given SPARQL endpoint /// </summary> public RDFConstructQueryResult ApplyToSPARQLEndpoint(RDFSPARQLEndpoint sparqlEndpoint) { RDFConstructQueryResult constructResult = new RDFConstructQueryResult(this.ToString()); if (sparqlEndpoint != null) { RDFQueryEvents.RaiseCONSTRUCTQueryEvaluation(String.Format("Evaluating CONSTRUCT query on SPARQL endpoint '{0}'...", sparqlEndpoint)); //Establish a connection to the given SPARQL endpoint using (WebClient webClient = new WebClient()) { //Insert reserved "query" parameter webClient.QueryString.Add("query", HttpUtility.UrlEncode(this.ToString())); //Insert user-provided parameters webClient.QueryString.Add(sparqlEndpoint.QueryParams); //Insert request headers webClient.Headers.Add(HttpRequestHeader.Accept, "application/turtle"); webClient.Headers.Add(HttpRequestHeader.Accept, "text/turtle"); //Send querystring to SPARQL endpoint var sparqlResponse = webClient.DownloadData(sparqlEndpoint.BaseAddress); //Parse response from SPARQL endpoint if (sparqlResponse != null) { using (var sStream = new MemoryStream(sparqlResponse)) { constructResult = RDFConstructQueryResult.FromRDFGraph(RDFGraph.FromStream(RDFModelEnums.RDFFormats.Turtle, sStream)); } constructResult.ConstructResults.TableName = this.ToString(); } } //Eventually adjust column names (should start with "?") Int32 columnsCount = constructResult.ConstructResults.Columns.Count; for (Int32 i = 0; i < columnsCount; i++) { if (!constructResult.ConstructResults.Columns[i].ColumnName.StartsWith("?")) { constructResult.ConstructResults.Columns[i].ColumnName = "?" + constructResult.ConstructResults.Columns[i].ColumnName; } } RDFQueryEvents.RaiseCONSTRUCTQueryEvaluation(String.Format("Evaluated CONSTRUCT query on SPARQL endpoint '{0}': Found '{1}' results.", sparqlEndpoint, constructResult.ConstructResultsCount)); } return(constructResult); }
/// <summary> /// Applies the query to the given SPARQL endpoint /// </summary> public RDFConstructQueryResult ApplyToSPARQLEndpoint(RDFSPARQLEndpoint sparqlEndpoint) { string constructQueryString = this.ToString(); RDFConstructQueryResult constructResult = new RDFConstructQueryResult(constructQueryString); if (sparqlEndpoint != null) { //Establish a connection to the given SPARQL endpoint using (WebClient webClient = new WebClient()) { //Insert reserved "query" parameter webClient.QueryString.Add("query", HttpUtility.UrlEncode(constructQueryString)); //Insert user-provided parameters webClient.QueryString.Add(sparqlEndpoint.QueryParams); //Insert request headers webClient.Headers.Add(HttpRequestHeader.Accept, "application/turtle"); webClient.Headers.Add(HttpRequestHeader.Accept, "text/turtle"); //Send querystring to SPARQL endpoint byte[] sparqlResponse = webClient.DownloadData(sparqlEndpoint.BaseAddress); //Parse response from SPARQL endpoint if (sparqlResponse != null) { using (MemoryStream sStream = new MemoryStream(sparqlResponse)) constructResult = RDFConstructQueryResult.FromRDFGraph(RDFGraph.FromStream(RDFModelEnums.RDFFormats.Turtle, sStream)); constructResult.ConstructResults.TableName = constructQueryString; } } //Eventually adjust column names (should start with "?") int columnsCount = constructResult.ConstructResults.Columns.Count; for (int i = 0; i < columnsCount; i++) { if (!constructResult.ConstructResults.Columns[i].ColumnName.StartsWith("?")) { constructResult.ConstructResults.Columns[i].ColumnName = string.Concat("?", constructResult.ConstructResults.Columns[i].ColumnName); } } } return(constructResult); }