Пример #1
0
        /// <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());
        }
Пример #2
0
 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);
             }
         }
     }
 }
Пример #3
0
 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();
        }
Пример #5
0
        /// <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>
        /// 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");
            }
        }