Hi,

There are numerous ways, to import data into the semantic repository. It depends on the specific circumstances which method will suit you best.

If you want to enrich the knowledge base with some information you already know, the best way is to import it in Sesame on startup. This is easily done by constructing an ntriples file containing those facts. In your case, I guess Sani Abacha and Mohammed Abacha both exist as trusted entities in your KB and you know their URIs. Let's say they are http://www.ontotext.com/kim/2006/05/wkb#Person_T.1 for Sani Abacha and http://www.ontotext.com/kim/2006/05/wkb#Person_T.2 for Mohammed Abacha. Then you should add this triple to the file:

<http://www.ontotext.com/kim/2006/05/wkb#Person_T.1> <http://proton.semanticweb.org/2005/04/protont#hasChild> <http://www.ontotext.com/kim/2006/05/wkb#Person_T.2> .

Describe all the relations you know in this file, then include the file in $KIM_HOME/config/sesame.inmem.conf . This will make Sesame read and import the triples on startup. Beware though, that when you change the file you will need to clear the cache in $KIM_HOME/context/default/populated.

Another way to import multiple statements in the semantic repository is through the SemanticRepositoryAPI's importData() method.

If you have to get the URIs at runtime and create the relations there, you can do it with SemanticRepositoryAPI's addStatement() mechanism. This is an example code describing how to do that:


       // connect to KIMService (deployed on specific host and port)
       KIMService serviceKim = GetService.from();
       // obtain the semantic repository interface
       apiSesame = serviceKim.getSemanticRepositoryAPI();

       SemanticQueryResult person1result = apiSesame
.evaluateSelectSeRQL("select X from {X} rdf:type {<"+PROTONTConstants.CLASS_PERSON+">}; rdfs:label {\"Sani Abacha\"} ");
       if (person1result.size() != 1)
throw new RuntimeException("Unexpected result size: " + person1result.size());
       String person1 = person1result.iterator().next().get(0).toString();
SemanticQueryResult person2result = apiSesame .evaluateSelectSeRQL("select X from {X} rdf:type {<"+PROTONTConstants.CLASS_PERSON+">}; rdfs:label {\"Mohammed Abacha\"} ");
       if (person1result.size() != 1)
throw new RuntimeException("Unexpected result size: " + person1result.size());
       String person2 = person1result.iterator().next().get(0).toString();
apiSesame.addStatement(new URIImpl(person1), new URIImpl(PROTONTConstants.PROPERTY_HAS_CHILD), new URIImpl(person2)); You can find all the information you need about proton on its homepage - http://proton.semanticweb.org/ . Please have in mind the namespace the different modules use. In your version it should be http://proton.semanticweb.org/2006/05/protont for the top module, http://proton.semanticweb.org/2006/05/protonu for the uppper module etc. Using old namespace is a mistake easy to make and hard to find.

Greetings,
Philip


Kaspar Fischer wrote:
Dear list,

I want to add structured data to KIM. Looking at the APIs, I see to ways:

- SemanticRepositoryAPI's addStatement(): adds a triple (subject, predicate, object) http://nmwiki.semanticannotation.com/kim-javadoc/com/ontotext/kim/client/semanticrepository/SimplifiedSemanticRepositoryAPI.html#addStatement(org.openrdf.model.Resource,%20org.openrdf.model.URI,%20org.openrdf.model.Value)

- SemanticRepositoryAPI's importData() variants: adds data from a RDF file http://nmwiki.semanticannotation.com/kim-javadoc/com/ontotext/kim/client/semanticrepository/SemanticRepositoryAPI.html#importData(java.lang.String,%20java.lang.String,%20org.openrdf.sesame.constants.RDFFormat,%20boolean)

Does anybody have some sample/unit test code to illustrate both methods?

For instance, I have to person entities in my repo: "Sani Abacha" and "Mohammed Abacha", the former's son. I want to add the relationship ("Sani Abacha", hasChild, "Mohammed Abacha"), for instance. In order to use SemanticRepositoryAPI's addStatement(), I would search for the two entities using SeRQL, RQL, or the QueryAPI (all work for this, right?) and would look up the desired relation in http://proton.semanticweb.org/2005/04/protont (is there a documentation/"ProtonDoc" for it?). Correct?

Thanks,
Kaspar
_______________________________________________
Kim-discussion mailing list
Kim-discussion@ontotext.com
http://ontotext.com/mailman/listinfo/kim-discussion


_______________________________________________
Kim-discussion mailing list
Kim-discussion@ontotext.com
http://ontotext.com/mailman/listinfo/kim-discussion

Reply via email to