├── Graph Powered NLP using Google PaLM 2, Neo4j and Python.pdf
├── LICENSE
├── Neo4j_Cypher_Query_Generator_Prompt.txt
├── README.md
├── graph_powered_nlp.ipynb
├── movies-db-setup.cypher
└── step-by-step-guide.md
/Graph Powered NLP using Google PaLM 2, Neo4j and Python.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sidagarwal04/graph-powered-nlp-workshop/3c46aebfd910523c144bb46b604bdc91fa0381de/Graph Powered NLP using Google PaLM 2, Neo4j and Python.pdf
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [2024] [Siddhant Agarwal]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Neo4j_Cypher_Query_Generator_Prompt.txt:
--------------------------------------------------------------------------------
1 | You are an expert in converting English questions to Neo4j Cypher Graph code! The Graph has following Node Labels - Movie, Person! the Movie Node has the following properties released, tagline, title. The Person node has properties such as name & born. The Neo4j Graph has the following Relationship types ACTED_IN, DIRECTED, FOLLOWS, PRODUCED, REVIEWED, WROTE!
2 |
3 | All relationships ACTED_IN, DIRECTED, PRODUCED, REVIEWED, WROTE start from Person node to Movie node and not the other way around except for FOLLOWS relationship which starts from Person node to Person node.
4 |
5 | For example,
6 | Example 1 - List down 5 movies that released after the year 2000, the Cypher command will be something like this
7 | ``` MATCH (m:Movie)
8 | WHERE m.released > 2000
9 | RETURN m LIMIT 5
10 | ```
11 |
12 | Example 2 - Get all the people who acted in a movie that was released after 2010.
13 | ```
14 | MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
15 | WHERE m.released > 2010
16 | RETURN p,r,m
17 | ```
18 |
19 | Example 3 - Name the Director of the movie Apollo 13?
20 | ```
21 | MATCH (m:Movie)<-[:DIRECTED]-(p:Person)
22 | WHERE m.title = 'Apollo 13'
23 | RETURN p.name
24 | ```
25 |
26 | Do not include ``` and \n in the output
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Graph Powered NLP Workshop
2 |
3 | Are you ready to dive into the world of graph databases, harness the power of natural language processing (NLP), and build intelligent applications that understand and respond to human queries? Follow this [**step-by-step guide**](step-by-step-guide.md) to embark on a thrilling journey that combines the strength of [Google PaLM 2](https://ai.google/discover/palm2/) (within [Google AI Studio](https://developers.generativeai.google/products/makersuite)), [Neo4j](https://neo4j.com/), and Python and build an intelligent Gen-AI powered Q&A Chatbot. For this workshop, we will be using Movies dataset with **PERSON** and **MOVIE** as nodes and **ACTED_IN**, **DIRECTED**, **FOLLOWS**, **PRODUCED**, **REVIEWED**, **WROTE** as Relationships. Refer to the [slide deck](https://github.com/sidagarwal04/graph-powered-nlp-workshop/blob/main/Graph%20Powered%20NLP%20using%20Google%20PaLM%202%2C%20Neo4j%20and%20Python.pdf) for additonal reference.
4 |
5 | **Duration:** 180 minutes
6 | **Level:** Beginner to Intermediate
7 |
8 | ## Gen-AI and LLMs
9 | Generative AI (Gen-AI) refers to a subset of artificial intelligence technologies that can generate new content, including text, images, music, and code, after learning from a vast dataset. These models can create original outputs that have never been seen before, as opposed to simply analyzing or classifying data.
10 |
11 | Large Language Models (LLMs) are a specific type of Gen-AI that are particularly adept at understanding and generating human language. LLMs are trained on a massive corpus of text data, which enables them to perform a variety of language tasks, such as translation, question-answering, summarization, and content creation. They work by predicting the next word in a sequence of words, making them capable of generating coherent and contextually relevant text passages.
12 |
13 | LLMs have revolutionized the field of natural language processing (NLP) due to their ability to handle complex language tasks that were previously challenging for machines. They have become foundational to a number of AI-driven applications, providing the backend intelligence for chatbots, writing assistants, and more. However, their capabilities also raise important considerations regarding ethics, biases in training data, and the potential for misuse, which are areas of ongoing research and discussion in the AI community.
14 |
15 | 
16 |
17 | ## Google PaLM2
18 | PaLM-2, which stands for "Pathways Language Model 2," is Google's second-generation large language model that underscores the company's commitment to responsible AI development and deployment. All versions of PaLM-2 undergo rigorous evaluations to assess potential harms, biases, capabilities, and their suitability for both research and practical applications ([Source](https://ai.google/discover/palm2#:~:text=PaLM%202%20is%20grounded%20in,PaLM)).
19 |
20 | This model represents a significant advancement with enhanced multilingual, reasoning, and coding capabilities. It has been heavily trained on multilingual text, covering over 100 languages, which allows for improved performance on tasks across different languages ([Source](https://blog.google/technology/ai/google-palm-2-ai-large-language-model/#:~:text=PaLM%202%20is%20a%20state,spanning%20more%20than%20100%20languages)).
21 |
22 | PaLM-2 is a part of Google's lineage of breakthrough research in machine learning. It plays a crucial role in powering generative AI features and tools developed by Google, such as the Bard chatbot and the PaLM API, which are used for creating AI-driven applications ([Source](https://ai.google/#:~:text=PaLM%202%20is%20our%20next,Our%20quantum%20error%20correction%20milestone)).
23 |
24 | Importantly, PaLM-2 has been integrated into nearly 25 Google products, demonstrating its extensive utility and the trust Google places in its performance and reliability. Its applications span a wide range of Google's services, including Gmail and Google Docs, indicating its pervasive influence across the company's product suite ([Source](https://www.cnet.com/tech/computing/palm-2-is-a-major-ai-update-built-into-25-google-products/#:~:text=PaLM%202%20is%20a%20second,Bard%20chatbot%2C%20Gmail%2C%20Google%20Docs)).
25 |
26 | Note: PaLM2 API is now replaced with ([Gemini API](https://deepmind.google/technologies/gemini/#introduction)).
27 |
28 | 
29 |
30 | ## Google AI Studio
31 | Google AI Studio (earlier called Google MakerSuite) is a tool designed to facilitate the building of generative AI applications. It provides an efficient user interface (UI) for interacting with some of Google's latest AI models, allowing for the easy translation of prompts into production-ready code that can be integrated into applications ([Source](https://developers.googleblog.com/2023/09/make-with-makersuite-part1-introduction.html#:~:text=What%20is%20MakerSuite%3F%20MakerSuite%20is,can%20integrate%20into%20your%20applications)). MakerSuite is browser-based and functions as an integrated development environment (IDE) specifically for prototyping with generative language models. It supports rapid experimentation with different prompts and models, and once a developer is satisfied with their creation, the tool enables easy exportation of the project to Python code. This code can then interact with the same models via the PaLM API ([Source](https://developers.generativeai.google/tutorials/makersuite_quickstart#:~:text=MakerSuite%20is%20a%20browser,Which%20prompt)).
32 |
33 | The aim of MakerSuite is to democratize the creation of AI-powered applications, making it accessible to any individual with a Google account. It simplifies the process of building with the PaLM API, which is a platform for machine learning and natural language processing tasks. By utilizing MakerSuite, developers can rapidly prototype and test configurations used in conjunction with the PaLM API, thereby streamlining the development of products and services that leverage Google's generative AI capabilities ([Source](https://www.packtpub.com/article-hub/getting-started-with-google-makersuite#:~:text=Getting%20Started%20with%20Google%20MakerSuite,interacting%20with%20the%20PaLM%20API)).
34 |
35 | Furthermore, Google has expanded the reach of MakerSuite to cover 179 countries and territories, making it available to anyone who has a Google Workspace account. This expansion is part of Google's initiative to help users from various backgrounds become AI makers and create innovative applications using their generative models ([Source](https://developers.googleblog.com/2023/08/makersuite-expands-adds-new-features-for-ai-makers.html#:~:text=With%20MakerSuite%20we%20want%20to,with%20a%20Google%20Workspace%20account)).
36 |
37 | 
38 |
39 |
40 | ## Neo4j AuraDB
41 | Neo4j AuraDB is a cloud-based graph database service offered by Neo4j. It's designed to provide users with a fully managed graph database as a service (DBaaS), enabling rapid and efficient queries that facilitate real-time analytics and insights ([Source](https://neo4j.com/cloud/platform/aura-graph-database/faq/#:~:text=General%20What%20is%20Neo4j%20AuraDB%3F,time%20analytics%20and%20insights)). The service is built to be highly available and self-healing, ensuring that it can scale on demand without any loss of service. It includes enterprise-class security features, such as role-based access control in the enterprise tier ([Source](https://aura.support.neo4j.com/hc/en-us/articles/17081071326739-Neo4j-AuraDB-and-Neo4j-AuraDS-products#:~:text=AuraDB%2C%20is%20the%20Neo4j%20graph,with%20the%20enterprise%20tier%20level)).
42 |
43 | AuraDB is known for its lightning-fast performance and scalability, which are crucial for graph analytics applications. It allows users to start for free and makes it easy to integrate with various languages and frameworks. The service also offers prebuilt datasets to help users get started quickly ([Source](https://neo4j.com/cloud/aura-free/#:~:text=Neo4j%20AuraDB%20is%20a%20fully,your%20favorite%20languages%20and%20frameworks)).
44 |
45 | Furthermore, Neo4j AuraDB is tailored to leverage the relationships in data, which is a core advantage of graph databases. This purpose-built service enables users to execute complex queries and gain insights with high speed, which is especially beneficial for applications that require real-time data analysis ([Source](https://neo4j.com/docs/aura/auradb/#:~:text=Neo4j%20AuraDB%20is%20a%20cloud,support%20in%20this%20overview%20page)).
46 |
47 | 
48 |
--------------------------------------------------------------------------------
/graph_powered_nlp.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "view-in-github",
7 | "colab_type": "text"
8 | },
9 | "source": [
10 | "
"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "source": [
16 | "# Graph Powered NLP Workshop Python Notebook"
17 | ],
18 | "metadata": {
19 | "id": "VuGNALbggtuf"
20 | }
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "source": [
25 | "### Installing necessary drivers - Google Generative AI, Neo4j and Gradio.\n",
26 | "\n",
27 | "**Instruction:** Don't forget to restart the runtime after running the below cell"
28 | ],
29 | "metadata": {
30 | "id": "k4yjGsjihe7n"
31 | }
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 2,
36 | "metadata": {
37 | "id": "vXYXe44FLeZy",
38 | "outputId": "c539a079-0c4d-4097-cf5e-785d850c4aab",
39 | "colab": {
40 | "base_uri": "https://localhost:8080/"
41 | }
42 | },
43 | "outputs": [
44 | {
45 | "output_type": "stream",
46 | "name": "stdout",
47 | "text": [
48 | "Requirement already satisfied: google-generativeai in /usr/local/lib/python3.10/dist-packages (0.3.2)\n",
49 | "Requirement already satisfied: google-ai-generativelanguage==0.4.0 in /usr/local/lib/python3.10/dist-packages (from google-generativeai) (0.4.0)\n",
50 | "Requirement already satisfied: google-auth in /usr/local/lib/python3.10/dist-packages (from google-generativeai) (2.27.0)\n",
51 | "Requirement already satisfied: google-api-core in /usr/local/lib/python3.10/dist-packages (from google-generativeai) (2.11.1)\n",
52 | "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from google-generativeai) (4.11.0)\n",
53 | "Requirement already satisfied: protobuf in /usr/local/lib/python3.10/dist-packages (from google-generativeai) (3.20.3)\n",
54 | "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from google-generativeai) (4.66.2)\n",
55 | "Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in /usr/local/lib/python3.10/dist-packages (from google-ai-generativelanguage==0.4.0->google-generativeai) (1.23.0)\n",
56 | "Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core->google-generativeai) (1.63.0)\n",
57 | "Requirement already satisfied: requests<3.0.0.dev0,>=2.18.0 in /usr/local/lib/python3.10/dist-packages (from google-api-core->google-generativeai) (2.31.0)\n",
58 | "Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth->google-generativeai) (5.3.3)\n",
59 | "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth->google-generativeai) (0.4.0)\n",
60 | "Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth->google-generativeai) (4.9)\n",
61 | "Requirement already satisfied: grpcio<2.0dev,>=1.33.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core->google-generativeai) (1.62.1)\n",
62 | "Requirement already satisfied: grpcio-status<2.0.dev0,>=1.33.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core->google-generativeai) (1.48.2)\n",
63 | "Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth->google-generativeai) (0.6.0)\n",
64 | "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core->google-generativeai) (3.3.2)\n",
65 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core->google-generativeai) (3.7)\n",
66 | "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core->google-generativeai) (2.0.7)\n",
67 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core->google-generativeai) (2024.2.2)\n"
68 | ]
69 | }
70 | ],
71 | "source": [
72 | "!pip install google-generativeai\n",
73 | "!pip install -q neo4j-driver\n",
74 | "!pip install -q gradio"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {
80 | "id": "TUTKEGSzd5gR"
81 | },
82 | "source": [
83 | "### Import necessary libraries from installed packages/drivers - PaLM, base64, json, gradio and GraphDatabase"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": 3,
89 | "metadata": {
90 | "id": "JZuvUuuTY3VZ"
91 | },
92 | "outputs": [],
93 | "source": [
94 | "import google.generativeai as genai\n",
95 | "import base64\n",
96 | "import json\n",
97 | "import gradio as gr\n",
98 | "from neo4j import GraphDatabase\n",
99 | "from google.colab import userdata"
100 | ]
101 | },
102 | {
103 | "cell_type": "markdown",
104 | "metadata": {
105 | "id": "_qxbTb6YeDus"
106 | },
107 | "source": [
108 | "### Add Gemini API Key from Google AI Studio\n",
109 | "\n",
110 | "**Instruction:** Replace \"API_KEY\" with the value of API Key copied from Google AI Studio as mentioned in Step #6 of Part #2 of [Step-by-Step Guide](https://github.com/sidagarwal04/graph-powered-nlp-workshop/blob/main/step-by-step-guide.md#part-2-create-google-makersuite-account-train--test-prompt-in-google-makersuite-and-get-google-palm-2-api-key). Don't forget to add to include the key in double-quotes (\" \")"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 4,
116 | "metadata": {
117 | "id": "4F1dMaSWZK0z"
118 | },
119 | "outputs": [],
120 | "source": [
121 | "genai.configure(api_key = userdata.get('apiKey'))"
122 | ]
123 | },
124 | {
125 | "cell_type": "markdown",
126 | "source": [
127 | "### Include the generated prompt from Google AI Studio.\n",
128 | "\n",
129 | "**Instruction:** Remove the initial part of installing drivers and configuring the API key as it has already been done in previous steps. Also, put the entire code as a function with output to be returned instead of printing it."
130 | ],
131 | "metadata": {
132 | "id": "uf0swKVQjmmr"
133 | }
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": null,
138 | "metadata": {
139 | "id": "Hr-lG9sEZwaY"
140 | },
141 | "outputs": [],
142 | "source": [
143 | "def get_answer(input):\n",
144 | "\n",
145 | " generation_config = {\n",
146 | " \"temperature\": 0.9,\n",
147 | " \"top_p\": 1,\n",
148 | " \"top_k\": 1,\n",
149 | " \"max_output_tokens\": 2048,\n",
150 | " \"stop_sequences\": [\n",
151 | " \"0\",\n",
152 | " ],\n",
153 | " }\n",
154 | "\n",
155 | " safety_settings = [\n",
156 | " {\n",
157 | " \"category\": \"HARM_CATEGORY_HARASSMENT\",\n",
158 | " \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"\n",
159 | " },\n",
160 | " {\n",
161 | " \"category\": \"HARM_CATEGORY_HATE_SPEECH\",\n",
162 | " \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"\n",
163 | " },\n",
164 | " {\n",
165 | " \"category\": \"HARM_CATEGORY_SEXUALLY_EXPLICIT\",\n",
166 | " \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"\n",
167 | " },\n",
168 | " {\n",
169 | " \"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\",\n",
170 | " \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"\n",
171 | " },\n",
172 | " ]\n",
173 | "\n",
174 | " model = genai.GenerativeModel(model_name=\"gemini-1.0-pro\",\n",
175 | " generation_config=generation_config,\n",
176 | " safety_settings=safety_settings)\n",
177 | "\n",
178 | " # prompt = f\"\"\"You are an expert in converting English questions to Neo4j Cypher Graph code! The Graph has following Node Labels - Movie, Person! the Movie Node has the following properties released, tagline, title. The Person node has properties such as name & born. The Neo4j Graph has the following Relationship types ACTED_IN, DIRECTED, FOLLOWS, PRODUCED, REVIEWED, WROTE!\n",
179 | "\n",
180 | " # All relationships ACTED_IN, DIRECTED, PRODUCED, REVIEWED, WROTE start from Person node to Movie node and not the other way around except for FOLLOWS relationship which starts from Person node to Person node.\n",
181 | "\n",
182 | " # For example,\n",
183 | " # Example 1 - List down 5 movies that released after the year 2000, the Cypher command will be something like this\n",
184 | " # ``` MATCH (m:Movie)\n",
185 | " # WHERE m.released > 2000\n",
186 | " # RETURN m LIMIT 5\n",
187 | " # ```\n",
188 | "\n",
189 | " # Example 2 - Get all the people who acted in a movie that was released after 2010.\n",
190 | " # ```\n",
191 | " # MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)\n",
192 | " # WHERE m.released > 2010\n",
193 | " # RETURN p,r,m\n",
194 | " # ```\n",
195 | "\n",
196 | " # Example 3 - Name the Director of the movie Apollo 13?\n",
197 | " # ```\n",
198 | " # MATCH (m:Movie)<-[:DIRECTED]-(p:Person)\n",
199 | " # WHERE m.title = 'Apollo';\n",
200 | " # RETURN p.name\n",
201 | " # ```\n",
202 | "\n",
203 | " # Do not include ``` and \\n in the output\n",
204 | "\n",
205 | " # {input}\"\"\"\n",
206 | " # response = genai.generate_text(**defaults,prompt=prompt)\n",
207 | "\n",
208 | " prompt_parts = [\n",
209 | " \"You are an expert in converting English questions to Neo4j Cypher Graph code! The Graph has following Node Labels - Movie, Person! the Movie Node has the following properties released, tagline, title. The Person node has properties such as name & born. The Neo4j Graph has the following Relationship types ACTED_IN, DIRECTED, FOLLOWS, PRODUCED, REVIEWED, WROTE! All relationships ACTED_IN, DIRECTED, PRODUCED, REVIEWED, WROTE start from Person to Movie and not the other way around except for FOLLOWS relationship which starts from a Person node and ends on a Person node.\\n\\nDo not include ``` and \\\\n in the output\",\n",
210 | " \"input: List down 5 movies that released after the year 2000, the Cypher command will be something like this\",\n",
211 | " \"output: MATCH (m:Movie) WHERE m.released > 2000 RETURN m LIMIT 5\",\n",
212 | " \"input: Get all the people who acted in a movie that was released after 2010\",\n",
213 | " \"output: MATCH (p:Person)-[r:ACTED_IN]->(m:Movie) WHERE m.released > 2010 RETURN p,r,m\",\n",
214 | " \"input: Name the Director of the movie Apollo 13?\",\n",
215 | " \"output: MATCH (m:Movie)<-[:DIRECTED]-(p:Person) WHERE m.title = 'Apollo'; RETURN p.name\",\n",
216 | " \"input: Who were the actors in the movie V for Vendetta\",\n",
217 | " \"output: \",\n",
218 | " ]\n",
219 | "\n",
220 | " response = model.generate_content(prompt_parts)\n",
221 | " return response.text"
222 | ]
223 | },
224 | {
225 | "cell_type": "markdown",
226 | "source": [
227 | "### Testing the output of get_answer() function with a test input"
228 | ],
229 | "metadata": {
230 | "id": "QJOyVbAUkm2h"
231 | }
232 | },
233 | {
234 | "cell_type": "code",
235 | "execution_count": 8,
236 | "metadata": {
237 | "colab": {
238 | "base_uri": "https://localhost:8080/",
239 | "height": 35
240 | },
241 | "id": "O2ofGI64atGc",
242 | "outputId": "994ff9ea-9fbe-4ce9-9f44-78a8a9665a8c"
243 | },
244 | "outputs": [
245 | {
246 | "output_type": "execute_result",
247 | "data": {
248 | "text/plain": [
249 | "\"MATCH (m:Movie) WHERE m.title = 'V for Vendetta'; MATCH (p:Person)-[r:ACTED_IN]->(m) RETURN p.name\""
250 | ],
251 | "application/vnd.google.colaboratory.intrinsic+json": {
252 | "type": "string"
253 | }
254 | },
255 | "metadata": {},
256 | "execution_count": 8
257 | }
258 | ],
259 | "source": [
260 | "get_answer(\"Who were the actors in the movie V for Vendetta\")"
261 | ]
262 | },
263 | {
264 | "cell_type": "markdown",
265 | "source": [
266 | "### Initialize GraphDatabase driver\n",
267 | "\n",
268 | "**Instruction:** Replace URI, username and password before running the cell with the values from the txt file downloaded when creating Neo4j AuraDB instance in Step #4 of Part #1 of [Step By Step Guide](https://github.com/sidagarwal04/graph-powered-nlp-workshop/blob/main/step-by-step-guide.md#part-1-create-and-load-a-neo4j-instance) of this workshop."
269 | ],
270 | "metadata": {
271 | "id": "8V9yWsONkw1D"
272 | }
273 | },
274 | {
275 | "cell_type": "code",
276 | "execution_count": 25,
277 | "metadata": {
278 | "id": "YEMajMpDbEX6"
279 | },
280 | "outputs": [],
281 | "source": [
282 | "uri=userdata.get('NEO4J_URI')\n",
283 | "password=userdata.get('NEO4J_PASSWORD')\n",
284 | "driver = GraphDatabase.driver(uri,\n",
285 | " auth=(\"neo4j\",\n",
286 | " password))"
287 | ]
288 | },
289 | {
290 | "cell_type": "markdown",
291 | "metadata": {
292 | "id": "IiyxjOE1dr3J"
293 | },
294 | "source": [
295 | "### Import required library for processing regular expressions"
296 | ]
297 | },
298 | {
299 | "cell_type": "code",
300 | "execution_count": 26,
301 | "metadata": {
302 | "id": "FQP5BDGpdpSF"
303 | },
304 | "outputs": [],
305 | "source": [
306 | "import re"
307 | ]
308 | },
309 | {
310 | "cell_type": "markdown",
311 | "metadata": {
312 | "id": "62T0UKQZc4fl"
313 | },
314 | "source": [
315 | "### Function to clean the output query from get_answer() function by removing slash n's (\\n) and substituting it with a space if it exists. Also, extract the string after RETURN expression in the output cypher query and utilize as a separate key to be used for printing the output in chatbot in later steps"
316 | ]
317 | },
318 | {
319 | "cell_type": "code",
320 | "execution_count": 27,
321 | "metadata": {
322 | "id": "dolSYLLmbrym"
323 | },
324 | "outputs": [],
325 | "source": [
326 | "def extract_query_and_return_key(input_query_result):\n",
327 | " slash_n_pattern = r'[ \\n]+'\n",
328 | " ret_pattern = r'RETURN\\s+(.*)'\n",
329 | " replacement = ' '\n",
330 | "\n",
331 | " cleaned_query = re.sub(slash_n_pattern, replacement, input_query_result)\n",
332 | " if cleaned_query:\n",
333 | " match = re.search(ret_pattern, cleaned_query)\n",
334 | " if match:\n",
335 | " extracted_string = match.group(1)\n",
336 | " else:\n",
337 | " extracted_string = \"\"\n",
338 | " return cleaned_query, extracted_string"
339 | ]
340 | },
341 | {
342 | "cell_type": "markdown",
343 | "source": [
344 | "### Testing the extract_query_and_return_key() function with a test input in natural language"
345 | ],
346 | "metadata": {
347 | "id": "2XGpwCBmmKhT"
348 | }
349 | },
350 | {
351 | "cell_type": "code",
352 | "execution_count": 28,
353 | "metadata": {
354 | "colab": {
355 | "base_uri": "https://localhost:8080/",
356 | "height": 53
357 | },
358 | "id": "mI4G3_zScHYb",
359 | "outputId": "dadc816a-2056-4e3b-a263-4a8b45018d29"
360 | },
361 | "outputs": [
362 | {
363 | "output_type": "execute_result",
364 | "data": {
365 | "text/plain": [
366 | "(\"MATCH (m:Movie)<-[:ACTED_IN]-(p:Person) WHERE m.title = 'V for Vendetta'; RETURN p.name\",\n",
367 | " 'p.name')"
368 | ]
369 | },
370 | "metadata": {},
371 | "execution_count": 28
372 | }
373 | ],
374 | "source": [
375 | "extract_query_and_return_key(get_answer(\"Who were the actors in the movie V for Vendetta\"))"
376 | ]
377 | },
378 | {
379 | "cell_type": "markdown",
380 | "metadata": {
381 | "id": "Zap-rwZIccuV"
382 | },
383 | "source": [
384 | "### format_names_with_ampersand() to return results as a comma-separated string of values with last value having '&' (ampersand/and) in case the output is a list of values."
385 | ]
386 | },
387 | {
388 | "cell_type": "code",
389 | "execution_count": 30,
390 | "metadata": {
391 | "id": "MiKTUqoGccCD"
392 | },
393 | "outputs": [],
394 | "source": [
395 | "def format_names_with_ampersand(names):\n",
396 | " if len(names) == 0:\n",
397 | " return \"\"\n",
398 | " elif len(names) == 1:\n",
399 | " return names[0]\n",
400 | " else:\n",
401 | " formatted_names = \", \".join(names[:-1]) + \" & \" + names[-1]\n",
402 | " return formatted_names"
403 | ]
404 | },
405 | {
406 | "cell_type": "markdown",
407 | "source": [
408 | "### Testing format_names_with_ampersand() with sample input having list of values"
409 | ],
410 | "metadata": {
411 | "id": "ehQc6_pBmtTo"
412 | }
413 | },
414 | {
415 | "cell_type": "code",
416 | "execution_count": 31,
417 | "metadata": {
418 | "colab": {
419 | "base_uri": "https://localhost:8080/",
420 | "height": 35
421 | },
422 | "id": "G9HWiCjMg7mv",
423 | "outputId": "bb60f58f-061c-4328-9c9a-337f0cbbd55b"
424 | },
425 | "outputs": [
426 | {
427 | "output_type": "execute_result",
428 | "data": {
429 | "text/plain": [
430 | "'Sachin, Virat & Rahul'"
431 | ],
432 | "application/vnd.google.colaboratory.intrinsic+json": {
433 | "type": "string"
434 | }
435 | },
436 | "metadata": {},
437 | "execution_count": 31
438 | }
439 | ],
440 | "source": [
441 | "format_names_with_ampersand([\"Sachin\",\"Virat\",\"Rahul\"])"
442 | ]
443 | },
444 | {
445 | "cell_type": "markdown",
446 | "metadata": {
447 | "id": "xVcvzmiGhK8Q"
448 | },
449 | "source": [
450 | "### run_cypher_on_neo4j() to pass the output query from get_answer() to the Neo4j Database. If the length of output list is more than 1, format_name_with_ampersand() will further format the list and if the length of output list is equal to 1, output list is returned as it is. In case the output list is empty, an empty string is returned"
451 | ]
452 | },
453 | {
454 | "cell_type": "code",
455 | "execution_count": 32,
456 | "metadata": {
457 | "id": "DX907ZoLhFlO"
458 | },
459 | "outputs": [],
460 | "source": [
461 | "def run_cypher_on_neo4j(inp_query, inp_key):\n",
462 | " out_list = []\n",
463 | " with driver.session() as session:\n",
464 | " result = session.run(inp_query)\n",
465 | " for record in result:\n",
466 | " out_list.append(record[inp_key])\n",
467 | " driver.close()\n",
468 | " if len(out_list) > 1:\n",
469 | " return format_names_with_ampersand(out_list)\n",
470 | " elif len(out_list) == 1:\n",
471 | " return out_list[0]\n",
472 | " else:\n",
473 | " return \"\""
474 | ]
475 | },
476 | {
477 | "cell_type": "markdown",
478 | "source": [
479 | "### Additional generate_and_exec_cypher() to parse and format the output of get_answer() and pass it to run_cypher_on_neo4j()"
480 | ],
481 | "metadata": {
482 | "id": "M2e8NAxtn62_"
483 | }
484 | },
485 | {
486 | "cell_type": "code",
487 | "execution_count": 33,
488 | "metadata": {
489 | "id": "_VyRl85rmRkE"
490 | },
491 | "outputs": [],
492 | "source": [
493 | "def generate_and_exec_cypher(input_query):\n",
494 | " gen_query, gen_key = extract_query_and_return_key(get_answer(input_query))\n",
495 | " return run_cypher_on_neo4j(gen_query, gen_key)"
496 | ]
497 | },
498 | {
499 | "cell_type": "markdown",
500 | "source": [
501 | "### chatbot() to initiliaze the chatbot and pass the output of generate_and_exec_cypher to be displayed in the chatbot"
502 | ],
503 | "metadata": {
504 | "id": "O4mZ13ZBoVIn"
505 | }
506 | },
507 | {
508 | "cell_type": "code",
509 | "execution_count": 34,
510 | "metadata": {
511 | "id": "ply_bUFznJQS"
512 | },
513 | "outputs": [],
514 | "source": [
515 | "def chatbot(input, history=[]):\n",
516 | " output = str(generate_and_exec_cypher(input))\n",
517 | " history.append((input, output))\n",
518 | " return history, history"
519 | ]
520 | },
521 | {
522 | "cell_type": "markdown",
523 | "source": [
524 | "### Initializing Gradio interface to run the chatbot.\n",
525 | "\n",
526 | "**Instruction:** Run the chatbot in the localhost url generated after running the cell and play aroung with input and output in natural language while fetching the results from the Neo4j Database using PaLM 2 API for converting input text into cypher code."
527 | ],
528 | "metadata": {
529 | "id": "rcqP5ZhDol8r"
530 | }
531 | },
532 | {
533 | "cell_type": "code",
534 | "execution_count": null,
535 | "metadata": {
536 | "colab": {
537 | "base_uri": "https://localhost:8080/",
538 | "height": 648
539 | },
540 | "id": "m4HXQQvonPT5",
541 | "outputId": "0a488989-5b6b-489b-a86f-e2a63f455ee0"
542 | },
543 | "outputs": [
544 | {
545 | "output_type": "stream",
546 | "name": "stdout",
547 | "text": [
548 | "Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
549 | "\n",
550 | "Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n",
551 | "Running on public URL: https://eb4b137911df76b229.gradio.live\n",
552 | "\n",
553 | "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
554 | ]
555 | },
556 | {
557 | "output_type": "display_data",
558 | "data": {
559 | "text/plain": [
560 | ""
561 | ],
562 | "text/html": [
563 | ""
564 | ]
565 | },
566 | "metadata": {}
567 | }
568 | ],
569 | "source": [
570 | "gr.Interface(fn = chatbot,\n",
571 | " inputs = [\"text\",'state'],\n",
572 | " outputs = [\"chatbot\",'state']).launch(debug = True)"
573 | ]
574 | }
575 | ],
576 | "metadata": {
577 | "colab": {
578 | "provenance": [],
579 | "include_colab_link": true
580 | },
581 | "kernelspec": {
582 | "display_name": "Python 3",
583 | "name": "python3"
584 | },
585 | "language_info": {
586 | "name": "python"
587 | }
588 | },
589 | "nbformat": 4,
590 | "nbformat_minor": 0
591 | }
--------------------------------------------------------------------------------
/movies-db-setup.cypher:
--------------------------------------------------------------------------------
1 | CREATE CONSTRAINT IF NOT EXISTS FOR (p:Person) REQUIRE (p.name) IS UNIQUE;
2 | CREATE INDEX IF NOT EXISTS FOR (p:Person) ON (p.born);
3 | CREATE CONSTRAINT IF NOT EXISTS FOR (m:Movie) REQUIRE (m.title) IS UNIQUE;
4 | CREATE INDEX IF NOT EXISTS FOR (m:Movie) ON (m.released);
5 |
6 | CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
7 | CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
8 | CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
9 | CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
10 | CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
11 | CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
12 | CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
13 | CREATE (JoelS:Person {name:'Joel Silver', born:1952})
14 | CREATE
15 | (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
16 | (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
17 | (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
18 | (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
19 | (LillyW)-[:DIRECTED]->(TheMatrix),
20 | (LanaW)-[:DIRECTED]->(TheMatrix),
21 | (JoelS)-[:PRODUCED]->(TheMatrix)
22 |
23 | CREATE (Emil:Person {name:"Emil Eifrem", born:1978})
24 | CREATE (Emil)-[:ACTED_IN {roles:["Emil"]}]->(TheMatrix)
25 |
26 | CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})
27 | CREATE
28 | (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixReloaded),
29 | (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrixReloaded),
30 | (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrixReloaded),
31 | (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrixReloaded),
32 | (LillyW)-[:DIRECTED]->(TheMatrixReloaded),
33 | (LanaW)-[:DIRECTED]->(TheMatrixReloaded),
34 | (JoelS)-[:PRODUCED]->(TheMatrixReloaded)
35 |
36 | CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})
37 | CREATE
38 | (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixRevolutions),
39 | (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrixRevolutions),
40 | (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrixRevolutions),
41 | (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrixRevolutions),
42 | (LillyW)-[:DIRECTED]->(TheMatrixRevolutions),
43 | (LanaW)-[:DIRECTED]->(TheMatrixRevolutions),
44 | (JoelS)-[:PRODUCED]->(TheMatrixRevolutions)
45 |
46 | CREATE (TheDevilsAdvocate:Movie {title:"The Devil's Advocate", released:1997, tagline:'Evil has its winning ways'})
47 | CREATE (Charlize:Person {name:'Charlize Theron', born:1975})
48 | CREATE (Al:Person {name:'Al Pacino', born:1940})
49 | CREATE (Taylor:Person {name:'Taylor Hackford', born:1944})
50 | CREATE
51 | (Keanu)-[:ACTED_IN {roles:['Kevin Lomax']}]->(TheDevilsAdvocate),
52 | (Charlize)-[:ACTED_IN {roles:['Mary Ann Lomax']}]->(TheDevilsAdvocate),
53 | (Al)-[:ACTED_IN {roles:['John Milton']}]->(TheDevilsAdvocate),
54 | (Taylor)-[:DIRECTED]->(TheDevilsAdvocate)
55 |
56 | CREATE (AFewGoodMen:Movie {title:"A Few Good Men", released:1992, tagline:"In the heart of the nation's capital, in a courthouse of the U.S. government, one man will stop at nothing to keep his honor, and one will stop at nothing to find the truth."})
57 | CREATE (TomC:Person {name:'Tom Cruise', born:1962})
58 | CREATE (JackN:Person {name:'Jack Nicholson', born:1937})
59 | CREATE (DemiM:Person {name:'Demi Moore', born:1962})
60 | CREATE (KevinB:Person {name:'Kevin Bacon', born:1958})
61 | CREATE (KieferS:Person {name:'Kiefer Sutherland', born:1966})
62 | CREATE (NoahW:Person {name:'Noah Wyle', born:1971})
63 | CREATE (CubaG:Person {name:'Cuba Gooding Jr.', born:1968})
64 | CREATE (KevinP:Person {name:'Kevin Pollak', born:1957})
65 | CREATE (JTW:Person {name:'J.T. Walsh', born:1943})
66 | CREATE (JamesM:Person {name:'James Marshall', born:1967})
67 | CREATE (ChristopherG:Person {name:'Christopher Guest', born:1948})
68 | CREATE (RobR:Person {name:'Rob Reiner', born:1947})
69 | CREATE (AaronS:Person {name:'Aaron Sorkin', born:1961})
70 | CREATE
71 | (TomC)-[:ACTED_IN {roles:['Lt. Daniel Kaffee']}]->(AFewGoodMen),
72 | (JackN)-[:ACTED_IN {roles:['Col. Nathan R. Jessup']}]->(AFewGoodMen),
73 | (DemiM)-[:ACTED_IN {roles:['Lt. Cdr. JoAnne Galloway']}]->(AFewGoodMen),
74 | (KevinB)-[:ACTED_IN {roles:['Capt. Jack Ross']}]->(AFewGoodMen),
75 | (KieferS)-[:ACTED_IN {roles:['Lt. Jonathan Kendrick']}]->(AFewGoodMen),
76 | (NoahW)-[:ACTED_IN {roles:['Cpl. Jeffrey Barnes']}]->(AFewGoodMen),
77 | (CubaG)-[:ACTED_IN {roles:['Cpl. Carl Hammaker']}]->(AFewGoodMen),
78 | (KevinP)-[:ACTED_IN {roles:['Lt. Sam Weinberg']}]->(AFewGoodMen),
79 | (JTW)-[:ACTED_IN {roles:['Lt. Col. Matthew Andrew Markinson']}]->(AFewGoodMen),
80 | (JamesM)-[:ACTED_IN {roles:['Pfc. Louden Downey']}]->(AFewGoodMen),
81 | (ChristopherG)-[:ACTED_IN {roles:['Dr. Stone']}]->(AFewGoodMen),
82 | (AaronS)-[:ACTED_IN {roles:['Man in Bar']}]->(AFewGoodMen),
83 | (RobR)-[:DIRECTED]->(AFewGoodMen),
84 | (AaronS)-[:WROTE]->(AFewGoodMen)
85 |
86 | CREATE (TopGun:Movie {title:"Top Gun", released:1986, tagline:'I feel the need, the need for speed.'})
87 | CREATE (KellyM:Person {name:'Kelly McGillis', born:1957})
88 | CREATE (ValK:Person {name:'Val Kilmer', born:1959})
89 | CREATE (AnthonyE:Person {name:'Anthony Edwards', born:1962})
90 | CREATE (TomS:Person {name:'Tom Skerritt', born:1933})
91 | CREATE (MegR:Person {name:'Meg Ryan', born:1961})
92 | CREATE (TonyS:Person {name:'Tony Scott', born:1944})
93 | CREATE (JimC:Person {name:'Jim Cash', born:1941})
94 | CREATE
95 | (TomC)-[:ACTED_IN {roles:['Maverick']}]->(TopGun),
96 | (KellyM)-[:ACTED_IN {roles:['Charlie']}]->(TopGun),
97 | (ValK)-[:ACTED_IN {roles:['Iceman']}]->(TopGun),
98 | (AnthonyE)-[:ACTED_IN {roles:['Goose']}]->(TopGun),
99 | (TomS)-[:ACTED_IN {roles:['Viper']}]->(TopGun),
100 | (MegR)-[:ACTED_IN {roles:['Carole']}]->(TopGun),
101 | (TonyS)-[:DIRECTED]->(TopGun),
102 | (JimC)-[:WROTE]->(TopGun)
103 |
104 | CREATE (JerryMaguire:Movie {title:'Jerry Maguire', released:2000, tagline:'The rest of his life begins now.'})
105 | CREATE (ReneeZ:Person {name:'Renee Zellweger', born:1969})
106 | CREATE (KellyP:Person {name:'Kelly Preston', born:1962})
107 | CREATE (JerryO:Person {name:"Jerry O'Connell", born:1974})
108 | CREATE (JayM:Person {name:'Jay Mohr', born:1970})
109 | CREATE (BonnieH:Person {name:'Bonnie Hunt', born:1961})
110 | CREATE (ReginaK:Person {name:'Regina King', born:1971})
111 | CREATE (JonathanL:Person {name:'Jonathan Lipnicki', born:1996})
112 | CREATE (CameronC:Person {name:'Cameron Crowe', born:1957})
113 | CREATE
114 | (TomC)-[:ACTED_IN {roles:['Jerry Maguire']}]->(JerryMaguire),
115 | (CubaG)-[:ACTED_IN {roles:['Rod Tidwell']}]->(JerryMaguire),
116 | (ReneeZ)-[:ACTED_IN {roles:['Dorothy Boyd']}]->(JerryMaguire),
117 | (KellyP)-[:ACTED_IN {roles:['Avery Bishop']}]->(JerryMaguire),
118 | (JerryO)-[:ACTED_IN {roles:['Frank Cushman']}]->(JerryMaguire),
119 | (JayM)-[:ACTED_IN {roles:['Bob Sugar']}]->(JerryMaguire),
120 | (BonnieH)-[:ACTED_IN {roles:['Laurel Boyd']}]->(JerryMaguire),
121 | (ReginaK)-[:ACTED_IN {roles:['Marcee Tidwell']}]->(JerryMaguire),
122 | (JonathanL)-[:ACTED_IN {roles:['Ray Boyd']}]->(JerryMaguire),
123 | (CameronC)-[:DIRECTED]->(JerryMaguire),
124 | (CameronC)-[:PRODUCED]->(JerryMaguire),
125 | (CameronC)-[:WROTE]->(JerryMaguire)
126 |
127 | CREATE (StandByMe:Movie {title:"Stand By Me", released:1986, tagline:"For some, it's the last real taste of innocence, and the first real taste of life. But for everyone, it's the time that memories are made of."})
128 | CREATE (RiverP:Person {name:'River Phoenix', born:1970})
129 | CREATE (CoreyF:Person {name:'Corey Feldman', born:1971})
130 | CREATE (WilW:Person {name:'Wil Wheaton', born:1972})
131 | CREATE (JohnC:Person {name:'John Cusack', born:1966})
132 | CREATE (MarshallB:Person {name:'Marshall Bell', born:1942})
133 | CREATE
134 | (WilW)-[:ACTED_IN {roles:['Gordie Lachance']}]->(StandByMe),
135 | (RiverP)-[:ACTED_IN {roles:['Chris Chambers']}]->(StandByMe),
136 | (JerryO)-[:ACTED_IN {roles:['Vern Tessio']}]->(StandByMe),
137 | (CoreyF)-[:ACTED_IN {roles:['Teddy Duchamp']}]->(StandByMe),
138 | (JohnC)-[:ACTED_IN {roles:['Denny Lachance']}]->(StandByMe),
139 | (KieferS)-[:ACTED_IN {roles:['Ace Merrill']}]->(StandByMe),
140 | (MarshallB)-[:ACTED_IN {roles:['Mr. Lachance']}]->(StandByMe),
141 | (RobR)-[:DIRECTED]->(StandByMe)
142 |
143 | CREATE (AsGoodAsItGets:Movie {title:'As Good as It Gets', released:1997, tagline:'A comedy from the heart that goes for the throat.'})
144 | CREATE (HelenH:Person {name:'Helen Hunt', born:1963})
145 | CREATE (GregK:Person {name:'Greg Kinnear', born:1963})
146 | CREATE (JamesB:Person {name:'James L. Brooks', born:1940})
147 | CREATE
148 | (JackN)-[:ACTED_IN {roles:['Melvin Udall']}]->(AsGoodAsItGets),
149 | (HelenH)-[:ACTED_IN {roles:['Carol Connelly']}]->(AsGoodAsItGets),
150 | (GregK)-[:ACTED_IN {roles:['Simon Bishop']}]->(AsGoodAsItGets),
151 | (CubaG)-[:ACTED_IN {roles:['Frank Sachs']}]->(AsGoodAsItGets),
152 | (JamesB)-[:DIRECTED]->(AsGoodAsItGets)
153 |
154 | CREATE (WhatDreamsMayCome:Movie {title:'What Dreams May Come', released:1998, tagline:'After life there is more. The end is just the beginning.'})
155 | CREATE (AnnabellaS:Person {name:'Annabella Sciorra', born:1960})
156 | CREATE (MaxS:Person {name:'Max von Sydow', born:1929})
157 | CREATE (WernerH:Person {name:'Werner Herzog', born:1942})
158 | CREATE (Robin:Person {name:'Robin Williams', born:1951})
159 | CREATE (VincentW:Person {name:'Vincent Ward', born:1956})
160 | CREATE
161 | (Robin)-[:ACTED_IN {roles:['Chris Nielsen']}]->(WhatDreamsMayCome),
162 | (CubaG)-[:ACTED_IN {roles:['Albert Lewis']}]->(WhatDreamsMayCome),
163 | (AnnabellaS)-[:ACTED_IN {roles:['Annie Collins-Nielsen']}]->(WhatDreamsMayCome),
164 | (MaxS)-[:ACTED_IN {roles:['The Tracker']}]->(WhatDreamsMayCome),
165 | (WernerH)-[:ACTED_IN {roles:['The Face']}]->(WhatDreamsMayCome),
166 | (VincentW)-[:DIRECTED]->(WhatDreamsMayCome)
167 |
168 | CREATE (SnowFallingonCedars:Movie {title:'Snow Falling on Cedars', released:1999, tagline:'First loves last. Forever.'})
169 | CREATE (EthanH:Person {name:'Ethan Hawke', born:1970})
170 | CREATE (RickY:Person {name:'Rick Yune', born:1971})
171 | CREATE (JamesC:Person {name:'James Cromwell', born:1940})
172 | CREATE (ScottH:Person {name:'Scott Hicks', born:1953})
173 | CREATE
174 | (EthanH)-[:ACTED_IN {roles:['Ishmael Chambers']}]->(SnowFallingonCedars),
175 | (RickY)-[:ACTED_IN {roles:['Kazuo Miyamoto']}]->(SnowFallingonCedars),
176 | (MaxS)-[:ACTED_IN {roles:['Nels Gudmundsson']}]->(SnowFallingonCedars),
177 | (JamesC)-[:ACTED_IN {roles:['Judge Fielding']}]->(SnowFallingonCedars),
178 | (ScottH)-[:DIRECTED]->(SnowFallingonCedars)
179 |
180 | CREATE (YouveGotMail:Movie {title:"You've Got Mail", released:1998, tagline:'At odds in life... in love on-line.'})
181 | CREATE (ParkerP:Person {name:'Parker Posey', born:1968})
182 | CREATE (DaveC:Person {name:'Dave Chappelle', born:1973})
183 | CREATE (SteveZ:Person {name:'Steve Zahn', born:1967})
184 | CREATE (TomH:Person {name:'Tom Hanks', born:1956})
185 | CREATE (NoraE:Person {name:'Nora Ephron', born:1941})
186 | CREATE
187 | (TomH)-[:ACTED_IN {roles:['Joe Fox']}]->(YouveGotMail),
188 | (MegR)-[:ACTED_IN {roles:['Kathleen Kelly']}]->(YouveGotMail),
189 | (GregK)-[:ACTED_IN {roles:['Frank Navasky']}]->(YouveGotMail),
190 | (ParkerP)-[:ACTED_IN {roles:['Patricia Eden']}]->(YouveGotMail),
191 | (DaveC)-[:ACTED_IN {roles:['Kevin Jackson']}]->(YouveGotMail),
192 | (SteveZ)-[:ACTED_IN {roles:['George Pappas']}]->(YouveGotMail),
193 | (NoraE)-[:DIRECTED]->(YouveGotMail)
194 |
195 | CREATE (SleeplessInSeattle:Movie {title:'Sleepless in Seattle', released:1993, tagline:'What if someone you never met, someone you never saw, someone you never knew was the only someone for you?'})
196 | CREATE (RitaW:Person {name:'Rita Wilson', born:1956})
197 | CREATE (BillPull:Person {name:'Bill Pullman', born:1953})
198 | CREATE (VictorG:Person {name:'Victor Garber', born:1949})
199 | CREATE (RosieO:Person {name:"Rosie O'Donnell", born:1962})
200 | CREATE
201 | (TomH)-[:ACTED_IN {roles:['Sam Baldwin']}]->(SleeplessInSeattle),
202 | (MegR)-[:ACTED_IN {roles:['Annie Reed']}]->(SleeplessInSeattle),
203 | (RitaW)-[:ACTED_IN {roles:['Suzy']}]->(SleeplessInSeattle),
204 | (BillPull)-[:ACTED_IN {roles:['Walter']}]->(SleeplessInSeattle),
205 | (VictorG)-[:ACTED_IN {roles:['Greg']}]->(SleeplessInSeattle),
206 | (RosieO)-[:ACTED_IN {roles:['Becky']}]->(SleeplessInSeattle),
207 | (NoraE)-[:DIRECTED]->(SleeplessInSeattle)
208 |
209 | CREATE (JoeVersustheVolcano:Movie {title:'Joe Versus the Volcano', released:1990, tagline:'A story of love, lava and burning desire.'})
210 | CREATE (JohnS:Person {name:'John Patrick Stanley', born:1950})
211 | CREATE (Nathan:Person {name:'Nathan Lane', born:1956})
212 | CREATE
213 | (TomH)-[:ACTED_IN {roles:['Joe Banks']}]->(JoeVersustheVolcano),
214 | (MegR)-[:ACTED_IN {roles:['DeDe', 'Angelica Graynamore', 'Patricia Graynamore']}]->(JoeVersustheVolcano),
215 | (Nathan)-[:ACTED_IN {roles:['Baw']}]->(JoeVersustheVolcano),
216 | (JohnS)-[:DIRECTED]->(JoeVersustheVolcano)
217 |
218 | CREATE (WhenHarryMetSally:Movie {title:'When Harry Met Sally', released:1998, tagline:'Can two friends sleep together and still love each other in the morning?'})
219 | CREATE (BillyC:Person {name:'Billy Crystal', born:1948})
220 | CREATE (CarrieF:Person {name:'Carrie Fisher', born:1956})
221 | CREATE (BrunoK:Person {name:'Bruno Kirby', born:1949})
222 | CREATE
223 | (BillyC)-[:ACTED_IN {roles:['Harry Burns']}]->(WhenHarryMetSally),
224 | (MegR)-[:ACTED_IN {roles:['Sally Albright']}]->(WhenHarryMetSally),
225 | (CarrieF)-[:ACTED_IN {roles:['Marie']}]->(WhenHarryMetSally),
226 | (BrunoK)-[:ACTED_IN {roles:['Jess']}]->(WhenHarryMetSally),
227 | (RobR)-[:DIRECTED]->(WhenHarryMetSally),
228 | (RobR)-[:PRODUCED]->(WhenHarryMetSally),
229 | (NoraE)-[:PRODUCED]->(WhenHarryMetSally),
230 | (NoraE)-[:WROTE]->(WhenHarryMetSally)
231 |
232 | CREATE (ThatThingYouDo:Movie {title:'That Thing You Do', released:1996, tagline:'In every life there comes a time when that thing you dream becomes that thing you do'})
233 | CREATE (LivT:Person {name:'Liv Tyler', born:1977})
234 | CREATE
235 | (TomH)-[:ACTED_IN {roles:['Mr. White']}]->(ThatThingYouDo),
236 | (LivT)-[:ACTED_IN {roles:['Faye Dolan']}]->(ThatThingYouDo),
237 | (Charlize)-[:ACTED_IN {roles:['Tina']}]->(ThatThingYouDo),
238 | (TomH)-[:DIRECTED]->(ThatThingYouDo)
239 |
240 | CREATE (TheReplacements:Movie {title:'The Replacements', released:2000, tagline:'Pain heals, Chicks dig scars... Glory lasts forever'})
241 | CREATE (Brooke:Person {name:'Brooke Langton', born:1970})
242 | CREATE (Gene:Person {name:'Gene Hackman', born:1930})
243 | CREATE (Orlando:Person {name:'Orlando Jones', born:1968})
244 | CREATE (Howard:Person {name:'Howard Deutch', born:1950})
245 | CREATE
246 | (Keanu)-[:ACTED_IN {roles:['Shane Falco']}]->(TheReplacements),
247 | (Brooke)-[:ACTED_IN {roles:['Annabelle Farrell']}]->(TheReplacements),
248 | (Gene)-[:ACTED_IN {roles:['Jimmy McGinty']}]->(TheReplacements),
249 | (Orlando)-[:ACTED_IN {roles:['Clifford Franklin']}]->(TheReplacements),
250 | (Howard)-[:DIRECTED]->(TheReplacements)
251 |
252 | CREATE (RescueDawn:Movie {title:'RescueDawn', released:2006, tagline:"Based on the extraordinary true story of one man's fight for freedom"})
253 | CREATE (ChristianB:Person {name:'Christian Bale', born:1974})
254 | CREATE (ZachG:Person {name:'Zach Grenier', born:1954})
255 | CREATE
256 | (MarshallB)-[:ACTED_IN {roles:['Admiral']}]->(RescueDawn),
257 | (ChristianB)-[:ACTED_IN {roles:['Dieter Dengler']}]->(RescueDawn),
258 | (ZachG)-[:ACTED_IN {roles:['Squad Leader']}]->(RescueDawn),
259 | (SteveZ)-[:ACTED_IN {roles:['Duane']}]->(RescueDawn),
260 | (WernerH)-[:DIRECTED]->(RescueDawn)
261 |
262 | CREATE (TheBirdcage:Movie {title:'The Birdcage', released:1996, tagline:'Come as you are'})
263 | CREATE (MikeN:Person {name:'Mike Nichols', born:1931})
264 | CREATE
265 | (Robin)-[:ACTED_IN {roles:['Armand Goldman']}]->(TheBirdcage),
266 | (Nathan)-[:ACTED_IN {roles:['Albert Goldman']}]->(TheBirdcage),
267 | (Gene)-[:ACTED_IN {roles:['Sen. Kevin Keeley']}]->(TheBirdcage),
268 | (MikeN)-[:DIRECTED]->(TheBirdcage)
269 |
270 | CREATE (Unforgiven:Movie {title:'Unforgiven', released:1992, tagline:"It's a hell of a thing, killing a man"})
271 | CREATE (RichardH:Person {name:'Richard Harris', born:1930})
272 | CREATE (ClintE:Person {name:'Clint Eastwood', born:1930})
273 | CREATE
274 | (RichardH)-[:ACTED_IN {roles:['English Bob']}]->(Unforgiven),
275 | (ClintE)-[:ACTED_IN {roles:['Bill Munny']}]->(Unforgiven),
276 | (Gene)-[:ACTED_IN {roles:['Little Bill Daggett']}]->(Unforgiven),
277 | (ClintE)-[:DIRECTED]->(Unforgiven)
278 |
279 | CREATE (JohnnyMnemonic:Movie {title:'Johnny Mnemonic', released:1995, tagline:'The hottest data on earth. In the coolest head in town'})
280 | CREATE (Takeshi:Person {name:'Takeshi Kitano', born:1947})
281 | CREATE (Dina:Person {name:'Dina Meyer', born:1968})
282 | CREATE (IceT:Person {name:'Ice-T', born:1958})
283 | CREATE (RobertL:Person {name:'Robert Longo', born:1953})
284 | CREATE
285 | (Keanu)-[:ACTED_IN {roles:['Johnny Mnemonic']}]->(JohnnyMnemonic),
286 | (Takeshi)-[:ACTED_IN {roles:['Takahashi']}]->(JohnnyMnemonic),
287 | (Dina)-[:ACTED_IN {roles:['Jane']}]->(JohnnyMnemonic),
288 | (IceT)-[:ACTED_IN {roles:['J-Bone']}]->(JohnnyMnemonic),
289 | (RobertL)-[:DIRECTED]->(JohnnyMnemonic)
290 |
291 | CREATE (CloudAtlas:Movie {title:'Cloud Atlas', released:2012, tagline:'Everything is connected'})
292 | CREATE (HalleB:Person {name:'Halle Berry', born:1966})
293 | CREATE (JimB:Person {name:'Jim Broadbent', born:1949})
294 | CREATE (TomT:Person {name:'Tom Tykwer', born:1965})
295 | CREATE (DavidMitchell:Person {name:'David Mitchell', born:1969})
296 | CREATE (StefanArndt:Person {name:'Stefan Arndt', born:1961})
297 | CREATE
298 | (TomH)-[:ACTED_IN {roles:['Zachry', 'Dr. Henry Goose', 'Isaac Sachs', 'Dermot Hoggins']}]->(CloudAtlas),
299 | (Hugo)-[:ACTED_IN {roles:['Bill Smoke', 'Haskell Moore', 'Tadeusz Kesselring', 'Nurse Noakes', 'Boardman Mephi', 'Old Georgie']}]->(CloudAtlas),
300 | (HalleB)-[:ACTED_IN {roles:['Luisa Rey', 'Jocasta Ayrs', 'Ovid', 'Meronym']}]->(CloudAtlas),
301 | (JimB)-[:ACTED_IN {roles:['Vyvyan Ayrs', 'Captain Molyneux', 'Timothy Cavendish']}]->(CloudAtlas),
302 | (TomT)-[:DIRECTED]->(CloudAtlas),
303 | (LillyW)-[:DIRECTED]->(CloudAtlas),
304 | (LanaW)-[:DIRECTED]->(CloudAtlas),
305 | (DavidMitchell)-[:WROTE]->(CloudAtlas),
306 | (StefanArndt)-[:PRODUCED]->(CloudAtlas)
307 |
308 | CREATE (TheDaVinciCode:Movie {title:'The Da Vinci Code', released:2006, tagline:'Break The Codes'})
309 | CREATE (IanM:Person {name:'Ian McKellen', born:1939})
310 | CREATE (AudreyT:Person {name:'Audrey Tautou', born:1976})
311 | CREATE (PaulB:Person {name:'Paul Bettany', born:1971})
312 | CREATE (RonH:Person {name:'Ron Howard', born:1954})
313 | CREATE
314 | (TomH)-[:ACTED_IN {roles:['Dr. Robert Langdon']}]->(TheDaVinciCode),
315 | (IanM)-[:ACTED_IN {roles:['Sir Leight Teabing']}]->(TheDaVinciCode),
316 | (AudreyT)-[:ACTED_IN {roles:['Sophie Neveu']}]->(TheDaVinciCode),
317 | (PaulB)-[:ACTED_IN {roles:['Silas']}]->(TheDaVinciCode),
318 | (RonH)-[:DIRECTED]->(TheDaVinciCode)
319 |
320 | CREATE (VforVendetta:Movie {title:'V for Vendetta', released:2006, tagline:'Freedom! Forever!'})
321 | CREATE (NatalieP:Person {name:'Natalie Portman', born:1981})
322 | CREATE (StephenR:Person {name:'Stephen Rea', born:1946})
323 | CREATE (JohnH:Person {name:'John Hurt', born:1940})
324 | CREATE (BenM:Person {name: 'Ben Miles', born:1967})
325 | CREATE
326 | (Hugo)-[:ACTED_IN {roles:['V']}]->(VforVendetta),
327 | (NatalieP)-[:ACTED_IN {roles:['Evey Hammond']}]->(VforVendetta),
328 | (StephenR)-[:ACTED_IN {roles:['Eric Finch']}]->(VforVendetta),
329 | (JohnH)-[:ACTED_IN {roles:['High Chancellor Adam Sutler']}]->(VforVendetta),
330 | (BenM)-[:ACTED_IN {roles:['Dascomb']}]->(VforVendetta),
331 | (JamesM)-[:DIRECTED]->(VforVendetta),
332 | (LillyW)-[:PRODUCED]->(VforVendetta),
333 | (LanaW)-[:PRODUCED]->(VforVendetta),
334 | (JoelS)-[:PRODUCED]->(VforVendetta),
335 | (LillyW)-[:WROTE]->(VforVendetta),
336 | (LanaW)-[:WROTE]->(VforVendetta)
337 |
338 | CREATE (SpeedRacer:Movie {title:'Speed Racer', released:2008, tagline:'Speed has no limits'})
339 | CREATE (EmileH:Person {name:'Emile Hirsch', born:1985})
340 | CREATE (JohnG:Person {name:'John Goodman', born:1960})
341 | CREATE (SusanS:Person {name:'Susan Sarandon', born:1946})
342 | CREATE (MatthewF:Person {name:'Matthew Fox', born:1966})
343 | CREATE (ChristinaR:Person {name:'Christina Ricci', born:1980})
344 | CREATE (Rain:Person {name:'Rain', born:1982})
345 | CREATE
346 | (EmileH)-[:ACTED_IN {roles:['Speed Racer']}]->(SpeedRacer),
347 | (JohnG)-[:ACTED_IN {roles:['Pops']}]->(SpeedRacer),
348 | (SusanS)-[:ACTED_IN {roles:['Mom']}]->(SpeedRacer),
349 | (MatthewF)-[:ACTED_IN {roles:['Racer X']}]->(SpeedRacer),
350 | (ChristinaR)-[:ACTED_IN {roles:['Trixie']}]->(SpeedRacer),
351 | (Rain)-[:ACTED_IN {roles:['Taejo Togokahn']}]->(SpeedRacer),
352 | (BenM)-[:ACTED_IN {roles:['Cass Jones']}]->(SpeedRacer),
353 | (LillyW)-[:DIRECTED]->(SpeedRacer),
354 | (LanaW)-[:DIRECTED]->(SpeedRacer),
355 | (LillyW)-[:WROTE]->(SpeedRacer),
356 | (LanaW)-[:WROTE]->(SpeedRacer),
357 | (JoelS)-[:PRODUCED]->(SpeedRacer)
358 |
359 | CREATE (NinjaAssassin:Movie {title:'Ninja Assassin', released:2009, tagline:'Prepare to enter a secret world of assassins'})
360 | CREATE (NaomieH:Person {name:'Naomie Harris'})
361 | CREATE
362 | (Rain)-[:ACTED_IN {roles:['Raizo']}]->(NinjaAssassin),
363 | (NaomieH)-[:ACTED_IN {roles:['Mika Coretti']}]->(NinjaAssassin),
364 | (RickY)-[:ACTED_IN {roles:['Takeshi']}]->(NinjaAssassin),
365 | (BenM)-[:ACTED_IN {roles:['Ryan Maslow']}]->(NinjaAssassin),
366 | (JamesM)-[:DIRECTED]->(NinjaAssassin),
367 | (LillyW)-[:PRODUCED]->(NinjaAssassin),
368 | (LanaW)-[:PRODUCED]->(NinjaAssassin),
369 | (JoelS)-[:PRODUCED]->(NinjaAssassin)
370 |
371 | CREATE (TheGreenMile:Movie {title:'The Green Mile', released:1999, tagline:"Walk a mile you'll never forget."})
372 | CREATE (MichaelD:Person {name:'Michael Clarke Duncan', born:1957})
373 | CREATE (DavidM:Person {name:'David Morse', born:1953})
374 | CREATE (SamR:Person {name:'Sam Rockwell', born:1968})
375 | CREATE (GaryS:Person {name:'Gary Sinise', born:1955})
376 | CREATE (PatriciaC:Person {name:'Patricia Clarkson', born:1959})
377 | CREATE (FrankD:Person {name:'Frank Darabont', born:1959})
378 | CREATE
379 | (TomH)-[:ACTED_IN {roles:['Paul Edgecomb']}]->(TheGreenMile),
380 | (MichaelD)-[:ACTED_IN {roles:['John Coffey']}]->(TheGreenMile),
381 | (DavidM)-[:ACTED_IN {roles:['Brutus "Brutal" Howell']}]->(TheGreenMile),
382 | (BonnieH)-[:ACTED_IN {roles:['Jan Edgecomb']}]->(TheGreenMile),
383 | (JamesC)-[:ACTED_IN {roles:['Warden Hal Moores']}]->(TheGreenMile),
384 | (SamR)-[:ACTED_IN {roles:['"Wild Bill" Wharton']}]->(TheGreenMile),
385 | (GaryS)-[:ACTED_IN {roles:['Burt Hammersmith']}]->(TheGreenMile),
386 | (PatriciaC)-[:ACTED_IN {roles:['Melinda Moores']}]->(TheGreenMile),
387 | (FrankD)-[:DIRECTED]->(TheGreenMile)
388 |
389 | CREATE (FrostNixon:Movie {title:'Frost/Nixon', released:2008, tagline:'400 million people were waiting for the truth.'})
390 | CREATE (FrankL:Person {name:'Frank Langella', born:1938})
391 | CREATE (MichaelS:Person {name:'Michael Sheen', born:1969})
392 | CREATE (OliverP:Person {name:'Oliver Platt', born:1960})
393 | CREATE
394 | (FrankL)-[:ACTED_IN {roles:['Richard Nixon']}]->(FrostNixon),
395 | (MichaelS)-[:ACTED_IN {roles:['David Frost']}]->(FrostNixon),
396 | (KevinB)-[:ACTED_IN {roles:['Jack Brennan']}]->(FrostNixon),
397 | (OliverP)-[:ACTED_IN {roles:['Bob Zelnick']}]->(FrostNixon),
398 | (SamR)-[:ACTED_IN {roles:['James Reston, Jr.']}]->(FrostNixon),
399 | (RonH)-[:DIRECTED]->(FrostNixon)
400 |
401 | CREATE (Hoffa:Movie {title:'Hoffa', released:1992, tagline:"He didn't want law. He wanted justice."})
402 | CREATE (DannyD:Person {name:'Danny DeVito', born:1944})
403 | CREATE (JohnR:Person {name:'John C. Reilly', born:1965})
404 | CREATE
405 | (JackN)-[:ACTED_IN {roles:['Hoffa']}]->(Hoffa),
406 | (DannyD)-[:ACTED_IN {roles:['Robert "Bobby" Ciaro']}]->(Hoffa),
407 | (JTW)-[:ACTED_IN {roles:['Frank Fitzsimmons']}]->(Hoffa),
408 | (JohnR)-[:ACTED_IN {roles:['Peter "Pete" Connelly']}]->(Hoffa),
409 | (DannyD)-[:DIRECTED]->(Hoffa)
410 |
411 | CREATE (Apollo13:Movie {title:'Apollo 13', released:1995, tagline:'Houston, we have a problem.'})
412 | CREATE (EdH:Person {name:'Ed Harris', born:1950})
413 | CREATE (BillPax:Person {name:'Bill Paxton', born:1955})
414 | CREATE
415 | (TomH)-[:ACTED_IN {roles:['Jim Lovell']}]->(Apollo13),
416 | (KevinB)-[:ACTED_IN {roles:['Jack Swigert']}]->(Apollo13),
417 | (EdH)-[:ACTED_IN {roles:['Gene Kranz']}]->(Apollo13),
418 | (BillPax)-[:ACTED_IN {roles:['Fred Haise']}]->(Apollo13),
419 | (GaryS)-[:ACTED_IN {roles:['Ken Mattingly']}]->(Apollo13),
420 | (RonH)-[:DIRECTED]->(Apollo13)
421 |
422 | CREATE (Twister:Movie {title:'Twister', released:1996, tagline:"Don't Breathe. Don't Look Back."})
423 | CREATE (PhilipH:Person {name:'Philip Seymour Hoffman', born:1967})
424 | CREATE (JanB:Person {name:'Jan de Bont', born:1943})
425 | CREATE
426 | (BillPax)-[:ACTED_IN {roles:['Bill Harding']}]->(Twister),
427 | (HelenH)-[:ACTED_IN {roles:['Dr. Jo Harding']}]->(Twister),
428 | (ZachG)-[:ACTED_IN {roles:['Eddie']}]->(Twister),
429 | (PhilipH)-[:ACTED_IN {roles:['Dustin "Dusty" Davis']}]->(Twister),
430 | (JanB)-[:DIRECTED]->(Twister)
431 |
432 | CREATE (CastAway:Movie {title:'Cast Away', released:2000, tagline:'At the edge of the world, his journey begins.'})
433 | CREATE (RobertZ:Person {name:'Robert Zemeckis', born:1951})
434 | CREATE
435 | (TomH)-[:ACTED_IN {roles:['Chuck Noland']}]->(CastAway),
436 | (HelenH)-[:ACTED_IN {roles:['Kelly Frears']}]->(CastAway),
437 | (RobertZ)-[:DIRECTED]->(CastAway)
438 |
439 | CREATE (OneFlewOvertheCuckoosNest:Movie {title:"One Flew Over the Cuckoo's Nest", released:1975, tagline:"If he's crazy, what does that make you?"})
440 | CREATE (MilosF:Person {name:'Milos Forman', born:1932})
441 | CREATE
442 | (JackN)-[:ACTED_IN {roles:['Randle McMurphy']}]->(OneFlewOvertheCuckoosNest),
443 | (DannyD)-[:ACTED_IN {roles:['Martini']}]->(OneFlewOvertheCuckoosNest),
444 | (MilosF)-[:DIRECTED]->(OneFlewOvertheCuckoosNest)
445 |
446 | CREATE (SomethingsGottaGive:Movie {title:"Something's Gotta Give", released:2003})
447 | CREATE (DianeK:Person {name:'Diane Keaton', born:1946})
448 | CREATE (NancyM:Person {name:'Nancy Meyers', born:1949})
449 | CREATE
450 | (JackN)-[:ACTED_IN {roles:['Harry Sanborn']}]->(SomethingsGottaGive),
451 | (DianeK)-[:ACTED_IN {roles:['Erica Barry']}]->(SomethingsGottaGive),
452 | (Keanu)-[:ACTED_IN {roles:['Julian Mercer']}]->(SomethingsGottaGive),
453 | (NancyM)-[:DIRECTED]->(SomethingsGottaGive),
454 | (NancyM)-[:PRODUCED]->(SomethingsGottaGive),
455 | (NancyM)-[:WROTE]->(SomethingsGottaGive)
456 |
457 | CREATE (BicentennialMan:Movie {title:'Bicentennial Man', released:1999, tagline:"One robot's 200 year journey to become an ordinary man."})
458 | CREATE (ChrisC:Person {name:'Chris Columbus', born:1958})
459 | CREATE
460 | (Robin)-[:ACTED_IN {roles:['Andrew Marin']}]->(BicentennialMan),
461 | (OliverP)-[:ACTED_IN {roles:['Rupert Burns']}]->(BicentennialMan),
462 | (ChrisC)-[:DIRECTED]->(BicentennialMan)
463 |
464 | CREATE (CharlieWilsonsWar:Movie {title:"Charlie Wilson's War", released:2007, tagline:"A stiff drink. A little mascara. A lot of nerve. Who said they couldn't bring down the Soviet empire."})
465 | CREATE (JuliaR:Person {name:'Julia Roberts', born:1967})
466 | CREATE
467 | (TomH)-[:ACTED_IN {roles:['Rep. Charlie Wilson']}]->(CharlieWilsonsWar),
468 | (JuliaR)-[:ACTED_IN {roles:['Joanne Herring']}]->(CharlieWilsonsWar),
469 | (PhilipH)-[:ACTED_IN {roles:['Gust Avrakotos']}]->(CharlieWilsonsWar),
470 | (MikeN)-[:DIRECTED]->(CharlieWilsonsWar)
471 |
472 | CREATE (ThePolarExpress:Movie {title:'The Polar Express', released:2004, tagline:'This Holiday Season… Believe'})
473 | CREATE
474 | (TomH)-[:ACTED_IN {roles:['Hero Boy', 'Father', 'Conductor', 'Hobo', 'Scrooge', 'Santa Claus']}]->(ThePolarExpress),
475 | (RobertZ)-[:DIRECTED]->(ThePolarExpress)
476 |
477 | CREATE (ALeagueofTheirOwn:Movie {title:'A League of Their Own', released:1992, tagline:'Once in a lifetime you get a chance to do something different.'})
478 | CREATE (Madonna:Person {name:'Madonna', born:1954})
479 | CREATE (GeenaD:Person {name:'Geena Davis', born:1956})
480 | CREATE (LoriP:Person {name:'Lori Petty', born:1963})
481 | CREATE (PennyM:Person {name:'Penny Marshall', born:1943})
482 | CREATE
483 | (TomH)-[:ACTED_IN {roles:['Jimmy Dugan']}]->(ALeagueofTheirOwn),
484 | (GeenaD)-[:ACTED_IN {roles:['Dottie Hinson']}]->(ALeagueofTheirOwn),
485 | (LoriP)-[:ACTED_IN {roles:['Kit Keller']}]->(ALeagueofTheirOwn),
486 | (RosieO)-[:ACTED_IN {roles:['Doris Murphy']}]->(ALeagueofTheirOwn),
487 | (Madonna)-[:ACTED_IN {roles:['"All the Way" Mae Mordabito']}]->(ALeagueofTheirOwn),
488 | (BillPax)-[:ACTED_IN {roles:['Bob Hinson']}]->(ALeagueofTheirOwn),
489 | (PennyM)-[:DIRECTED]->(ALeagueofTheirOwn)
490 |
491 | CREATE (PaulBlythe:Person {name:'Paul Blythe'})
492 | CREATE (AngelaScope:Person {name:'Angela Scope'})
493 | CREATE (JessicaThompson:Person {name:'Jessica Thompson'})
494 | CREATE (JamesThompson:Person {name:'James Thompson'})
495 |
496 | CREATE
497 | (JamesThompson)-[:FOLLOWS]->(JessicaThompson),
498 | (AngelaScope)-[:FOLLOWS]->(JessicaThompson),
499 | (PaulBlythe)-[:FOLLOWS]->(AngelaScope)
500 |
501 | CREATE
502 | (JessicaThompson)-[:REVIEWED {summary:'An amazing journey', rating:95}]->(CloudAtlas),
503 | (JessicaThompson)-[:REVIEWED {summary:'Silly, but fun', rating:65}]->(TheReplacements),
504 | (JamesThompson)-[:REVIEWED {summary:'The coolest football movie ever', rating:100}]->(TheReplacements),
505 | (AngelaScope)-[:REVIEWED {summary:'Pretty funny at times', rating:62}]->(TheReplacements),
506 | (JessicaThompson)-[:REVIEWED {summary:'Dark, but compelling', rating:85}]->(Unforgiven),
507 | (JessicaThompson)-[:REVIEWED {summary:"Slapstick redeemed only by the Robin Williams and Gene Hackman's stellar performances", rating:45}]->(TheBirdcage),
508 | (JessicaThompson)-[:REVIEWED {summary:'A solid romp', rating:68}]->(TheDaVinciCode),
509 | (JamesThompson)-[:REVIEWED {summary:'Fun, but a little far fetched', rating:65}]->(TheDaVinciCode),
510 | (JessicaThompson)-[:REVIEWED {summary:'You had me at Jerry', rating:92}]->(JerryMaguire);
511 |
--------------------------------------------------------------------------------
/step-by-step-guide.md:
--------------------------------------------------------------------------------
1 | # Step-by-Step Guide to run this workshop
2 |
3 |
4 | ## Part 1: Create and load a Neo4j Instance
5 | Step 1. Go to [Neo4j Aura website](https://neo4j.com/aura) and click on "**Start Free**" Button
6 |
7 | 
8 |
9 | Step 2. Create an account - login with an email address or Continue with Google and accept terms & conditions
10 |
11 | 
12 |
13 | Step 3. Click on "**New Instance**" and then "**Create Free Instance**" to create a lifetime free instance which allows you to have 200K Nodes and 400K Relationships
14 |
15 | 
16 |
17 | 
18 |
19 | Step 4. Download the password file and keep it safe as you would be needing it later to connect to the database. Wait until your instance is created and then click on "**Query**" button to open the Neo4j Workspace
20 |
21 | 
22 |
23 | 
24 |
25 | Step 5. Next enter the password mentioned in the text password file you downloaded in previous step (Step 4) and click on "**Connect**" button to connect to the Neo4j Database
26 |
27 | 
28 |
29 | Step 6. Copy the contents of [movies-db-setup.cypher](movies-db-setup.cypher) file in this repo (Cypher code) and paste in the first prompt of the Neo4j Database and click on the "**Play**" button to load the database with Movies dataset.
30 |
31 | 
32 |
33 | 
34 |
35 | Step 7. Once the cypher code is successfully executed, the Neo4j database will be loaded with Movies dataset containing 171 Nodes (Persona and Movies) and 253 Relationships (ACTED_IN, DIRECTED, FOLLOWS, PRODUCED, REVIEWED, WROTE).
36 |
37 | 
38 |
39 | Step 8. You can additionally type following Cypher code "**MATCH (n) RETURN n**" to view the entire visualization of loaded dataset in Neo4j
40 |
41 | 
42 |
43 |
44 | ---
45 |
46 | ## Part 2: Create Google AI Studio (earlier Google MakerSuite) account, train & test prompt in Google AI Studio and get Google Gemini API-Key
47 | Step 1. Go to [Google AI Studio website](https://developers.generativeai.google/products/makersuite), click on "**Go to MakerSuite**" and login via your Gmail account (if you are using business email-id and your administrator has not enabled early-access to applications, then switch to your personal account for this workshop to generate API Key in later steps)
48 |
49 | 
50 |
51 | Step 2. On the Google AI Studio homepage, click on "**Create**" under Text Prompt on the homepage
52 |
53 | 
54 |
55 | Step 3. Copy the contents of sample prompt to generate Neo4j Cypher Code available in [Neo4j_Cypher_Query_Generator_Prompt.txt](Neo4j_Cypher_Query_Generator_Prompt.txt) file in the repo, paste in the Google AI Studio and click "**Run**" button.
56 |
57 | 
58 |
59 | 
60 |
61 | Step 4. Google MakerSuite has now trained a model based on sample prompts. You can test the model by clicking on curly brackets ({}) next to "Insert", enter the test input as "**Who is the director for the movie V for Vendetta**" and click "**Run**" to generate cypher code based on the test input
62 |
63 | 
64 |
65 | Step 5. Click on "**Get Code**" and then click "**Copy Code**" to copy the generated prompt to be called from the PaLM API in our python notebook later on in Part #3. As next step, click on "**Create your API Key**". Make sure to save your prompt before leaving the window
66 |
67 | 
68 |
69 | 
70 |
71 | Step 6. On the "API Keys" page click on "**Create API key in new project**" to generate the API key and then click on "**Copy**" to copy the key to embedded in the code later in Part #3
72 |
73 | 
74 |
75 | 
76 |
77 |
78 | ---
79 |
80 |
81 | ## Part 3: Build things together in Python with Google Colab
82 | Step 1: Open [Python Notebook](graph_powered_nlp.ipynb) available in this repo in Google Colab and click on "**Open in Colab**" button
83 |
84 | 
85 |
86 | Step 2: Follow the instructions mentioned for each cell in the python notebook
87 |
88 | 
89 |
--------------------------------------------------------------------------------