示例#1
0
        public string getSPARQL(SPARQLQueryType queryType)
        {
            StringBuilder query = new StringBuilder();

            foreach (SPARQLPrefix prefix in this.Prefixes)
            {
                query.AppendLine(prefix.GetPrefix());
            }

            switch (queryType)
            {
            case SPARQLQueryType.SELECTDISTINCT:
                query.AppendLine("SELECT DISTINCT");
                foreach (string variable in this.Variables)
                {
                    query.AppendLine(variable);
                }
                foreach (string source in this.Sources)
                {
                    query.AppendLine(String.Format("FROM <{0}>", source));
                }
                query.AppendLine("WHERE ");
                query.AppendLine("{");

                foreach (SPARQLTemplate template in this.Templates)
                {
                    query.Append(template.getWHERE_SPARQL());
                }
                query.AppendLine("}");
                break;

            case SPARQLQueryType.SELECT:
                query.AppendLine("SELECT");
                foreach (string variable in this.Variables)
                {
                    query.AppendLine(variable);
                }
                foreach (string source in this.Sources)
                {
                    query.AppendLine(String.Format("FROM <{0}>", source));
                }
                query.AppendLine("WHERE ");
                query.AppendLine("{");

                foreach (SPARQLTemplate template in this.Templates)
                {
                    query.Append(template.getWHERE_SPARQL());
                }
                query.AppendLine("}");
                break;

            case SPARQLQueryType.INSERTTEMPORAL:
                query.AppendLine("INSERT {");
                foreach (SPARQLTemplate template in this.Templates)
                {
                    query.Append(template.getINSERTTEMPORAL_SPARQL());
                }
                query.AppendLine("}");
                query.AppendLine("WHERE ");
                query.AppendLine("{");

                foreach (SPARQLTemplate template in this.Templates)
                {
                    query.Append(template.getWHERE_SPARQL());
                }
                query.AppendLine("}");
                break;

            case SPARQLQueryType.SELECTFORDELETE:
                query.AppendLine("SELECT");
                foreach (string variable in this.Variables)
                {
                    query.AppendLine(variable);
                }
                query.AppendLine("WHERE ");
                query.AppendLine("{");

                foreach (SPARQLTemplate template in this.Templates)
                {
                    query.Append(template.getDELETEWHERE_SPARQL());
                }
                query.AppendLine("}");
                break;

            case SPARQLQueryType.INSERT:
                query.AppendLine("INSERT {");
                foreach (SPARQLTemplate template in this.Templates)
                {
                    query.Append(template.getINSERT_SPARQL());
                }
                query.AppendLine("}");
                return(query.ToString());
            }


            return(query.ToString());
        }
示例#2
0
 public SPARQLQuery(SPARQLQueryType type)
     : this()
 {
     Type = type;
 }