In Susper knowledge graph,we were unable to get results for multi word query from Wikipedia API and also we were unable to decide how much information should be shown in knowledge graph which was retrieved from Wikipedia API.For example for a query donald trump we do not get information (https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=donald%20trump) . Also for searching for any query like india (https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=india) we get a lot of information. Earlier we used Angular slice pipe to display only 600 characters in knowledge graph (Infobox) but almost for all queries the sentences were terminated before it was completed. In this blog, I will describe how we solved both problems in knowledge graph.
Getting results for multi word query from Wikipedia API:
On searching a lot we found that the results were present on Wikipedia for multi word queries but these queries must have its starting letters as capital letters. For example we do not get results for queries such as donald trump
but when we make a query for Donald Trump
Like this we now get results for almost all queries.
Limiting information in Knowledge Graph without terminating the sentences:
To solve this issue, we decided to show only four lines of data retrieved from Wikipedia API
For this we have implemented a getPosition function which will take three parameters a string, a substring and a index. Here string is the whole string from which the function will return the index of index position substring.
Using this we limited results to 4 lines without terminating each line in middle.
1.W3Schools Regular Expression: https://www.w3schools.com/jsref/jsref_obj_regexp.asp
3.Wikipedia API: https://www.mediawiki.org/wiki/API:Main_page