Skip to content

carlosfmorenog/rgu_phd_coding_task_kg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Knowledeg Grapth Technical Interview question

Task 1 (Knowledge extraction from text)

a) First of all, I created a function to import the content of the senteces.txt file into memory or my notebook.
image
This functon reads the content in the file specified and returns it.

b) Also, A function was created to extract all the entities in pasages.
image
This function loops through each sentence and then extracts the entities and also calls the extract relations fuction to extract the relations in each sentence and return them accordingly. The entities are paired together but the relatons are seperated.

I also created a fuction to extract all relationships from the sentences.This function works be first looking for the ROOT dependency. If the sentence has a ROOT dependency, it will go on to check if the ROOT is followed by an dobj. it will check till all the conditions in the specified rule are met. But if the matcher does not find the root dependency, it will go on to check whether the next item in the rule is available until all the conditions are checked. The image below shows the code snippet of the extract relationship function.

image

c) I also created a function that takes the extrated entities and relationships as its parameters and then converts them into a datafram of three columns ['source','target','edge']. The source stores the subject and the target stores all the objects while the edge stores all the edges.
image
This method first extracts the entities and relations into a dictionary and the used pandas.Dataframe to convert the generated dictionary in to a dataframe. The image below shows how the dataframe looks like after it was generated.
image


Task 2(Creation and visualisation of knowledge graph)

a) I made use of the NetworkX and matplotlib libray in generating the Knowlegde Grapth. The NetworkX library was used to draw and configure the Knowlegde graph. It was used to load the dataframe and then converted into the graph. matplotlib was then used to visualize the graph. The image below gives a snippet of the code used to perform this action

image

The image below shows how the Knowledge graph looked like after it was generated.

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 100.0%