HowTo -- Querying Knowledge Graphs across the Web using ChatGPT & SPARQL

ChatGPT offers a powerful language processing service deployed on the World Wide Web (Web) as a utility. This service also provides an invaluable tool for unraveling some of the deeper, yet generally misunderstood and underutilized aspects of HTTP-based hyperlinks, which happen to form the foundation of the Web.

The combined prowess of ChatGPT and HTTP has the potential to profoundly influence the nature of computing for the better if we play our cards right regarding open standards adoption and usage, as well as the nature of ventures that attract professional investment.

In this post, I demonstrate declarative querying over the Web (actually, a Semantic Web) that leverages the power of hyperlinks as pointers and addresses, working symbiotically with the conversational user interface offered by ChatGPT. Essentially, querying the Web without any plugins!

As per usual, I provide a session transcript that leverages SPARQL (the Query Language, Protocol, and Serialization Format combo), Linked Data Principles, the publicly accessible Virtuoso instance behind our URIBurner service, and Knowledge Graphs (one local and the other from an Apple product page).

Transcript

Q: Create a clickable link for the following SPARQL query using https://linkeddata.uriburner.com/sparql as its endpoint.

DEFINE get:soft "soft"
SELECT (SAMPLE(?s) AS ?EntityID) (COUNT(*) AS ?count) (?o AS ?EntityTypeID)
FROM <urn:schemaorg:data:abox>
WHERE {
        ?s a ?o .
        FILTER (CONTAINS(STR(?o),'schema'))
}
GROUP BY ?o
ORDER BY DESC (?count)
LIMIT 50

A:
Here’s the clickable link for the SPARQL query with the specified endpoint:

Run SPARQL Query

Screenshot

Q: Given the template:

Provide a starting point for exploring knowledge graph <A>;SELECT (SAMPLE(?s) AS ?EntityID) (COUNT(*) AS ?count) (?o AS ?EntityTypeID) FROM <A> GROUP BY ?o ORDER BY DESC (?count);

Generate a clickable sparql query link for exploring urn:schemaorg:data:abox', using https://linkeddata.uriburner.com/sparql` as the query service endpoint.

A:
Using the provided template, here’s a clickable SPARQL query link for exploring urn:schemaorg:data:abox with the specified endpoint:

Explore Knowledge Graph urn:schemaorg:data:abox

Note:
This generates an incorrect SPARQL query due to syntactic errors in the template.

Screenshot

Q: Redo, using the following template:
Provide a starting point for exploring knowledge graph <A>;SELECT (SAMPLE(?s) AS ?EntityID) (COUNT(*) AS ?count) (?o AS ?EntityTypeID) FROM <A> WHERE { ?s a ?o . FILTER (CONTAINS(STR(?o),'schema'))} GROUP BY ?o ORDER BY DESC (?count) ;

A:
Using the revised template, here’s a clickable SPARQL query link for exploring urn:schemaorg:data:abox with the specified endpoint:

Explore Knowledge Graph urn:schemaorg:data:abox

Screenshot

Note:
I introduced a SPARQL query template associated with a natural language prompt, which will be in use for the remainder of the ChatGPT session.

Q: Redo, changing the &format parameter value to "text/x-html+tr"

A:
Explore Knowledge Graph urn:schemaorg:data:abox

Note:
The links in this particular page will resolve, unlike the prior variant due to the &format parameter value change – which will be revisited later in this post.

Q: Redo, limiting output to the top 10 entity types.

A:
Using the revised template with a limit of 10, here’s a clickable SPARQL query link for exploring the top 10 entity types in urn:schemaorg:data:abox with the specified endpoint:

Explore Top 10 Entity Types in Knowledge Graph urn:schemaorg:data:abox

Screenshot

Q: Redo, but focus specifically on the following entity types:

  1. schema:Product
  2. schem:Offer
  3. schema:Course
  4. schema:FAQPage
  5. schema:DataFeed

A:
Using the revised template and focusing specifically on the mentioned entity types, here’s a clickable SPARQL query link for exploring urn:schemaorg:data:abox with the specified endpoint:

Explore Specific Entity Types in Knowledge Graph urn:schemaorg:data:abox

Screenshot

Q: Redo, but using the Knowledge Graph denoted by https://www.apple.com/shop/buy-iphone/iphone-14-pro while also adding an &sponger:get=add parameter to the generated clickable link.

A:
To explore the Knowledge Graph denoted by https://www.apple.com/shop/buy-iphone/iphone-14-pro, you’ll need to replace the graph URI with the URL-encoded version of the provided URL. Additionally, add the &sponger:get=add parameter to the generated clickable link.

Here’s the clickable SPARQL query link with the specified endpoint and the &sponger:get=add parameter:

Explore Specific Entity Types in Knowledge Graph for iPhone 14 Pro

Screenshot

Note:
You may initially see an empty SPARQL Query Solution Page when clicking on the link above if this is the first time the page denoted by the hyperlink has been used as a query target.

Q: Redo, adding the following right at the start of the underlying SPARQL: DEFINE get:soft "soft", and removing the &sponger:get=add parameter.

A:
Here’s the clickable SPARQL query link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query and removing the &sponger:get=add parameter:

Explore Specific Entity Types in Knowledge Graph for iPhone 14 Pro

Note:
Adding the “DEFINE get:soft ‘soft’” pragma invokes Virtuoso’s native HTTP cache-invalidation scheme when resolving https://www.apple.com/shop/buy-iphone/iphone-14-pro in the following order:
1. HTTP GET operation to retrieve the document content at that web address
2. Discovery and extraction of metadata embedded in the document’s <head/> section
3. Transformation to RDF and persistence to a named graph (document identifier) within Virtuoso’s native RDF storage
4. Generation of a SPARQL query solution
5. Presentation of the SPARQL query solution using a preferred format (designated by a parameter in the hyperlink) or HTML, which is the default.

This data transformation functionality is protected by an attribute-based access control (ABAC) system configured to only grant usage privileges to authenticated users who are authenticated using a variety of authentication protocols. It is also worth noting that this demonstrates a business model entry point that is native to both the Internet and Web, courtesy of the combined effects of HTTPS and the notion of a Semantic Web.

Screenshot (depicting Multi-Protocol Authentication Challenge)

chatgpt-uriburner-sparql-7

Screenshot

Q: Redo, changing the &format parameter value to "text/x-html+tr"

A:
Here’s the clickable SPARQL query link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query, removing the &sponger:get=add parameter, and changing the &format parameter value to “text/x-html+tr”:

Explore Specific Entity Types in Knowledge Graph for iPhone 14 Pro

Note:
The "text/x-html+tr" hyperlink parameter value is used by Virtuoso as a signal to handle resolution using its native Faceted Search & Browsing engine, which enables powerful Knowledge Graph exploration and serendipitous discovery. Naturally, this interface also provides controls for invoking cache invalidation whenever empty pages or stale data is encountered.

Q: Redo, adding schema:Recipe to the entity type scope.

A:
Here’s the clickable SPARQL query link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query, removing the &sponger:get=add parameter, changing the &format parameter value to “text/x-html+tr”, and adding schema:Recipe to the entity type scope:

Explore Specific Entity Types in Knowledge Graph for iPhone 14 Pro

Note:
The SPARQL query solution page doesn’t include any schema:Recipe related data since there is no such data embedded in https://www.apple.com/shop/buy-iphone/iphone-14-pro.

Q: Redo, changing the Knowledge Graph target back to its prior setting

A:
Here’s the clickable SPARQL query link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query, removing the &sponger:get=add parameter, changing the &format parameter value to “text/x-html+tr”, adding schema:Recipe to the entity type scope, and changing the Knowledge Graph target back to urn:schemaorg:data:abox:

Explore Specific Entity Types in Knowledge Graph urn:schemaorg:data:abox

Note:
The SPARQL query solution page now includes schema:Recipe related information since the named graph targeted by the query is urn:schemaorg:data:abox rather than https://www.apple.com/shop/buy-iphone/iphone-14-pro.

Q: Generate a clickable SPARQL Query Editor link by replacing the &query parameter with &qtx

A:
Here’s the clickable SPARQL Query Editor link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query, removing the &sponger:get=add parameter, changing the &format parameter value to “text/x-html+tr”, adding schema:Recipe to the entity type scope, using the Knowledge Graph target urn:schemaorg:data:abox, and replacing the &query parameter with &qtx:

SPARQL Query Editor for Specific Entity Types in Knowledge Graph urn:schemaorg:data:abox

Note:

An incorrect hyperlink has been constructed by ChatGPT.

Screenshot

Q: Sure? I just want you to replace &query in the clickable SPARQL Query link with &qtxt

A:
Apologies for the confusion. Here’s the clickable SPARQL Query Editor link with the &qtxt parameter as requested:

SPARQL Query Editor for Specific Entity Types in Knowledge Graph urn:schemaorg:data:abox

Screenshot

Q: Repeat, but generating a clickable SPARQL query link that confines entity type to http://schema.org/Intangible/FinancialQuote

A:
Here’s the clickable SPARQL query link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query, confining the entity type to http://schema.org/Intangible/FinancialQuote, and using the Knowledge Graph target urn:schemaorg:data:abox:

Explore FinancialQuote Entity Type in Knowledge Graph urn:schemaorg:data:abox

Note:
Incorrect response from ChatGPT.

Screenshot

Q: Yes, but I wanted a clickable SPARQL Query Solution link rather than a Query Editor link.

A:
Apologies for the confusion. Here’s the clickable SPARQL query solution link with the specified endpoint, incorporating the “DEFINE get:soft ‘soft’” statement at the beginning of the query, confining the entity type to http://schema.org/Intangible/FinancialQuote, and using the Knowledge Graph target urn:schemaorg:data:abox:

Explore FinancialQuote Entity Type in Knowledge Graph urn:schemaorg:data:abox

Screenshot

Screenshot (Selected Entity Description)

Screenshot (Entity Type Instances via Inverse Links)

Related