Skip to content

Commit

Permalink
updated swiftformat rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 9, 2024
1 parent 51c5e82 commit 40b0d3f
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ extension AWSPredictionsPlugin {
config: PredictionsPluginConfiguration
) -> PollyClientTypes.VoiceId {
if let voice,
let pollyVoiceID = PollyClientTypes.VoiceId(rawValue: voice.id)
{
let pollyVoiceID = PollyClientTypes.VoiceId(rawValue: voice.id) {
return pollyVoiceID
}

if let configVoice = config.convert.speechGenerator?.voiceID,
let pollyVoiceID = PollyClientTypes.VoiceId(rawValue: configVoice)
{
let pollyVoiceID = PollyClientTypes.VoiceId(rawValue: configVoice) {
return pollyVoiceID
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public final class FaceLivenessSession: LivenessService {

private let livenessServiceDispatchQueue = DispatchQueue(
label: "com.amazon.aws.amplify.liveness.service",
qos: .userInteractive)
qos: .userInteractive
)

init(
websocket: WebSocketSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ class InterpretTextMultiService: MultiServiceBehavior {
offlineResult: [Predictions.KeyPhrase]?
) -> [Predictions.KeyPhrase]? {
if let onlineKeyPhrases = onlineResult,
let offlineKeyPhrases = offlineResult
{
let offlineKeyPhrases = offlineResult {
let onlineKeyPhraseSet = Set<Predictions.KeyPhrase>(onlineKeyPhrases)
let offlineKeyPhraseSet = Set<Predictions.KeyPhrase>(offlineKeyPhrases)
return Array(onlineKeyPhraseSet.union(offlineKeyPhraseSet))
Expand All @@ -126,8 +125,7 @@ class InterpretTextMultiService: MultiServiceBehavior {
offlineResult: [Predictions.Entity.DetectionResult]?
) -> [Predictions.Entity.DetectionResult]? {
if let onlineEntities = onlineResult,
let offlineEntities = offlineResult
{
let offlineEntities = offlineResult {
let onlineEntitiesSet = Set<Predictions.Entity.DetectionResult>(onlineEntities)
let offlineEntitiesSet = Set<Predictions.Entity.DetectionResult>(offlineEntities)
return Array(onlineEntitiesSet.union(offlineEntitiesSet))
Expand All @@ -143,8 +141,7 @@ class InterpretTextMultiService: MultiServiceBehavior {
offlineResult: [Predictions.SyntaxToken]?
) -> [Predictions.SyntaxToken]? {
if let onlineSyntax = onlineResult,
let offlineSyntax = offlineResult
{
let offlineSyntax = offlineResult {
let onlineSyntaxSet = Set<Predictions.SyntaxToken>(onlineSyntax)
let offlineSyntaxSet = Set<Predictions.SyntaxToken>(offlineSyntax)
return Array(onlineSyntaxSet.union(offlineSyntaxSet))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ struct SigV4Signer {
hostHeader,
uniquingKeysWith: { _, host in
host
})
}
)

let url = url.path.isEmpty
? url.appendingPathComponent("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ enum PluginErrorMessage {

static let invalidRegion: PluginErrorString = (
"The region is invalid",
"Make sure the region is one of the AWS regions, like 'us-east-1', etc...")
"Make sure the region is one of the AWS regions, like 'us-east-1', etc..."
)

static let serviceConfigurationInitializationError: PluginErrorString = (
"Could not initialize service configuration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ extension IdentifyTextResultTransformers {

if !rows.contains(row),
!cols.contains(row),
let cell = constructTableCell(cellBlock, blockMap)
{
let cell = constructTableCell(cellBlock, blockMap) {
table.cells.append(cell)
rows.insert(row)
cols.insert(col)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ enum IdentifyTextResultTransformers {
boundingBox: boundingBox,
polygon: polygon,
page: block.page ?? 0
)
)
}

static func processSelectionElementBlock(block: TextractClientTypes.Block) -> Predictions.Selection? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ extension CoreMLPredictionsPlugin {
let recoverySuggestion = CoreMLPluginErrorString.decodeConfigurationError.recoverySuggestion
throw PluginError.pluginConfigurationError(errorDescription, recoverySuggestion)
}
configure(naturalLanguageBehavior: CoreMLNaturalLanguageAdapter(),
visionBehavior: CoreMLVisionAdapter(),
speechBehavior: CoreMLSpeechAdapter())
configure(
naturalLanguageBehavior: CoreMLNaturalLanguageAdapter(),
visionBehavior: CoreMLVisionAdapter(),
speechBehavior: CoreMLSpeechAdapter()
)
}

func configure(naturalLanguageBehavior: CoreMLNaturalLanguageBehavior,
visionBehavior: CoreMLVisionBehavior,
speechBehavior: CoreMLSpeechBehavior,
queue: OperationQueue = OperationQueue())
{
func configure(
naturalLanguageBehavior: CoreMLNaturalLanguageBehavior,
visionBehavior: CoreMLVisionBehavior,
speechBehavior: CoreMLSpeechBehavior,
queue: OperationQueue = OperationQueue()
) {
coreMLNaturalLanguage = naturalLanguageBehavior
coreMLVision = visionBehavior
coreMLSpeech = speechBehavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ class CoreMLVisionAdapter: CoreMLVisionBehavior {

var entities: [Predictions.Entity] = []
for observation in observations {
let pose = Predictions.Pose(pitch: 0.0, // CoreML doesnot return pitch
roll: observation.roll?.doubleValue ?? 0.0,
yaw: observation.yaw?.doubleValue ?? 0.0)
let entityMetaData = Predictions.Entity.Metadata(confidence: Double(observation.confidence),
pose: pose)
let pose = Predictions.Pose(
pitch: 0.0, // CoreML doesnot return pitch
roll: observation.roll?.doubleValue ?? 0.0,
yaw: observation.yaw?.doubleValue ?? 0.0
)
let entityMetaData = Predictions.Entity.Metadata(
confidence: Double(observation.confidence),
pose: pose
)
let entity = Predictions.Entity(
boundingBox: observation.boundingBox,
landmarks: mapLandmarks(observation.landmarks),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,42 @@ typealias PluginErrorString = (errorDescription: ErrorDescription, recoverySugge
enum CoreMLPluginErrorString {
static let decodeConfigurationError: PluginErrorString = (
"Unable to decode configuration",
"Make sure the plugin configuration is JSONValue")
"Make sure the plugin configuration is JSONValue"
)

static let configurationObjectExpected: PluginErrorString = (
"Configuration was not a dictionary literal",
"Make sure the value for the plugin is a dictionary literal with keys 'Bucket' and 'Region'")
"Make sure the value for the plugin is a dictionary literal with keys 'Bucket' and 'Region'"
)

static let operationNotSupported: PluginErrorString = (
"This operation is not supported.",
"Operation is not currently supported by offline mode.")
"Operation is not currently supported by offline mode."
)

static let detectTextNoResult: PluginErrorString = (
"Detect text return with no result",
"The input might not have enough data points to find text")
"The input might not have enough data points to find text"
)

static let detectLabelsNoResult: PluginErrorString = (
"Detect labels return with no result",
"The input might not have enough data points to find labels")
"The input might not have enough data points to find labels"
)

static let detectEntitiesNoResult: PluginErrorString = (
"Detect entities returned with no result",
"The input might not have enough data points to find entities")
"The input might not have enough data points to find entities"
)

static let transcriptionNoResult: PluginErrorString = (
"Speech to text returned with no result",
"The audio file may be corrupt or hard to understand.")
"The audio file may be corrupt or hard to understand."
)

static let requestObjectExpected: PluginErrorString = (
"The object sent over doesn't match the request object for this type of request",
"Make sure you are sending over the correct type for the data needed for this request.")
"Make sure you are sending over the correct type for the data needed for this request."
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,26 @@ class PredictionsPluginConfigurationTests: XCTestCase {
do {
let configuration = try JSONDecoder().decode(PredictionsPluginConfiguration.self, from: inputJsonData)
XCTAssertNotNil(configuration, "Configuration should not be nil")
XCTAssertEqual(configuration.defaultRegion,
"us-west-2",
"Default value should be equal to the input")
XCTAssertEqual(configuration.identify.region,
"us-west-2",
"Region value for identify should be equal to the input")
XCTAssertEqual(configuration.interpret.region,
"us-west-2",
"Region value for interpret should be equal to the input")
XCTAssertEqual(configuration.convert.region,
"us-west-2",
"Region value for convert should be equal to the input")
XCTAssertEqual(
configuration.defaultRegion,
"us-west-2",
"Default value should be equal to the input"
)
XCTAssertEqual(
configuration.identify.region,
"us-west-2",
"Region value for identify should be equal to the input"
)
XCTAssertEqual(
configuration.interpret.region,
"us-west-2",
"Region value for interpret should be equal to the input"
)
XCTAssertEqual(
configuration.convert.region,
"us-west-2",
"Region value for convert should be equal to the input"
)
} catch {
XCTFail("Decoding the json data should not produce any error \(error)")
}
Expand Down

0 comments on commit 40b0d3f

Please sign in to comment.