Building knowledge map - Preliminary Study

The content of this article comes from medium article

A Knowledge Graph understanding and implementation tutorial for beginners[1]


What is knowledge map?

The content of knowledge map usually exists in the form of triple, subject predicate object (SPO).

Here's a chestnut:

Leonard Nimoy was an actor who played the character Spock in the science-fiction movie Star Trek

The above sentences can be extracted into the following triples:

In the form of knowledge map, it can be expressed as follows:

The graph composed of nodes and relationships above is a simple knowledge map.

How to build a simple knowledge map?

It can be divided into the following two steps:

  • Knowledge extraction
    • Information extraction, getting triples
    • Entity recognition, entity linking, entity disambiguation, entity resolution
  • Figure construction
    • storage
    • query

Knowledge extraction step is the key to construct knowledge map, triples can be obtained by dependency analysis.

Building a simple knowledge map

Only code execution process and results are shown here. For complete code, please refer to github.

1. Triple extraction

With spacy

inputText = 'Startup companies create jobs and innovation. Bill Gates supports entrepreneurship.'

# Step 1: Knowledge Extraction. Output: SOP triples
knowledgeExtractionObj = KnowledgeExtraction()
sop_list = knowledgeExtractionObj.retrieveKnowledge(inputText)
#list_sop = sop_list.as_doc()
sop_list_strings = []
for sop in sop_list:
    temp = []



2. Entity link

# Step 2: Entity recognition and linking. This step needs to be linked.
entityRecognitionLinkingObj = EntityRecognitionLinking()
entityRelJson = entityRecognitionLinkingObj.entityRecogLink(inputText)

entityLinkTriples = []
for sop in sop_list_strings:
    tempTriple = ['', '', '']
    for resource in entityRelJson['Resources']:
        if resource['@surfaceForm'] == sop[0]:
            tempTriple[0] = resource['@URI']
        if resource['@surfaceForm'] == sop[1]:
            tempTriple[1] = resource['@URI']
        if resource['@surfaceForm'] == sop[2]:
            tempTriple[2] = resource['@URI']


3. Figure construction

Using neo4j

# Step 3: Knowledge Graph creation.
graphPopulationObj = GraphPopulation()
graphPopulationObj = graphPopulationObj.popGraph(
    sop_list_strings, entityLinkTriples)

The final figure is as follows:

Possible problems

  • Q1
AuthError: The client is unauthorized due to authentication failure.

terms of settlement:

Ensure that the passwords are consistent with the settings when configuring the graph database (as shown in the following configuration, user: neo4j, password: neo4j)

config.DATABASE_URL = 'bolt://neo4j:neo4j@localhost:7687'#default
  • Q2
ServiceUnavailable: Failed to establish connection to (' , 7687) (reason [winerror 10061] could not connect because the target computer actively refused. )

terms of settlement:

Make sure that neo4j is open before executing the diagram creation code

If you have any questions, please leave a message and communicate with us





Tags: github Database

Posted on Tue, 19 May 2020 04:58:27 -0700 by keyurjbhatt