Ejemplo n.º 1
0
    public static void Main()
    {
        Store store = new MemoryStore();

        store.Import(RdfReader.LoadFromUri(new Uri(example_foaf_file)));

        // Dump out the data, for fun
        using (RdfWriter writer = new RdfXmlWriter(Console.Out)) {
            writer.Write(store);
        }

        Console.WriteLine("These are the people in the file:");
        foreach (Statement s in store.Select(new Statement(null, rdftype, foafPerson)))
        {
            foreach (Resource r in store.SelectObjects(s.Subject, foafname))
            {
                Console.WriteLine(r);
            }
        }
        Console.WriteLine();

        Console.WriteLine("And here's RDF/XML just for some of the file:");
        using (RdfWriter w = new RdfXmlWriter(Console.Out)) {
            store.Select(new Statement(null, foafname, null), w);
            store.Select(new Statement(null, foafknows, null), w);
        }
        Console.WriteLine();
    }
Ejemplo n.º 2
0
    public static void Main()
    {
        // Create the instance data

        MemoryStore dataModel = new MemoryStore();

        BNode me  = new BNode("me");
        BNode you = new BNode("you");

        Entity rdfType    = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
        Entity rdfsLabel  = "http://www.w3.org/2000/01/rdf-schema#label";
        Entity foafPerson = "http://xmlns.com/foaf/0.1/Person";
        Entity foafAgent  = "http://xmlns.com/foaf/0.1/Agent";
        Entity foafName   = "http://xmlns.com/foaf/0.1/name";

        dataModel.Add(new Statement(me, rdfType, foafPerson));
        dataModel.Add(new Statement(you, rdfType, foafPerson));
        dataModel.Add(new Statement(me, foafName, (Literal)"John Doe"));
        dataModel.Add(new Statement(you, foafName, (Literal)"Sam Smith"));

        // Create the RDFS engine and apply it to the data model.

        RDFS engine = new RDFS();

        engine.LoadSchema(RdfReader.LoadFromUri(new Uri("http://xmlns.com/foaf/0.1/index.rdf")));

        dataModel.AddReasoner(engine);

        // Query the data model

        // Ask for who are typed as Agents.  Note that the people are
        // typed as foaf:Person, and the schema asserts that foaf:Person
        // is a subclass of foaf:Agent.
        Console.WriteLine("Who are Agents?");
        foreach (Entity r in dataModel.SelectSubjects(rdfType, foafAgent))
        {
            Console.WriteLine("\t" + r);
        }

        // Ask for the rdfs:labels of everyone.  Note that the data model
        // has foaf:names for the people, and the schema asserts that
        // foaf:name is a subproperty of rdfs:label.
        Console.WriteLine("People's labels:");
        foreach (Statement s in dataModel.Select(new Statement(null, rdfsLabel, null)))
        {
            Console.WriteLine("\t" + s);
        }
    }
Ejemplo n.º 3
0
    public static void Main(string[] args)
    {
        string uri = "http://www.mozilla.org/news.rdf";

        if (args.Length > 0)
        {
            uri = args[0];
        }

        MemoryStore store = new MemoryStore();

        // Here's one way...

        store.Import(RdfReader.LoadFromUri(new Uri(uri)));

        using (RdfWriter writer = new N3Writer(Console.Out))
            store.Select(writer);

        // Or....

        RdfReader file = RdfReader.LoadFromUri(new Uri(uri));

        file.Select(new StatementPrinter());
    }