Skip to content

Commit

Permalink
feat(discov2): generation release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
apaparazzi0329 committed May 11, 2021
1 parent ba5e8a8 commit be98f0c
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 15 deletions.
168 changes: 158 additions & 10 deletions Sources/DiscoveryV2/Discovery.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2019, 2020.
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
**/

/**
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-36b26b63-20201028-122900
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-902c9336-20210507-162723
**/

// swiftlint:disable file_length
Expand Down Expand Up @@ -742,10 +742,103 @@ public class Discovery {
}

/**
Query system notices.
Query collection notices.
Queries for notices (errors or warnings) that might have been generated by the system. Notices are generated when
ingesting documents and performing relevance training.
Finds collection-level notices (errors and warnings) that are generated when documents are ingested.
- parameter projectID: The ID of the project. This information can be found from the deploy page of the Discovery
administrative tooling.
- parameter collectionID: The ID of the collection.
- parameter filter: A cacheable query that excludes documents that don't mention the query content. Filter
searches are better for metadata-type searches and for assessing the concepts in the data set.
- parameter query: A query search returns all documents in your data set with full enrichments and full text, but
with the most relevant documents listed first.
- parameter naturalLanguageQuery: A natural language query that returns relevant documents by utilizing training
data and natural language understanding.
- parameter count: Number of results to return. The maximum for the **count** and **offset** values together in
any one query is **10000**.
- parameter offset: The number of query results to skip at the beginning. For example, if the total number of
results that are returned is 10 and the offset is 8, it returns the last two results. The maximum for the
**count** and **offset** values together in any one query is **10000**.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
public func queryCollectionNotices(
projectID: String,
collectionID: String,
filter: String? = nil,
query: String? = nil,
naturalLanguageQuery: String? = nil,
count: Int? = nil,
offset: Int? = nil,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<QueryNoticesResponse>?, WatsonError?) -> Void)
{
// construct header parameters
var headerParameters = defaultHeaders
let sdkHeaders = Shared.getSDKHeaders(serviceName: serviceName, serviceVersion: serviceVersion, methodName: "queryCollectionNotices")
headerParameters.merge(sdkHeaders) { (_, new) in new }
headerParameters["Accept"] = "application/json"
if let headers = headers {
headerParameters.merge(headers) { (_, new) in new }
}

// construct query parameters
var queryParameters = [URLQueryItem]()
queryParameters.append(URLQueryItem(name: "version", value: version))
if let filter = filter {
let queryParameter = URLQueryItem(name: "filter", value: filter)
queryParameters.append(queryParameter)
}
if let query = query {
let queryParameter = URLQueryItem(name: "query", value: query)
queryParameters.append(queryParameter)
}
if let naturalLanguageQuery = naturalLanguageQuery {
let queryParameter = URLQueryItem(name: "natural_language_query", value: naturalLanguageQuery)
queryParameters.append(queryParameter)
}
if let count = count {
let queryParameter = URLQueryItem(name: "count", value: "\(count)")
queryParameters.append(queryParameter)
}
if let offset = offset {
let queryParameter = URLQueryItem(name: "offset", value: "\(offset)")
queryParameters.append(queryParameter)
}

// construct REST request
let path = "/v2/projects/\(projectID)/collections/\(collectionID)/notices"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
completionHandler(nil, RestError.urlEncoding(path: path))
return
}

// ensure that serviceURL is set
guard let serviceEndpoint = serviceURL else {
completionHandler(nil, RestError.noEndpoint)
return
}

let request = RestRequest(
session: session,
authenticator: authenticator,
errorResponseDecoder: errorResponseDecoder,
method: "GET",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters,
queryItems: queryParameters
)

// execute REST request
request.responseObject(completionHandler: completionHandler)
}

/**
Query project notices.
Finds project-level notices (errors and warnings). Currently, project-level notices are generated by relevancy
training.
- parameter projectID: The ID of the project. This information can be found from the deploy page of the Discovery
administrative tooling.
Expand Down Expand Up @@ -1569,6 +1662,62 @@ public class Discovery {
// swiftlint:enable identifier_name
}

/**
Delete a training data query.
Removes details from a training data query, including the query string and all examples.
- parameter projectID: The ID of the project. This information can be found from the deploy page of the Discovery
administrative tooling.
- parameter queryID: The ID of the query used for training.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
public func deleteTrainingQuery(
projectID: String,
queryID: String,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<Void>?, WatsonError?) -> Void)
{
// construct header parameters
var headerParameters = defaultHeaders
let sdkHeaders = Shared.getSDKHeaders(serviceName: serviceName, serviceVersion: serviceVersion, methodName: "deleteTrainingQuery")
headerParameters.merge(sdkHeaders) { (_, new) in new }
if let headers = headers {
headerParameters.merge(headers) { (_, new) in new }
}

// construct query parameters
var queryParameters = [URLQueryItem]()
queryParameters.append(URLQueryItem(name: "version", value: version))

// construct REST request
let path = "/v2/projects/\(projectID)/training_data/queries/\(queryID)"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
completionHandler(nil, RestError.urlEncoding(path: path))
return
}

// ensure that serviceURL is set
guard let serviceEndpoint = serviceURL else {
completionHandler(nil, RestError.noEndpoint)
return
}

let request = RestRequest(
session: session,
authenticator: authenticator,
errorResponseDecoder: errorResponseDecoder,
method: "DELETE",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters,
queryItems: queryParameters
)

// execute REST request
request.response(completionHandler: completionHandler)
}

/**
Analyze a Document.
Expand Down Expand Up @@ -1722,7 +1871,7 @@ public class Discovery {
- parameter projectID: The ID of the project. This information can be found from the deploy page of the Discovery
administrative tooling.
- parameter enrichment:
- parameter enrichment: Information about a specific enrichment.
- parameter file: The enrichment file to upload.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
Expand All @@ -1731,20 +1880,19 @@ public class Discovery {
projectID: String,
enrichment: CreateEnrichment,
file: Data? = nil,
fileContentType: String,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<Enrichment>?, WatsonError?) -> Void)
{
// construct body
let multipartFormData = MultipartFormData()
guard let enrichmentJSON = try? JSON.encoder.encode(enrichment) else {
completionHandler(nil, WatsonError.serialization(values: "request body"))
completionHandler(nil, RestError.serialization(values: "enrichment"))
return
}
multipartFormData.append(enrichmentJSON, withName: "enrichment", mimeType: "application/json")

multipartFormData.append(enrichmentJSON, withName: "enrichment")
if let file = file {
multipartFormData.append(file, withName: "file", mimeType: fileContentType, fileName: "filename")
multipartFormData.append(file, withName: "file", mimeType: "application/octet-stream", fileName: "filename")
}
guard let body = try? multipartFormData.toData() else {
completionHandler(nil, RestError.serialization(values: "request multipart form data"))
Expand Down
46 changes: 44 additions & 2 deletions Sources/DiscoveryV2/Models/QueryLargePassages.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2019, 2020.
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,6 +53,27 @@ public struct QueryLargePassages: Codable, Equatable {
*/
public var characters: Int?

/**
When true, `answer` objects are returned as part of each passage in the query results. The primary difference
between an `answer` and a `passage` is that the length of a passage is defined by the query, where the length of an
`answer` is calculated by Discovery based on how much text is needed to answer the question./n/nThis parameter is
ignored if passages are not enabled for the query, or no **natural_language_query** is specified./n/nIf the
**find_answers** parameter is set to `true` and **per_document** parameter is also set to `true`, then the document
search results and the passage search results within each document are reordered using the answer confidences. The
goal of this reordering is to do as much as possible to make sure that the first answer of the first passage of the
first document is the best answer. Similarly, if the **find_answers** parameter is set to `true` and
**per_document** parameter is set to `false`, then the passage search results are reordered in decreasing order of
the highest confidence answer for each document and passage./n/nThe **find_answers** parameter is **beta**
functionality available only on managed instances and should not be used in a production environment. This
parameter is not available on installed instances of Discovery.
*/
public var findAnswers: Bool?

/**
The number of `answer` objects to return per passage if the **find_answers** parmeter is specified as `true`.
*/
public var maxAnswersPerPassage: Int?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case enabled = "enabled"
Expand All @@ -61,6 +82,8 @@ public struct QueryLargePassages: Codable, Equatable {
case fields = "fields"
case count = "count"
case characters = "characters"
case findAnswers = "find_answers"
case maxAnswersPerPassage = "max_answers_per_passage"
}

/**
Expand All @@ -74,6 +97,21 @@ public struct QueryLargePassages: Codable, Equatable {
- parameter count: The maximum number of passages to return. The search returns fewer passages if the requested
total is not found. The maximum is `100`.
- parameter characters: The approximate number of characters that any one passage will have.
- parameter findAnswers: When true, `answer` objects are returned as part of each passage in the query results.
The primary difference between an `answer` and a `passage` is that the length of a passage is defined by the
query, where the length of an `answer` is calculated by Discovery based on how much text is needed to answer the
question./n/nThis parameter is ignored if passages are not enabled for the query, or no
**natural_language_query** is specified./n/nIf the **find_answers** parameter is set to `true` and
**per_document** parameter is also set to `true`, then the document search results and the passage search results
within each document are reordered using the answer confidences. The goal of this reordering is to do as much as
possible to make sure that the first answer of the first passage of the first document is the best answer.
Similarly, if the **find_answers** parameter is set to `true` and **per_document** parameter is set to `false`,
then the passage search results are reordered in decreasing order of the highest confidence answer for each
document and passage./n/nThe **find_answers** parameter is **beta** functionality available only on managed
instances and should not be used in a production environment. This parameter is not available on installed
instances of Discovery.
- parameter maxAnswersPerPassage: The number of `answer` objects to return per passage if the **find_answers**
parmeter is specified as `true`.
- returns: An initialized `QueryLargePassages`.
*/
Expand All @@ -83,7 +121,9 @@ public struct QueryLargePassages: Codable, Equatable {
maxPerDocument: Int? = nil,
fields: [String]? = nil,
count: Int? = nil,
characters: Int? = nil
characters: Int? = nil,
findAnswers: Bool? = nil,
maxAnswersPerPassage: Int? = nil
)
{
self.enabled = enabled
Expand All @@ -92,6 +132,8 @@ public struct QueryLargePassages: Codable, Equatable {
self.fields = fields
self.count = count
self.characters = characters
self.findAnswers = findAnswers
self.maxAnswersPerPassage = maxAnswersPerPassage
}

}
14 changes: 13 additions & 1 deletion Sources/DiscoveryV2/Models/QueryResponsePassage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2020.
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,6 +56,16 @@ public struct QueryResponsePassage: Codable, Equatable {
*/
public var field: String?

/**
An estimate of the probability that the passage is relevant.
*/
public var confidence: Double?

/**
An array of extracted answers to the specified query.
*/
public var answers: [ResultPassageAnswer]?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case passageText = "passage_text"
Expand All @@ -65,6 +75,8 @@ public struct QueryResponsePassage: Codable, Equatable {
case startOffset = "start_offset"
case endOffset = "end_offset"
case field = "field"
case confidence = "confidence"
case answers = "answers"
}

}
14 changes: 13 additions & 1 deletion Sources/DiscoveryV2/Models/QueryResultPassage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2019, 2020.
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,12 +41,24 @@ public struct QueryResultPassage: Codable, Equatable {
*/
public var field: String?

/**
Estimate of the probability that the passage is relevant.
*/
public var confidence: Double?

/**
An arry of extracted answers to the specified query.
*/
public var answers: [ResultPassageAnswer]?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case passageText = "passage_text"
case startOffset = "start_offset"
case endOffset = "end_offset"
case field = "field"
case confidence = "confidence"
case answers = "answers"
}

}
Loading

0 comments on commit be98f0c

Please sign in to comment.