/// <summary> /// Gets a Graph from the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> /// <remarks> /// If the Graph has been modified during the active Transaction the modified version is returned rather than the original version /// </remarks> public sealed override IGraph this[Uri graphUri] { get { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this.DefaultGraph != null) { return this.DefaultGraph; } else if (this._modifiableGraphs.HasGraph(graphUri)) { return this._modifiableGraphs.Graph(graphUri); } else { return this.GetGraphInternal(null); } } else if (this._modifiableGraphs.HasGraph(graphUri)) { return this._modifiableGraphs.Graph(graphUri); } else { return this.GetGraphInternal(graphUri); } } }
/// <summary> /// Sends a HEAD Command to the Protocol Server to determine whether a given Graph exists /// </summary> /// <param name="graphUri">URI of the Graph to check for</param> public virtual bool GraphExists(Uri graphUri) { return this.GraphExists(graphUri.ToSafeString()); }
/// <summary> /// Loads a Graph from the SQL Store into a Graph object /// </summary> /// <param name="graphUri">Uri of the Graph to load</param> /// <returns></returns> public IGraph Load(Uri graphUri) { Graph g = new Graph(); try { //Get the Database Connection this._manager.Open(true); //Retrieve the existing Graph ID if any if (!this._manager.Exists(graphUri)) { throw new RdfStorageException("The Graph '" + graphUri.ToSafeString() + "' does not exist in the underlying Store"); } String graphID = this._manager.GetGraphID(graphUri); g.BaseUri = graphUri; //Load Namespaces this._manager.LoadNamespaces(g, graphID); //Load Triples this._manager.LoadTriples(g, graphID); this._manager.Close(true); } catch { this._manager.Close(true, true); throw; } return g; }
/// <summary> /// Removes a Graph from the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> public override sealed void RemoveGraph(Uri graphUri) { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this.DefaultGraphUris.Any()) { foreach (Uri u in this.DefaultGraphUris) { if (this.IsDefaultGraph(u)) { //Default Graph gets cleared GraphPersistenceWrapper wrapper = new GraphPersistenceWrapper(this[u]); wrapper.Clear(); this._actions.Add(new GraphPersistenceAction(wrapper, GraphPersistenceActionType.Modified)); } else { //Other Graphs get actually deleted this._actions.Add(new GraphPersistenceAction(this[u], GraphPersistenceActionType.Deleted)); } } } else if (this.HasGraph(graphUri)) { this._actions.Add(new GraphPersistenceAction(this[graphUri], GraphPersistenceActionType.Deleted)); this.RemoveGraphInternal(graphUri); } } else if (this.HasGraph(graphUri)) { this._actions.Add(new GraphPersistenceAction(this[graphUri], GraphPersistenceActionType.Deleted)); this.RemoveGraphInternal(graphUri); } }
/// <summary> /// Loads a Graph from the Store /// </summary> /// <param name="handler">RDF Handler</param> /// <param name="graphUri">Uri of the Graph to load</param> /// <remarks>If a Null Uri is specified then the default graph (statements with no context in Sesame parlance) will be loaded</remarks> public virtual void LoadGraph(IRdfHandler handler, Uri graphUri) { this.LoadGraph(handler, graphUri.ToSafeString()); }
/// <summary> /// Gets whether this Command affects the given Graph /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> public override bool AffectsGraph(Uri graphUri) { switch (this._mode) { case ClearMode.All: return true; case ClearMode.Default: return graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri); case ClearMode.Named: return graphUri != null && !graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri); case ClearMode.Graph: if (this._graphUri == null) { return graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri); } else { return this._graphUri.ToString().Equals(graphUri.ToSafeString()); } default: //No Other Clear Modes but have to keep the compiler happy return true; } }
/// <summary> /// Creates a new connection to a Fuseki Server /// </summary> /// <param name="serviceUri">The /data URI of the Fuseki Server</param> public FusekiConnector(Uri serviceUri) : this(serviceUri.ToSafeString()) { }
/// <summary> /// Deletes a Graph from the Sesame store /// </summary> /// <param name="graphUri">URI of the Graph to delete</param> public virtual void DeleteGraph(Uri graphUri) { this.DeleteGraph(graphUri.ToSafeString()); }
/// <summary> /// Determines whether a given String is a valid Plain Literal for the given Datatype /// </summary> /// <param name="value">Value</param> /// <param name="dt">Datatype</param> /// <param name="syntax">Turtle Syntax</param> /// <returns></returns> public static bool IsValidPlainLiteral(String value, Uri dt, TurtleSyntax syntax) { StringComparison comparison = (syntax == TurtleSyntax.Original ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); if ((value.Equals("true", comparison) || value.Equals("false", comparison)) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeBoolean)) { return true; } else if (_validDecimal.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDecimal)) { return true; } else if (_validInteger.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeInteger)) { return true; } else if (_validDouble.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDouble)) { return true; } else { return false; } }
/// <summary> /// Removes a Graph from the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> protected override void RemoveGraphInternal(Uri graphUri) { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this._store.HasGraph(null)) { this._store.Graphs[null].Clear(); } } else { this._store.Remove(graphUri); } }
public override bool Contains(Uri graphUri) { if (base.Contains(graphUri)) { return true; } else if (!this._removedGraphs.Contains(graphUri.ToSafeString())) { //Try and load the Graph and return true if anything is returned Graph g = new Graph(); try { this._manager.LoadGraph(g, graphUri); if (g.Triples.Count > 0) { //If we're going to return true we must also store the Graph in the collection //for later use g.BaseUri = graphUri; this.Add(g, true); return true; } else { return false; } } catch { //If trying to load the Graph errors then it doesn't exist so return false return false; } } else { return false; } }
/// <summary> /// Gets the Graph describing the given resource from the Store /// </summary> /// <param name="handler">RDF Handler</param> /// <param name="resourceUri">URI of Resource to Describe</param> public void Describe(IRdfHandler handler, Uri resourceUri) { if (!resourceUri.Equals(String.Empty)) { this.DescribeInternal(handler, resourceUri.ToSafeString(), "meta"); } }
/// <summary> /// Creates a new SPARQL Graph Store HTTP Protocol Connector /// </summary> /// <param name="serviceUri">URI of the Protocol Server</param> /// <param name="proxy">Proxy Server</param> public SparqlHttpProtocolConnector(Uri serviceUri, WebProxy proxy) : this(serviceUri.ToSafeString(), proxy) { }
/// <summary> /// Creates a new SPARQL Graph Store HTTP Protocol Connector /// </summary> /// <param name="serviceUri">URI of the Protocol Server</param> public SparqlHttpProtocolConnector(Uri serviceUri) : this(serviceUri.ToSafeString()) { }
/// <summary> /// Creates a new connection to a Fuseki Server /// </summary> /// <param name="serviceUri">The /data URI of the Fuseki Server</param> /// <param name="proxy">Proxy Server</param> public FusekiConnector(Uri serviceUri, WebProxy proxy) : this(serviceUri.ToSafeString(), proxy) { }
/// <summary> /// Determines whether a given String is a valid Plain Literal for the given Datatype /// </summary> /// <param name="value">Value</param> /// <param name="dt">Datatype</param> /// <returns></returns> public static bool IsValidPlainLiteral(String value, Uri dt) { if ((value.Equals("true") || value.Equals("false")) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeBoolean)) { return true; } else if (_validDecimal.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDecimal)) { return true; } else if (_validInteger.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeInteger)) { return true; } else if (_validDouble.IsMatch(value) && dt.ToSafeString().Equals(XmlSpecsHelper.XmlSchemaDataTypeDouble)) { return true; } else { return false; } }
/// <summary> /// Removes a Graph from the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> public virtual void RemoveGraph(Uri graphUri) { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this._defaultGraph != null) { this._defaultGraph.Value.Clear(); } else if (this.HasGraph(graphUri)) { this.RemoveGraphInternal(graphUri); } } else if (this.HasGraph(graphUri)) { this.RemoveGraphInternal(graphUri); } }
/// <summary> /// Loads a Graph from the Store /// </summary> /// <param name="g">Graph to load into</param> /// <param name="graphUri">Uri of the Graph to load</param> /// <remarks>If a Null Uri is specified then the default graph (statements with no context in Sesame parlance) will be loaded</remarks> public virtual void LoadGraph(IGraph g, Uri graphUri) { this.LoadGraph(g, graphUri.ToSafeString()); }
/// <summary> /// Gets whether a Graph with the given URI is the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> public bool HasGraph(Uri graphUri) { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this._defaultGraph != null) { return true; } else { return this.HasGraphInternal(null); } } else { return this.HasGraphInternal(graphUri); } }
/// <summary> /// Updates a Graph /// </summary> /// <param name="graphUri">Uri of the Graph to update</param> /// <param name="additions">Triples to be added</param> /// <param name="removals">Triples to be removed</param> public virtual void UpdateGraph(Uri graphUri, IEnumerable<Triple> additions, IEnumerable<Triple> removals) { this.UpdateGraph(graphUri.ToSafeString(), additions, removals); }
/// <summary> /// Gets the Graph with the given URI from the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> /// <remarks> /// <para> /// This property need only return a read-only view of the Graph, code which wishes to modify Graphs should use the <see cref="ISparqlDataset.GetModifiableGraph">GetModifiableGraph()</see> method to guarantee a Graph they can modify and will be persisted to the underlying storage /// </para> /// </remarks> public virtual IGraph this[Uri graphUri] { get { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this._defaultGraph != null) { return this._defaultGraph.Value; } else { return this.GetGraphInternal(null); } } else { return this.GetGraphInternal(graphUri); } } }
/// <summary> /// Gets whether the Command affects a given Graph /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> public override bool AffectsGraph(Uri graphUri) { if (graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) graphUri = null; List<String> affectedUris = new List<string>(); if (this._pattern.IsGraph) { affectedUris.Add(this._pattern.GraphSpecifier.Value); } else { affectedUris.Add(String.Empty); } if (this._pattern.HasChildGraphPatterns) { affectedUris.AddRange(from p in this._pattern.ChildGraphPatterns where p.IsGraph select p.GraphSpecifier.Value); } if (affectedUris.Any(u => u != null && u.Equals(GraphCollection.DefaultGraphUri))) affectedUris.Add(String.Empty); return affectedUris.Contains(graphUri.ToSafeString()); }
/// <summary> /// Removes a Graph from the Dataset /// </summary> /// <param name="graphUri">Graph URI</param> public sealed override void RemoveGraph(Uri graphUri) { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this.DefaultGraph != null) { GraphPersistenceWrapper wrapper = new GraphPersistenceWrapper(DefaultGraph); wrapper.Clear(); this._actions.Add(new GraphPersistenceAction(wrapper, GraphPersistenceActionType.Modified)); } else if (this.HasGraph(graphUri)) { this._actions.Add(new GraphPersistenceAction(this[graphUri], GraphPersistenceActionType.Deleted)); this.RemoveGraphInternal(graphUri); } } else if (this.HasGraph(graphUri)) { this._actions.Add(new GraphPersistenceAction(this[graphUri], GraphPersistenceActionType.Deleted)); this.RemoveGraphInternal(graphUri); } }
/// <summary> /// Gets whether the Command affects a given Graph /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> public override bool AffectsGraph(Uri graphUri) { if (this._graphUri == null) { return graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri); } else { return this._graphUri.ToString().Equals(graphUri.ToSafeString()); } }
/// <summary> /// Gets a Graph from the dataset /// </summary> /// <param name="graphUri">Graph URI</param> /// <returns></returns> public override IGraph this[Uri graphUri] { get { if (graphUri == null || graphUri.ToSafeString().Equals(GraphCollection.DefaultGraphUri)) { if (this.DefaultGraphUris.Any()) { if (this.DefaultGraphUris.Count() == 1) { return new Graph(new QuadDatasetTripleCollection(this, this.DefaultGraphUris.First())); } else { IEnumerable<IGraph> gs = (from u in this.DefaultGraphUris select new Graph(new QuadDatasetTripleCollection(this, u))).OfType<IGraph>(); return new UnionGraph(gs.First(), gs.Skip(1)); } } else if (this._modifiableGraphs.HasGraph(graphUri)) { return this._modifiableGraphs.Graph(graphUri); } else { return this.GetGraphInternal(null); } } else if (this._modifiableGraphs.HasGraph(graphUri)) { return this._modifiableGraphs.Graph(graphUri); } else { return this.GetGraphInternal(graphUri); } } }