The diagram below represents the Ontology that I created using Protege 3.4.8.

RDF - Graphical Representation

What I would like is to create a dotNet application that can add instances (or individuals) to the same, automatically after reading values from a database, say an Excel file. For e.g.: If I have an Excel file that has the following data,

Person | Name | Gender | Characteristics P1 A Male Linear P2 B Female Random

I can add these data manually through Protege itself and the following data will be appended to the RDF file within the rdf tags:

<Person rdf:ID="P1"> <hasCharacteristics rdf:resource="#Linear"/> <hasSex rdf:resource="#Male"/> <name rdf:datatype="&xsd;string">A</name> </Person> <Person rdf:ID="P2"> <hasCharacteristics rdf:resource="#Random"/> <hasSex rdf:resource="#Female"/> <name rdf:datatype="&xsd;string">B</name> </Person>

How can I do the same using dotNetRDF as I need to add more that 100 records into the RDF file after reading the same from an Excel file?

asked 15 Jan '13, 01:02

George%20Abraham's gravatar image

George Abraham
accept rate: 16%

edited 15 Jan '13, 01:05

@Rob Vesse or someone, Please help... Thanks in advance..

(16 Jan '13, 05:24) George Abraham George%20Abraham's gravatar image

As far as writing the code to read the records from Excel you will have to do that yourself. But to create the individuals you simply use the Node and Triple API of dotNetRDF. See the Hello World example for some very simple examples of this.

So for example to create the first person in your example there you might do the following:

//Set up a Graph to hold the data
Graph g = new Graph();
g.NamespaceMap.AddNamespace(String.Empty, new Uri("http://your-domain.com/namespace#"));

//Create Nodes to represent your terms
INode rdfType = g.CreateUriNode("rdf:type");
INode person = g.CreateUriNode(":Person");
INode hasCharacteristics = g.CreateUriNode(":hasCharacteristics");
INode hasSex = g.CreateUriNode(":hasSex");
INode name = g.CreateUriNode(":name");

//Create the Triples to represent the first Person
INode p1 = g.CreateBlankNode();
g.Assert(p1, rdfType, person);
g.Assert(p1, hasCharacteristics, g.CreateUriNode(":Linear"));
g.Assert(p1, hasSex, g.CreateUriNode(":Male"));
g.Assert(p1, name, "A".ToLiteral(g));
permanent link

answered 16 Jan '13, 05:32

Rob%20Vesse's gravatar image

Rob Vesse ♦
accept rate: 29%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 15 Jan '13, 01:02

question was seen: 6,316 times

last updated: 16 Jan '13, 05:32