diff --git a/tutorials/Create Entities.ipynb b/tutorials/Create Entities.ipynb index ee4eca2..c4f579e 100644 --- a/tutorials/Create Entities.ipynb +++ b/tutorials/Create Entities.ipynb @@ -31,7 +31,7 @@ "\n", "This guide requires you install Godel's data-tools.\n", "\n", - "You can do this with `pip install godel[data-tools]` and comes pre-installed if using the godel docker image." + "You can do this with `pip install godel` and comes pre-installed if using the godel docker image." ] }, { @@ -43,7 +43,7 @@ "\n", "Let's connect the python wrapper to the Golden GraphQL API.\n", "\n", - "Make sure you ran through the prerequisites for this guide and have learned to authenticate and retrieve your JWT token in Godel." + "Make sure you ran through the prerequisites for this guide and have learned how to authenticate and retrieve your JWT token in Godel." ] }, { @@ -55,7 +55,7 @@ "source": [ "from godel import GoldenAPI\n", "\n", - "JWT_TOKEN = \"ey098sd908v79899789877986567967845jh567hj5679568df678678daf6786789s569ghm567457hm8g567n8678fb8790678sd56756n456h8d4f5gn865648\"\n", + "JWT_TOKEN = \"\" # TODO: Enter your JWT token\n", "goldapi = GoldenAPI(jwt_token=JWT_TOKEN)" ] }, @@ -99,29 +99,81 @@ " \n", " \n", " 0\n", - " d95ef4b0-e006-4203-bfb4-adbe99f63ce7\n", - " Miles Wolff\n", - " Id nihil blanditiis eius fugit odit blanditiis...\n", - " https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHir...\n", + " f25272da-d6be-4eef-8c06-a33eeafbc5c6\n", + " A. D. Miles\n", + " American comedy actor and writer\n", " None\n", - " /entity/d95ef4b0-e006-4203-bfb4-adbe99f63ce7\n", + " 1148852\n", + " /entity/f25272da-d6be-4eef-8c06-a33eeafbc5c6\n", + " \n", + " \n", + " 1\n", + " 0b178fa4-eb13-478f-8a8a-234a5bb27112\n", + " Miles Teller\n", + " American actor\n", + " https://golden-media.s3.amazonaws.com/topics/1...\n", + " 3482005\n", + " /entity/0b178fa4-eb13-478f-8a8a-234a5bb27112\n", + " \n", + " \n", + " 2\n", + " f32cc7fa-8477-408a-a131-71f01034443f\n", + " Mile Škorić\n", + " Croatian association football player\n", + " https://golden-storage-production.s3.amazonaws...\n", + " 4847572\n", + " /entity/f32cc7fa-8477-408a-a131-71f01034443f\n", + " \n", + " \n", + " 3\n", + " 37028d18-a2fd-4d9a-9bf9-7e3dfa8790ed\n", + " Open Mile (company)\n", + " Company\n", + " https://golden-storage-production.s3.amazonaws...\n", + " 5368783\n", + " /entity/37028d18-a2fd-4d9a-9bf9-7e3dfa8790ed\n", + " \n", + " \n", + " 4\n", + " 56bd0505-5aa7-4617-a8cd-70f5ac60fb14\n", + " MARVEL'S Spider-Man Miles Morales\n", + " Marvel's Spider-Man: Miles Morales is a 2020 a...\n", + " https://golden-storage-production.s3.amazonaws...\n", + " 11886359\n", + " /entity/56bd0505-5aa7-4617-a8cd-70f5ac60fb14\n", " \n", " \n", "\n", "" ], "text/plain": [ - " id name \\\n", - "0 d95ef4b0-e006-4203-bfb4-adbe99f63ce7 Miles Wolff \n", + " id name \\\n", + "0 f25272da-d6be-4eef-8c06-a33eeafbc5c6 A. D. Miles \n", + "1 0b178fa4-eb13-478f-8a8a-234a5bb27112 Miles Teller \n", + "2 f32cc7fa-8477-408a-a131-71f01034443f Mile Škorić \n", + "3 37028d18-a2fd-4d9a-9bf9-7e3dfa8790ed Open Mile (company) \n", + "4 56bd0505-5aa7-4617-a8cd-70f5ac60fb14 MARVEL'S Spider-Man Miles Morales \n", "\n", " description \\\n", - "0 Id nihil blanditiis eius fugit odit blanditiis... \n", + "0 American comedy actor and writer \n", + "1 American actor \n", + "2 Croatian association football player \n", + "3 Company \n", + "4 Marvel's Spider-Man: Miles Morales is a 2020 a... \n", "\n", - " thumbnail goldenId \\\n", - "0 https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHir... None \n", + " thumbnail goldenId \\\n", + "0 None 1148852 \n", + "1 https://golden-media.s3.amazonaws.com/topics/1... 3482005 \n", + "2 https://golden-storage-production.s3.amazonaws... 4847572 \n", + "3 https://golden-storage-production.s3.amazonaws... 5368783 \n", + "4 https://golden-storage-production.s3.amazonaws... 11886359 \n", "\n", " pathname \n", - "0 /entity/d95ef4b0-e006-4203-bfb4-adbe99f63ce7 " + "0 /entity/f25272da-d6be-4eef-8c06-a33eeafbc5c6 \n", + "1 /entity/0b178fa4-eb13-478f-8a8a-234a5bb27112 \n", + "2 /entity/f32cc7fa-8477-408a-a131-71f01034443f \n", + "3 /entity/37028d18-a2fd-4d9a-9bf9-7e3dfa8790ed \n", + "4 /entity/56bd0505-5aa7-4617-a8cd-70f5ac60fb14 " ] }, "execution_count": 2, @@ -132,10 +184,10 @@ "source": [ "import pandas as pd\n", "\n", - "# Test with search\n", + "# Test connection with search\n", "search_results = goldapi.entity_search(name=\"Miles\")\n", "search_results_df = pd.DataFrame(search_results[\"data\"][\"entityByName\"][\"nodes\"])\n", - "search_results_df" + "search_results_df.head()" ] }, { @@ -145,12 +197,12 @@ "source": [ "### 2. Get Predicates and Templates\n", "\n", - "You can run the code below to get the list of accepted predicates into the knowledge graph, its data types, and submit templates for different kinds of entities." + "You can run the code below to get the list of accepted predicates into the knowledge graph and its data types." ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 3, "id": "1150a6ee-5cd6-4831-9ce7-1ce7564658bc", "metadata": { "tags": [] @@ -183,6 +235,11 @@ " \n", " \n", " \n", + " Spotify Artist ID\n", + " 09dec055-52d8-42e6-9fc0-56ecac599a8b\n", + " STRING\n", + " \n", + " \n", " CEO\n", " 0a87e996-34b4-46ba-909a-70ab67b1f811\n", " ENTITY\n", @@ -198,11 +255,6 @@ " ANY_URI\n", " \n", " \n", - " Total funding amount\n", - " 13a7e8b6-7270-4c99-81e9-9d752e0c295c\n", - " FLOAT\n", - " \n", - " \n", " Whitepaper\n", " 14fa743c-8161-42e8-a92f-5c29c70e87f8\n", " ANY_URI\n", @@ -212,15 +264,15 @@ "" ], "text/plain": [ - " id objectType\n", - "CEO 0a87e996-34b4-46ba-909a-70ab67b1f811 ENTITY\n", - "Email address 0efd0441-1ffc-4e30-8806-e58c434770c8 STRING\n", - "YouTube channel 12acb8fe-0573-4ca8-8cc1-180cc6ba3486 ANY_URI\n", - "Total funding amount 13a7e8b6-7270-4c99-81e9-9d752e0c295c FLOAT\n", - "Whitepaper 14fa743c-8161-42e8-a92f-5c29c70e87f8 ANY_URI" + " id objectType\n", + "Spotify Artist ID 09dec055-52d8-42e6-9fc0-56ecac599a8b STRING\n", + "CEO 0a87e996-34b4-46ba-909a-70ab67b1f811 ENTITY\n", + "Email address 0efd0441-1ffc-4e30-8806-e58c434770c8 STRING\n", + "YouTube channel 12acb8fe-0573-4ca8-8cc1-180cc6ba3486 ANY_URI\n", + "Whitepaper 14fa743c-8161-42e8-a92f-5c29c70e87f8 ANY_URI" ] }, - "execution_count": 12, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -330,7 +382,7 @@ "id": "595f0c04-3abb-4d56-a86f-529a4afbbcb7", "metadata": {}, "source": [ - "We need source data on the entity you would like to submit" + "You will need to input the source data of the entity you would like to submit." ] }, { @@ -341,8 +393,8 @@ "outputs": [], "source": [ "name = \"John Doe\"\n", - "is_a = \"0c4e6054-5fd8-48a8-817c-f6611278f755\" # Persion Template Entity Id\n", - "ceo_of = \"20ab9281-fd5f-4717-ab73-ecd24fff66fe\" # Huel and Sons Entity ID\n", + "is_a = templates_df[\"entityId\"][\"Person\"] # Person Entity ID \n", + "ceo_of = \"36b56cea-db86-482f-8b63-5b4e75b3b968\" # \"Huel\" Entity ID\n", "email_address = \"john.doe@example.com\"\n", "citation_urls = [\"https://golden.com/wiki/johndoe\"]" ] @@ -360,11 +412,11 @@ "id": "fb8fa1ac-a108-4a1a-9de4-cfbef98f22b1", "metadata": {}, "source": [ - "We're going to create the `CreateEntityInput`, which requires Minimum Disambiguated Triples (MDTs).\n", + "We're going to use `CreateEntityInput`, which requires Minimum Disambiguated Triples (MDTs), to submit the new entity.\n", "\n", - "MDTs are the required triples you must submit along with the entity you want to create.\n", + "MDTs are the required triples you must submit along with the entity you want to create. This helps us with disambiguation, deduplication, and arbitrary entity submissions with zero triples.\n", "\n", - "This helps us with disambiguation, deduplication, and arbitrary entity submissions with zero triples." + "First, view the `StatementInputRecordInput` object schema." ] }, { @@ -379,7 +431,6 @@ "text": [ "input CreateEntityInput {\n", " clientMutationId: String\n", - " name: String!\n", " statements: [StatementInputRecordInput]\n", "}\n" ] @@ -413,7 +464,7 @@ "id": "89a3207b-d34b-4e29-a717-6ddb3bf71c61", "metadata": {}, "source": [ - "First, create your triples with the `StatementInputRecordInput`'s.\n", + "Create your triples with `StatementInputRecordInput`.\n", "\n", "You'll notice that the \"CEO of\" statement is commented out. Without this, even if you have the email address statement, you will not be able to submit the entity since it does not fulfill the MDTs required.\n", "\n", @@ -422,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 7, "id": "011cdf1e-2961-41cd-8926-ef0c4de9793c", "metadata": {}, "outputs": [], @@ -433,40 +484,40 @@ "# Add Template\n", "statements.append(\n", " StatementInputRecordInput(\n", - " predicate_id = predicates[\"Is a\"][\"id\"],\n", - " object_entity_id = is_a,\n", - " citation_urls = [],\n", - " qualifiers = [],\n", + " predicate_id=predicates[\"Is a\"][\"id\"],\n", + " object_entity_id=is_a,\n", + " citation_urls=citation_urls,\n", + " qualifiers=[],\n", " )\n", ")\n", "\n", "# Add Name\n", "statements.append(\n", " StatementInputRecordInput(\n", - " predicate_id = predicates[\"Name\"][\"id\"],\n", - " object_value = name,\n", - " citation_urls = [],\n", - " qualifiers = [],\n", + " predicate_id=predicates[\"Name\"][\"id\"],\n", + " object_value=name,\n", + " citation_urls=citation_urls,\n", + " qualifiers=[],\n", " )\n", ")\n", "\n", "# Add Email Address\n", "statements.append(\n", " StatementInputRecordInput(\n", - " predicate_id = predicates[\"Email address\"][\"id\"],\n", - " object_value = email_address,\n", - " citation_urls = [],\n", - " qualifiers = [],\n", + " predicate_id=predicates[\"Email address\"][\"id\"],\n", + " object_value=email_address,\n", + " citation_urls=citation_urls,\n", + " qualifiers=[],\n", " )\n", ")\n", "\n", "# Add CEO of\n", "# statements.append(\n", "# StatementInputRecordInput(\n", - "# predicate_id = predicates[\"CEO of\"][\"id\"],\n", - "# object_entity_id = ceo_of,\n", - "# citation_urls = citation_urls,\n", - "# qualifiers = [],\n", + "# predicate_id=predicates[\"CEO of\"][\"id\"],\n", + "# object_entity_id=ceo_of,\n", + "# citation_urls=citation_urls,\n", + "# qualifiers=[],\n", "# )\n", "# )" ] @@ -481,25 +532,28 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 8, "id": "ede39730-3318-428f-8076-76f1ad674466", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'name': 'John Doe',\n", - " 'statements': [{'predicateId': '94a8d215-ce32-4379-b18e-2aebf0794882',\n", + "{'statements': [{'predicateId': '94a8d215-ce32-4379-b18e-2aebf0794882',\n", " 'objectEntityId': '0c4e6054-5fd8-48a8-817c-f6611278f755',\n", " 'citationUrls': ['https://golden.com/wiki/johndoe'],\n", " 'qualifiers': []},\n", + " {'predicateId': 'a27218b8-6a4d-47bb-95b6-5a55334fac1c',\n", + " 'objectValue': 'John Doe',\n", + " 'citationUrls': ['https://golden.com/wiki/johndoe'],\n", + " 'qualifiers': []},\n", " {'predicateId': '0efd0441-1ffc-4e30-8806-e58c434770c8',\n", " 'objectValue': 'john.doe@example.com',\n", " 'citationUrls': ['https://golden.com/wiki/johndoe'],\n", " 'qualifiers': []}]}" ] }, - "execution_count": 13, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -507,7 +561,7 @@ "source": [ "# Create Entity Input\n", "create_entity_input = CreateEntityInput(\n", - " statements = statements\n", + " statements=statements\n", ")\n", "create_entity_input.__to_json_value__()" ] @@ -530,7 +584,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "id": "ff7a5315-d485-44a3-a739-78eb6d9d3268", "metadata": { "tags": [] @@ -546,26 +600,28 @@ { "data": { "text/plain": [ - "{'errors': [{'extensions': {'messages': [], 'exception': {}},\n", - " 'message': 'All required statements must be provided:\\n- entity type \"person\" must have a statement from at least one of these predicates: \"website\", \"angelListUrl\", \"linkedInUrl\", \"founderOf\", \"ceoOf\"',\n", + "{'errors': [{'errcode': '22023',\n", + " 'extensions': {'messages': [], 'exception': {'errcode': '22023'}},\n", + " 'message': 'All required statements must be provided:\\n- entity type 0c4e6054-5fd8-48a8-817c-f6611278f755 must have a valid statement from at least one of these predicates: 7f15d788-5df1-4ff3-a5e5-4c9e8e2c57af, 8c4d6279-199f-4e46-9ef7-8702bad1e152, 42cb158b-e836-45ed-9b56-034668b8f05a, 3104de39-071c-47b8-86b4-d62ccc4a4fa6, 2f30a94e-cd5e-496f-bec8-01bfb01da128, e4f94b98-c56a-4bd2-a9fd-5fd11603e7e8',\n", " 'locations': [{'line': 2, 'column': 1}],\n", " 'path': ['createEntity'],\n", - " 'stack': ['Error: All required statements must be provided:',\n", - " '- entity type \"person\" must have a statement from at least one of these predicates: \"website\", \"angelListUrl\", \"linkedInUrl\", \"founderOf\", \"ceoOf\"',\n", - " ' at checkMinimumRequiredStatements (/home/andrew/golden/dapp/app/db/entityMinimumRequiredStatements.ts:74:11)',\n", - " ' at createEntityWrapper (/home/andrew/golden/dapp/db/graphql/plugins/CreateEntityPlugin.server.ts:17:33)',\n", - " ' at resolve (/home/andrew/golden/dapp/node_modules/graphile-utils/src/makeWrapResolversPlugin.ts:180:18)',\n", - " ' at resolve (/home/andrew/golden/dapp/node_modules/@graphile/operation-hooks/lib/OperationHooksCorePlugin.js:122:38)',\n", - " ' at runMicrotasks ()',\n", - " ' at processTicksAndRejections (node:internal/process/task_queues:96:5)',\n", - " ' at async /home/andrew/golden/dapp/node_modules/postgraphile/src/postgraphile/withPostGraphileContext.ts:227:16',\n", - " ' at async withAuthenticatedPgClient (/home/andrew/golden/dapp/node_modules/postgraphile/src/postgraphile/withPostGraphileContext.ts:169:20)',\n", - " ' at async /home/andrew/golden/dapp/node_modules/postgraphile/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts:926:26',\n", - " ' at async Promise.all (index 0)']}],\n", + " 'stack': ['error: All required statements must be provided:',\n", + " '- entity type 0c4e6054-5fd8-48a8-817c-f6611278f755 must have a valid statement from at least one of these predicates: 7f15d788-5df1-4ff3-a5e5-4c9e8e2c57af, 8c4d6279-199f-4e46-9ef7-8702bad1e152, 42cb158b-e836-45ed-9b56-034668b8f05a, 3104de39-071c-47b8-86b4-d62ccc4a4fa6, 2f30a94e-cd5e-496f-bec8-01bfb01da128, e4f94b98-c56a-4bd2-a9fd-5fd11603e7e8',\n", + " ' at Parser.parseErrorMessage (/web/node_modules/pg-protocol/src/parser.ts:369:69)',\n", + " ' at Parser.handlePacket (/web/node_modules/pg-protocol/src/parser.ts:188:21)',\n", + " ' at Parser.parse (/web/node_modules/pg-protocol/src/parser.ts:103:30)',\n", + " ' at Socket. (/web/node_modules/pg-protocol/src/index.ts:7:48)',\n", + " ' at Socket.emit (node:events:513:28)',\n", + " ' at Socket.emit (node:domain:552:15)',\n", + " ' at addChunk (node:internal/streams/readable:324:12)',\n", + " ' at readableAddChunk (node:internal/streams/readable:297:9)',\n", + " ' at Socket.Readable.push (node:internal/streams/readable:234:10)',\n", + " ' at TCP.onStreamRead (node:internal/stream_base_commons:190:23)',\n", + " ' at TCP.callbackTrampoline (node:internal/async_hooks:130:17)']}],\n", " 'data': {'createEntity': None}}" ] }, - "execution_count": 14, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -577,7 +633,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 20, "id": "3d341ff4-ac0c-414a-8694-cf7c3900378e", "metadata": {}, "outputs": [ @@ -617,8 +673,8 @@ " \n", " 0\n", " Entity\n", - " 18998a05-d972-44cc-9d45-c75c9477c98d\n", - " /entity/18998a05-d972-44cc-9d45-c75c9477c98d\n", + " 5c3465d5-4a9a-46a3-a9cc-eeb5113ebc40\n", + " /entity/5c3465d5-4a9a-46a3-a9cc-eeb5113ebc40\n", " John Doe\n", " None\n", " None\n", @@ -632,10 +688,10 @@ ], "text/plain": [ " __typename id \\\n", - "0 Entity 18998a05-d972-44cc-9d45-c75c9477c98d \n", + "0 Entity 5c3465d5-4a9a-46a3-a9cc-eeb5113ebc40 \n", "\n", " pathname name description \\\n", - "0 /entity/18998a05-d972-44cc-9d45-c75c9477c98d John Doe None \n", + "0 /entity/5c3465d5-4a9a-46a3-a9cc-eeb5113ebc40 John Doe None \n", "\n", " thumbnail goldenId isA \\\n", "0 None None {'nodes': [{'id': '0c4e6054-5fd8-48a8-817c-f66... \n", @@ -644,12 +700,13 @@ "0 {'nodes': [{'__typename': 'Statement', 'id': '... " ] }, - "execution_count": 10, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "# Below is a dataframe of your new entity once submitted with the required MDTs. \n", "created_data_df = pd.DataFrame([data[\"data\"][\"createEntity\"][\"entity\"]])\n", "created_data_df" ] @@ -664,17 +721,17 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 21, "id": "8597d5d1-1cdb-4e05-9a10-1889de890701", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'https://dapp.golden.xyz/entity/18998a05-d972-44cc-9d45-c75c9477c98d'" + "'https://dapp.golden.xyz/entity/5c3465d5-4a9a-46a3-a9cc-eeb5113ebc40'" ] }, - "execution_count": 11, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -697,7 +754,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3.8.13 64-bit", "language": "python", "name": "python3" }, @@ -711,7 +768,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.5" + "version": "3.8.13" + }, + "vscode": { + "interpreter": { + "hash": "7f0162e0494ffd197d4c84e1c52fbcf566b58529937a5cd0230e5e855992544a" + } } }, "nbformat": 4,