Gunakan DetectPiiEntities dengan AWS SDK atau CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan DetectPiiEntities dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanDetectPiiEntities.

Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

using System; using System.Threading.Tasks; using Amazon.Comprehend; using Amazon.Comprehend.Model; /// <summary> /// This example shows how to use the Amazon Comprehend service to find /// personally identifiable information (PII) within text submitted to the /// DetectPiiEntitiesAsync method. /// </summary> public class DetectingPII { /// <summary> /// This method calls the DetectPiiEntitiesAsync method to locate any /// personally dientifiable information within the supplied text. /// </summary> public static async Task Main() { var comprehendClient = new AmazonComprehendClient(); var text = @"Hello Paul Santos. The latest statement for your credit card account 1111-0000-1111-0000 was mailed to 123 Any Street, Seattle, WA 98109."; var request = new DetectPiiEntitiesRequest { Text = text, LanguageCode = "EN", }; var response = await comprehendClient.DetectPiiEntitiesAsync(request); if (response.Entities.Count > 0) { foreach (var entity in response.Entities) { var entityValue = text.Substring(entity.BeginOffset, entity.EndOffset - entity.BeginOffset); Console.WriteLine($"{entity.Type}: {entityValue}"); } } } }
CLI
AWS CLI

Untuk mendeteksi entitas pii dalam teks input

detect-pii-entitiesContoh berikut menganalisis teks input dan mengidentifikasi entitas yang berisi informasi yang dapat diidentifikasi secara pribadi (). PII Skor kepercayaan model yang telah dilatih sebelumnya juga merupakan output untuk setiap prediksi.

aws comprehend detect-pii-entities \ --language-code en \ --text "Hello Zhang Wei, I am John. Your AnyCompany Financial Services, LLC credit card \ account 1111-XXXX-1111-XXXX has a minimum payment of $24.53 that is due by July 31st. Based on your autopay settings, \ we will withdraw your payment on the due date from your bank account number XXXXXX1111 with the routing number XXXXX0000. \ Customer feedback for Sunshine Spa, 123 Main St, Anywhere. Send comments to Alice at AnySpa@example.com."

Output:

{ "Entities": [ { "Score": 0.9998322129249573, "Type": "NAME", "BeginOffset": 6, "EndOffset": 15 }, { "Score": 0.9998878240585327, "Type": "NAME", "BeginOffset": 22, "EndOffset": 26 }, { "Score": 0.9994089603424072, "Type": "CREDIT_DEBIT_NUMBER", "BeginOffset": 88, "EndOffset": 107 }, { "Score": 0.9999760985374451, "Type": "DATE_TIME", "BeginOffset": 152, "EndOffset": 161 }, { "Score": 0.9999449253082275, "Type": "BANK_ACCOUNT_NUMBER", "BeginOffset": 271, "EndOffset": 281 }, { "Score": 0.9999847412109375, "Type": "BANK_ROUTING", "BeginOffset": 306, "EndOffset": 315 }, { "Score": 0.999925434589386, "Type": "ADDRESS", "BeginOffset": 354, "EndOffset": 365 }, { "Score": 0.9989161491394043, "Type": "NAME", "BeginOffset": 394, "EndOffset": 399 }, { "Score": 0.9994171857833862, "Type": "EMAIL", "BeginOffset": 403, "EndOffset": 418 } ] }

Untuk informasi selengkapnya, lihat Informasi Identifikasi Pribadi (PII) di Panduan Pengembang Amazon Comprehend.

Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

class ComprehendDetect: """Encapsulates Comprehend detection functions.""" def __init__(self, comprehend_client): """ :param comprehend_client: A Boto3 Comprehend client. """ self.comprehend_client = comprehend_client def detect_pii(self, text, language_code): """ Detects personally identifiable information (PII) in a document. PII can be things like names, account numbers, or addresses. :param text: The document to inspect. :param language_code: The language of the document. :return: The list of PII entities along with their confidence scores. """ try: response = self.comprehend_client.detect_pii_entities( Text=text, LanguageCode=language_code ) entities = response["Entities"] logger.info("Detected %s PII entities.", len(entities)) except ClientError: logger.exception("Couldn't detect PII entities.") raise else: return entities