private void GetTripleText(OwlInstanceSupertype oc, PropertyInfo info, IGraph g, StringBuilder sb) { if (info.GetValue(oc, null) != null) { if (info.GetOwlResource() == null) { return; } sb.Append(this.FormatAsUri(oc.InstanceUri)); sb.Append(' '); sb.Append(this.FormatAsUri(info.GetOwlResourceUri())); sb.Append(' '); String dtUri = info.GetDatatypeUri(); if (dtUri == null) { sb.Append(this.Format(g.CreateLiteralNode(info.GetValue(oc, null).ToString()))); } else { sb.Append(this.Format(g.CreateLiteralNode(info.GetValue(oc, null).ToString(), new Uri(dtUri)))); } sb.AppendLine(" ."); } }
/// <summary> /// Assigns the instance URI from the SPARQL result bindings. /// </summary> /// <param name="obj">The object to assign the URI to.</param> /// <param name="queryAlias">The query alias that was used in LINQ and SPARQL.</param> /// <param name="semwebResult">The semweb result to take the value from.</param> private void AssignInstanceUri(OwlInstanceSupertype obj, string queryAlias, SparqlResult result) { // if there is no alias, then there's no way to work out what contains the instance URI if (string.IsNullOrEmpty(queryAlias)) { return; } // if there is a binding with the same name as the alias if (result.Variables.Contains(queryAlias)) { // get string representation of the instance URI string uri = result[queryAlias].ToString(); // is it enclosed in angle brackets? then strip them. if (uri.StartsWith("<") && uri.EndsWith(">")) { uri = uri.Substring(1, uri.Length - 2); } // can this be parsed as a URI? if so then assign to instance URI property of obj if (Uri.IsWellFormedUriString(uri, UriKind.RelativeOrAbsolute)) { obj.InstanceUri = uri; } } }
private static void AddPropertyToStore(OwlInstanceSupertype supertype, PropertyInfo pi, IInMemoryQueryableStore ms) { if (supertype == null) { throw new ArgumentNullException("supertype"); } if (pi == null) { throw new ArgumentNullException("pi"); } if (ms == null) { throw new ArgumentNullException("ms"); } if (pi.GetValue(supertype, null) != null) { Add(supertype.InstanceUri, pi.GetOwlResourceUri(), pi.GetValue(supertype, null).ToString(), ms); #region Tracing #line hidden if (Logger.IsDebugEnabled) { Logger.Debug("Added property {0} to store.", pi.Name); } #line default #endregion } }
/// <summary> /// Assigns the <see cref="RdfDataContext"/> to the instance. /// </summary> /// <remarks> /// this is used in case it needs it to lazily load references later on. /// </remarks> /// <param name="obj">the object that has just been deserialised.</param> /// <param name="dataContext">The <see cref="RdfDataContext"/> through which the query was run that led to the instance being deserialised.</param> private void AssignDataContext(OwlInstanceSupertype obj, RdfDataContext dataContext) { if (obj != null) { obj.DataContext = DataContext; } // TODO: assign event handlers for NotifyPropertyChanged }
/// <summary> /// Saves an Object to the underlying Store using SPARQL Update /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">Graph URI</param> /// <remarks> /// Does not remove any previous version of the Object, to do this use the <see cref="LinqUpdateProcessor.DeleteObject">DeleteObject()</see> method prior to saving an Object /// </remarks> public void SaveObject(OwlInstanceSupertype oc, String graphUri) { if (oc == null) { throw new ArgumentNullException("oc", "Cannot persist a Null Object"); } SparqlUpdateCommandSet cmds = this._parser.ParseFromString(this.GetSaveCommandText(oc, graphUri)); this._underlyingProcessor.ProcessCommandSet(cmds); }
/// <summary> /// Deletes an Object from the underlying Store using SPARQL Update /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> public void DeleteObject(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) { throw new ArgumentNullException("oc", "Cannot delete a Null Object"); } SparqlUpdateCommandSet cmds = this._parser.ParseFromString(this.GetDeletionCommandText(oc, graphUri, mode)); this._underlyingProcessor.ProcessCommandSet(cmds); }
/// <summary> /// Returns true if the result is unique among the results so far received. /// </summary> /// <param name="obj">The object that is potentially to be added to the results collection.</param> /// <returns>true if there is no object among the <see cref="IncomingResults"/> with the same <see cref="OwlInstanceSupertype.InstanceUri"/>.</returns> private bool ObjectIsUniqueSoFar(OwlInstanceSupertype obj) { if (obj == null) { return(true); } return(IncomingResults .Cast <OwlInstanceSupertype>() .Where(o => o.InstanceUri == obj.InstanceUri) .Count() == 0); }
public void InstanceUriTest() { OwlInstanceSupertype target = new OwlInstanceSupertype(); string val = "http://tempuri.net/uri"; // TODO: Assign to an appropriate value for the property target.InstanceUri = val; Assert.AreEqual(val, target.InstanceUri, "VDS.RDF.Linq.OwlInstanceSupertype.InstanceUri was not set correctly."); }
/// <summary> /// Gets the Text of the SPARQL Update Command which will be used to Save the Object to the underlying Store /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to save to</param> /// <returns></returns> public String GetSaveCommandText(OwlInstanceSupertype oc, String graphUri) { if (oc == null) { throw new ArgumentNullException("oc", "Cannot persist a Null Object"); } Type t = oc.GetType(); PropertyInfo[] propInfo = t.GetProperties(); //Start building an INSERT DATA command StringBuilder persistCommand = new StringBuilder(); persistCommand.AppendLine("INSERT DATA {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } //Assert the Type Triple persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.Append(" a "); persistCommand.Append(this.FormatAsUri(OwlClassSupertype.GetOwlClassUri(t))); persistCommand.AppendLine(" ."); //Assert Triples for annotated properties Graph g = new Graph(); foreach (PropertyInfo info in propInfo) { this.GetTripleText(oc, info, g, persistCommand); } //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the INSERT DATA command persistCommand.AppendLine("}"); return(persistCommand.ToString()); }
public static void Add(this IInMemoryQueryableStore ms, OwlInstanceSupertype oc) { using (var ls = new LoggingScope("MemoryStoreExtensions.Add")) { Type t = oc.GetType(); Console.WriteLine(oc.InstanceUri); PropertyInfo[] pia = t.GetProperties(); IGraph g = ms.GetDefaultGraph(); g.Assert(g.CreateUriNode(new Uri(oc.InstanceUri)), g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)), g.CreateUriNode(new Uri(OwlClassSupertype.GetOwlClassUri(t)))); foreach (PropertyInfo pi in pia) { if (pi.IsOntologyResource()) { AddPropertyToStore(oc, pi, ms); } } } }
/// <summary> /// Gets the Text of the SPARQL Update Command which will be used to Save the Object to the underlying Store /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to save to</param> /// <returns></returns> public String GetSaveCommandText(OwlInstanceSupertype oc, String graphUri) { if (oc == null) throw new ArgumentNullException("oc", "Cannot persist a Null Object"); Type t = oc.GetType(); PropertyInfo[] propInfo = t.GetProperties(); //Start building an INSERT DATA command StringBuilder persistCommand = new StringBuilder(); persistCommand.AppendLine("INSERT DATA {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } //Assert the Type Triple persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.Append(" a "); persistCommand.Append(this.FormatAsUri(OwlClassSupertype.GetOwlClassUri(t))); persistCommand.AppendLine(" ."); //Assert Triples for annotated properties Graph g = new Graph(); foreach (PropertyInfo info in propInfo) { this.GetTripleText(oc, info, g, persistCommand); } //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the INSERT DATA command persistCommand.AppendLine("}"); return persistCommand.ToString(); }
private static void AddPropertyToStore(OwlInstanceSupertype supertype, PropertyInfo pi, IInMemoryQueryableStore ms) { if (supertype == null) throw new ArgumentNullException("supertype"); if (pi == null) throw new ArgumentNullException("pi"); if (ms == null) throw new ArgumentNullException("ms"); if (pi.GetValue(supertype, null) != null) { Add(supertype.InstanceUri, pi.GetOwlResourceUri(), pi.GetValue(supertype, null).ToString(), ms); #region Tracing #line hidden if (Logger.IsDebugEnabled) { Logger.Debug("Added property {0} to store.", pi.Name); } #line default #endregion } }
public DeletionAction(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { this._oc = oc; this._graphUri = graphUri; this._mode = mode; }
public static bool StmtSubjectWithObjectAndPredicate(this OwlInstanceSupertype set, string objectUri, string predicateUri) { return(true); }
/// <summary> /// Gets the Text of the SPARQL Update Command which will be used to Delete the Object from the underlying Store /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> /// <returns></returns> public String GetDeletionCommandText(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) throw new ArgumentNullException("oc", "Cannot delete a Null Object"); StringBuilder persistCommand = new StringBuilder(); switch (mode) { case LinqDeleteMode.DeleteAll: //Delete all the Triples with this Object's Instance URI as the Subject/Object //Start building a pair of DELETE WHERE commands persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.AppendLine(" ?p ?o ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the first DELETE WHERE command persistCommand.AppendLine("} ;"); //Create the second DELETE WHERE command persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append("?s ?p "); persistCommand.AppendLine(this.FormatAsUri(oc.InstanceUri) + " ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the second DELETE WHERE command persistCommand.AppendLine("} ;"); return persistCommand.ToString(); case LinqDeleteMode.DeleteValues: //Delete the specific Values associated with this Object Type t = oc.GetType(); PropertyInfo[] propInfo = t.GetProperties(); //Start building an DELETE DATA command persistCommand.AppendLine("DELETE DATA {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } //Assert the Type Triple persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.Append(" a "); persistCommand.Append(this.FormatAsUri(OwlClassSupertype.GetOwlClassUri(t))); persistCommand.AppendLine(" ."); //Assert Triples for annotated properties Graph g = new Graph(); foreach (PropertyInfo info in propInfo) { this.GetTripleText(oc, info, g, persistCommand); } //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the DELETE DATA command persistCommand.AppendLine("}"); return persistCommand.ToString(); default: throw new LinqToRdfException("Not a valid Linq Delete Mode"); } }
public AdditionAction(OwlInstanceSupertype oc, String graphUri) { this._oc = oc; this._graphUri = graphUri; }
/// <summary> /// Saves an Object to the underlying Store using SPARQL Update /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">Graph URI</param> /// <remarks> /// Does not remove any previous version of the Object, to do this use the <see cref="LinqUpdateProcessor.DeleteObject">DeleteObject()</see> method prior to saving an Object /// </remarks> public void SaveObject(OwlInstanceSupertype oc, String graphUri) { if (oc == null) throw new ArgumentNullException("oc", "Cannot persist a Null Object"); SparqlUpdateCommandSet cmds = this._parser.ParseFromString(this.GetSaveCommandText(oc, graphUri)); this._underlyingProcessor.ProcessCommandSet(cmds); }
private void GetTripleText(OwlInstanceSupertype oc, PropertyInfo info, IGraph g, StringBuilder sb) { if (info.GetValue(oc, null) != null) { if (info.GetOwlResource() == null) return; sb.Append(this.FormatAsUri(oc.InstanceUri)); sb.Append(' '); sb.Append(this.FormatAsUri(info.GetOwlResourceUri())); sb.Append(' '); String dtUri = info.GetDatatypeUri(); if (dtUri == null) { sb.Append(this.Format(g.CreateLiteralNode(info.GetValue(oc, null).ToString()))); } else { sb.Append(this.Format(g.CreateLiteralNode(info.GetValue(oc, null).ToString(), new Uri(dtUri)))); } sb.AppendLine(" ."); } }
/// <summary> /// Deletes an Object from the underlying Store using SPARQL Update /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> public void DeleteObject(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) throw new ArgumentNullException("oc", "Cannot delete a Null Object"); SparqlUpdateCommandSet cmds = this._parser.ParseFromString(this.GetDeletionCommandText(oc, graphUri, mode)); this._underlyingProcessor.ProcessCommandSet(cmds); }
/// <summary> /// Gets the Text of the SPARQL Update Command which will be used to Delete the Object from the underlying Store /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> /// <returns></returns> public String GetDeletionCommandText(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) { throw new ArgumentNullException("oc", "Cannot delete a Null Object"); } StringBuilder persistCommand = new StringBuilder(); switch (mode) { case LinqDeleteMode.DeleteAll: //Delete all the Triples with this Object's Instance URI as the Subject/Object //Start building a pair of DELETE WHERE commands persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.AppendLine(" ?p ?o ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the first DELETE WHERE command persistCommand.AppendLine("} ;"); //Create the second DELETE WHERE command persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append("?s ?p "); persistCommand.AppendLine(this.FormatAsUri(oc.InstanceUri) + " ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the second DELETE WHERE command persistCommand.AppendLine("} ;"); return(persistCommand.ToString()); case LinqDeleteMode.DeleteValues: //Delete the specific Values associated with this Object Type t = oc.GetType(); PropertyInfo[] propInfo = t.GetProperties(); //Start building an DELETE DATA command persistCommand.AppendLine("DELETE DATA {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } //Assert the Type Triple persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.Append(" a "); persistCommand.Append(this.FormatAsUri(OwlClassSupertype.GetOwlClassUri(t))); persistCommand.AppendLine(" ."); //Assert Triples for annotated properties Graph g = new Graph(); foreach (PropertyInfo info in propInfo) { this.GetTripleText(oc, info, g, persistCommand); } //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the DELETE DATA command persistCommand.AppendLine("}"); return(persistCommand.ToString()); default: throw new LinqToRdfException("Not a valid Linq Delete Mode"); } }
/// <summary> /// Returns true if the result is unique among the results so far received. /// </summary> /// <param name="obj">The object that is potentially to be added to the results collection.</param> /// <returns>true if there is no object among the <see cref="IncomingResults"/> with the same <see cref="OwlInstanceSupertype.InstanceUri"/>.</returns> private bool ObjectIsUniqueSoFar(OwlInstanceSupertype obj) { if (obj == null) { return true; } return IncomingResults .Cast<OwlInstanceSupertype>() .Where(o => o.InstanceUri == obj.InstanceUri) .Count() == 0; }
public static bool OccursAsStmtObjectWithUri(this OwlInstanceSupertype set, string Uri) { return(true); }