要先建好Azure Language Services或 Azure AI Service (包含很多azure服務)
Azure Language 能用各種語言不用裝套件直接打, 也能用Postman測, 但官網範例是錯的
.net語法可參考 [AI] Azure PII進行資料遮罩(舊寫法,仍可用)
以下為呼叫方法:
URL: https://XXXX.cognitiveservices.azure.com/language/:analyze-text?api-version=2024-11-15-preview
Header: Ocp-Apim-Subscription-Key=你的key
Body:以json格式傳送如下內容:
{"kind": "PiiEntityRecognition",
"parameters":{
"modelVersion": "latest",
"piiCategories": ["Address","Person","CreditCardNumber","PhoneNumber","TWNationalID","TWResidentCertificate","TWPassportNumber"] ,
//容器不看 redactionPolicy 參數
"redactionPolicy": {"policyKind": "CharacterMask",//CharacterMask, NoMask, EntityMask
"redactionCharacter": "*"}},//可替換的只有半形符號,ex.- ^ + *
"analysisInput":{
"documents":
[{"id":"1","text":"ebay 王大明 Ms. Mary 台灣國台北巿獨立路一段自由巷 帳戶:4987135588888888"},
{"id":"2","text":"卡號:4987135588888888 王小強 Mr.John Lee, TEL:0800080080 No. 123, Ziyou Road, Hualien City, Taiwan"}
]
}
}
回覆資料如下:
{
"kind": "PiiEntityRecognitionResults",
"results": {
"documents": [
{
"redactedText": "ebay *** Ms. **** ************** 帳戶:4987135588888888",
"id": "1",
"entities": [
{
"text": "王大明",
"category": "Person",
"type": "Person",
"offset": 5,
"length": 3,
"confidenceScore": 0.97,
"tags": [
{
"name": "Person",
"confidenceScore": 0.97
}
]
},
{
"text": "Mary",
"category": "Person",
"type": "Person",
"offset": 13,
"length": 4,
"confidenceScore": 0.58,
"tags": [
{
"name": "Person",
"confidenceScore": 0.58
}
]
},
{
"text": "台灣國台北巿獨立路一段自由巷",
"category": "Address",
"type": "Address",
"offset": 18,
"length": 14,
"confidenceScore": 0.9,
"tags": [
{
"name": "Address",
"confidenceScore": 0.9
}
]
}
],
"warnings": []
},
{
"redactedText": "卡號***************** *** Mr.********, TEL:********** *****************************************",
"id": "2",
"entities": [
{
"text": ":4987135588888888",
"category": "CreditCardNumber",
"type": "CreditCardNumber",
"offset": 2,
"length": 17,
"confidenceScore": 0.94,
"tags": [
{
"name": "CreditCardNumber",
"confidenceScore": 0.94
}
]
},
{
"text": "王小強",
"category": "Person",
"type": "Person",
"offset": 20,
"length": 3,
"confidenceScore": 0.99,
"tags": [
{
"name": "Person",
"confidenceScore": 0.99
}
]
},
{
"text": "John Lee",
"category": "Person",
"type": "Person",
"offset": 27,
"length": 8,
"confidenceScore": 0.93,
"tags": [
{
"name": "Person",
"confidenceScore": 0.93
}
]
},
{
"text": "0800080080",
"category": "PhoneNumber",
"type": "PhoneNumber",
"offset": 41,
"length": 10,
"confidenceScore": 0.8,
"tags": [
{
"name": "PhoneNumber",
"confidenceScore": 0.8
}
]
},
{
"text": "No. 123, Ziyou Road, Hualien City, Taiwan",
"category": "Address",
"type": "Address",
"offset": 52,
"length": 41,
"confidenceScore": 0.94,
"tags": [
{
"name": "Address",
"confidenceScore": 0.94
}
]
}
],
"warnings": []
}
],
"errors": [],
"modelVersion": "2025-02-01"
}
}
測試過帳戶改成銀行帳戶, 就會被遮罩
Taiwan is a country. 臺灣是我的國家