├── CONTRIBUTING.md ├── DEBUGGING.md ├── DEVELOPING.md ├── LICENSE ├── MAINTAINERS.md ├── README.md ├── data ├── Archive.zip ├── config_classification.txt └── config_relations.txt ├── doc └── source │ └── images │ ├── architecture.png │ ├── example.png │ ├── graph.png │ ├── step1.png │ ├── step2.png │ └── streaming.png └── notebooks └── knowledge_graph.ipynb /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This is an open source project, and we appreciate your help! 4 | 5 | We use the GitHub issue tracker to discuss new features and non-trivial bugs. 6 | 7 | In addition to the issue tracker, [#journeys on 8 | Slack](https://dwopen.slack.com) is the best way to get into contact with the 9 | project's maintainers. 10 | 11 | To contribute code, documentation, or tests, please submit a pull request to 12 | the GitHub repository. Generally, we expect two maintainers to review your pull 13 | request before it is approved for merging. For more details, see the 14 | [MAINTAINERS](MAINTAINERS.md) page. 15 | -------------------------------------------------------------------------------- /DEBUGGING.md: -------------------------------------------------------------------------------- 1 | Troubleshooting 2 | =============== 3 | 4 | Jupyter Notebooks 5 | ----------------- 6 | 7 | * Make sure the pip install ran correctly. You might need to restart the 8 | kernel and run the cells from the top after the pip install runs the first 9 | time. 10 | * Many of the cells rely on variables that are set in earlier cells. Some of 11 | these are cleared in later cells. Start over at the top when troubleshooting. 12 | * Many of the cells rely on service credentials from IBM Cloud that are set in 13 | earlier cells. Make sure to add your service credentials correctly. 14 | 15 | Package not found errors 16 | ------------------------ 17 | 18 | You might encounter this nltk error, `package not found`. To avoid that please follow the steps given below: 19 | 20 | 1. run nltk.download() : 21 | 2. Type `d` and press enter 22 | 23 |  24 | 25 | 3. Type `all` and press enter 26 | 27 |  28 | 29 | If you encouter a streaming body object: 30 | 31 | Make sure the StreamingBody object variable in cell 2.2 is mentioned in the highlighted space. 32 | 33 |  34 | -------------------------------------------------------------------------------- /DEVELOPING.md: -------------------------------------------------------------------------------- 1 | Tips for Developers 2 | =================== 3 | 4 | The notebook is designed to be run top-down. Settings in early cells are used 5 | in later cells. Some variables are also cleared to free up memory. So, although 6 | you can often run single cell repeatedly while testing changes, you may want 7 | to start over from the top if anything seems to be missing. 8 | 9 | Setting credentials 10 | ------------------- 11 | Credentials need to be added to the notebook to access some IBM Cloud services. 12 | The credentials are set near the top of the notebook to make it 13 | more obvious that they need to be set and also to make it more obvious that 14 | you will be saving a notebook with credentials. You should not share your 15 | notebook with anyone that you would not share your credentials with 16 | unless you use the ``share`` feature with the ``Only text and output`` or 17 | ``All content excluding sensitive code cells`` option. 18 | 19 | The ```@hidden_cell``` magic is used to mark the credentials cells as 20 | "sensitive". If you do any rearranging of sensitive code, remember to identify 21 | sensitive cells with ``@hidden_cell``. 22 | 23 | Installing Python packages 24 | -------------------------- 25 | A notebook can use ```!pip install``` to install the Python packages 26 | from PyPI. You can follow this example if you decide to use additional Python 27 | packages in your notebook. Check the output to see that the install was 28 | successful. See the "Controlling output" section below for more information on 29 | how to suppress/show the output. You might want to use ``DEBUG = True`` until 30 | you've verified that the pip install was successful. 31 | 32 | > **Note**: After running a cell with pip install, you may need to restart 33 | the kernel and then run the cells again from the top. 34 | 35 | Importing libraries 36 | ------------------- 37 | Import and some setup of libraries is done near the top. This is another 38 | example of why cells need to run top-down. Keeping the imports near the top 39 | is a Python PEP8 style convention. Python does not require this convention, 40 | but Python developers are used to looking for imports at the top. 41 | 42 | Defining global variables and helper functions 43 | ---------------------------------------------- 44 | After the imports, a few global variables and helper functions are defined. 45 | These allow for code re-use. These cells need to run before other cells can 46 | use the functions and globals. These values do not change. You can change 47 | and run the later cells over and over without always restarting from the top. 48 | 49 | Controlling output 50 | ------------------ 51 | One of the great things about notebooks is that you can use them to document 52 | what you are doing, show your work, show the results, and document your 53 | conclusion -- all in one place. Sharing "your work" (the code) is a great 54 | feature, but to make the "only text and output" web page look nice and clean 55 | you can use the following tips. 56 | 57 | #### @hidden_cell magic 58 | 59 | The @hidden_cell magic is used to mark the credentials cells as "sensitive". 60 | If you do any rearranging of sensitive code, remember to identify sensitive 61 | cells with @hidden_cell. 62 | 63 | #### Ending with a semi-colon 64 | 65 | Statements in a notebook can end with a semi-colon. It looks like 66 | bad Python, but it is actually a trick to prevent these statements from 67 | showing their result in the output. 68 | 69 | #### if DEBUG 70 | 71 | A DEBUG boolean and 'if' statements can be used throughout the notebook 72 | wherever some print statements are handy during development and might be 73 | handy in the future, but are not something you want to share in the final 74 | output. 75 | 76 | #### %%capture captured_io 77 | 78 | "%%capture captured_io" magic can be used to capture the output when nothing 79 | else works. You can use that to hide the "!pip install" output and add a cell 80 | right after it that will print the captured output if DEBUG is True. 81 | -------------------------------------------------------------------------------- /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 [yyyy] [name of copyright owner] 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 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # Maintainers Guide 2 | 3 | This guide is intended for maintainers - anybody with commit access to one or 4 | more Code Pattern repositories. 5 | 6 | ## Methodology 7 | 8 | This repository does not have a traditional release management cycle, but 9 | should instead be maintained as a useful, working, and polished reference at 10 | all times. While all work can therefore be focused on the master branch, the 11 | quality of this branch should never be compromised. 12 | 13 | The remainder of this document details how to merge pull requests to the 14 | repositories. 15 | 16 | ## Merge approval 17 | 18 | The project maintainers use LGTM (Looks Good To Me) in comments on the pull 19 | request to indicate acceptance prior to merging. A change requires LGTMs from 20 | two project maintainers. If the code is written by a maintainer, the change 21 | only requires one additional LGTM. 22 | 23 | ## Reviewing Pull Requests 24 | 25 | We recommend reviewing pull requests directly within GitHub. This allows a 26 | public commentary on changes, providing transparency for all users. When 27 | providing feedback be civil, courteous, and kind. Disagreement is fine, so long 28 | as the discourse is carried out politely. If we see a record of uncivil or 29 | abusive comments, we will revoke your commit privileges and invite you to leave 30 | the project. 31 | 32 | During your review, consider the following points: 33 | 34 | ### Does the change have positive impact? 35 | 36 | Some proposed changes may not represent a positive impact to the project. Ask 37 | whether or not the change will make understanding the code easier, or if it 38 | could simply be a personal preference on the part of the author (see 39 | [bikeshedding](https://en.wiktionary.org/wiki/bikeshedding)). 40 | 41 | Pull requests that do not have a clear positive impact should be closed without 42 | merging. 43 | 44 | ### Do the changes make sense? 45 | 46 | If you do not understand what the changes are or what they accomplish, ask the 47 | author for clarification. Ask the author to add comments and/or clarify test 48 | case names to make the intentions clear. 49 | 50 | At times, such clarification will reveal that the author may not be using the 51 | code correctly, or is unaware of features that accommodate their needs. If you 52 | feel this is the case, work up a code sample that would address the pull 53 | request for them, and feel free to close the pull request once they confirm. 54 | 55 | ### Does the change introduce a new feature? 56 | 57 | For any given pull request, ask yourself "is this a new feature?" If so, does 58 | the pull request (or associated issue) contain narrative indicating the need 59 | for the feature? If not, ask them to provide that information. 60 | 61 | Are new unit tests in place that test all new behaviors introduced? If not, do 62 | not merge the feature until they are! Is documentation in place for the new 63 | feature? (See the documentation guidelines). If not do not merge the feature 64 | until it is! Is the feature necessary for general use cases? Try and keep the 65 | scope of any given component narrow. If a proposed feature does not fit that 66 | scope, recommend to the user that they maintain the feature on their own, and 67 | close the request. You may also recommend that they see if the feature gains 68 | traction among other users, and suggest they re-submit when they can show such 69 | support. 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Build a knowledge base with domain specific documents 2 | 3 | In any business, word documents are a common occurence. They contain information in the form of raw text, tables and images. All of them contain important facts. The data used in this code pattern comes from two Wikipedia articles. The first is taken from the Wikipedia page of oncologist [Suresh H. Advani](https://en.wikipedia.org/wiki/Suresh_H._Advani) the second is from the Wikipedia page about [Oncology](https://en.wikipedia.org/wiki/Oncology). These files are zipped up as [archive.zip](data/archive.zip). 4 | 5 | In the figure below, there is a textual information about an oncologist Suresh H. Advani present in a word document. The table consists of the awards that he has been awarded by various organisations. 6 | 7 |  8 | 9 | In this Code pattern, we address the problem of extracting knowledge out of **text and tables** in word documents. A knowledge graph is built from the knowledge extracted making the knowledge queryable. 10 | 11 | Some of the challenges in extracting knowledge from word documents are: 12 | 13 | 1. The Natural Language Processing (NLP) tools cannot access the text inside word documents. The word documents need to be converted to plain text files. 14 | 1. There are business and domain experts who understand the keywords and entities that are present in the documents. But training the NLP tool to extract domain specific keywords and entities is a big effort. Also, it is impractical in many scenarios to find sufficient number of documents to train the NLP tool to process the text. 15 | 16 | This pattern uses the below methodology to overcome the challenges: 17 | 18 | * The [`python package mammoth`](https://pypi.org/project/mammoth/) library is used to convert `.docx` files to html (semi-structured format). 19 | * Watson Natural Language Understanding (Watson NLU) is used to extract the common entities. 20 | * A rules based approach that is explained in the code pattern [Extend Watson text Classification](https://developer.ibm.com/code/patterns/extend-watson-text-classification/) is used to augment the output from Watson NLU. The rules based approach does not require training documents or training effort. A configuration file is taken as input by the algorithm. This file needs to be configured by the domain expert. 21 | * Watson NLU is used to extract the relations between entities. 22 | * A rules based approach that is explained in the code pattern [Watson Document Correlation](https://developer.ibm.com/code/patterns/watson-document-correlation/) is used to augment the output from Watson NLU. A configuration file is taken as input by the algorithm. This file needs to be configured by the domain expert. 23 | 24 | The best of both worlds - training and rules based approach is used to extract knowledge out of documents. 25 | 26 | In this Pattern we will demonstrate: 27 | 28 | * Extracting the information from the documents- free-floating text and Table text. 29 | * [Cleaning the data](https://developer.ibm.com/code/patterns/extend-watson-text-classification/) pattern to extract entities from documents 30 | * Use [Watson Document Correlation](https://developer.ibm.com/codetterns/watson-document-correlation/) pattern to extract relationships between entities 31 | * Build a knowledge base(graph) from it. 32 | 33 | What makes this Code Pattern valuable: 34 | 35 | * The ability to process the tables in docx files along with free-floating text. 36 | * And also the strategy on combining the results of the real-time analysis by Watson NLU and the results from the rules defined by a Subject matter expert or Domain expert. 37 | 38 | This Code Pattern is intended to help Developers, Data Scientists to give structure to the unstructured data. This can be used to shape their analysis significantly and use the data for further processing to get better Insights. 39 | 40 | ## Flow 41 | 42 |  43 | 44 | 1. The unstructured text data from the docx files (html tables and free floating text) that need to be analyzed and correlated is extracted from the documents using python code. 45 | 1. Use Extend Watson text Classification text is classified using Watson NLU and also tagged using the code pattern - [Extend Watson text classification](https://github.com/IBM/watson-document-classifier) 46 | 1. The text is correlated with other text using the code pattern - [Correlate documents](https://github.com/IBM/watson-document-co-relation) 47 | 1. The results are filtered using python code. 48 | 1. The knowledge graph is constructed. 49 | 50 | ## Video 51 | 52 | [](https://youtu.be/lC2-h2ac_Jg) 53 | 54 | ## Included components 55 | 56 | * [IBM Watson Studio](https://www.ibm.com/cloud/watson-studio): Analyze data using RStudio, Jupyter, and Python in a configured, collaborative environment that includes IBM value-adds, such as managed Spark. 57 | * [Watson Natural Language Understanding](https://cloud.ibm.com/catalog/services/natural-language-understanding): A IBM Cloud service that can analyze text to extract meta-data from content such as concepts, entities, keywords, categories, sentiment, emotion, relations, semantic roles, using natural language understanding. 58 | * [Jupyter Notebooks](http://jupyter.org/): An open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. 59 | 60 | ## Steps 61 | 62 | Follow these steps to setup and run this code pattern. The steps are described in detail below. 63 | 64 | 1. [Create IBM Cloud services](#1-create-ibm-cloud-services) 65 | 1. [Run using a Jupyter notebook in the IBM Watson Studio](#2-run-using-a-jupyter-notebook-in-the-ibm-watson-studio) 66 | 1. [Analyze the results](#3-analyze-the-results) 67 | 68 | ### 1. Create IBM Cloud services 69 | 70 | Create the following IBM Cloud service and name it wdc-NLU-service: 71 | 72 | * [**Watson Natural Language Understanding**](https://cloud.ibm.com/catalog/services/natural-language-understanding) 73 | 74 | ### 2. Run using a Jupyter notebook in the IBM Watson Studio 75 | 76 | 1. [Create a new Watson Studio project](#21-create-a-new-watson-studio-project) 77 | 2. [Create the notebook](#22-create-the-notebook) 78 | 3. [Run the notebook](#23-run-the-notebook) 79 | 4. [Upload data](#24-upload-data) 80 | 5. [Save and Share](#25-save-and-share) 81 | 82 | #### 2.1 Create a new Watson Studio project 83 | 84 | * Log into IBM's [Watson Studio](https://dataplatform.cloud.ibm.com). Once in, you'll land on the dashboard. 85 | 86 | * Create a new project by clicking `+ New project` and choosing `Data Science`: 87 | 88 |  89 | 90 | * Enter a name for the project name and click `Create`. 91 | 92 | * **NOTE**: By creating a project in Watson Studio a free tier `Object Storage` service and `Watson Machine Learning` service will be created in your IBM Cloud account. Select the `Free` storage type to avoid fees. 93 | 94 |  95 | 96 | #### 2.2 Create the notebook 97 | 98 | * From the new project `Overview` panel, click `+ Add to project` on the top right and choose the `Notebook` asset type. 99 | 100 |  101 | 102 | * Fill in the following information: 103 | 104 | * Select the `From URL` tab. [1] 105 | * Enter a `Name` for the notebook and optionally a description. [2] 106 | * Under `Notebook URL` provide the following url: [https://raw.githubusercontent.com/IBM/build-knowledge-base-with-domain-specific-documents/master/notebooks/knowledge_graph.ipynb](https://raw.githubusercontent.com/IBM/build-knowledge-base-with-domain-specific-documents/master/notebooks/knowledge_graph.ipynb) [3] 107 | * For `Runtime` select the `Python 3.5` option. [4] 108 | 109 |  110 | 111 | * Click the `Create` button. 112 | 113 | * **TIP:** Once successfully imported, the notebook should appear in the `Notebooks` section of the `Assets` tab. 114 | 115 | #### 2.3 Run the notebook 116 | 117 | * Use the menu pull-down `Cell > Run All` to run the notebook, or run the cells one at a time top-down using the play button. 118 | 119 | * As the cells run, watch the output for results or errors. A running cell will have a label like `In [*]`. A completed cell will have a run sequence number instead of the asterisk. 120 | 121 | #### 2.4 Upload data 122 | 123 | #### Upload the data and configuration to the notebook 124 | 125 | * This notebook uses the data in [datqa](data). We need to load these assets to our project. 126 | 127 | * From the new project `Overview` panel, click `+ Add to project` on the top right and choose the `Data` asset type. 128 | 129 |  130 | 131 | * A panel on the right of the screen will appear to assit you in uploading data. Follow the numbered steps in the image below. 132 | 133 | * Ensure you're on the `Load` tab. [1] 134 | * Click on the `browse` option. From your machine, browse to the location of the [`archive.zip`](data/archive.zip), [`config_relations.txt`](data/config_relations.txt), and [`config_classification.txt`](data/config_classification.txt) files in this repository, and upload it. [not numbered] 135 | * Once uploaded, go to the `Files` tab. [2] 136 | * Ensure the files appear. [3] 137 | 138 |  139 | 140 | > **NOTE**: It is possible to use your own data and configuration files. If you use a configuration file from your computer, make sure to conform to the JSON structure given in `data/config_classification.txt`. 141 | 142 | ### 3. Analyze the results 143 | 144 | As we step through the notebook we first the following: 145 | 146 | * The configuration files (`config_classification.txt` and `config_relations.txt`) are loaded. 147 | * The unstructured information is extracted using python package mammoth. Mammoth converts the `.docx` files to `.html` from where text in the tables is also analysed along with free floating text. 148 | * The results from Watson Natural Language Understanding are analyzed and augmented using the configuration files. 149 | * The entities are augmented using the `config_classification.txt` and the relationships are augmented using `config_relations.txt`. 150 | * The results are then filtered and formatted to pick up the relevant relations and discard the ones which are not relevant. 151 | * The filtered relaionships are sent to draw graph function in the notebook, which will construct the knowledge graph. 152 | 153 |  154 | 155 | ## Learn more 156 | 157 | * **Data Analytics Code Patterns**: Enjoyed this Code Pattern? Check out our other [Data Analytics Code Patterns](https://developer.ibm.com/code/technologies/data-science/) 158 | * **AI and Data Code Pattern Playlist**: Bookmark our [playlist](https://www.youtube.com/playlist?list=PLzUbsvIyrNfknNewObx5N7uGZ5FKH0Fde) with all of our Code Pattern videos 159 | * **Watson Studio**: Master the art of data science with IBM's [Watson Studio](https://dataplatform.ibm.com/) 160 | 161 | ## Troubleshooting 162 | 163 | [See DEBUGGING.md.](DEBUGGING.md) 164 | 165 | ## License 166 | 167 | This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the [Developer Certificate of Origin, Version 1.1](https://developercertificate.org/) and the [Apache License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt). 168 | 169 | [Apache License FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN) 170 | -------------------------------------------------------------------------------- /data/Archive.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/build-knowledge-base-with-domain-specific-documents/ea4c5d546381ffe61e2761b6603b9540b7890df3/data/Archive.zip -------------------------------------------------------------------------------- /data/config_classification.txt: -------------------------------------------------------------------------------- 1 | { 2 | "configuration": { 3 | "classification": { 4 | "stages": [ 5 | { 6 | "name": "Base Tagging", 7 | "steps": [ 8 | { 9 | "type": "keywords", 10 | "keywords": [ 11 | { 12 | "tag": "Passion", 13 | "text": "Science" 14 | }, 15 | { 16 | "tag": "Subjects", 17 | "text": "cosmology" 18 | } 19 | ] 20 | }, 21 | { 22 | "type": "d_regex", 23 | "d_regex": [ 24 | { 25 | "tag": "Date", 26 | "pattern": "(\\d+/\\d+/\\d+)" 27 | } 28 | ] 29 | }, 30 | { 31 | "type": "d_regex", 32 | "d_regex": [ 33 | { 34 | "tag": "Email", 35 | "pattern": "\\b[\\w.-]+?@\\w+?\\.\\w+?\\b" 36 | } 37 | ] 38 | }, 39 | { 40 | "type": "d_regex", 41 | "d_regex": [ 42 | { 43 | "tag": "PhoneNumber", 44 | "pattern": "[0-9]{10}" 45 | } 46 | ] 47 | }, 48 | { 49 | "type": "chunking", 50 | "chunk": [ 51 | { 52 | "tag": "NP", 53 | "pattern": "NP:{