Is there a way to find the row information in response result finding of Google DLP? - google-cloud-dlp

I am sending a multiple sentence at a time as a table and using inspect_content to find personal information for each sentences.
When I use the inspect_content function, I could receive a series of findings with various information.
However, I could not find which row the each inspect result came from.
I have to deliver both original text and the location range of each target info types.
Thank you for your precious time ^^
enter image description here

There is a rowIndex for inspect content.
Example request
{"item":{"table":{"headers":[{"name":"column1"}],"rows":[{"values":[{"stringValue":"not an email"}]},{"values":[{"stringValue":"test#gmail.com"}]}]}}}
Example response (see the table location)
{
"result": {
"findings": [
{
"infoType": {
"name": "EMAIL_ADDRESS"
},
"likelihood": "LIKELY",
"location": {
"byteRange": {
"end": "14"
},
"codepointRange": {
"end": "14"
},
"contentLocations": [
{
"recordLocation": {
"fieldId": {
"name": "column1"
},
"tableLocation": {
"rowIndex": "1"
}
}
}
]
},
"createTime": "2022-01-05T18:15:04.413Z",
"findingId": "2022-01-05T18:15:04.422252Z312288285164444315"
}
]
}
}

Related

Query Firebase using Rest Call

I am querying firestore using query
https://firestore.googleapis.com/v1/projects/myproject/databases/(default)/documents/mycollection
I am getting following Json. Can someone please help me how can I filter my query based on Rate field. I am writing following query and it doesn't work
https://firestore.googleapis.com/v1/projects/myproject/databases/(default)/documents/mycolletion?Rate="15"
{
"documents": [
{
"name": "0C45nDuozgQDOwEx5xHR",
"fields": {
"Clinic": {
"stringValue": "American Hospital"
},
"Rate": {
"stringValue": "140"
},
,`enter code here`
"createTime": "2020-06-28T20:32:18.776123Z",
"updateTime": "2020-07-22T21:19:24.061647Z"
},
{
"name": "Jm3tNVWmk4Q1pk87KL1m",
"fields": {
"Clinic": {
"stringValue": "Cleaveland clinic"
},
"Rate": {
"stringValue": "150"
},
"createTime": "2020-06-28T20:28:03.726819Z",
"updateTime": "2020-07-22T21:19:05.073019Z"
}
}
The problem is that the Rate field is an object (inside another object to make it worse), so in order to achieve that you would either need to update you Firestore structure to do it all in the request URL, or you would have to use a structured query in the body of the request.
Change the structure:
In order to work with the request you already have, you will need to change the structure to (using the 1st document as an example):
{
"name": "0C45nDuozgQDOwEx5xHR",
"Clinic": "American Hospital",
"Rate": "140",
"createTime": "2020-06-28T20:32:18.776123Z",
"updateTime": "2020-07-22T21:19:24.061647Z"
}
which in my opinion makes it simpler although I don't have the full picture
Have a Structured query in your request body:
To keep the structure you already have you will need to use thisURL:
https://firestore.googleapis.com/v1/projects/myproject/databases/(default)/documents/:runQuery
And add this to the body of the request:
"structuredQuery": {
"from": [{
"collectionId": "mycollection"
}],
"where": {
"fieldFilter": {
"fields": {
"Rate": {
"stringValue": "15"
}
}
}
}
}
You can check more details by checking the runQuery Documentation and the structuredQuery Documentation for what else you can do with these options.

Gremlin Query (JSON Output) using tree

Query:
g.withSack(0).V().hasLabel('A').has('label_A','A').union(__.emit().repeat(sack(sum).by(constant(1)).in()),emit().repeat(sack(sum).by(constant(-1)).out())).project('level','properties').by(sack()).by(tree().by(valueMap().by(unfold())).unfold())
Output:
{
"level": 1,
"properties": {
"key": {
"label_A": "A"
},
"value": {
"{label_A=A}": {}
}
}
},
{
"level": 2,
"properties": {
"key": {
"label_A": "A"
},
"value": {
"{label_A=A}": {}
}
}
}
}
Getting keys in json format but not values. Please suggest changes in query to acheive the values in json format.
The tree() step returns a tree structure in the form of a Map of Map instances essentially so the output is about what you can expect. In this case, I wonder if you need to use tree() and could instead get by with path() as it seems like it accomplishes the same result without the added structure:
g.withSack(0).
V().hasLabel('A').has('label_A','A').
union(__.emit().repeat(sack(sum).by(constant(1)).in()),
emit().repeat(sack(sum).by(constant(-1)).out())).
project('level','properties').
by(sack()).
by(path().by(elementMap()))

Updating item in DynamoDB fails for the UpdateExpression syntax

My table data looks like below one
{
"id": {
"S": "alpha-rocket"
},
"images": {
"SS": [
"apple/value:50",
"Mango/aa:284_454_51.0.0",
"Mango/bb:291",
"Mango/cc:4"
]
},
"product": {
"S": "fruit"
}
}
Below is my code to update table. The variables I am passing to function has values product_id has alpha-rocket, image_val has 284_454_53.0.0 and image has Mango/aa:284_454_53.0.0.
I am trying to update value of Mango/aa from 284_454_51.0.0 to 284_454_53.0.0 but getting an error "The document path provided in the update expression is invalid for update"
def update_player_score(product_id, image_val, image):
dynamo = boto3.resource('dynamodb')
tbl = dynamo.Table('<TableName>')
result = tbl.update_item(
expression_attribute_names: {
"#image_name" => "image_name"
},
expression_attribute_values: {
":image_val" => image_val,
},
key: {
"product" => "fruit",
"id" => product_id,
},
return_values: "ALL_NEW",
table_name: "orcus",
update_expression: "SET images.#image_val = :image_val",
}
Is there a way to update the value of Mango/aa or replace full string "Mango/aa:284_454_51.0.0" to "Mango/aa:284_454_53.0.0"
You cannot update a string in a list by matching the string. If you know the index of it you can replace the value of the string by index:
SET images[1] = : image_val
It seems like maybe what you want is not a list of strings, but another map. So instead of your data looking like it does you'd make it look like this, which would allow you to do the update you're looking for:
{
"id": {
"S": "alpha-rocket"
},
"images": {
"M": {
"apple" : {
"M": {
"value": {
"S": "50"
}
},
"Mango" : {
"M": {
"aa": {
"S": "284_454_51.0.0"
},
"bb": {
"S": "291"
},
"cc": {
"S": "4"
}
}
}
},
"product": {
"S": "fruit"
}
}
I would also consider putting the different values in different "rows" in the table and using queries to build the objects.

JSONAPI - Difference between self and related in a links resource

Why is the self and related references different in the below JSONAPI resource? Aren't they pointing to the same resource? What is the difference between going to /articles/1/relationships/tags and /articles/1/tags?
{
"links": {
"self": "/articles/1/relationships/tags",
"related": "/articles/1/tags"
},
"data": [
{ "type": "tags", "id": "2" },
{ "type": "tags", "id": "3" }
]
}
You can read about that here: https://github.com/json-api/json-api/issues/508.
Basically, with /articles/1/relationships/tags response will be object which represents relationship between articles and tags. The response could be something like this (what you put in your question):
{
"links": {
"self": "/articles/1/relationships/tags",
"related": "/articles/1/tags"
},
"data": [
{ "type": "tags", "id": "2" },
{ "type": "tags", "id": "3" }
]
}
This response gives only the necessary data (in primary data attribute - data) to manipulate the relationship and not resources connected with relationship. That being said, you'll call /articles/1/relationships/tags if you want to create new relationship, add a new tag (basically updating relationship) to article, read which tags belong to article (you only need identity to search them on server) or delete article tags.
On the other hand, calling /articles/1/tags will respond with tags as primary data with all the other properties that they have (articles, relationships, links, and other top-level attributes such include, emphasized text, links and/or jsonapi).
They are different. Here is an example from my project.
Try Get http://localhost:3000/phone-numbers/1/relationships/contact you will get response like this:
{
"links": {
"self": "http://localhost:3000/phone-numbers/1/relationships/contact",
"related": "http://localhost:3000/phone-numbers/1/contact"
},
"data": {
"type": "contacts",
"id": "1"
}
}
You didn't get the attributes and relationships which is probably you want to retrieve.
Then
Try Get http://localhost:3000/phone-numbers/1/contact you will get response like this:
{
"data": {
"id": "1",
"type": "contacts",
"links": {
"self": "http://localhost:3000/contacts/1"
},
"attributes": {
"name-first": "John",
"name-last": "Doe",
"email": "john.doe#boring.test",
"twitter": null
},
"relationships": {
"phone-numbers": {
"links": {
"self": "http://localhost:3000/contacts/1/relationships/phone-numbers",
"related": "http://localhost:3000/contacts/1/phone-numbers"
}
}
}
}
}
You can see you retrieved all the information you want, including the attributes and relationships.
But you should know that relationships can be used for some purpose. Please read http://jsonapi.org/format/#crud-updating-to-one-relationships as a sample.

JSONPath first occurrence of "gatherer"

I have a json file like this:
{
"cards": [
{
"artist": "Steve Argyle",
"images": {
"mtgimage": "http://mtgimage.com/set/pMPR/ponder.jpg"
},
},
{
"artist": "Mark Tedin",
"images": {
"gatherer": "http://gatherer.wizards.com/Handlers/Image.ashx?type=card&multiverseid=139512",
"mtgimage": "http://mtgimage.com/set/LRW/ponder.jpg"
},
},
{
"artist": "Dan Scott",
"images": {
"gatherer": "http://gatherer.wizards.com/Handlers/Image.ashx?type=card&multiverseid=190159",
"mtgimage": "http://mtgimage.com/set/M10/ponder.jpg"
},
}
]
}
I would like to get the first "gatherer" link from it using JSONPath.
I tried "$..gatherer[0]" but that doesn't work. However "$..gatherer" does give both instances:
[
"http:\/\/gatherer.wizards.com\/Handlers\/Image.ashx?type=card&multiverseid=139512",
"http:\/\/gatherer.wizards.com\/Handlers\/Image.ashx?type=card&multiverseid=190159"
]
How do I get only the first one? (without getting the last one in code, so only using a jsonpath string.)
(Tested with http://jsonpath.curiousconcept.com/ and in my program.)
You may need an interim step to save the array
var gatherers = $..gatherer; //however this gets it, I'm not sure
var first = gatherers[0];
that may work.

Resources