package org.epnoi.learner.relations.corpus.parallel;


import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import gate.Document;
import org.epnoi.model.rdf.RDFHelper;
import org.epnoi.uia.commons.GateUtils;

import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

public class UriToAnnotatedDocumentFlatMapper {

   private String uiaPath;
    private final String knowledgeBasePath = "/uia/annotatedcontent";

    public UriToAnnotatedDocumentFlatMapper(String uiaPath) {
        this.uiaPath=uiaPath;
    }

    public Iterable<Document> call(String uri) throws Exception {
        List<Document> sectionsAnnotatedContent = new ArrayList<>();

        Document annotatedContent = _obtainAnnotatedContent(uri);

        if (annotatedContent != null) {
            sectionsAnnotatedContent.add(annotatedContent);
        }
        return sectionsAnnotatedContent;
    }

    // --------------------------------------------------------------------------------------------------------------------

    private Document _obtainAnnotatedContent(String uri) {

        ClientConfig config = new DefaultClientConfig();

        Client client = Client.create(config);

        Document document = null;
        try {

            URI testServiceURI = UriBuilder.fromUri(this.uiaPath).build();
            WebResource service = client.resource(this.uiaPath);

            String content = service.path(knowledgeBasePath).queryParam("uri", uri)
                    .queryParam("type", RDFHelper.WIKIPEDIA_PAGE_CLASS).type(javax.ws.rs.core.MediaType.APPLICATION_XML)
                    .get(String.class);


            document = GateUtils.deserializeGATEDocument(content);
        } catch (Exception e) {
            e.printStackTrace();


        }

        return document;
    }

    // --------------------------------------------------------------------------------------------------------------------

}

@@ -268,24 +268,93 @@
 e.Document;%0A
+import org.epnoi.model.clients.thrift.AnnotatedContentServiceClient;%0A
 import org.e
@@ -1320,16 +1320,18 @@
  uri) %7B%0A
+/*
 %0A       
@@ -2014,32 +2014,543 @@
   %7D%0A
-%0A        return document
+        */%0A        AnnotatedContentServiceClient uiaService = new AnnotatedContentServiceClient();%0A        org.epnoi.model.Content%3CObject%3E resource = null;%0A        try %7B%0A            uiaService.init(%22localhost%22, 8585);%0A%0A            resource = uiaService.getAnnotatedDocument(uri, RDFHelper.WIKIPEDIA_PAGE_CLASS);%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A%0A        %7D%0A%0A/*%0A        System.out.println(%22(RESOURCE)====%3E %22 + resource);%0A        System.out.println(%22%3C--%22);%0A*/%0A        return (Document)resource.getContent()
 ;%0A  

The relational sentences corpus creator is alredy using the thrift service for retrieving annotated content