MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dlp/deIdentifyWithSimpleWordList.js:23–103  ·  view source on GitHub ↗
(projectId, textToInspect, words, customInfoTypeName)

Source from the content-addressed store, hash-verified

21// usage: node deIdentifyWithSimpleWordList.js my-project text-to-insect word-list custom-info-type-name
22
23function main(projectId, textToInspect, words, customInfoTypeName) {
24 words = words.split(',');
25 // [START dlp_deidentify_simple_word_list]
26 // Imports the Google Cloud Data Loss Prevention library
27 const DLP = require('@google-cloud/dlp');
28
29 // TODO(developer): Replace these variables before running the sample.
30 // const projectId = "your-project-id";
31
32 // The string to de-identify
33 // const textToInspect = 'Patient was seen in RM-YELLOW then transferred to rm green.';
34
35 // Words to look for during inspection
36 // const words = ['RM-GREEN', 'RM-YELLOW', 'RM-ORANGE'];
37
38 // Name of the custom info type
39 // const customInfoTypeName = 'CUSTOM_ROOM_ID';
40
41 async function deIdentifyWithSimpleWordList() {
42 // Initialize client that will be used to send requests. This client only needs to be created
43 // once, and can be reused for multiple requests. After completing all of your requests, call
44 // the "close" method on the client to safely clean up any remaining background resources.
45 const dlp = new DLP.DlpServiceClient();
46
47 // Construct the word list to be detected
48 const wordList = {
49 words: words,
50 };
51
52 // Specify the word list custom info type the inspection will look for.
53 const infoType = {
54 name: customInfoTypeName,
55 };
56 const customInfoType = {
57 infoType,
58 dictionary: {
59 wordList,
60 },
61 };
62
63 // Construct de-identify configuration
64 const deidentifyConfig = {
65 infoTypeTransformations: {
66 transformations: [
67 {
68 primitiveTransformation: {
69 replaceWithInfoTypeConfig: {},
70 },
71 },
72 ],
73 },
74 };
75
76 // Construct inspect configuration
77 const inspectConfig = {
78 customInfoTypes: [customInfoType],
79 };
80

Callers 1

Calls 1

Tested by

no test coverage detected