KIM Web Service API can be used by any programming language that has support for Web Services.
The idea of this demo is to show how to make queries and annotate documents using KIM through web-services. While doing semantic annotation, in terms of semantic terminology, we want to extract all the entities from the text and find out to which classes in the ontology hierarchy they belong to.
Software versions:
KIM version: 2.4 , 3.0
Tomcat version: 6.05
Visual Studio: 2008
You can browse a demo Visual Studio 2008 solution from here:
http://kimnetdemos.googlecode.com/svn/trunk/kim-dotnet-nosesame/
You can use a free SVN client (http://tortoisesvn.tigris.org/) and download the solution:
http://kimnetdemos.googlecode.com/svn/trunk/kim-dotnet-nosesame/
You need to have a KIM server running. You must also have the kim-ws-api.war (from “KIM clients”) directory installed in your Tomcat and the Tomcat server running. kim-ws-api.war is a client for KIM which provides the web-service functionality. Please refer to the KIM documentation for more instructions on how to start your KIM server and the Tomcat server.
1. References:
Open http://localhost:8080/kim-ws-api/ to see all the KIM APIs. If you can’t please check your tomcat and then your KIM server instance.
You need to add service references (Windows Communication Foundation) to 2 namespaces if they do not already exist in your project or they are incorrect. They could be incorrect because for example you are using a KIM server that is not on your localhost.
1. SemanticAnnotation (http://localhost:8080/kim-ws-api/services/SemanticAnnotationAPI?wsdl)
2. SemanticRepository (http://localhost:8080/kim-ws-api/services/SemanticRepositoryAPI?wsdl)
Other references are needed to exploit the rest of the functionality provided by KIM.
You can modify the references from the app.config to make sure they point to a working KIM instance. See installing KIM for more info about references. Also one may need to change the values of: maxBufferSize="200000" maxReceivedMessageSize="200000" in the app.config for WCF to prevent .NET from throwing “limit overflow” exception.
2. Queries:
In this document we use the SeRQL language. You can find a nice tutorial here:
http://www.openrdf.org/doc/sesame/users/ch06.html
SPARQL is supported in version 3.0 of KIM.
3. The actual code and some comments:
This code sample makes a query through web-services to KIM and gets a list of companies. The query is also limited to 20 results.
public static void QueryExample()
{
Console.WriteLine("Prcessing Query Example ...");
SemanticRepository.SemanticRepositoryAPI s = new SemanticRepository.SemanticRepositoryAPIClient();
String serql1 = "";
serql1 += "select company, name FROM ";
serql1 += "{company} <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> {<http://proton.semanticweb.org/2006/05/protonu#Company>},";
serql1 += "{company} <http://proton.semanticweb.org/2006/05/protons#hasMainAlias> {alias}, ";
serql1 += "{alias} <http://www.w3.org/2000/01/rdf-schema#label> {name}";
serql1 += " limit 20";
SemanticRepository.SemanticQueryResult result = s.evaluateSelectSeRQL(serql1);
Console.WriteLine(result.Rows.Count());
foreach (SemanticRepository.SemanticQueryResultRow row in result.Rows)
{
foreach (string v in row.Values)
{
Console.Write(v);
}
Console.WriteLine("");
Console.WriteLine("==================================");
}
}
4. Running the demo:
At best you should just need to click Ctrl+F5 in Visual Studio. You also need to supply a document to be annotated when using the Semantic Annotation API. This demo loads the following document through an Internet connection: http://kimnetdemos.googlecode.com/svn/trunk/Documents/sun-ibm.txt
You modify this demo to process thousands of documents.
5. Sesame for .NET
It might be helpful to use a .NET port of Sesame called dotsesame. I personally think that using the dotsesame helps making the code cleaner and easier to read. You should keep in mind two things: which version of .NET Sesame you need - dotsesame or dotsesame 2.x; you will need to use the IKVM dlls version 0.30, with newer version of IKVM you might be getting some weird exceptions.
Warning:
Make sure this demo references a working KIM instance: Ontotext own demo servers or you own local copy of KIM.
KIM is a semantic web platform developed by Ontotext.
Quick links:
The Semantic Annotation Workflow - KIM part 10
KIM Multi-threaded Clustered Client Application - KIM part 9
Gazetteers - KIM/GATE part 7
Strict Rules vs Machine Learning - KIM part 6
Tips and Tricks - KIM part 5
Using a Gate application - KIM part 4
Gate tutorial - KIM part 3
Using KIM from .NET - KIM part 2
Getting Started - KIM part 1
Installation - KIM part 0






