|
61 | 61 | "source": [
|
62 | 62 | "## Connect\n",
|
63 | 63 | "\n",
|
64 |
| - "Using the ArcGIS API for Python, you can connect to a `KnowledgeGraph` with `arcgis.graph`:" |
| 64 | + "Using the ArcGIS API for Python, you can connect to a [`KnowledgeGraph`](https://developers.arcgis.com/python/latest/api-reference/arcgis.graph.html#knowledgegraph) with [`arcgis.graph`](https://developers.arcgis.com/python/latest/api-reference/arcgis.graph.html):" |
65 | 65 | ]
|
66 | 66 | },
|
67 | 67 | {
|
|
90 | 90 | "metadata": {},
|
91 | 91 | "source": [
|
92 | 92 | "## Create\n",
|
93 |
| - "Using the ArcGIS API for Python, you can create a new Knowledge Graph using [create_service()](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.create_service)." |
| 93 | + "Using the ArcGIS API for Python, you can create a new Knowledge Graph using [`create_service()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.create_service)." |
94 | 94 | ]
|
95 | 95 | },
|
96 | 96 | {
|
|
166 | 166 | "metadata": {},
|
167 | 167 | "outputs": [],
|
168 | 168 | "source": [
|
169 |
| - "knowledge_graph.datamodel" |
| 169 | + "knowledge_graph.query_data_model(as_dict=False)" |
170 | 170 | ]
|
171 | 171 | },
|
172 | 172 | {
|
173 | 173 | "cell_type": "markdown",
|
174 | 174 | "metadata": {},
|
175 | 175 | "source": [
|
176 |
| - "The response from `datamodel` has many useful components that describe the schema of the knowledge graph. Important information to look for on the data model includes spatial reference, strictness, whether the service is arcgis managed, information on the unique identifier property, and search indexes. The data model also includes detailed information on each entity and relationship type.\n", |
| 176 | + "The response from `query_data_model()` has many useful components that describe the schema of the knowledge graph. When `as_dict` is set to `False`, the response will be a `GraphDataModel`. Important information to look for on the data model includes spatial reference, strictness, whether the service is arcgis managed, information on the unique identifier property, and search indexes. The data model also includes detailed information on each entity and relationship type.\n", |
177 | 177 | "\n",
|
178 | 178 | "```\n",
|
179 |
| - "{'data_model_timestamp': datetime.datetime(2023, 3, 22, 14, 4, 44, 432000),\n", |
180 |
| - " 'spatial_reference': {'wkid': 4326},\n", |
181 |
| - " 'entity_types': <dictionary of entity types>, # see below for more info on type dictionaries\n", |
182 |
| - " 'relationship_types': <dictionary of relationship types>, # see below for more info on type dictionaries\n", |
183 |
| - " 'strict': False,\n", |
184 |
| - " 'objectid_property': 'objectid',\n", |
185 |
| - " 'globalid_property': 'globalid',\n", |
186 |
| - " 'arcgis_managed': True,\n", |
187 |
| - " 'identifier_info': {'identifier_mapping_info': {'uniform_property': {'identifier_property_name': 'globalid'}},\n", |
188 |
| - " 'identifier_generation_info': {'uuid_method_hint': 'esriUUIDESRI'}},\n", |
189 |
| - " 'search_indexes': {'esri__search_idx': {'name': 'esri__search_idx',\n", |
190 |
| - " 'supported_category': 'Both',\n", |
191 |
| - " 'analyzers': [{'name': 'text_en'}, {'name': 'identity'}],\n", |
192 |
| - " 'search_properties': {'Document': {'property_names': ['metadata',\n", |
193 |
| - " 'keywords',\n", |
194 |
| - " 'fileExtension',\n", |
195 |
| - " 'globalid',\n", |
196 |
| - " 'name',\n", |
197 |
| - " 'text',\n", |
198 |
| - " 'title',\n", |
199 |
| - " 'contentType',\n", |
200 |
| - " 'url']},\n", |
201 |
| - " 'HasDocument': {'property_names': ['globalid']},\n", |
202 |
| - " 'Observation': {'property_names': ['quality_grade',\n", |
203 |
| - " 'globalid',\n", |
204 |
| - " 'time_observed',\n", |
205 |
| - " 'description',\n", |
206 |
| - " 'location',\n", |
207 |
| - " 'observation_url',\n", |
208 |
| - " 'photo_url',\n", |
209 |
| - " 'species_guess',\n", |
210 |
| - " 'most_disagree_with_identificati',\n", |
211 |
| - " 'place_guess']},\n", |
212 |
| - " 'Observed': {'property_names': ['globalid']},\n", |
213 |
| - " 'ObservedIn': {'property_names': ['globalid']},\n", |
214 |
| - " 'Reviewed': {'property_names': ['globalid']},\n", |
215 |
| - " 'Species': {'property_names': ['taxon_common_name',\n", |
216 |
| - " 'globalid',\n", |
217 |
| - " 'taxon_name',\n", |
218 |
| - " 'taxon_wikipedia',\n", |
219 |
| - " 'taxon_photo_url']},\n", |
220 |
| - " 'User': {'property_names': ['globalid', 'name', 'created_date']}}}}}\n", |
| 179 | + "GraphDataModel(\n", |
| 180 | + " data_model_timestamp=1737573982389, \n", |
| 181 | + " spatial_reference={'wkid': 4326}, \n", |
| 182 | + " entity_types=[\n", |
| 183 | + " EntityType(\n", |
| 184 | + " name='Vehicle', \n", |
| 185 | + " alias='', \n", |
| 186 | + " role='esriGraphNamedObjectRegular', \n", |
| 187 | + " strict=False, \n", |
| 188 | + " properties=[\n", |
| 189 | + " GraphProperty(name='objectid', alias='objectid', domain='', field_type='esriFieldTypeOID', geometry_type=None, has_z=False, has_m=False, default_value=None, nullable=False, visible=True, editable=False, required=True, is_system_maintained=True, role='esriGraphPropertyRegular'), \n", |
| 190 | + " GraphProperty(name='globalid', alias='globalid', domain='', field_type='esriFieldTypeGlobalID', geometry_type=None, has_z=False, has_m=False, default_value=None, nullable=False, visible=True, editable=False, required=True, is_system_maintained=True, role='esriGraphPropertyRegular'), \n", |
| 191 | + " GraphProperty(name='make', alias='', domain='', field_type='esriFieldTypeString', geometry_type=None, has_z=False, has_m=False, default_value=None, nullable=True, visible=True, editable=True, required=False, is_system_maintained=False, role='esriGraphPropertyRegular')\n", |
| 192 | + " ], \n", |
| 193 | + " field_indexes=[\n", |
| 194 | + " FieldIndex(name='esri__oid_idx', is_ascending=True, is_unique=True, fields=['objectid']), \n", |
| 195 | + " FieldIndex(name='esri__globalid_idx', is_ascending=True, is_unique=True, fields=['globalid'])\n", |
| 196 | + " ]\n", |
| 197 | + " )\n", |
| 198 | + " ],\n", |
| 199 | + " search_indexes=[\n", |
| 200 | + " SearchIndex(\n", |
| 201 | + " name='esri__search_idx', \n", |
| 202 | + " supported_category='both_entity_relationship', \n", |
| 203 | + " analyzers=[SearchAnalyzer(name='text_en'), \n", |
| 204 | + " SearchAnalyzer(name='identity')], \n", |
| 205 | + " search_properties={\n", |
| 206 | + " 'Document': SearchIndexProperties(property_names=['metadata', 'keywords', 'fileExtension', 'globalid', 'name', 'text', 'title', 'contentType', 'url']), \n", |
| 207 | + " 'HasDocument': SearchIndexProperties(property_names=['globalid']), \n", |
| 208 | + " 'Vehicle': SearchIndexProperties(property_names=['globalid', 'make'])\n", |
| 209 | + " }\n", |
| 210 | + " )\n", |
| 211 | + " ], \n", |
| 212 | + " provenance_source_type_values=ProvenanceSourceTypeValues(value_behavior_array=[]), \n", |
| 213 | + " constraint_rules=[\n", |
| 214 | + " RelationshipExclusionRule(name='HasDocumentRule', alias=\"Relationships of type 'HasDocument' can only have a destination entity of type 'Document'.\", disabled=False, role='esriGraphConstraintRuleRoleHasDocument', type='esriGraphRelationshipExclusionRuleType', origin_entity_types=SetOfNamedTypes(set=[], set_complement=[]), relationship_types=SetOfNamedTypes(set=['HasDocument'], set_complement=[]), destination_entity_types=SetOfNamedTypes(set=[], set_complement=['Document']))\n", |
| 215 | + " ]\n", |
| 216 | + ")\n", |
221 | 217 | "```\n",
|
222 | 218 | "\n",
|
223 | 219 | "Entity and relationship types each have a format very similar to each other including basic information about the type like the name, role and strictness as well as properties and field indexes on the type. For a single type, this could look like:\n",
|
224 | 220 | "```\n",
|
225 |
| - "{'Company': {\n", |
226 |
| - " 'name': 'Company',\n", |
227 |
| - " 'alias': '',\n", |
228 |
| - " 'role': 'esriGraphNamedObjectRegular',\n", |
229 |
| - " 'strict': False,\n", |
230 |
| - " 'properties': {\n", |
231 |
| - " 'name': {\n", |
232 |
| - " 'name': 'name',\n", |
233 |
| - " 'alias': 'name',\n", |
234 |
| - " 'fieldType': 'esriFieldTypeString',\n", |
235 |
| - " 'hasZ': False,\n", |
236 |
| - " 'hasM': False,\n", |
237 |
| - " 'nullable': True,\n", |
238 |
| - " 'editable': True,\n", |
239 |
| - " 'visible': True,\n", |
240 |
| - " 'required': False,\n", |
241 |
| - " 'isSystemMaintained': False,\n", |
242 |
| - " 'role': 'esriGraphPropertyRegular'\n", |
243 |
| - " },\n", |
244 |
| - " 'objectid': {\n", |
245 |
| - " 'name': 'objectid',\n", |
246 |
| - " 'alias': 'objectid',\n", |
247 |
| - " 'fieldType': 'esriFieldTypeOID',\n", |
248 |
| - " 'hasZ': False,\n", |
249 |
| - " 'hasM': False,\n", |
250 |
| - " 'nullable': False,\n", |
251 |
| - " 'editable': False,\n", |
252 |
| - " 'visible': True,\n", |
253 |
| - " 'required': True,\n", |
254 |
| - " 'isSystemMaintained': True,\n", |
255 |
| - " 'role': 'esriGraphPropertyRegular'\n", |
256 |
| - " },\n", |
257 |
| - " 'globalid': {\n", |
258 |
| - " 'name': 'globalid',\n", |
259 |
| - " 'alias': 'globalid',\n", |
260 |
| - " 'fieldType': 'esriFieldTypeGlobalID',\n", |
261 |
| - " 'hasZ': False,\n", |
262 |
| - " 'hasM': False,\n", |
263 |
| - " 'nullable': False,\n", |
264 |
| - " 'editable': False,\n", |
265 |
| - " 'visible': True,\n", |
266 |
| - " 'required': True,\n", |
267 |
| - " 'isSystemMaintained': True,\n", |
268 |
| - " 'role': 'esriGraphPropertyRegular'\n", |
269 |
| - " },\n", |
270 |
| - " 'shape': {\n", |
271 |
| - " 'name': 'shape',\n", |
272 |
| - " 'alias': 'shape',\n", |
273 |
| - " 'fieldType': 'esriFieldTypeGeometry',\n", |
274 |
| - " 'geometryType': 'esriGeometryPoint',\n", |
275 |
| - " 'hasZ': False,\n", |
276 |
| - " 'hasM': False,\n", |
277 |
| - " 'nullable': True,\n", |
278 |
| - " 'editable': True,\n", |
279 |
| - " 'visible': True,\n", |
280 |
| - " 'required': False,\n", |
281 |
| - " 'isSystemMaintained': False,\n", |
282 |
| - " 'role': 'esriGraphPropertyRegular'\n", |
283 |
| - " }\n", |
284 |
| - " },\n", |
285 |
| - " 'field_indexes': {\n", |
286 |
| - " 'esri__oid_idx': {\n", |
287 |
| - " 'name': 'esri__oid_idx',\n", |
288 |
| - " 'fields': ['objectid'],\n", |
289 |
| - " 'isAscending': True,\n", |
290 |
| - " 'isUnique': True\n", |
291 |
| - " },\n", |
292 |
| - " 'esri__globalid_idx': {\n", |
293 |
| - " 'name': 'esri__globalid_idx',\n", |
294 |
| - " 'fields': ['globalid'],\n", |
295 |
| - " 'isAscending': True,\n", |
296 |
| - " 'isUnique': True\n", |
297 |
| - " },\n", |
298 |
| - " 'esri__shape_geo_idx': {\n", |
299 |
| - " 'name': 'esri__shape_geo_idx',\n", |
300 |
| - " 'fields': ['shape'],\n", |
301 |
| - " 'isAscending': True,\n", |
302 |
| - " 'isUnique': False\n", |
303 |
| - " }\n", |
304 |
| - " }\n", |
305 |
| - "}\n", |
| 221 | + "EntityType(\n", |
| 222 | + " name='Vehicle', \n", |
| 223 | + " alias='', \n", |
| 224 | + " role='esriGraphNamedObjectRegular', \n", |
| 225 | + " strict=False, \n", |
| 226 | + " properties=[\n", |
| 227 | + " GraphProperty(name='objectid', alias='objectid', domain='', field_type='esriFieldTypeOID', geometry_type=None, has_z=False, has_m=False, default_value=None, nullable=False, visible=True, editable=False, required=True, is_system_maintained=True, role='esriGraphPropertyRegular'), \n", |
| 228 | + " GraphProperty(name='globalid', alias='globalid', domain='', field_type='esriFieldTypeGlobalID', geometry_type=None, has_z=False, has_m=False, default_value=None, nullable=False, visible=True, editable=False, required=True, is_system_maintained=True, role='esriGraphPropertyRegular'), \n", |
| 229 | + " GraphProperty(name='make', alias='', domain='', field_type='esriFieldTypeString', geometry_type=None, has_z=False, has_m=False, default_value=None, nullable=True, visible=True, editable=True, required=False, is_system_maintained=False, role='esriGraphPropertyRegular')\n", |
| 230 | + " ], \n", |
| 231 | + " field_indexes=[\n", |
| 232 | + " FieldIndex(name='esri__oid_idx', is_ascending=True, is_unique=True, fields=['objectid']), \n", |
| 233 | + " FieldIndex(name='esri__globalid_idx', is_ascending=True, is_unique=True, fields=['globalid'])\n", |
| 234 | + " ]\n", |
| 235 | + ")\n", |
306 | 236 | "```"
|
307 | 237 | ]
|
308 | 238 | },
|
|
332 | 262 | "name": "python",
|
333 | 263 | "nbconvert_exporter": "python",
|
334 | 264 | "pygments_lexer": "ipython3",
|
335 |
| - "version": "3.9.16" |
| 265 | + "version": "3.12.3" |
336 | 266 | },
|
337 | 267 | "vscode": {
|
338 | 268 | "interpreter": {
|
|
0 commit comments