Skip to content

Commit

Permalink
fix: Support analyze debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dlangst committed Apr 8, 2022
1 parent b77f1e9 commit ed6ce4e
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class AnnotatorForClinicalData extends BaseService {

public static final String VERSION = "version";

public static final String DEBUG = "debug";

private String version;

/**
Expand Down Expand Up @@ -698,6 +700,9 @@ public ServiceCall<Void> runPipeline(RunPipelineOptions runPipelineOptions) {
if (runPipelineOptions.returnAnalyzedText() != null) {
builder.query("return_analyzed_text", String.valueOf(runPipelineOptions.returnAnalyzedText()));
}
if (runPipelineOptions.debug() != null) {
builder.query("debug", String.valueOf(runPipelineOptions.debug()));
}
final JsonObject contentJson = new JsonObject();
if (runPipelineOptions.unstructured() != null) {
contentJson.add("unstructured", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(runPipelineOptions.unstructured()));
Expand Down Expand Up @@ -811,6 +816,7 @@ public ServiceCall<Void> runPipelineWithFlow(RunPipelineWithFlowOptions runPipel
if (runPipelineWithFlowOptions.debugTextRestore() != null) {
builder.query("debug_text_restore", String.valueOf(runPipelineWithFlowOptions.debugTextRestore()));
}
builder.query("debug", String.valueOf(runPipelineWithFlowOptions.debug()));
builder.bodyContent(runPipelineWithFlowOptions.contentType(), runPipelineWithFlowOptions.analyticFlowBeanInput(),
null, runPipelineWithFlowOptions.body());
ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
Expand Down Expand Up @@ -869,6 +875,7 @@ public ServiceCall<ContainerGroup> analyze(final AnalyzeOptions analyzeOptions)
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments));
builder.query(VERSION, version);
builder.query(RETURN_ANALYZED_TEXT, String.valueOf(analyzeOptions.returnAnalyzedText()));
builder.query(DEBUG, String.valueOf(analyzeOptions.debug()));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders(DEFAULT_SERVICE_NAME, "v1", "analyze");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
Expand Down Expand Up @@ -918,6 +925,7 @@ public ServiceCall<ContainerGroup> analyzeWithFlow(final AnalyzeWithFlowOptions
}
builder.query(VERSION, version);
builder.query(RETURN_ANALYZED_TEXT, String.valueOf(analyzeWithFlowOptions.returnAnalyzedText()));
builder.query(DEBUG, String.valueOf(analyzeWithFlowOptions.debug()));
builder.header("content-type", analyzeWithFlowOptions.contentType());

if (analyzeWithFlowOptions.contentType()
Expand All @@ -942,7 +950,7 @@ public ContainerGroup analyze(final String text, final Flow flow) {
AnnotatorFlow annotatorFlow = new AnnotatorFlow.Builder().flow(flow).build();
UnstructuredContainer unstructuredContainer = new UnstructuredContainer.Builder().text(text).build();
AnalyzeOptions options = new AnalyzeOptions.Builder().addUnstructured(unstructuredContainer)
.returnAnalyzedText(false).addAnnotatorFlows(annotatorFlow).build();
.returnAnalyzedText(false).debug(false).addAnnotatorFlows(annotatorFlow).build();

return this.analyze(options).execute().getResult();
}
Expand All @@ -960,7 +968,7 @@ public Response<ContainerGroup> analyzeInclResponseDetails(final String text, fi
AnnotatorFlow annotatorFlow = new AnnotatorFlow.Builder().flow(flow).build();
UnstructuredContainer unstructuredContainer = new UnstructuredContainer.Builder().text(text).build();
AnalyzeOptions options = new AnalyzeOptions.Builder().addUnstructured(unstructuredContainer)
.returnAnalyzedText(false).addAnnotatorFlows(annotatorFlow).build();
.returnAnalyzedText(false).debug(false).addAnnotatorFlows(annotatorFlow).build();

return this.analyze(options).execute();
}
Expand All @@ -979,7 +987,7 @@ public ContainerGroup analyze(final String text, final Flow flow, final boolean
AnnotatorFlow annotatorFlow = new AnnotatorFlow.Builder().flow(flow).build();
UnstructuredContainer unstructuredContainer = new UnstructuredContainer.Builder().text(text).build();
AnalyzeOptions options = new AnalyzeOptions.Builder().addUnstructured(unstructuredContainer)
.returnAnalyzedText(returnAnalyzedText).addAnnotatorFlows(annotatorFlow).build();
.returnAnalyzedText(returnAnalyzedText).debug(false).addAnnotatorFlows(annotatorFlow).build();

return this.analyze(options).execute().getResult();
}
Expand All @@ -999,7 +1007,28 @@ public Response<ContainerGroup> analyzeInclResponseDetails(final String text, fi
AnnotatorFlow annotatorFlow = new AnnotatorFlow.Builder().flow(flow).build();
UnstructuredContainer unstructuredContainer = new UnstructuredContainer.Builder().text(text).build();
AnalyzeOptions options = new AnalyzeOptions.Builder().addUnstructured(unstructuredContainer)
.returnAnalyzedText(returnAnalyzedText).addAnnotatorFlows(annotatorFlow).build();
.returnAnalyzedText(returnAnalyzedText).debug(false).addAnnotatorFlows(annotatorFlow).build();

return this.analyze(options).execute();
}

/**
* Method to analyze text with a manually defined annotator flow.
*
* @param text data to be analyzed
* @param flow analytics to appply to the text {@link Flow}
* @param returnAnalyzedText where to return the submitted data
* @param debug analyze debug flag
*
* @return the response with result representing {@link ContainerGroup}
*/

public Response<ContainerGroup> analyzeDebug(final String text, final Flow flow,
final boolean returnAnalyzedText, final boolean debug) {
AnnotatorFlow annotatorFlow = new AnnotatorFlow.Builder().flow(flow).build();
UnstructuredContainer unstructuredContainer = new UnstructuredContainer.Builder().text(text).build();
AnalyzeOptions options = new AnalyzeOptions.Builder().addUnstructured(unstructuredContainer)
.returnAnalyzedText(returnAnalyzedText).debug(debug).addAnnotatorFlows(annotatorFlow).build();

return this.analyze(options).execute();
}
Expand All @@ -1015,7 +1044,7 @@ public Response<ContainerGroup> analyzeInclResponseDetails(final String text, fi

public ContainerGroup analyzeWithFlow(final String flowId, final String text) {
AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId).text(text)
.returnAnalyzedText(false).build();
.returnAnalyzedText(false).debug(false).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute().getResult();
}
Expand All @@ -1026,12 +1055,12 @@ public ContainerGroup analyzeWithFlow(final String flowId, final String text) {
* @param flowId identifier of existing analytic flow to apply to the text
* @param text data to be analyzed
*
* @return the resopnse with result representing {@link ContainerGroup}
* @return the response with result representing {@link ContainerGroup}
*/

public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String flowId, final String text) {
AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId).text(text)
.returnAnalyzedText(false).build();
.returnAnalyzedText(false).debug(false).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute();
}
Expand All @@ -1043,12 +1072,30 @@ public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String
* @param text data to be analyzed
* @param returnAnalyzedText where to return the submitted data
*
* @return the resopnse with result representing {@link ContainerGroup}
* @return the response with result representing {@link ContainerGroup}
*/

public ContainerGroup analyzeWithFlow(final String flowId, final String text, final boolean returnAnalyzedText) {
AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId).text(text)
.returnAnalyzedText(returnAnalyzedText).build();
.returnAnalyzedText(returnAnalyzedText).debug(false).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute().getResult();
}

/**
* Method to analyze text with an existing annotator flow with analyze debug flag enabled.
*
* @param flowId identifier of existing analytic flow to apply to the text
* @param text data to be analyzed
* @param returnAnalyzedText where to return the submitted data
* @param debug turn on analyze debug flag
*
* @return the response with result representing {@link ContainerGroup}
*/

public ContainerGroup analyzeWithFlowDebug(final String flowId, final String text, final boolean returnAnalyzedText, final boolean debug) {
AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId).text(text)
.returnAnalyzedText(returnAnalyzedText).debug(debug).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute().getResult();
}
Expand All @@ -1060,13 +1107,13 @@ public ContainerGroup analyzeWithFlow(final String flowId, final String text, fi
* @param text data to be analyzed
* @param returnAnalyzedText where to return the submitted data
*
* @return the resopnse with result representing {@link ContainerGroup}
* @return the response with result representing {@link ContainerGroup}
*/

public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String flowId, final String text,
final boolean returnAnalyzedText) {
AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId).text(text)
.returnAnalyzedText(returnAnalyzedText).build();
.returnAnalyzedText(returnAnalyzedText).debug(false).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute();
}
Expand All @@ -1075,7 +1122,7 @@ public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String
* Method to analyze text with an existing annotator flow.
*
* @param flowId identifier of existing analytic flow to apply to the text
* @param unstructuredContainer {@link UnstructuredContainer} discovered cogntive artifacts
* @param unstructuredContainer {@link UnstructuredContainer} discovered cognitive artifacts
*
* @return the {@link ContainerGroup}
*/
Expand All @@ -1085,7 +1132,7 @@ public ContainerGroup analyzeWithFlow(final String flowId, final UnstructuredCon
.build();

AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId)
.returnAnalyzedText(false).request(requestContainer).build();
.returnAnalyzedText(false).debug(false).request(requestContainer).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute().getResult();
}
Expand All @@ -1094,18 +1141,23 @@ public ContainerGroup analyzeWithFlow(final String flowId, final UnstructuredCon
* Method to analyze text with an existing annotator flow.
*
* @param flowId identifier of existing analytic flow to apply to the text
* @param unstructuredContainer {@link UnstructuredContainer} discovered cogntive artifacts
* @param unstructuredContainer {@link UnstructuredContainer} discovered cognitive artifacts
*
* @return the resopnse with result representing {@link ContainerGroup}
* @return the response with result representing {@link ContainerGroup}
*
* Note: This method is incorrectly named (see analyzeWithFlowInclResponseDetails(String, UnstructuredContainer,
* boolean) since it does not accept a boolean. Will leave here for now to prevent a breaking a change and mark
* it deprecated.
*/

@Deprecated
public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String flowId,
final UnstructuredContainer unstructuredContainer) {
RequestContainer requestContainer = new RequestContainer.Builder().addUnstructured(unstructuredContainer)
.build();

AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId)
.returnAnalyzedText(false).request(requestContainer).build();
.returnAnalyzedText(false).debug(false).request(requestContainer).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute();
}
Expand All @@ -1117,7 +1169,7 @@ public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String
* @param unstructuredContainer {@link UnstructuredContainer}
* @param returnAnalyzedText where to return the submitted data
*
* @return the {@link ContainerGroup} discovered cogntive artifacts
* @return the {@link ContainerGroup} discovered cognitive artifacts
*/

public ContainerGroup analyzeWithFlow(final String flowId, final UnstructuredContainer unstructuredContainer,
Expand All @@ -1126,7 +1178,7 @@ public ContainerGroup analyzeWithFlow(final String flowId, final UnstructuredCon
.build();

AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId)
.returnAnalyzedText(returnAnalyzedText).request(requestContainer).build();
.returnAnalyzedText(returnAnalyzedText).debug(false).request(requestContainer).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute().getResult();
}
Expand All @@ -1138,7 +1190,7 @@ public ContainerGroup analyzeWithFlow(final String flowId, final UnstructuredCon
* @param unstructuredContainer {@link UnstructuredContainer}
* @param returnAnalyzedText where to return the submitted data
*
* @return the resopnse with result representing {@link ContainerGroup}
* @return the response with result representing {@link ContainerGroup}
*/

public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String flowId,
Expand All @@ -1147,7 +1199,29 @@ public Response<ContainerGroup> analyzeWithFlowInclResponseDetails(final String
.build();

AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId)
.returnAnalyzedText(returnAnalyzedText).request(requestContainer).build();
.returnAnalyzedText(returnAnalyzedText).debug(false).request(requestContainer).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute();
}

/**
* Method to analyze text with an existing annotator flow with analyze debug flag enabled.
*
* @param flowId identifier of existing analytic flow to apply to the text
* @param unstructuredContainer {@link UnstructuredContainer}
* @param returnAnalyzedText where to return the submitted data
* @param debug analyze debug flag enabled
*
* @return the response with result representing {@link ContainerGroup}
*/

public Response<ContainerGroup> analyzeWithFlowDebug(final String flowId,
final UnstructuredContainer unstructuredContainer, final boolean returnAnalyzedText, final boolean debug) {
RequestContainer requestContainer = new RequestContainer.Builder().addUnstructured(unstructuredContainer)
.build();

AnalyzeWithFlowOptions analyzeWithFlowOptions = new AnalyzeWithFlowOptions.Builder().flowId(flowId)
.returnAnalyzedText(returnAnalyzedText).debug(debug).request(requestContainer).build();

return this.analyzeWithFlow(analyzeWithFlowOptions).execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AnalyzeOptions extends GenericModel {
private List<UnstructuredContainer> unstructured;
private List<AnnotatorFlow> annotatorFlows;
private boolean returnAnalyzedText;
private boolean debug;


/**
Expand All @@ -36,12 +37,14 @@ public static class Builder {
private List<UnstructuredContainer> unstructured;
private List<AnnotatorFlow> annotatorFlows;
private boolean returnAnalyzedText;
private boolean debug;


private Builder(AnalyzeOptions analyzeOptions) {
unstructured = analyzeOptions.unstructured;
annotatorFlows = analyzeOptions.annotatorFlows;
returnAnalyzedText = analyzeOptions.returnAnalyzedText;
debug = analyzeOptions.debug;
}

/**
Expand Down Expand Up @@ -123,12 +126,24 @@ public Builder returnAnalyzedText(boolean returnAnalyzedText) {
this.returnAnalyzedText = returnAnalyzedText;
return this;
}

/**
* Set the debug flag.
*
* @param debug enable analyze debug flag
* @return the AnalyzeOptionsbuilder
*/
public Builder debug(boolean debug) {
this.debug = debug;
return this;
}
}

private AnalyzeOptions(Builder builder) {
unstructured = builder.unstructured;
annotatorFlows = builder.annotatorFlows;
returnAnalyzedText = builder.returnAnalyzedText;
debug = builder.debug;
}

/**
Expand Down Expand Up @@ -168,4 +183,15 @@ public List<AnnotatorFlow> annotatorFlows() {
public boolean returnAnalyzedText() {
return returnAnalyzedText;
}

/**
* Gets the debug flag.
*
* true or false
*
* @return the debug
*/
public boolean debug() {
return debug;
}
}
Loading

0 comments on commit ed6ce4e

Please sign in to comment.