Creating Relationships in Esri Knowledge Graph

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

In FME 2021.2, we have added a new reader and writer to allow you to work with Esri Knowledge in FME. In this tutorial, we’ll walk through how to create relationships between the entities we uploaded in the previous tutorial
 

Requirements

  

Step-by-step Instructions

Part 1: Join Roles and Movies to Create RolePlayed Relationship

1. Read in Roles CSV 
In FME Workbench, start a blank workspace. Add a Comma Separated Value (CSV) reader to the canvas and browse the file roles.csv (see attached). 
Click on the "Parameter..." button,
Under Dataset Parameter, Switch the value of the Feature Type Name(s) to From File Name(s) and Click OK. 
Step 1 ReadCSV.jpg

2. Inspect the Data
Click on the roles reader feature type to open the popup menu, then click the Inspect Source Data button to view the data in Visual Preview. 
RolesViewSourceData.png

In Visual Preview, you can see that the table contains the attributes personID and movieID. We will use these attributes to join with the Knowledge Graph entities created in the previous tutorial. 
Step 2 VisualPreview.jpg

3. Read in Esri Knowledge Graph
If you haven’t completed the previous tutorial, please pause here and complete that one first before proceeding. 

Add an Esri Knowledge reader to the canvas, and select the MovieDatabase_<yourname> Connection.
RolesReader.png
Click on the "Parameters" button
From Table, click on the ellipsis(...) 
In the Select Feature Type dialog, select "Country", "Movies", and "Persons" tables.  
Step 3 SelectTable.jpg

4. Update Person Attribute Names
Add an AttributeManager to the canvas after the "Persons" feature type. Open the AttributeManager transformer and perform the following operations.

Remove the attributes objectid and name.
Rename the attributes as below:
id --> personID 
globalid --> personGlobalID

Step 4 update attributename.jpg

5. Join Roles and Persons
Add a FeatureJoiner to the canvas and connect the Left input port to the roles reader feature type and the Right input port to the AttributeManager. 
PersonRolesFJ.png

In the parameters, set the Join On to personID for both Left and Right. 
Step 5 FeatureJoiner.jpg

6. Update Movies Attribute Names
Add an AttributeManager to the canvas and connect it to the Movies reader feature type.Open the AttributeManager transformer and perform the following operation

Remove the attributes objectid, title, and year 
Rename the attributes as below:
id --> movieID
globalid --> movieGlobalID
 
Step 6 update attribute movie.jpg

7. Join Movies and Persons
Add another FeatureJoiner to the canvas and connect the Left input port to the Joined output port on the other FeatureJoiner, then connect the Right input port to the AttributeManager_2 (coming from the movies reader feature type). 
FJMoviesFJConnection.png

In the parameters, set the Join On to movieID for both Left and Right. 
Step 7 FeatureJoin.jpg

8. Prepare Data to Create a Relationship 
This step will prepare the two key attributes to define the relationship between entities, Movies, and Persons.  Add another AttributeManager to the canvas and connect it to the Joined output port on the FeatureJoiner_2. Open the AttributeManager transformer and perform the following operations.

Remove the following attributes movieID, personID, movieID, and country 
Rename the attributes as below.
personGlobalID --> kg_origin_id 
movieGlobalID   --> kg_dest_id 
NOTE: Please ensure that the attribute names are correct, as these are case-sensitive  
Step 8 add kg_ids.jpg

9. Write RolePlayed Relationship 
Add an Esri Knowledge writer to the canvas and select the MovieDatabase_<yourname> Connection. Set the Feature Class or Table Definition to Automatic, then click OK. 
KGWriter1.png

In the Feature Type dialog, set the Feature Class or Table Name to RolePlayed and select kg_relationship as Geometry. 
Step 9 RolePlayed FS.jpg

Connect the RolePlayed writer feature type to the AttributeManager_3 coming from the second FeatureJoiner. 
RolePlayedConnection.png

 

Part 2: Join Country and Movies to Create MadeIn Relationship

10. Update Country Attribute Names
Add an AttributeManager to the canvas and connect it to the Country reader feature type.Open the AttributeManager transformer and perform the following operations.
Remove the attribute objectid
Rename the attributes as below:
globalid --> countryGlobalID. 
Step 10.jpg

11. Join Country and Movies
Add another FeatureJoiner to the canvas, connect the Left input port to the AttributeManager coming from the movies reader feature type, then connect the Right input port to the AttributeManager coming from the country reader feature type. 
MoviesCountryFJ.png

In the parameters, set the Join On Left to country coming from the Movies entity, and Right to name coming from the Country entity. 
Step 11 FeatureJoin.jpg

12. Prepare Data to Create a Relationship 
In this step, prepare the data to create a relationship between two entities, "Movies", and "Country".  Add another AttributeManager to the canvas and connect it to the Joined output port on the FeatureJoiner_3. Open the AttributeManager transformer and perform the following operation
Remove attributes movieID, name 
Rename the attributes as below.
movieGlobalID --> kg_origin_id 
countryGlobalID   --> kg_dest_id 
Step 12 AttributeManager.jpg

13. Write MadeIn Relationship Out to Esri Knowledge Graph
Click the Writers drop-down on the top menu bar and select Add Feature Type. 
AddFT.png

In the Add Feature Type dialog, set the Feature Class or Table Name to MadeIn, then change the Geometry to kg_relationship. 
Step 13 MadeIn Feature.jpg

Connect the MadeIn writer feature type to the AttributeManager_5.
FinalWorkspace.png

 

Part 3: View Output Relationships in ArcGIS Pro

14. Run the Workspace and View Output in ArcGIS Pro. 
Run the workspace, then view the output in ArcGIS Pro. In ArcGIS Pro, click on Investigation, then click on the RolePlayed relationship and view the table.
Step 14 RolesPlayed.jpg

Next, click on the MadeIn relationship and view the table. 
Step 14 MadeIn.jpg

To view all the relationships together, right-click on Relationship Types > Add To New > Link Chart. Now you can view the newly created relationship in the Link Chart. Notice that Persons are connected to the Movies entity by connection RolePlayed and countries by the MadeIn relationship. 
RelationshipChartArc.png



 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.