Skip to content

Commit 72d3b58

Browse files
holtskinnerdandhleetelpirion
authored
docs(samples): Created Initial Enterprise Knowledge Graph Sample (GoogleCloudPlatform#8800)
* docs(samples): Created Initial Enterprise Knowledge Graph Sample - To be added to https://cloud.google.com/enterprise-knowledge-graph/docs/search-api - Replacement for googleapis/google-cloud-python#10796 * docs(samples): Added CODEOWNERS and blunderbuss for EKG * fix: Changed Import to avoid failing tests * docs(samples): Split search sample into Basic/Advanced Examples * fix: Changed CODEOWNERS to include dee-data-ai * docs(samples): Added Create Entity Reconciliation Job Sample * docs(samples): Added remaining CRUD operations for Entity Reconciliation Samples - Added Exception Handling to Create to avoid quota issues * fix(samples): Adjusted Tests for Create/Delete/Cancel * docs(samples): Created Initial Enterprise Knowledge Graph Sample - To be added to https://cloud.google.com/enterprise-knowledge-graph/docs/search-api - Replacement for googleapis/google-cloud-python#10796 * docs(samples): Added CODEOWNERS and blunderbuss for EKG * fix: Changed Import to avoid failing tests * docs(samples): Split search sample into Basic/Advanced Examples * fix: Changed CODEOWNERS to include dee-data-ai * docs(samples): Added Create Entity Reconciliation Job Sample * docs(samples): Added remaining CRUD operations for Entity Reconciliation Samples - Added Exception Handling to Create to avoid quota issues * fix(samples): Adjusted Tests for Create/Delete/Cancel * Update .github/CODEOWNERS Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com> * Update enterpriseknowledgegraph/entity_reconciliation/cancel_entity_reconciliation_job_sample.py Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com> * Update create_entity_reconciliation_job_sample.py * Update create_entity_reconciliation_job_sample.py * Update search_public_kg_sample.py * Update search_sample.py * Addressed comments about optional values * Apply suggestions from code review Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com> * Added noxfile_config with override for Python 2.7, 3.6, and 3.11 * Moved noxfile to main enterpriseknowledgegraph directory * Added lookup Code Samples * docs(samples): Upgrade enterpriseknowledgegraph to `0.3.0` to support 3.11 * Remove Noxfile Config Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com> Co-authored-by: Eric Schmidt <erschmid@google.com>
1 parent a3d9a80 commit 72d3b58

24 files changed

Lines changed: 968 additions & 0 deletions

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
/dns/**/* @GoogleCloudPlatform/python-samples-reviewers
4646
/documentai/**/* @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/python-samples-reviewers
4747
/endpoints/**/* @GoogleCloudPlatform/python-samples-reviewers
48+
/enterpriseknowledgegraph/**/* @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/python-samples-reviewers
4849
/eventarc/**/* @GoogleCloudPlatform/aap-dpes @GoogleCloudPlatform/python-samples-reviewers
4950
/error_reporting/**/* @GoogleCloudPlatform/python-samples-reviewers
5051
/firestore/**/* @GoogleCloudPlatform/cloud-native-db-dpes @GoogleCloudPlatform/python-samples-reviewers

.github/blunderbuss.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ assign_issues_by:
8484
to:
8585
- GoogleCloudPlatform/api-iot
8686
- labels:
87+
- 'api: enterpriseknowledgegraph'
8788
- 'api: documentai'
8889
- 'api: language'
8990
- 'api: texttospeech'
@@ -185,6 +186,7 @@ assign_prs_by:
185186
to:
186187
- GoogleCloudPlatform/infra-db-dpes
187188
- labels:
189+
- 'api: enterpriseknowledgegraph'
188190
- 'api: documentai'
189191
- 'api: retail'
190192
to:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# [START enterpriseknowledgegraph_cancel_entity_reconciliation_job]
17+
18+
from google.cloud import enterpriseknowledgegraph as ekg
19+
20+
# TODO(developer): Uncomment these variables before running the sample.
21+
# project_id = 'YOUR_PROJECT_ID'
22+
# location = 'YOUR_GRAPH_LOCATION' # Values: 'global'
23+
# job_id = 'YOUR_JOB_ID' # Entity Reconciliation Job ID
24+
25+
26+
def cancel_entity_reconciliation_job_sample(
27+
project_id: str, location: str, job_id: str
28+
) -> None:
29+
# Create a client
30+
client = ekg.EnterpriseKnowledgeGraphServiceClient()
31+
32+
# The full resource name of the job
33+
# e.g. projects/{project_id}/locations/{location}/entityReconciliationJobs/{entity_reconciliation_job}
34+
name = client.entity_reconciliation_job_path(
35+
project=project_id, location=location, entity_reconciliation_job=job_id
36+
)
37+
38+
# Initialize request argument(s)
39+
request = ekg.CancelEntityReconciliationJobRequest(name=name)
40+
41+
# Make the request
42+
client.cancel_entity_reconciliation_job(request=request)
43+
44+
print(f"Job: {name} successfully cancelled")
45+
46+
47+
# [END enterpriseknowledgegraph_cancel_entity_reconciliation_job]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import os
17+
18+
from google.api_core.exceptions import InvalidArgument, NotFound
19+
20+
import cancel_entity_reconciliation_job_sample
21+
22+
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
23+
location = "global"
24+
job_id = "5285051433452986163"
25+
26+
27+
def test_cancel_entity_reconciliation_job(capsys):
28+
try:
29+
cancel_entity_reconciliation_job_sample.cancel_entity_reconciliation_job_sample(
30+
project_id=project_id, location=location, job_id=job_id
31+
)
32+
except (InvalidArgument, NotFound) as e:
33+
print(e.message)
34+
35+
out, _ = capsys.readouterr()
36+
37+
assert "cancel" in out
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# [START enterpriseknowledgegraph_create_entity_reconciliation_job]
17+
18+
from google.cloud import enterpriseknowledgegraph as ekg
19+
20+
# TODO(developer): Uncomment these variables before running the sample.
21+
# project_id = 'YOUR_PROJECT_ID'
22+
# location = 'YOUR_GRAPH_LOCATION' # Values: 'global'
23+
# input_dataset = 'YOUR_INPUT_DATASET' # BigQuery Dataset Name
24+
# input_table = 'YOUR_INPUT_TABLE' # BigQuery Table Name
25+
# mapping_file_uri = 'YOUR_MAPPING_FILE # GCS Path. Example: gs://ekg-test-gcs/mapping.yml
26+
# output_dataset = 'YOUR_OUTPUT_DATASET' # BigQuery Dataset Name
27+
28+
# Refer to https://cloud.google.com/enterprise-knowledge-graph/docs/schema
29+
# entity_type = ekg.InputConfig.EntityType.Person
30+
31+
32+
def create_entity_reconciliation_job_sample(
33+
project_id: str,
34+
location: str,
35+
input_dataset: str,
36+
input_table: str,
37+
mapping_file_uri: str,
38+
entity_type: int,
39+
output_dataset: str,
40+
) -> None:
41+
# Create a client
42+
client = ekg.EnterpriseKnowledgeGraphServiceClient()
43+
44+
# The full resource name of the location
45+
# e.g. projects/{project_id}/locations/{location}
46+
parent = client.common_location_path(project=project_id, location=location)
47+
48+
# Input Parameters
49+
input_config = ekg.InputConfig(
50+
bigquery_input_configs=[
51+
ekg.BigQueryInputConfig(
52+
bigquery_table=client.table_path(
53+
project=project_id, dataset=input_dataset, table=input_table
54+
),
55+
gcs_uri=mapping_file_uri,
56+
)
57+
],
58+
entity_type=entity_type,
59+
)
60+
61+
# Output Parameters
62+
output_config = ekg.OutputConfig(
63+
bigquery_dataset=client.dataset_path(project=project_id, dataset=output_dataset)
64+
)
65+
66+
entity_reconciliation_job = ekg.EntityReconciliationJob(
67+
input_config=input_config, output_config=output_config
68+
)
69+
70+
# Initialize request argument(s)
71+
request = ekg.CreateEntityReconciliationJobRequest(
72+
parent=parent, entity_reconciliation_job=entity_reconciliation_job
73+
)
74+
75+
# Make the request
76+
response = client.create_entity_reconciliation_job(request=request)
77+
78+
print(f"Job: {response.name}")
79+
print(
80+
f"Input Table: {response.input_config.bigquery_input_configs[0].bigquery_table}"
81+
)
82+
print(f"Output Dataset: {response.output_config.bigquery_dataset}")
83+
print(f"State: {response.state.name}")
84+
85+
86+
# [END enterpriseknowledgegraph_create_entity_reconciliation_job]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import os
17+
18+
from google.api_core.exceptions import ResourceExhausted
19+
from google.cloud import enterpriseknowledgegraph as ekg
20+
21+
import create_entity_reconciliation_job_sample
22+
23+
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
24+
location = "global"
25+
input_dataset = "ekg_entity_reconciliation"
26+
input_table = "patients"
27+
mapping_file_uri = "gs://cloud-samples-data/ekg/quickstart/test_mapping1.yml"
28+
entity_type = ekg.InputConfig.EntityType.PERSON
29+
output_dataset = "ekg_entity_reconciliation"
30+
31+
32+
def test_create_entity_reconciliation_job(capsys):
33+
34+
try:
35+
create_entity_reconciliation_job_sample.create_entity_reconciliation_job_sample(
36+
project_id=project_id,
37+
location=location,
38+
input_dataset=input_dataset,
39+
input_table=input_table,
40+
mapping_file_uri=mapping_file_uri,
41+
entity_type=entity_type,
42+
output_dataset=output_dataset,
43+
)
44+
except (ResourceExhausted) as e:
45+
# Quota for simultaneous jobs is 2
46+
print(e.message)
47+
48+
out, _ = capsys.readouterr()
49+
50+
assert "Job: projects/" in out or "Resource Exhausted" in out
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# [START enterpriseknowledgegraph_delete_entity_reconciliation_job]
17+
18+
from google.cloud import enterpriseknowledgegraph as ekg
19+
20+
# TODO(developer): Uncomment these variables before running the sample.
21+
# project_id = 'YOUR_PROJECT_ID'
22+
# location = 'YOUR_GRAPH_LOCATION' # Values: 'global'
23+
# job_id = 'YOUR_JOB_ID' # Entity Reconciliation Job ID
24+
25+
26+
def delete_entity_reconciliation_job_sample(
27+
project_id: str, location: str, job_id: str
28+
) -> None:
29+
# Create a client
30+
client = ekg.EnterpriseKnowledgeGraphServiceClient()
31+
32+
# The full resource name of the job
33+
# e.g. projects/{project_id}/locations/{location}/entityReconciliationJobs/{entity_reconciliation_job}
34+
name = client.entity_reconciliation_job_path(
35+
project=project_id, location=location, entity_reconciliation_job=job_id
36+
)
37+
38+
# Initialize request argument(s)
39+
request = ekg.DeleteEntityReconciliationJobRequest(name=name)
40+
41+
# Make the request
42+
client.delete_entity_reconciliation_job(request=request)
43+
44+
print(f"Job: {name} successfully deleted")
45+
46+
47+
# [END enterpriseknowledgegraph_delete_entity_reconciliation_job]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import os
17+
18+
from google.api_core.exceptions import InvalidArgument, NotFound
19+
20+
import delete_entity_reconciliation_job_sample
21+
22+
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
23+
location = "global"
24+
job_id = "5285051433452986164"
25+
26+
27+
def test_delete_entity_reconciliation_job(capsys):
28+
try:
29+
delete_entity_reconciliation_job_sample.delete_entity_reconciliation_job_sample(
30+
project_id=project_id, location=location, job_id=job_id
31+
)
32+
except (InvalidArgument, NotFound) as e:
33+
print(e.message)
34+
35+
out, _ = capsys.readouterr()
36+
37+
assert "projects/" in out
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# [START enterpriseknowledgegraph_get_entity_reconciliation_job]
17+
18+
from google.cloud import enterpriseknowledgegraph as ekg
19+
20+
# TODO(developer): Uncomment these variables before running the sample.
21+
# project_id = 'YOUR_PROJECT_ID'
22+
# location = 'YOUR_GRAPH_LOCATION' # Values: 'global'
23+
# job_id = 'YOUR_JOB_ID' # Entity Reconciliation Job ID
24+
25+
26+
def get_entity_reconciliation_job_sample(
27+
project_id: str, location: str, job_id: str
28+
) -> None:
29+
# Create a client
30+
client = ekg.EnterpriseKnowledgeGraphServiceClient()
31+
32+
# The full resource name of the job
33+
# e.g. projects/{project_id}/locations/{location}/entityReconciliationJobs/{entity_reconciliation_job}
34+
name = client.entity_reconciliation_job_path(
35+
project=project_id, location=location, entity_reconciliation_job=job_id
36+
)
37+
38+
# Initialize request argument(s)
39+
request = ekg.GetEntityReconciliationJobRequest(name=name)
40+
41+
# Make the request
42+
response = client.get_entity_reconciliation_job(request=request)
43+
44+
print(f"Job: {response.name}")
45+
print(
46+
f"Input Table: {response.input_config.bigquery_input_configs[0].bigquery_table}"
47+
)
48+
print(f"Output Dataset: {response.output_config.bigquery_dataset}")
49+
print(f"State: {response.state.name}")
50+
51+
52+
# [END enterpriseknowledgegraph_get_entity_reconciliation_job]

0 commit comments

Comments
 (0)