Skip to content

Use Natural Language Framework for redaction #1

@eonist

Description

@eonist
let text = "John Doe lives in New York."
let tagger = NLTagger(tagSchemes: [.nameType])
tagger.string = text

tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .nameType) { tag, tokenRange in
    if tag == .personalName || tag == .placeName {
        // Redact the sensitive information
        text.replaceSubrange(tokenRange, with: "[REDACTED]")
    }
    return true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions