本文整理汇总了C#中SparqlResultSet类的典型用法代码示例。如果您正苦于以下问题:C# SparqlResultSet类的具体用法?C# SparqlResultSet怎么用?C# SparqlResultSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparqlResultSet类属于命名空间,在下文中一共展示了SparqlResultSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SparqlResult
internal SparqlResult(object resultObject, SparqlQueryContext sparqlQueryContext)
{
if (resultObject == null) throw new ArgumentNullException(nameof(resultObject));
if (sparqlQueryContext == null) throw new ArgumentNullException(nameof(sparqlQueryContext));
SourceSparqlQueryContext = sparqlQueryContext;
ResultGraph = resultObject as IGraph;
if (ResultGraph == null)
{
ResultSet = resultObject as SparqlResultSet;
if (ResultSet == null)
{
throw new ArgumentException(
$"Result object must be either a {typeof (IGraph).FullName} or a {typeof (SparqlResultSet).FullName} instance. Got a {resultObject.GetType().FullName}");
}
ResultFormat = sparqlQueryContext.SparqlResultsFormat ?? SparqlResultsFormat.Xml;
}
if (resultObject is IGraph)
{
ResultGraph = resultObject as IGraph;
ResultFormat = sparqlQueryContext.GraphResultsFormat ?? RdfFormat.RdfXml;
}
}
示例2: Query
/// <summary>
/// Makes a SPARQL Query against the Knowledge Base
/// </summary>
/// <param name="sparqlQuery">SPARQL Query</param>
/// <returns></returns>
public Object Query(String sparqlQuery)
{
SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri(this._sparqlUri));
using (HttpWebResponse response = endpoint.QueryRaw(sparqlQuery))
{
try
{
ISparqlResultsReader sparqlParser = MimeTypesHelper.GetSparqlParser(response.ContentType);
SparqlResultSet results = new SparqlResultSet();
sparqlParser.Load(results, new StreamReader(response.GetResponseStream()));
response.Close();
return results;
}
catch (RdfParserSelectionException)
{
IRdfReader parser = MimeTypesHelper.GetParser(response.ContentType);
Graph g = new Graph();
parser.Load(g, new StreamReader(response.GetResponseStream()));
response.Close();
return g;
}
}
}
示例3: Fill
public void Fill(SparqlResultSet results)
{
foreach (SparqlResult result in results)
{
this.ProcessResult(result);
}
}
示例4: Validate
/// <summary>
/// Validates the syntax to see if it is valid SPARQL Results
/// </summary>
/// <param name="data">Data to validate</param>
/// <returns></returns>
public ISyntaxValidationResults Validate(string data)
{
String message;
try
{
SparqlResultSet results = new SparqlResultSet();
StringParser.ParseResultSet(results, data);
message = "Valid SPARQL Results - " + results.Count + " Results - Parser: " + this._parser.GetType().Name;
return new SyntaxValidationResults(true, message, results);
}
catch (RdfParseException parseEx)
{
message = "Invalid SPARQL Results - Parsing Error from Parser: " + this._parser.GetType().Name + " - " + parseEx.Message;
return new SyntaxValidationResults(message, parseEx);
}
catch (RdfException rdfEx)
{
message = "Invalid SPARQL Results - RDF Error from Parser: " + this._parser.GetType().Name + " - " + rdfEx.Message;
return new SyntaxValidationResults(message, rdfEx);
}
catch (Exception ex)
{
message = "Invalid SPARQL Results - Error from Parser: " + this._parser.GetType().Name + " - " + ex.Message;
return new SyntaxValidationResults(message, ex);
}
}
示例5: SparqlXmlWriter
public void SparqlXmlWriter()
{
try
{
Graph g = new Graph();
FileLoader.Load(g, "InferenceTest.ttl");
Object results = g.ExecuteQuery("SELECT * WHERE {?s ?p ?o}");
if (results is SparqlResultSet)
{
TestTools.ShowResults(results);
}
StringBuilder output = new StringBuilder();
System.IO.StringWriter writer = new System.IO.StringWriter(output);
SparqlXmlWriter sparqlWriter = new SparqlXmlWriter();
sparqlWriter.Save((SparqlResultSet)results, writer);
Console.WriteLine();
Console.WriteLine(output.ToString());
Console.WriteLine();
SparqlXmlParser parser = new SparqlXmlParser();
SparqlResultSet results2 = new SparqlResultSet();
StringParser.ParseResultSet(results2, output.ToString());
Assert.AreEqual(((SparqlResultSet)results).Count, results2.Count, "Result Sets should have contained same number of Results");
Assert.IsTrue(((SparqlResultSet)results).Equals(results2), "Result Sets should have been equal");
}
catch (Exception ex)
{
TestTools.ReportError("Error", ex, true);
}
}
示例6: ResultSetWindow
public ResultSetWindow(SparqlResultSet results)
{
InitializeComponent();
this._formatter = new SparqlFormatter();
this._grid = this.gridResults;
this.RenderResultSet(results);
}
示例7: BrightstarSparqlResultSet
public BrightstarSparqlResultSet(object o)
{
if (o is SparqlResultSet)
{
_resultSet = o as SparqlResultSet;
ResultType = _resultSet.ResultsType == SparqlResultsType.VariableBindings
? BrightstarSparqlResultsType.VariableBindings
: BrightstarSparqlResultsType.Boolean;
}
else if (o is IGraph)
{
_graph = o as IGraph;
ResultType = BrightstarSparqlResultsType.Graph;
}
}
示例8: ExecuteQueryWithString
/// <summary>
/// overload of Execute query
/// </summary>
/// <param name="input">the query text as string</param>
/// <returns></returns>
public static SparqlResultSet ExecuteQueryWithString(string input)
{
//list to hold the results
SparqlResultSet resultSet = new SparqlResultSet();
try
{
//making the query
Object result = manager.Query(input);
resultSet = (SparqlResultSet)result;
}
catch { }
return resultSet;
}
示例9: Load
/// <summary>
/// Loads a Result Set from an Input Stream
/// </summary>
/// <param name="results">Result Set to load into</param>
/// <param name="input">Input Stream to read from</param>
public void Load(SparqlResultSet results, StreamReader input)
{
if (input == null) throw new RdfParseException("Cannot parse SPARQL Results from a null input stream");
//Check Encoding
if (input.CurrentEncoding != Encoding.UTF8)
{
#if !SILVERLIGHT
this.RaiseWarning("Expected Input Stream to be encoded as UTF-8 but got a Stream encoded as " + input.CurrentEncoding.EncodingName + " - Please be aware that parsing errors may occur as a result");
#else
this.RaiseWarning("Expected Input Stream to be encoded as UTF-8 but got a Stream encoded as " + input.CurrentEncoding.GetType().Name + " - Please be aware that parsing errors may occur as a result");
#endif
}
this.Load(results, (TextReader)input);
}
示例10: AsString
public string AsString(SparqlResultsFormat format)
{
var g = new VDS.RDF.Graph();
var results = new List<SparqlResult>();
foreach (var graphUri in Graphs)
{
var s = new Set();
s.Add(SparqlResultVariableName, g.CreateUriNode(new Uri(graphUri)));
results.Add(new SparqlResult(s));
}
var rs = new SparqlResultSet(results);
var writer = GetWriter(format);
var sw = new StringWriter();
writer.Save(rs, sw);
sw.Flush();
return sw.ToString();
}
示例11: ParsingResultSetHandlerImplicitSparqlRdfNTriples
public void ParsingResultSetHandlerImplicitSparqlRdfNTriples()
{
this.EnsureTestData("test.sparql.nt", new SparqlRdfWriter(new NTriplesWriter()));
SparqlRdfParser parser = new SparqlRdfParser(new NTriplesParser());
SparqlResultSet results = new SparqlResultSet();
parser.Load(results, "test.sparql.nt");
NTriplesFormatter formatter = new NTriplesFormatter();
foreach (SparqlResult r in results)
{
Console.WriteLine(r.ToString(formatter));
}
Assert.IsFalse(results.IsEmpty, "Result Set should not be empty");
Assert.AreEqual(SparqlResultsType.VariableBindings, results.ResultsType, "Results Type should be VariableBindings");
}
示例12: RequestWithHTTP
public static SparqlResultSet RequestWithHTTP(string request)
{
SparqlResultSet toreturn = new SparqlResultSet();
try
{
StreamReader sr = new StreamReader("endpointURI.txt");
SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri(sr.ReadLine()));
sr.Close();
endpoint.Timeout = 999999;
toreturn = endpoint.QueryWithResultSet(request);
}
catch (Exception e)
{
util.log(request + e.Message + "==>" + e.Data);
}
return toreturn;
}
示例13: ResultSetViewerForm
/// <summary>
/// Displays the given SPARQL Result Set
/// </summary>
/// <param name="results">SPARQL Result to display</param>
public ResultSetViewerForm(SparqlResultSet results)
{
InitializeComponent();
if (Constants.WindowIcon != null)
{
this.Icon = Constants.WindowIcon;
}
//Load Formatters
List<INodeFormatter> formatters = new List<INodeFormatter>();
Type targetType = typeof(INodeFormatter);
foreach (Type t in Assembly.GetAssembly(targetType).GetTypes())
{
if (t.Namespace == null) continue;
if (t.Namespace.Equals("VDS.RDF.Writing.Formatting"))
{
if (t.GetInterfaces().Contains(targetType))
{
try
{
INodeFormatter formatter = (INodeFormatter)Activator.CreateInstance(t);
formatters.Add(formatter);
if (formatter.GetType().Equals(this._formatter.GetType())) this._formatter = formatter;
}
catch
{
//Ignore this Formatter
}
}
}
}
formatters.Sort(new ToStringComparer<INodeFormatter>());
this.cboFormat.DataSource = formatters;
this.cboFormat.SelectedItem = this._formatter;
this.cboFormat.SelectedIndexChanged += new System.EventHandler(this.cboFormat_SelectedIndexChanged);
this.dgvResults.CellFormatting += new DataGridViewCellFormattingEventHandler(dgvTriples_CellFormatting);
this.dgvResults.CellContentClick += new DataGridViewCellEventHandler(dgvTriples_CellClick);
this._results = results;
this.Text = this.GetTitle();
}
示例14: IsConsistent
/// <summary>
/// Returns whether the Knowledge Base is consistent
/// </summary>
public bool IsConsistent()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Endpoint.Uri);
request.Method = this.Endpoint.HttpMethods.First();
request.ContentType = MimeTypesHelper.HttpSparqlAcceptHeader;
#if DEBUG
if (Options.HttpDebugging)
{
Tools.HttpDebugRequest(request);
}
#endif
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
#if DEBUG
if (Options.HttpDebugging)
{
Tools.HttpDebugResponse(response);
}
#endif
ISparqlResultsReader parser = MimeTypesHelper.GetSparqlParser(response.ContentType);
SparqlResultSet results = new SparqlResultSet();
parser.Load(results, new StreamReader(response.GetResponseStream()));
//Expect a boolean result set
return results.Result;
}
}
catch (WebException webEx)
{
#if DEBUG
if (Options.HttpDebugging)
{
if (webEx.Response != null) Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
}
#endif
throw new RdfReasoningException("A HTTP error occurred while communicating with the Pellet Server", webEx);
}
}
示例15: executeSparqlQuery
/// <summary>
/// do a HTTP request using a sparql query from a sparql endpoint stated in a file
/// </summary>
/// <param name="request">sparql Query to be executed</param>
/// <returns>set of results resulted from executing the query</returns>
public static SparqlResultSet executeSparqlQuery(string request)
{
SparqlResultSet toreturn = new SparqlResultSet();
try
{
string path = HttpRuntime.BinDirectory + "endpointURI.txt";
StreamReader sr = new StreamReader(path);
string endpointURI = sr.ReadLine();
SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri (endpointURI));
sr.Close();
endpoint.Timeout = 999999;
toreturn = endpoint.QueryWithResultSet(request);
}
catch (Exception e)
{
util.log(request + e.Message + "==>" + e.Data);
}
return toreturn;
}