本文整理汇总了C#中ITripleStore类的典型用法代码示例。如果您正苦于以下问题:C# ITripleStore类的具体用法?C# ITripleStore怎么用?C# ITripleStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITripleStore类属于命名空间,在下文中一共展示了ITripleStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FolderStoreParserContext
/// <summary>
/// Creates a new Folder Store Parser Context
/// </summary>
/// <param name="store">Triple Store to parse into</param>
/// <param name="folder">Folder</param>
/// <param name="format">Format</param>
/// <param name="threads">Threads to use</param>
public FolderStoreParserContext(ITripleStore store, String folder, FolderStoreFormat format, int threads)
: base(store)
{
this._folder = folder;
this._format = format;
this._threads = threads;
}
示例2: Write
/// <summary>
/// Writes the given Triple Store to a String and returns the output in your chosen concrete RDF dataset syntax
/// </summary>
/// <param name="store">Triple Store</param>
/// <param name="writer">Writer to use to generate conrete RDF Syntax</param>
/// <returns></returns>
public static String Write(ITripleStore store, IStoreWriter writer)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
writer.Save(store, new TextWriterParams(sw));
return sw.ToString();
}
示例3: ThreadedSqlStoreWriterContext
/// <summary>
/// Creates a new Threaded SQL Store Writer Context
/// </summary>
/// <param name="store">Triple Store to save</param>
/// <param name="manager">SQL IO Manager</param>
/// <param name="threads">Number of threads to use</param>
/// <param name="clearIfExists">Whether to clear graphs if they already exist</param>
public ThreadedSqlStoreWriterContext(ITripleStore store, IThreadedSqlIOManager manager, int threads, bool clearIfExists)
{
this._store = store;
this._manager = manager;
this._writeThreads = threads;
this._clearIfExists = clearIfExists;
}
示例4: BaseSparqlView
/// <summary>
/// Creates a new SPARQL View
/// </summary>
/// <param name="sparqlQuery">SPARQL Query</param>
/// <param name="store">Triple Store to query</param>
public BaseSparqlView(String sparqlQuery, ITripleStore store)
{
SparqlQueryParser parser = new SparqlQueryParser();
this._q = parser.ParseFromString(sparqlQuery);
this._store = store;
this._async = new UpdateViewDelegate(this.UpdateViewInternal);
this.Initialise();
}
示例5: Save
/// <summary>
/// Saves a Store in TriX format
/// </summary>
/// <param name="store">Store to save</param>
/// <param name="parameters">Parameters indicating a Stream to write to</param>
public void Save(ITripleStore store, IStoreParams parameters)
{
//Try and get the TextWriter to output to
TextWriter output = null;
if (parameters is StreamParams)
{
output = ((StreamParams)parameters).StreamWriter;
}
else if (parameters is TextWriterParams)
{
output = ((TextWriterParams)parameters).TextWriter;
}
if (output != null)
{
try
{
//Setup the XML document
XmlWriter writer = XmlWriter.Create(output, this.GetSettings());
writer.WriteStartDocument();
writer.WriteStartElement("TriX", TriXParser.TriXNamespaceURI);
writer.WriteStartAttribute("xmlns");
writer.WriteRaw(TriXParser.TriXNamespaceURI);
writer.WriteEndAttribute();
//Output Graphs as XML <graph> elements
foreach (IGraph g in store.Graphs)
{
this.GraphToTriX(g, writer);
}
//Save the XML to disk
writer.WriteEndDocument();
writer.Close();
output.Close();
}
catch
{
try
{
output.Close();
}
catch
{
//Just cleaning up
}
throw;
}
}
else
{
throw new RdfStorageException("Parameters for the TriXWriter must be of the type StreamParams/TextWriterParams");
}
}
示例6: FindBlankNodeOwner
private static IUriNode FindBlankNodeOwner(this IBlankNode blankNode, ITripleStore tripleStore)
{
INode current = blankNode;
while ((current = tripleStore.Triples.Where(triple => triple.Object.Equals(current)).Select(triple => triple.Subject).FirstOrDefault()) != null)
{
if (current is IUriNode)
{
return (IUriNode)current;
}
}
return null;
}
示例7: Save
/// <summary>
/// Saves the given Triple Store to the SQL Store that this class was instantiated with
/// </summary>
/// <param name="store">Store you wish to Save</param>
/// <param name="parameters">Parameters for the Store</param>
public virtual void Save(ITripleStore store, IStoreParams parameters)
{
if (parameters is ISQLIOParams)
{
SqlIOParams writeParams = (SqlIOParams)parameters;
writeParams.Manager.PreserveState = true;
SqlWriter writer = new SqlWriter(writeParams.Manager);
foreach (IGraph g in store.Graphs)
{
writer.Save(g, writeParams.ClearIfExists);
}
}
else
{
throw new RdfStorageException("Parameters for the SQLStoreWriter must implement the interface ISQLIOParams");
}
}
示例8: Save
/// <summary>
/// Saves the given Triple Store to an arbitrary store
/// </summary>
/// <param name="store">Store to Save</param>
/// <param name="parameters">Parameters for the Store</param>
/// <remarks>
/// Parameters must be of type <see cref="GenericIOParams">GenericIOParams</see>
/// </remarks>
public void Save(ITripleStore store, IStoreParams parameters)
{
if (parameters is GenericIOParams)
{
//Create the Writer Context
GenericStoreWriterContext context = new GenericStoreWriterContext(store, (GenericIOParams)parameters);
//Queue Graphs for Writing
foreach (IGraph g in store.Graphs)
{
context.Add(g.BaseUri);
}
//Start making the async calls
List<IAsyncResult> results = new List<IAsyncResult>();
WriteGraphsDelegate d = new WriteGraphsDelegate(this.WriteGraphs);
for (int i = 0; i < context.Threads; i++)
{
results.Add(d.BeginInvoke(context, null, null));
}
//Wait for all the async calls to complete
WaitHandle.WaitAll(results.Select(r => r.AsyncWaitHandle).ToArray());
RdfThreadedOutputException outputEx = new RdfThreadedOutputException(WriterErrorMessages.ThreadedOutputFailure("TSV"));
foreach (IAsyncResult result in results)
{
try
{
d.EndInvoke(result);
}
catch (Exception ex)
{
outputEx.AddException(ex);
}
}
//If there were any errors we'll throw an RdfThreadedOutputException now
if (outputEx.InnerExceptions.Any()) throw outputEx;
}
else
{
throw new RdfStorageException("Parameters for the GenericStoreWriter must be of type GenericIOParams");
}
}
示例9: ParseDataset
/// <summary>
/// Parses a raw RDF Dataset String (attempts to auto-detect the format)
/// </summary>
/// <param name="store">Store to load into</param>
/// <param name="data">Raw RDF Dataset String</param>
/// <remarks>
/// <p>
/// Auto-detection is based on testing the string to see if it contains certain keyword constructs which might indicate a particular syntax has been used. This detection may not always be accurate.
/// </p>
/// </remarks>
public static void ParseDataset(ITripleStore store, String data)
{
if (store == null) throw new RdfParseException("Cannot read a RDF dataset into a null Graph");
if (data == null) return;
//Try to guess the format
String format = "Unknown";
try
{
if (data.Contains("<?xml") && data.Contains("<TriX"))
{
//Probably TriX
format = "TriX";
ParseDataset(store, data, new TriXParser());
}
else if (data.Contains("@prefix") || data.Contains("@base"))
{
//Probably TriG
format = "TriG";
ParseDataset(store, data, new TriGParser());
}
else
{
//Take a stab at it being NQuads
//No real way to test as there's nothing particularly distinctive in NQuads
format = "NQuads";
ParseDataset(store, data, new NQuadsParser());
}
}
catch (RdfParseException parseEx)
{
//Wrap the exception in an informational exception about what we guessed
throw new RdfParseException("StringParser failed to parse the RDF Dataset string correctly, StringParser auto-detection guessed '" + format + "' but this failed to parse. RDF Dataset string may be malformed or StringParser may have guessed incorrectly", parseEx);
}
}
示例10: Load
/// <summary>
/// Loads Graphs into the store using the settings the Reader was instantiated with
/// </summary>
/// <param name="store">Store to load into</param>
/// <param name="parameters">Parameters indicating where to read from</param>
public void Load(ITripleStore store, IStoreParams parameters)
{
if (store == null) throw new RdfParseException("Cannot read RDF from a Folder Store into a null Triple Store");
this.Load(new StoreHandler(store), parameters);
}
示例11: Save
/// <summary>
/// Saves a Store in NQuads format
/// </summary>
/// <param name="store">Store to save</param>
/// <param name="parameters">Parameters indicating a Stream to write to</param>
public void Save(ITripleStore store, IStoreParams parameters)
{
ThreadedStoreWriterContext context = null;
if (parameters is StreamParams)
{
//Create a new Writer Context
#if !SILVERLIGHT
((StreamParams)parameters).Encoding = Encoding.ASCII;
#endif
context = new ThreadedStoreWriterContext(store, ((StreamParams)parameters).StreamWriter, this._prettyPrint, false);
}
else if (parameters is TextWriterParams)
{
context = new ThreadedStoreWriterContext(store, ((TextWriterParams)parameters).TextWriter, this._prettyPrint, false);
}
if (context != null)
{
//Check there's something to do
if (context.Store.Graphs.Count == 0)
{
context.Output.Close();
return;
}
try
{
if (this._multiThreaded)
{
//Queue the Graphs to be written
foreach (IGraph g in context.Store.Graphs)
{
if (g.BaseUri == null)
{
context.Add(UriFactory.Create(GraphCollection.DefaultGraphUri));
}
else
{
context.Add(g.BaseUri);
}
}
//Start making the async calls
List<IAsyncResult> results = new List<IAsyncResult>();
SaveGraphsDelegate d = new SaveGraphsDelegate(this.SaveGraphs);
for (int i = 0; i < this._threads; i++)
{
results.Add(d.BeginInvoke(context, null, null));
}
//Wait for all the async calls to complete
WaitHandle.WaitAll(results.Select(r => r.AsyncWaitHandle).ToArray());
RdfThreadedOutputException outputEx = new RdfThreadedOutputException(WriterErrorMessages.ThreadedOutputFailure("TSV"));
foreach (IAsyncResult result in results)
{
try
{
d.EndInvoke(result);
}
catch (Exception ex)
{
outputEx.AddException(ex);
}
}
context.Output.Close();
//If there were any errors we'll throw an RdfThreadedOutputException now
if (outputEx.InnerExceptions.Any()) throw outputEx;
}
else
{
foreach (IGraph g in context.Store.Graphs)
{
NTriplesWriterContext graphContext = new NTriplesWriterContext(g, context.Output);
foreach (Triple t in g.Triples)
{
context.Output.WriteLine(this.TripleToNQuads(graphContext, t));
}
}
context.Output.Close();
}
}
catch
{
try
{
context.Output.Close();
}
catch
{
//Just cleaning up
}
throw;
}
}
//.........这里部分代码省略.........
示例12: FolderStoreWriterContext
/// <summary>
/// Creates a new Writer Context
/// </summary>
/// <param name="store">Triple Store</param>
/// <param name="folder">Folder to write to</param>
/// <param name="format">Folder Store Format</param>
public FolderStoreWriterContext(ITripleStore store, String folder, FolderStoreFormat format)
: this(store, folder)
{
this._format = format;
}
示例13: TripleStoreEventArgs
/// <summary>
/// Creates a new set of Triple Store Event Arguments
/// </summary>
/// <param name="store">Triple Store</param>
/// <param name="g">Graph</param>
public TripleStoreEventArgs(ITripleStore store, IGraph g)
: this(store, new GraphEventArgs(g)) { }
示例14: Load
/// <summary>
/// Loads the contents of the given File into a Triple Store providing the RDF dataset format can be determined
/// </summary>
/// <param name="store">Triple Store to load into</param>
/// <param name="filename">File to load from</param>
/// <remarks>
/// <para>
/// The <see cref="FileLoader">FileLoader</see> attempts to select a Store Parser by examining the file extension to select the most likely MIME type for the file. This assume that the file extension corresponds to one of the recognized file extensions for a RDF dataset format the library supports. If this suceeds then a parser is chosen and used to parse the input file.
/// </para>
/// </remarks>
public static void Load(ITripleStore store, String filename)
{
FileLoader.Load(store, filename, null);
}
示例15: Save
/// <summary>
/// Saves a Triple Store to CSV Format
/// </summary>
/// <param name="store">Triple Store to save</param>
/// <param name="parameters">A set of <see cref="StreamParams">StreamParams</see></param>
public void Save(ITripleStore store, IStoreParams parameters)
{
ThreadedStoreWriterContext context = null;
if (parameters is StreamParams)
{
//Create a new Writer Context
context = new ThreadedStoreWriterContext(store, ((StreamParams)parameters).StreamWriter);
}
else if (parameters is TextWriterParams)
{
context = new ThreadedStoreWriterContext(store, ((TextWriterParams)parameters).TextWriter);
}
if (context != null)
{
//Check there's something to do
if (context.Store.Graphs.Count == 0)
{
context.Output.Close();
return;
}
//Queue the Graphs to be written
foreach (IGraph g in context.Store.Graphs)
{
context.Add(g.BaseUri);
}
//Start making the async calls
List<IAsyncResult> results = new List<IAsyncResult>();
SaveGraphsDeletegate d = new SaveGraphsDeletegate(this.SaveGraphs);
for (int i = 0; i < this._threads; i++)
{
results.Add(d.BeginInvoke(context, null, null));
}
//Wait for all the async calls to complete
WaitHandle.WaitAll(results.Select(r => r.AsyncWaitHandle).ToArray());
RdfThreadedOutputException outputEx = new RdfThreadedOutputException(WriterErrorMessages.ThreadedOutputFailure("CSV"));
foreach (IAsyncResult result in results)
{
try
{
d.EndInvoke(result);
}
catch (Exception ex)
{
outputEx.AddException(ex);
}
}
context.Output.Close();
//If there were any errors we'll throw an RdfThreadedOutputException now
if (outputEx.InnerExceptions.Any()) throw outputEx;
}
else
{
throw new RdfStorageException("Parameters for the CsvStoreWriter must be of the type StreamParams/TextWriterParams");
}
}