Search code examples
c#ontologydotnetrdf

Read RDF/XML file in c#


i'm struggling with reading OWL file in c# and i want to solve this problem, because i'm new to the semantic web world I have read about the dotnetrdf library which is used for reading OWL file in c# and asp.net through their documentation I found example about the Hello world my question here when i put the code

        IGraph g = new Graph();
        g.LoadFromFile("Helloworld.owl");
        IUriNode dotNetRDF = g.CreateUriNode(UriFactory.Create("http://www.dotnetrdf.org"));
        IUriNode says = g.CreateUriNode(UriFactory.Create("http://example.org/says"));
        ILiteralNode helloWorld = g.CreateLiteralNode("Hello World");
        ILiteralNode bonjourMonde = g.CreateLiteralNode("Bonjour tout le Monde", "fr");

        g.Assert(new Triple(dotNetRDF, says, helloWorld));
        g.Assert(new Triple(dotNetRDF, says, bonjourMonde));
        foreach (Triple t in g.Triples)
        {
            Console.WriteLine(t.ToString());
        }
        Console.ReadLine();

it give me the output like this

http://www.dotnetrdf.org/ , http://example.org/says , Hello World
http://www.dotnetrdf.org/ , http://example.org/says , Bonjour tout le Monde@fr

so how can i display the result without the URI, please any idea about this???


Solution

  • With Console.WriteLine(t.ToString()) a string representation of the Triple objects is printed to the console. If you want to access a specific member (have a look at http://www.dotnetrdf.org/api/dotNetRDF~VDS.RDF.Triple~Members.html) then you can access directly. e.g.

    foreach (Triple t in g.Triples)
    {
         Console.WriteLine(t.Predicate);
         Console.WriteLine(t.Subject);
         Console.WriteLine(t.Object);
    }
    

    Hope this helps.