Chapter 8. Querying Structured Data in a Natural Way

In the previous chapter, we learned how we can use the current context to extend our knowledge on a certain topic. Throughout this chapter, we will continue discussing about the knowledge APIs. More specifically, we will learn how to explore relationships between academic papers and journals. We will see how we can interpret natural language queries, and retrieve query expressions. Using these expressions, we will learn how to find academic entities. We will then focus more on how to set up this kind of service on your own. At the end of this chapter, we will look at QnA Maker to see how we can create FAQ services from existing content.

This chapter will cover the following topics:

  • Interpreting natural-language user queries using Project Academic Knowledge
  • Assisting the user with queries using autocomplete features
  • Using autocomplete queries to retrieve academic entities
  • Calculating the distribution of academic entities from queries
  • Hosting the Project Knowledge Exploration Service with your own schema
  • Creating an FAQ service from existing content using QnA Maker

Tapping into academic content using the academic API

Microsoft Academic Graph (MAG) is a knowledge base for web-scale, heterogeneous entity graphs. Entities model scholarly activities, and contain information such as the field of study, author(s), institution, and more.

Data contained in MAG is indexed from the Bing web index. As this is continuously indexed, the data is always up to date.

Using the Project Academic Knowledge API, we can tap into this knowledge base. This API allows us to combine search suggestions, research paper graph search results, and histogram distributions. The API enables a knowledge-driven and interactive dialog.

When a user searches for research papers, the API can provide query completion. It may suggest queries based on the input. With a complete query, we can evaluate a query expression. This will retrieve a set of matching paper entities from the knowledge base.

Setting up an example project

To test Project Academic Knowledge, we will first want to create a new example project. We will create this from the MVVM template created in Chapter 1, Getting Started with Microsoft Cognitive Services.

Project Academic Knowledge does not have any client packages available. This means that we need to call the API ourselves. Copy the WebRequest.cs file from the Model folder in the smart house application and paste it into the Model folder of the newly created project. Make sure that you correct the namespace.

To be able to compile this, we will need to add references to System.Web and System.Runtime.Serializable. We will also be working with JSON, so go ahead and add the Newtonsoft.Json package through the NuGet package manager.

As this will be the only API tested in this sample project, we can add UI elements in the MainView.xaml file. Open this file now.

Our View should have a TextBox element for our input query. It should have a ComboBox element to list the suggested query expressions. We need three Button elements, one for Interpret, one for Evaluate, and one for Histogram, which are all functions we will be executing. Last but not least, we need a TextBox element to display our results.

In the MainViewModel.cs file, we will need to add corresponding properties. Add three string properties, one for the input query, one for the results, and one for the selected query expression. Add an ObservableCollection property of the string type for our available query expressions. We also need three ICommand properties, one for each of our buttons.

Add a private member for our WebRequest object. Make the constructor look like the following:

    public MainViewModel()
    {
        _webRequest = new WebRequest("https://api.labs.cognitive.microsoft.com/academic/v1.0/", 
        "API_KEY_HERE");

        InterpretCommand = new DelegateCommand(Interpret, CanInterpret);
        EvaluateCommand = new DelegateCommand(Evaluate, CanExecuteCommands);
        CalculateHistogramCommand = new DelegateCommand (CalculateHistogram,  
        CanExecuteCommands);
    }

Note

If you have not already done so, sign up for an API key at https://labs.cognitive.microsoft.com/en-us/project-academic-knowledge and click the Subscribe button.

The CanInterpret parameter should return true if we have entered any text into the query textbox. The CanExecuteCommands parameter should return true if we have selected a query expression. We will cover Interpret, Evaluate, and the CalculateHistogram parameters in the upcoming sections.

Make sure that the application compiles and runs before continuing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.233.205