Skip to content

Commit

Permalink
Merge pull request #62 from zeroae/i/handle-single-value-annotations-…
Browse files Browse the repository at this point in the history
…query

GATE Cloud Client compatibility
  • Loading branch information
sodre authored Mar 13, 2021
2 parents d1770eb + 3ee1db2 commit 0521572
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
38 changes: 38 additions & 0 deletions examples/complete/http/test-annotations-query.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### POST Single AnnotationRequest
POST {{endpoint}}/{{name}}?annotations=:Token
Content-Type: application/fastinfoset
Accept: application/json

< ./hello-world.finf
> {%
client.test("Request executed successfully", function() {
client.assert(response.body.entities.Token.length === 3, "Expected 3 tokens.");
});
%}


### POST MultiValue AnnotationRequest
POST {{endpoint}}/{{name}}?annotations=:Token&annotations=:Sentence
Content-Type: application/fastinfoset
Accept: application/json

< ./hello-world.finf
> {%
client.test("Request executed successfully", function() {
client.assert(response.body.entities.Token.length === 3, "Expected 3 tokens.");
client.assert(response.body.entities.Sentence.length === 1, "Expected 1 sentence.");
});
%}

### POST multi-valued comma separated annotations query
POST {{endpoint}}/{{name}}?annotations=:Token, :Sentence
Content-Type: application/fastinfoset
Accept: application/json

< ./hello-world.finf
> {%
client.test("Request executed successfully", function() {
client.assert(response.body.entities.Token.length === 3, "Expected 3 tokens.");
client.assert(response.body.entities.Sentence.length === 1, "Expected 1 sentence.");
});
%}
8 changes: 7 additions & 1 deletion src/main/java/co/zeroae/gate/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.net.URLStreamHandler;
import java.util.*;
import java.util.function.Supplier;

/**
* This class implements a GATE application using AWS Lambda.
Expand Down Expand Up @@ -139,7 +140,12 @@ public APIGatewayProxyResponseEvent handleExecute(APIGatewayProxyRequestEvent in

AWSXRay.beginSubsegment("Gate Export");
AWSXRay.getCurrentSubsegment().putMetadata("Content-Type", response.getHeaders().get("Content-Type"));
final List<String> annotationSelector = mQueryStringParams.get("annotations");
final List<String> annotationSelector = ((Supplier<List<String>>) () -> {
String singleValued = queryStringParams.get("annotations");
if (singleValued == null)
return mQueryStringParams.get("annotations");
return Arrays.asList(singleValued.split("\\s*,\\s*"));
}).get();

try {
return export(exporter, doc, annotationSelector, response).withStatusCode(200);
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/co/zeroae/gate/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,20 @@ public void testAnnotationSelector() throws Exception {
// Now we downselect to only one field.
input.withMultiValueQueryStringParameters(new HashMap<>())
.getMultiValueQueryStringParameters()
.put("annotations", Collections.singletonList(":Token"));
.put("annotations", Collections.singletonList(":Token"));
result = app.handleRequest(input, context);

doc = Utils.xmlToDocument(new StringReader(result.getBody()));
assertEquals(1, doc.getAnnotations().getAllTypes().size());

input.withMultiValueQueryStringParameters(null)
.withQueryStringParameters(new HashMap<>())
.getQueryStringParameters()
.put("annotations", ":Token, :Sentence");
result = app.handleRequest(input, context);
doc = Utils.xmlToDocument(new StringReader(result.getBody()));
assertEquals(2, doc.getAnnotations().getAllTypes().size());

}

@Test
Expand Down

0 comments on commit 0521572

Please sign in to comment.