Search in sources :

Example 56 with Value

use of com.ibm.watson.assistant.v1.model.Value in project java-sdk by watson-developer-cloud.

the class Assistant method getSynonym.

/**
 * Get entity value synonym.
 *
 * <p>Get information about a synonym of an entity value.
 *
 * @param getSynonymOptions the {@link GetSynonymOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Synonym}
 */
public ServiceCall<Synonym> getSynonym(GetSynonymOptions getSynonymOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSynonymOptions, "getSynonymOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", getSynonymOptions.workspaceId());
    pathParamsMap.put("entity", getSynonymOptions.entity());
    pathParamsMap.put("value", getSynonymOptions.value());
    pathParamsMap.put("synonym", getSynonymOptions.synonym());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}/synonyms/{synonym}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getSynonym");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (getSynonymOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getSynonymOptions.includeAudit()));
    }
    ResponseConverter<Synonym> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Synonym>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Synonym(com.ibm.watson.assistant.v1.model.Synonym)

Example 57 with Value

use of com.ibm.watson.assistant.v1.model.Value in project java-sdk by watson-developer-cloud.

the class Assistant method updateSynonym.

/**
 * Update entity value synonym.
 *
 * <p>Update an existing entity value synonym with new text.
 *
 * <p>If you want to update multiple synonyms with a single API call, consider using the **[Update
 * entity](#update-entity)** or **[Update entity value](#update-entity-value)** method instead.
 *
 * @param updateSynonymOptions the {@link UpdateSynonymOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Synonym}
 */
public ServiceCall<Synonym> updateSynonym(UpdateSynonymOptions updateSynonymOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateSynonymOptions, "updateSynonymOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateSynonymOptions.workspaceId());
    pathParamsMap.put("entity", updateSynonymOptions.entity());
    pathParamsMap.put("value", updateSynonymOptions.value());
    pathParamsMap.put("synonym", updateSynonymOptions.synonym());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}/synonyms/{synonym}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateSynonym");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (updateSynonymOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateSynonymOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateSynonymOptions.newSynonym() != null) {
        contentJson.addProperty("synonym", updateSynonymOptions.newSynonym());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Synonym> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Synonym>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Synonym(com.ibm.watson.assistant.v1.model.Synonym)

Example 58 with Value

use of com.ibm.watson.assistant.v1.model.Value in project dna by leifeld.

the class Sql method getShallowStatements.

/**
 * Get a shallow representation of all statements in a specific document for
 * the purpose of painting the statements in the text. For this purpose,
 * variable contents, date, coder name etc. are unnecessary. This speeds up
 * the retrieval.
 *
 * @param documentId  ID of the document for which statements are retrieved.
 * @return Array list of statements.
 */
public ArrayList<Statement> getShallowStatements(int documentId) {
    String query = "SELECT S.ID, S.Start, S.Stop, S.StatementTypeId, " + "T.Label AS StatementTypeLabel, T.Red AS StatementTypeRed, " + "T.Green AS StatementTypeGreen, T.Blue AS StatementTypeBlue, " + "S.Coder, C.Red AS CoderRed, C.Green AS CoderGreen, C.Blue AS CoderBlue " + "FROM STATEMENTS S LEFT JOIN CODERS C ON C.ID = S.Coder " + "LEFT JOIN STATEMENTTYPES T ON T.ID = S.StatementTypeId " + "WHERE S.DocumentId = ? ORDER BY Start ASC;";
    ArrayList<Statement> statements = new ArrayList<Statement>();
    try (Connection conn = ds.getConnection();
        PreparedStatement s = conn.prepareStatement(query)) {
        ResultSet r;
        s.setInt(1, documentId);
        r = s.executeQuery();
        while (r.next()) {
            Statement statement = new Statement(r.getInt("ID"), r.getInt("Start"), r.getInt("Stop"), r.getInt("StatementTypeId"), r.getString("StatementTypeLabel"), new Color(r.getInt("StatementTypeRed"), r.getInt("StatementTypeGreen"), r.getInt("StatementTypeBlue")), r.getInt("Coder"), "", new Color(r.getInt("CoderRed"), r.getInt("CoderGreen"), r.getInt("CoderBlue")), new ArrayList<Value>(), documentId, null, null);
            statements.add(statement);
        }
        LogEvent l = new LogEvent(Logger.MESSAGE, "[SQL] " + statements.size() + " statement(s) have been retrieved for Document " + documentId + ".", statements.size() + " statement(s) have been retrieved for for Document " + documentId + ".");
        Dna.logger.log(l);
    } catch (SQLException e) {
        LogEvent l = new LogEvent(Logger.WARNING, "[SQL] Failed to retrieve statements for Document " + documentId + ".", "Attempted to retrieve all statements for Document " + documentId + " from the database, but something went wrong. You should double-check if the statements are all shown!", e);
        Dna.logger.log(l);
    }
    return statements;
}
Also used : LogEvent(logger.LogEvent) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(model.Statement) Color(java.awt.Color) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Value(model.Value) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)22 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)22 Test (org.testng.annotations.Test)22 HashMap (java.util.HashMap)21 Test (org.junit.Test)20 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)15 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)14 Value (com.ibm.watson.assistant.v1.model.Value)12 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)11 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)10 Synonym (com.ibm.watson.assistant.v1.model.Synonym)10 JsonObject (com.google.gson.JsonObject)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)7 DeleteValueOptions (com.ibm.watson.assistant.v1.model.DeleteValueOptions)7 Entity (com.ibm.watson.assistant.v1.model.Entity)7 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)5 CreateSynonymOptions (com.ibm.watson.assistant.v1.model.CreateSynonymOptions)5 DeleteSynonymOptions (com.ibm.watson.assistant.v1.model.DeleteSynonymOptions)5 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)5 Value (com.ibm.watson.developer_cloud.conversation.v1.model.Value)5