Exemplo n.º 1
0
    static void Main(string[] args)
    {
        ParserFactory      parserFactory      = new XsltParserFactory();
        TripleStoreFactory tripleStoreFactory = new MemoryTripleStoreFactory();

        TripleStore model = tripleStoreFactory.MakeTripleStore();

        // Parse the bloggers RDF file
        FileStream fileStream = new FileStream("./bloggers.rdf", FileMode.Open);

        Parser parser = parserFactory.MakeParser(tripleStoreFactory.MakeResourceFactory(), new StatementFactory());

        parser.NewStatement += model.GetStatementHandler();
        parser.Parse(fileStream, "");
        parser.NewStatement -= model.GetStatementHandler();


        /* Define the query. Equivalent to:
         *      ?blogger rdf:type foaf:Agent .
         *      ?blogger foaf:name ?name .
         */
        Query queryListOfBloggers = new Query();

        queryListOfBloggers.AddPattern(new Pattern(new Variable("blogger"), new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new UriRef("http://xmlns.com/foaf/0.1/Agent")));
        queryListOfBloggers.AddPattern(new Pattern(new Variable("blogger"), new UriRef("http://xmlns.com/foaf/0.1/name"), new Variable("name")));

        IEnumerator solutions = model.Solve(queryListOfBloggers);

        while (solutions.MoveNext())
        {
            QuerySolution solution = (QuerySolution)solutions.Current;
            Console.WriteLine(solution["name"]);
        }
    }
Exemplo n.º 2
0
 /// <summary>Parses the supplied RDF and adds any resulting statements into the KnowledgeBase</summary>
 /// <param name="reader">The TextReader containing the RDF data to read.</param>
 /// <param name="baseUri">A uri to be used by the KnowledgeBase to resolve relative uris in the RDF data.</param>
 public virtual void IncludeSchema(TextReader reader, string baseUri)
 {
     try {
         Parser parser = GetParser();
         parser.NewStatement += itsSchemas.GetStatementHandler();
         parser.Parse(reader, baseUri);
         parser.NewStatement -= itsSchemas.GetStatementHandler();
     }
     catch (ParserException e) {
         throw new KnowledgeBaseException("Problem including RDF from reader", e);
     }
 }
Exemplo n.º 3
0
        public void ReadAndWriteRdf()
        {
            StringReader reader = new StringReader("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description rdf:about=\"http://example.org/node\"><rdf:type rdf:resource=\"http://example.org/type\"/></rdf:Description></rdf:RDF>");

            TripleStore store = MakeNewTripleStore();

            SemPlan.Spiral.Core.ParserFactory parserFactory = new SemPlan.Spiral.XsltParser.XsltParserFactory();
            SemPlan.Spiral.Core.Parser        parser        = parserFactory.MakeParser(new ResourceFactory(), new StatementFactory());

            parser.NewStatement += store.GetStatementHandler();
            parser.Parse(reader, "http://example.org/node");
            parser.NewStatement -= store.GetStatementHandler();

            StringWriter  output = new StringWriter();
            NTripleWriter writer = new NTripleWriter(output);

            store.Write(writer);

            Assert.AreEqual("<http://example.org/node> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/type> .\r\n", output.ToString());
            store.Clear();
        }
Exemplo n.º 4
0
        /// <summary>Examines the supplied ConciseBoundedDescription and attempts to locate more information about the described resource.</summary>
        /// <param name="resourceDescription">A ConciseBoundedDescription about which more information is required.</param>
        /// <param name="investigator">An investigator that encapsulates the algorithm to be used to locate more information.</param>
        public virtual void Investigate(ConciseBoundedDescription resourceDescription, Investigator investigator)
        {
            SemPlan.Spiral.Core.ResourceFactory resourceFactory = itsTripleStoreFactory.MakeResourceFactory();

            investigator.NewStatement += itsAssertions.GetStatementHandler();
            investigator.investigate(resourceDescription, this, itsParserFactory, resourceFactory, itsStatementFactory, itsDereferencer);
            investigator.NewStatement -= itsAssertions.GetStatementHandler();
        }