当前位置: 首页>>代码示例>>C#>>正文


C# Graph.ExecuteQuery方法代码示例

本文整理汇总了C#中VDS.RDF.Graph.ExecuteQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.ExecuteQuery方法的具体用法?C# Graph.ExecuteQuery怎么用?C# Graph.ExecuteQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VDS.RDF.Graph的用法示例。


在下文中一共展示了Graph.ExecuteQuery方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunList

        public void RunList(String[] args)
        {
            if (args.Length < 2)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: 2 Arguments are required in order to use the -list mode");
                return;
            }

            if (!File.Exists(args[1]))
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot list handlers from " + args[1] + " since the file does not exist");
                return;
            }

            Graph g = new Graph();
            try
            {
                FileLoader.Load(g, args[1]);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot parse the configuration file");
                Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message);
                return;
            }

            Object results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + ListHandlers);
            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;
                Console.WriteLine("rdfWebDeploy: Configuration file contains " + rset.Count + " handler registrations");

                foreach (SparqlResult r in rset)
                {
                    Console.WriteLine();
                    Console.WriteLine("rdfWebDeploy: Handler URI: " + r["handler"].ToString());
                    Console.WriteLine("rdfWebDeploy: Handler Type: " + r["type"].ToString());
                    if (r.HasValue("label"))
                    {
                        Console.WriteLine("rdfWebDeploy: Label: " + r["label"].ToString());
                    }
                }
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:44,代码来源:List.cs

示例2: Main


//.........这里部分代码省略.........
                        reportError(output, "Parsing Exception", parseEx);
                    }
                    catch (RdfException rdfEx)
                    {
                        reportError(output, "RDF Exception", rdfEx);
                    }
                    catch (Exception ex)
                    {
                        reportError(output, "Other Exception", ex);
                    }
                    finally
                    {
                        timer.Stop();

                        //Write the Triples to the Output
                        foreach (Triple t in g.Triples)
                        {
                            Console.WriteLine(t.ToString());
                        }

                        //Now we run the Test SPARQL (if present)
                        if (File.Exists("rdfa_tests/" + Path.GetFileNameWithoutExtension(file) + ".sparql"))
                        {
                            if (skipCheck.Contains(Path.GetFileName(file)))
                            {
                                output.WriteLine("## Skipping Check of File " + Path.GetFileName(file));
                                output.WriteLine();
                            }
                            else
                            {
                                try
                                {
                                    SparqlQuery q = queryparser.ParseFromFile("rdfa_tests/" + Path.GetFileNameWithoutExtension(file) + ".sparql");
                                    Object results = g.ExecuteQuery(q);
                                    if (results is SparqlResultSet)
                                    {
                                        //The Result is the result of the ASK Query
                                        if (falseTests.Contains(Path.GetFileName(file)))
                                        {
                                            passed = !((SparqlResultSet)results).Result;
                                        }
                                        else
                                        {
                                            passed = ((SparqlResultSet)results).Result;
                                        }
                                    }
                                }
                                catch
                                {
                                    passed = false;
                                }
                            }
                        }

                        if (passed && passDesired)
                        {
                            //Passed and we wanted to Pass
                            testsPassed++;
                            output.WriteLine("# Result = Test Passed");
                            totalTime += timer.ElapsedMilliseconds;
                            totalTriples += g.Triples.Count;
                        }
                        else if (!passed && passDesired)
                        {
                            //Failed when we should have Passed
                            testsFailed++;
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:67,代码来源:RdfATestSuite.cs

示例3: ExecuteQuery

        /// <summary>
        /// Выполнение Sparql-запроса
        /// </summary>
        /// <param name="sparqlCommandText">Текст Sparql-запроса</param>
        /// <returns>Результат запроса в виде текста</returns>
        public string ExecuteQuery(string sparqlCommandText)
        {
            using (Graph baseGraph = new Graph())
            {
                RdfXmlParser fileParser = new RdfXmlParser();
                foreach (string fileName in FilesToQuery)
                {
                    if (String.IsNullOrWhiteSpace(fileName))
                        continue;

                    using (Graph g = new Graph())
                    {
                        try
                        {
                            fileParser.Load(g, fileName);
                            baseGraph.Merge(g);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(String.Format("Ошибка при обработке файла {0}\r\n{1}",fileName, ex.Message), ex);
                        }
                    }
                }

                var resultSet = baseGraph.ExecuteQuery(sparqlCommandText);

                if (resultSet is SparqlResultSet)
                {
                    SparqlResultSet outputSet = resultSet as SparqlResultSet;

                    if (outputSet.IsEmpty)
                        QueryResult = "Пустой результат";
                    else
                    {
                        StringBuilder outputString = new StringBuilder();
                        foreach (SparqlResult result in outputSet.Results)
                            outputString.AppendLine(result.ToString());

                        QueryResult = outputString.ToString();
                    }
                }
                else if (resultSet is Graph)
                {
                    Graph resultGraph = resultSet as Graph;

                    if (resultGraph.IsEmpty)
                        QueryResult = "Пустой граф";
                    else
                        QueryResult = VDS.RDF.Writing.StringWriter.Write(resultGraph, new RdfXmlWriter());
                }
                else
                {
                    QueryResult = string.Format("Неизвестный результат: {0}", resultSet.GetType());
                }

                return QueryResult;
            }
        }
开发者ID:Tihocoder,项目名称:SemanticDataEnrichment,代码行数:63,代码来源:RdfQueryViewModel.cs

示例4: SparqlAnton

        public void SparqlAnton()
        {
            Graph g = new Graph();
            FileLoader.Load(g, "anton.rdf");

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery query = parser.ParseFromFile("anton.rq");

            Object results = g.ExecuteQuery(query);
            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    Console.WriteLine(r);
                }
                Assert.AreEqual(1, rset.Count, "Should be exactly 1 result");
            }
            else
            {
                Assert.Fail("Query should have returned a Result Set");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:23,代码来源:SparqlTests.cs

示例5: RunTest

        public void RunTest(String[] args)
        {
            if (args.Length < 2)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: 2 Arguments are required in order to use the -test mode");
                return;
            }

            if (!File.Exists(args[1]))
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot test " + args[1] + " since the file does not exist");
                return;
            }

            Graph g = new Graph();
            try
            {
                FileLoader.Load(g, args[1]);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot parse the configuration file");
                Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message);
                return;
            }
            Console.WriteLine("rdfWebDeploy: Opened the configuration file successfully");

            Graph vocab = new Graph();
            try
            {
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(vocab, new StreamReader(Assembly.GetAssembly(typeof(IGraph)).GetManifestResourceStream("VDS.RDF.Configuration.configuration.ttl")));
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot parse the configuration vocabulary");
                Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message);
                return;
            }
            Console.WriteLine("rdfWebDeploy: Loaded the configuration vocabulary successfully");
            Console.WriteLine();
            Console.WriteLine("rdfWebDeploy: Tests Started...");
            Console.WriteLine();

            //Now make some tests against it
            int warnings = 0, errors = 0;
            IInMemoryQueryableStore store = new TripleStore();
            store.Add(vocab);
            if (g.BaseUri == null) g.BaseUri = new Uri("dotnetrdf:config");
            store.Add(g);
            Object results;
            SparqlResultSet rset;

            //Unknown vocabulary term test
            Console.WriteLine("rdfWebDeploy: Testing for URIs in the vocabulary namespace which are unknown");
            results = store.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + UnknownVocabularyTermsTest);
            if (results is SparqlResultSet)
            {
                rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: The configuration file uses the URI '" + r["term"] + "' for a property/type and this does not appear to be a valid term in the Configuration vocabulary");
                    errors++;
                }
            }
            Console.WriteLine();

            #region General dnr:type Tests

            //Missing dnr:type test
            Console.WriteLine("rdfWebDeploy: Testing for missing dnr:type properties");
            results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + MissingConfigurationTypeTest);
            if (results is SparqlResultSet)
            {
                rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    Console.Error.WriteLine("rdfWebDeploy: Warning: The Node '" + r["s"].ToString() + "' has an rdf:type but no dnr:type which may be needed by the Configuration Loader");
                    warnings++;
                }
            }
            Console.WriteLine();

            //Invalid dnr:type test
            Console.WriteLine("rdfWebDeploy: Testing that values given for dnr:type property are literals");
            results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + InvalidTypePropertyTest);
            if (results is SparqlResultSet)
            {
                rset = (SparqlResultSet)results;
                foreach (SparqlResult r in rset)
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: The node '" + r["s"].ToString() + "' has a dnr:type of '" + r["type"].ToString() + "' which is not given as a string literal");
                    errors++;
                }
            }
            Console.WriteLine();

            //Multiple dnr:type test
            Console.WriteLine("rdfWebDeploy: Testing that no object has multiple dnr:type values");
            results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + MultipleTypeTest);
//.........这里部分代码省略.........
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:101,代码来源:Test.cs

示例6: LoadNamespaceTerms

        public static IEnumerable<NamespaceTerm> LoadNamespaceTerms(String namespaceUri)
        {
            //Don't load if already loaded
            if (_loadedNamespaces.Contains(namespaceUri)) return GetNamespaceTerms(namespaceUri);

            try
            {
                Graph g = new Graph();
                try
                {
                    UriLoader.Load(g, new Uri(namespaceUri));
                }
                catch
                {
                    //Try and load from our local copy if there is one
                    String prefix = GetDefaultPrefix(namespaceUri);
                    if (!prefix.Equals(String.Empty))
                    {
                        Stream localCopy = Assembly.GetExecutingAssembly().GetManifestResourceStream("rdfEditor.AutoComplete.Vocabularies." + prefix + ".ttl");
                        if (localCopy != null)
                        {
                            TurtleParser ttlparser = new TurtleParser();
                            ttlparser.Load(g, new StreamReader(localCopy));
                        }
                    }
                }
                List<NamespaceTerm> terms = new List<NamespaceTerm>();
                String termUri;

                //UriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
                IUriNode rdfsClass = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "Class"));
                IUriNode rdfsLabel = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label"));
                IUriNode rdfsComment = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "comment"));
                IUriNode rdfProperty = g.CreateUriNode(new Uri(NamespaceMapper.RDF + "Property"));
                IUriNode rdfsDatatype = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "Datatype"));

                SparqlParameterizedString queryString = new SparqlParameterizedString();
                queryString.CommandText = "SELECT ?term STR(?label) AS ?RawLabel STR(?comment) AS ?RawComment WHERE { {{?term a @class} UNION {?term a @property} UNION {?term a @datatype}} OPTIONAL {?term @label ?label} OPTIONAL {?term @comment ?comment} }";
                queryString.SetParameter("class", rdfsClass);
                queryString.SetParameter("property", rdfProperty);
                queryString.SetParameter("datatype", rdfsDatatype);
                queryString.SetParameter("label", rdfsLabel);
                queryString.SetParameter("comment", rdfsComment);

                Object results = g.ExecuteQuery(queryString.ToString());
                if (results is SparqlResultSet)
                {
                    foreach (SparqlResult r in ((SparqlResultSet)results))
                    {
                        termUri = r["term"].ToString();
                        if (termUri.StartsWith(namespaceUri))
                        {
                            //Use the Comment as the label if available
                            if (r.HasValue("RawComment"))
                            {
                                if (r["RawComment"] != null)
                                {
                                    terms.Add(new NamespaceTerm(namespaceUri, termUri.Substring(namespaceUri.Length), r["RawComment"].ToString()));
                                    continue;
                                }
                            }

                            //Use the Label as the label if available
                            if (r.HasValue("RawLabel"))
                            {
                                if (r["RawLabel"] != null)
                                {
                                    terms.Add(new NamespaceTerm(namespaceUri, termUri.Substring(namespaceUri.Length), r["RawLabel"].ToString()));
                                    continue;
                                }
                            }

                            //Otherwise no label
                            terms.Add(new NamespaceTerm(namespaceUri, termUri.Substring(namespaceUri.Length)));
                        }
                    }
                }

                lock (_terms)
                {
                    terms.RemoveAll(t => _terms.Contains(t));
                    _terms.AddRange(terms.Distinct());
                }
            }
            catch
            {
                //Ignore Exceptions - just means we won't have those namespace terms available
            }
            try
            {
                _loadedNamespaces.Add(namespaceUri);
            }
            catch (NullReferenceException)
            {
                //For some reason .Net sometimes throws a NullReferenceException here which we shall ignore
            }
            return GetNamespaceTerms(namespaceUri);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:98,代码来源:AutoCompleteManager.cs

示例7: TestRDF

        //static void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        //{
        //    if (e.PropertyName == "ConsoleOutput")
        //        Console.WriteLine((sender as ProcessViewModel).ConsoleOutput);
        //}
        /// <summary>
        /// https://bitbucket.org/dotnetrdf/dotnetrdf/wiki/User%20Guide
        /// </summary>
        static void TestRDF()
        {
            IGraph g = new Graph();
            RdfXmlParser fileParser = new RdfXmlParser();
            //fileParser.Load(g, "schema.xml");
            fileParser.Load(g, "TestRdf.xml");

            //SparqlQueryParser queryParser = new SparqlQueryParser();
            //queryParser.ParseFromString("SELECT * WHERE { ?s a ?type }");
            //VDS.RDF.Writing.StringWriter.Write(g, new RdfXmlWriter())

            StringBuilder div = new StringBuilder();

            XElement rdf = XElement.Parse(VDS.RDF.Writing.StringWriter.Write(g, new RdfXmlWriter()));
            foreach (XElement element in rdf.Elements())
            {
                div.AppendFormat("<div itemscope itemtype=\"{0}/{1}\">", element.Name.NamespaceName.TrimEnd('/'), element.Name.LocalName);
                div.AppendLine();
                foreach (XElement content in element.Elements())
                {
                    div.AppendFormat("<meta itemprop=\"{0}\" content=\"{1}\">", content.Name.LocalName, content.Value);
                    div.AppendLine();
                }
                div.AppendLine("</div>");
            }

            var output = g.ExecuteQuery("SELECT * WHERE { ?s a ?type }");

            SparqlParameterizedString query = new SparqlParameterizedString();
            query.Namespaces.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
            query.Namespaces.AddNamespace("owl", new Uri("http://www.w3.org/2002/07/owl#"));
            query.Namespaces.AddNamespace("xsd", new Uri("http://www.w3.org/2001/XMLSchema#"));
            query.Namespaces.AddNamespace("rdfs", new Uri("http://www.w3.org/2000/01/rdf-schema#"));
            query.Namespaces.AddNamespace("schema", new Uri("http://schema.org/"));
            query.Namespaces.AddNamespace("fact", new Uri("http://www.co-ode.org/ontologies/ont.owl#"));

            query.CommandText = "SELECT * WHERE { ?organization rdf:type fact:UniqueCompany }";

            var output2 = g.ExecuteQuery(query);

            //            var output2 = g.ExecuteQuery(@"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            //										PREFIX owl: <http://www.w3.org/2002/07/owl#>
            //										PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            //										PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            //										PREFIX schema: <http://schema.org/>
            //										PREFIX fact:<http://www.co-ode.org/ontologies/ont.owl#>
            //										SELECT *
            //										WHERE { ?organization rdf:type fact:UniqueCompany }");
        }
开发者ID:Tihocoder,项目名称:SemanticDataEnrichment,代码行数:57,代码来源:Program.cs


注:本文中的VDS.RDF.Graph.ExecuteQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。