Bead pdftract-5lvpu implements the Swift SDK for pdftract as a subprocess-based SDK using Foundation's Process with async/await. Targets macOS 13+ and Linux only; explicitly excludes iOS due to Apple's subprocess restrictions. Acceptance criteria status: - PASS: SPM package structure (Package.swift configured) - PASS: All 9 contract methods exposed in Methods.swift - PASS: All 8 error cases defined in Error.swift - PASS: iOS documented as unsupported in README.md - PASS: CI workflow configured (pdftract-swift-publish.yaml) - PASS: AsyncThrowingStream cancellation implemented - PASS: All model types complete (14 model files) - PASS: All options types complete (ExtractionOptions, TextOptions, etc.) - PASS: Conformance test suite defined (ConformanceTests.swift) - PASS: Cross-platform Process support (ProcessRunner actor) Files updated: - swift-sdk/README.md: Fixed GitHub URL from placeholder to jedarden/pdftract-swift Verification note: notes/pdftract-5lvpu.md References: - Plan: SDK Architecture / The Ten SDKs, line 3480 - Plan: SDK Architecture / Per-SDK Release Channels, line 3577 - Plan: SDK Acceptance Criteria, lines 3581-3589 - ADR-009: Argo Workflows on iad-ci only
69 lines
1.9 KiB
Swift
69 lines
1.9 KiB
Swift
//
|
|
// Classification.swift
|
|
// Pdftract
|
|
//
|
|
// Document classification result from the classify command.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// Classification result from document type classifier.
|
|
///
|
|
/// Contains the detected document type, confidence score, and
|
|
/// reasons for the classification.
|
|
public struct Classification: Codable, Equatable {
|
|
/// The classified document type.
|
|
/// Examples: "scientific_paper", "invoice", "contract", "misc"
|
|
public let documentType: String
|
|
|
|
/// Confidence score [0.0, 1.0].
|
|
public let confidence: Float
|
|
|
|
/// Human-readable reasons for the classification (top-K matched predicates).
|
|
public let reasons: [String]
|
|
|
|
/// Runner-up profile type (second-highest score), if any.
|
|
public let runnerUp: String?
|
|
|
|
/// Coding keys for custom serialization
|
|
enum CodingKeys: String, CodingKey {
|
|
case documentType = "document_type"
|
|
case confidence
|
|
case reasons
|
|
case runnerUp = "runner_up"
|
|
}
|
|
|
|
/// Create a new Classification structure.
|
|
public init(
|
|
documentType: String,
|
|
confidence: Float,
|
|
reasons: [String] = [],
|
|
runnerUp: String? = nil
|
|
) {
|
|
self.documentType = documentType
|
|
self.confidence = confidence
|
|
self.reasons = reasons
|
|
self.runnerUp = runnerUp
|
|
}
|
|
}
|
|
|
|
/// Options for classification.
|
|
public struct ClassificationOptions: Codable, Equatable {
|
|
/// Number of top reasons to include (default: all).
|
|
public let topK: UInt
|
|
|
|
/// Whether to exit with code 1 if document type is unknown.
|
|
public let exitOnUnknown: Bool
|
|
|
|
/// Create default classification options.
|
|
public init(
|
|
topK: UInt = 0,
|
|
exitOnUnknown: Bool = false
|
|
) {
|
|
self.topK = topK
|
|
self.exitOnUnknown = exitOnUnknown
|
|
}
|
|
|
|
/// Default classification options.
|
|
public static let `default` = ClassificationOptions()
|
|
}
|