本文整理汇总了C#中SparqlResultsFormat类的典型用法代码示例。如果您正苦于以下问题:C# SparqlResultsFormat类的具体用法?C# SparqlResultsFormat怎么用?C# SparqlResultsFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparqlResultsFormat类属于命名空间,在下文中一共展示了SparqlResultsFormat类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetString
public string GetString(SparqlResultsFormat format, IRdfWriter graphWriter = null)
{
switch (ResultType)
{
case BrightstarSparqlResultsType.VariableBindings:
case BrightstarSparqlResultsType.Boolean:
var stringWriter = new System.IO.StringWriter();
var sparqlXmlWriter = GetSparqlWriter(format);
sparqlXmlWriter.Save(_resultSet, stringWriter);
return stringWriter.GetStringBuilder().ToString();
case BrightstarSparqlResultsType.Graph:
if (graphWriter == null)
{
#if WINDOWS_PHONE
// Cannot use DTD because the mobile version of XmlWriter doesn't support writing a DOCTYPE.
graphWriter = new RdfXmlWriter(WriterCompressionLevel.High, false);
#else
graphWriter = new RdfXmlWriter();
#endif
}
return StringWriter.Write(_graph, graphWriter);
default:
throw new BrightstarInternalException(
String.Format("Unrecognized result type when serializing results string: {0}",
ResultType));
}
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:27,代码来源:BrightstarSparqlResultSet.cs
示例2: SparqlResultModel
public SparqlResultModel(string storeName, IBrightstarService service, SparqlRequestObject sparqlRequest, SparqlResultsFormat resultsFormat)
{
_storeName = storeName;
_sparqlRequest = sparqlRequest;
_service = service;
ResultsFormat = resultsFormat;
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:7,代码来源:SparqlResultModel.cs
示例3: ExecuteSparqlQuery
public static string ExecuteSparqlQuery(this IStore store, string sparqlExpression,
SparqlResultsFormat resultsFormat)
{
var query = ParseSparql(sparqlExpression);
var resultsStream = new MemoryStream();
store.ExecuteSparqlQuery(query, resultsFormat.WithEncoding(new UTF8Encoding(false)), resultsStream);
var ret = Encoding.UTF8.GetString(resultsStream.ToArray());
return ret;
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:9,代码来源:StoreExtensions.cs
示例4: Query
public static string Query(this StoreWorker storeWorker, string sparqlExpression,
SparqlResultsFormat resultsFormat, string[] defaultGraphUris)
{
var query = ParseSparql(sparqlExpression);
using (var resultsStream = new MemoryStream())
{
storeWorker.Query(query, resultsFormat.WithEncoding(new UTF8Encoding(false)), resultsStream, defaultGraphUris);
return Encoding.UTF8.GetString(resultsStream.ToArray());
}
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:10,代码来源:StoreExtensions.cs
示例5: SparqlResultModel
public SparqlResultModel(string storeName, ulong commitId, IBrightstarService service,
SparqlRequestObject sparqlRequest, SparqlResultsFormat resultsFormat, RdfFormat graphFormat)
{
_storeName = storeName;
_commitId = commitId;
_sparqlRequest = sparqlRequest;
_service = service;
ResultsFormat = resultsFormat;
GraphFormat = graphFormat;
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:10,代码来源:SparqlResultModel.cs
示例6: GetResultsStream
public Stream GetResultsStream(SparqlResultsFormat format, RdfFormat graphFormat, DateTime? ifNotModifiedSince, out ISerializationFormat streamFormat)
{
if (_commitId > 0)
{
var commitPointInfo = _service.GetCommitPoint(_storeName, _commitId);
if (commitPointInfo == null) throw new InvalidCommitPointException();
return _service.ExecuteQuery(commitPointInfo, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, format, graphFormat, out streamFormat);
}
return _service.ExecuteQuery(_storeName, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, ifNotModifiedSince, format, graphFormat, out streamFormat);
}
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:10,代码来源:SparqlQueryProcessingModel.cs
示例7: GetSparqlWriter
private ISparqlResultsWriter GetSparqlWriter(SparqlResultsFormat format)
{
var ext = format.DefaultExtension;
if (ext.Equals(SparqlResultsFormat.Xml.DefaultExtension))
return new SparqlXmlWriter();
if (ext.Equals(SparqlResultsFormat.Json.DefaultExtension))
return new SparqlJsonWriter();
if (ext.Equals(SparqlResultsFormat.Tsv.DefaultExtension))
return new SparqlTsvWriter();
if (ext.Equals(SparqlResultsFormat.Csv.DefaultExtension))
return new SparqlCsvWriter();
throw new BrightstarInternalException("Unsupported SPARQL results format");
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:13,代码来源:BrightstarSparqlResultSet.cs
示例8: GetWriter
private static ISparqlResultsWriter GetWriter(SparqlResultsFormat format)
{
if (format == SparqlResultsFormat.Csv)
{
return new SparqlCsvWriter();
}
if (format == SparqlResultsFormat.Tsv)
{
return new SparqlTsvWriter();
}
if (format == SparqlResultsFormat.Json)
{
return new SparqlJsonWriter();
}
return new SparqlXmlWriter();
}
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:16,代码来源:GraphListModel.cs
示例9: SparqlQueryHandler
public SparqlQueryHandler(ISerializationFormat targetFormat,
IEnumerable<string> defaultGraphUris)
{
if (targetFormat is SparqlResultsFormat)
{
_sparqlResultsFormat = targetFormat as SparqlResultsFormat;
}
if (targetFormat is RdfFormat)
{
_rdfFormat = targetFormat as RdfFormat;
}
if (defaultGraphUris != null)
{
_defaultGraphUris = defaultGraphUris.Select(g => new Uri(g)).ToList();
}
}
开发者ID:rexwhitten,项目名称:BrightstarDB,代码行数:16,代码来源:SparqlQueryHandler.cs
示例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();
}
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:17,代码来源:GraphListModel.cs
示例11: SparqlQueryResponse
public SparqlQueryResponse(SparqlQueryProcessingModel model, DateTime? ifNotModifiedSince, SparqlResultsFormat format)
{
try
{
var resultStream = model.GetResultsStream(format, ifNotModifiedSince);
Contents = resultStream.CopyTo;
ContentType = format.MediaTypes[0];
StatusCode = HttpStatusCode.OK;
}
catch (InvalidCommitPointException)
{
StatusCode = HttpStatusCode.NotFound;
}
catch (BrightstarStoreNotModifiedException)
{
StatusCode = HttpStatusCode.NotModified;
}
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:18,代码来源:SparqlQueryResponse.cs
示例12: SparqlQueryResponse
public SparqlQueryResponse(SparqlQueryProcessingModel model, DateTime? ifNotModifiedSince, SparqlResultsFormat format, RdfFormat graphFormat)
{
try
{
ISerializationFormat streamFormat;
var resultStream = model.GetResultsStream(format, graphFormat, ifNotModifiedSince, out streamFormat);
Contents = resultStream.CopyTo;
ContentType = streamFormat.ToString();
StatusCode = HttpStatusCode.OK;
}
catch (InvalidCommitPointException)
{
StatusCode = HttpStatusCode.NotFound;
}
catch (BrightstarStoreNotModifiedException)
{
StatusCode = HttpStatusCode.NotModified;
}
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:19,代码来源:SparqlQueryResponse.cs
示例13: MakeQueryCacheKey
private static string MakeQueryCacheKey(string storeName, long commitTime, string query, IEnumerable<string> defaultGraphUris, SparqlResultsFormat format)
{
var graphHashCode = defaultGraphUris == null ? 0 : String.Join(",", defaultGraphUris).GetHashCode();
return storeName + "_" + commitTime + "_" + query.GetHashCode() + "_" + graphHashCode + "." +
format.DefaultExtension;
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:6,代码来源:ServerCore.cs
示例14: Query
public string Query(string storeName, string queryExpression, IEnumerable<string> defaultGraphUris, SparqlResultsFormat resultsFormat)
{
var g = defaultGraphUris == null ? null : defaultGraphUris.ToArray();
Logging.LogDebug("Query {0} {1}", storeName, queryExpression);
var currentCommitPoint = _storeManager.GetMasterFile(Path.Combine(_baseLocation, storeName)).GetLatestCommitPoint();
var cacheKey = MakeQueryCacheKey(storeName, currentCommitPoint.CommitTime.Ticks,
queryExpression, g, resultsFormat);
var cachedResult = GetCachedResult(cacheKey);
if (cachedResult != null)
{
Logging.LogDebug("Returning cached result for query Query {0} {1}", storeName, queryExpression);
return cachedResult;
}
var storeWorker = GetStoreWorker(storeName);
var result = storeWorker.Query(queryExpression, resultsFormat, g);
//add to cache
CacheResult(cacheKey, result);
return result;
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:19,代码来源:ServerCore.cs
示例15: WriteResults
private static void WriteResults(SparqlResultsFormat resultsFormat, Stream responseStream, string results)
{
StreamWriter streamWriter;
if (resultsFormat.DefaultExtension.Equals(SparqlResultsFormat.Xml.DefaultExtension) &&
!resultsFormat.Encoding.Equals(Encoding.Unicode))
{
// We need to rewrite the XML, otherwise the encoding setting is wrong
XDocument resultsDoc = XDocument.Parse(results);
streamWriter = new StreamWriter(responseStream, resultsFormat.Encoding);
resultsDoc.Save(streamWriter);
streamWriter.Flush();
}
else
{
streamWriter = new StreamWriter(responseStream, resultsFormat.Encoding);
streamWriter.Write(results);
streamWriter.Flush();
}
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:19,代码来源:ServerCore.cs
示例16: Query
// operations
public ISerializationFormat Query(string storeName, string queryExpression, IEnumerable<string> defaultGraphUris,
DateTime? ifNotModifiedSince,
SparqlResultsFormat sparqlResultFormat, RdfFormat graphFormat,
Stream responseStream)
{
Logging.LogDebug("Query {0} {1}", storeName, queryExpression);
var commitPoint =
_storeManager.GetMasterFile(Path.Combine(_baseLocation, storeName)).GetCommitPoints().First();
if (ifNotModifiedSince.HasValue && ifNotModifiedSince > commitPoint.CommitTime)
{
throw new BrightstarStoreNotModifiedException();
}
var g = defaultGraphUris == null ? null : defaultGraphUris.ToArray();
var query = ParseSparql(queryExpression);
var targetFormat = QueryReturnsGraph(query) ? (ISerializationFormat) graphFormat : sparqlResultFormat;
var cacheKey = MakeQueryCacheKey(storeName, commitPoint.CommitTime.Ticks, query, g, targetFormat);
var cachedResult = GetCachedResult(cacheKey);
if (cachedResult == null)
{
// Not in the cache so execute the query on the StoreWorker
var storeWorker = GetStoreWorker(storeName);
var cacheStream = new MemoryStream();
storeWorker.Query(query, targetFormat, cacheStream, g);
cachedResult = CacheResult(cacheKey, cacheStream.ToArray());
}
cachedResult.WriteTo(responseStream);
return targetFormat;
}
开发者ID:rexwhitten,项目名称:BrightstarDB,代码行数:30,代码来源:ServerCore.cs
示例17: ExecuteQuery
/// <summary>
/// Query a specific commit point of a store
/// </summary>
/// <param name="commitPoint">The commit point be queried</param>
/// <param name="queryExpression">The SPARQL query string</param>
/// <param name="defaultGraphUri">The URI of the default graph for the query</param>
/// <param name="resultsFormat">OPTIONAL: Specifies the serialization format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
/// <returns>A stream containing XML SPARQL results</returns>
public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression,
string defaultGraphUri, SparqlResultsFormat resultsFormat = null)
{
return ExecuteQuery(commitPoint, queryExpression, new[] {defaultGraphUri}, resultsFormat);
}
开发者ID:stangelandcl,项目名称:BrightstarDB,代码行数:13,代码来源:BrightstarServiceClient.cs
示例18: ExecuteQuery
/// <summary>
/// Query the store using a SPARQL query
/// </summary>
/// <param name="storeName">The name of the store to query</param>
/// <param name="queryExpression">SPARQL query string</param>
/// <param name="defaultGraphUris">An enumeration over the URIs of the graphs that will be taken together as the default graph for the query</param>
/// <param name="ifNotModifiedSince">OPTIONAL : If this parameter is provided and the store has not been changed since the time specified,
/// a BrightstarClientException will be raised with the message "Store not modified".</param>
/// <param name="resultsFormat">OPTIONAL: Specifies the serialization format for the SPARQL results. Defaults to <see cref="SparqlResultsFormat.Xml"/></param>
/// <param name="graphFormat">OPTIONAL: Specifies the serialization format for RDF graph results. Defaults to <see cref="RdfFormat.RdfXml"/></param>
/// <returns>A stream containing XML SPARQL result XML</returns>
public Stream ExecuteQuery(string storeName, string queryExpression, IEnumerable<string> defaultGraphUris,
DateTime? ifNotModifiedSince = null,
SparqlResultsFormat resultsFormat = null, RdfFormat graphFormat = null)
{
ISerializationFormat streamFormat;
return ExecuteQuery(storeName, queryExpression, defaultGraphUris, ifNotModifiedSince,
resultsFormat ?? SparqlResultsFormat.Xml, graphFormat ?? RdfFormat.RdfXml,
out streamFormat);
}
开发者ID:jamescoffman23,项目名称:BrightstarDB,代码行数:20,代码来源:EmbeddedBrightstarService.cs
示例19: TestSparqlPostSucceeds
private static void TestSparqlPostSucceeds(string storeName, string query, IEnumerable<string> defaultGraphUris, IEnumerable<string> namedGraphUris, MediaRange accept, SparqlResultsFormat expectedQueryFormat, Action<Mock<IBrightstarService>> brightstarSetup)
{
// Setup
var brightstar = new Mock<IBrightstarService>();
brightstar.Setup(s => s.ExecuteQuery(storeName, query, defaultGraphUris, null, expectedQueryFormat))
.Returns(new MemoryStream(Encoding.UTF8.GetBytes("Mock Results")))
.Verifiable();
if (brightstarSetup != null) brightstarSetup(brightstar);
var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));
// Execute
var response = app.Post("/" + storeName + "/sparql", with =>
{
with.Body(query);
with.Header("Content-Type", "application/sparql-query");
if (defaultGraphUris != null)
{
foreach (var defaultGraphUri in defaultGraphUris)
{
with.Query("default-graph-uri", defaultGraphUri);
}
}
if (namedGraphUris != null)
{
foreach (var namedGraphUri in namedGraphUris)
{
with.Query("named-graph-uri", namedGraphUri);
}
}
with.Accept(accept);
});
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(response.ContentType, Is.EqualTo(accept.ToString()));
Assert.That(response.Body.AsString(), Is.EqualTo("Mock Results"));
brightstar.Verify();
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:37,代码来源:SparqlUrlSpec.cs
注:本文中的SparqlResultsFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论