As part of our enterprise cross media search solution with MICO platform, we have implemented a Java client to connect with MICO platform. But the idea of MICO client is that it is not limited to our use case. It is aimed at providing a set of generic methods to access MICO API and other projects are encouraged to use this client library. Currently, this provides a set of methods for creating and submitting content items to the MICO platform and also provides a query client for querying Marmotta back-end for extracted metadata for content items. Source code for MICO client can be found on GitHub here. MICO Java Client is released under Apache License, Version 2.0.

Building MICO Client

git clone https://github.com/zaizi/mico-client.git
cd mico-client
mvn clean install -DskipTest

Using MICO Client in a Java Project

Add MICO Client as a dependency

<dependency>
      <groupId>org.zaizi</groupId>
      <artifactId>mico.client</artifactId>
      <version>1.0</version>
</dependency>

 

Create and Inject a Content Item to MICO Platform

Injector classes provide methods for creating and submitting content items to MICO platform.

MicoClientFactory micoClientfactory = new MicoClientFactory(MICO_HOST, MICO_USER, MICO_PASSWORD);
Injector injector = micoClientfactory.createInjectorClient();
ContentItem contentItem = injector.createContentItem();
ContentPart contentPart = injector.addContentPart(contentItem, mimetype, name, inputstream);
contentItem.addContentPart(contentPart);
injector.submitContentItem(contentItem);

Querying MICO platform

You can use QueryClient for querying extractor results from MICO platform. Internally this uses Anno4j for querying the platform. Since MICO extractor process is asynchronous, you will need to use StatusChecker to poll the status of a given content item to identify whether the content item is processed or not by the extractors chain.

MicoClientFactory micoClientfactory = new MicoClientFactory(MICO_HOST, MICO_USER, MICO_PASSWORD);
QueryClient queryClient = micoClientfactory.createQueryServiceClient();
StatusChecker statusChecker = micoClientfactory.createStatusChecker();
List<StatusResponse> statusResponses = statusChecker.checkItemStatus(micoItem.getMicoUri(), true);
if (!statusResponses.isEmpty())
{
    StatusResponse statusResponse = statusResponses.get(0);
    if (statusResponse.isFinished()){
           List<LinkedEntity> linkedEntities = queryClient.getLinkedEntities(contentItemUri);
    }
}

LDPathUtil class provides a way to create more complex queries using the power of LDPath filtering. For example following example returns linked entities without entity type “dbo:TopicalConcept”.

Map<String,String> namespaces = new HashMap<String,String>();
namespaces.put("dbo", "http://dbpedia.org/ontology/");
Map<String,String> pathValues = new HashMap<String,String>();
pathValues.put("fam:entity-type", "dbo:TopicalConcept");
boolean conjunction = true;
boolean disjunction = false;
boolean notFilter = true;
String criteria = LDPathUtil.getResourcePathValueTests("oa:hasBody", pathValues, conjunction, disjunction, notFilter);
 
List<LinkedEntity> linkedEntities = queryClient.getLinkedEntities(contentItemUri, namespaces,
                            criteria);

We will keep you updated with improvements on MICO Client. Please contact us for more details and any issues on our GitHub page.