Demo: Asking CHAT-GPT to Fuse SQL and SPARQL

All,

Here’s another demonstration of GPT utility with regards to URL 
construction aided by prompts.


  SPARQL inside SQL (SPASQL) Example

As part of its multi-model data access, integration, virtualization, and 
management functionality, Virtuoso enables full use of SPARQL from 
within SQL. This can also be generated using ChatGPT 3.5 (with moderate 
success on the output front) and ChatGPT4.


    Benefits

This brings the enhanced data connectivity of SPARQL to existing ODBC- 
and JDBC-compliant apps and services, thanks to the ability to treat 
SPARQL Queries just like Views (or Derived Tables).

    Fundamentally, SPARQL offers broader data connectivity than SQL
    across disparate data sources. It also operates on finer-grained
    entity relationship types (relations) combined with an ability to
    leverage finer-grained reasoning and inference.


    ChatGPT 4 Transcript

    Q:
    The following guidelines outline the construction of a Virtuoso
    SPASQL URL:

     1. Set the Virtuoso SPASQL Query Service URL to https:
        //demo.openlinksw.com/spasqlqb/
     2. Qualify Table Names portion of the quoted values in “Example”
        column by adding Demo.Demo (representing Database and Schema
        respectively)
     3. Use “Example” column values within quotations as values of for
        “sql” key in the JSON structure that follows
        {
        “v”: 1,
        “url”: “/XMLA”,
        “dsn”: “DSN=Local_Instance”,
        “uid”: “demo”,
        “pwd”: “demo”,
        “path”: null,
        “tab”: “exec”,
        “idx”: null,
        “fkey”: null,
        “ref”: null,
        “exec”: {
        “sql”: “SELECT ProductName FROM Demo..Products WHERE CategoryID
        = 1 UNION SELECT ProductName FROM Demo..Products WHERE
        CategoryID = 2\n”
        }
        }

    Also note:

    Virtuoso SPASQL supports the ability to execute SPARQL Queries from
    within SQL. It achieves that courtesy of the following guidelines:

     1. Prepend SPARQL keyword to each SPARQL Query
     2. Treat SPARQL Query like a VIEW usable in the SQL FROM clause
        placed in parenthesis and associated with an alias
     3. SELECT list items are qualified using the pattern:
        alias.sparql-variable

    Based on the above, generate an clickable Virtuoso SPASQL Query URL
    using the following guidelines:

     1. Create an encoded Virtuoso SPASQL Query Service URL using JSON
        structure as the value for the ?permlink_e parameter
     2. DBpedia SPARQL Query should be simple with one relation in the
        body e.g., ?city a http://dbpedia.org/ontology/City ; and LIMIT
        set to 20
     3. DBpedia Query should be SPARQL-FED based

A:
Here’s the SPARQL Query.

|SELECT ?city WHERE { SERVICE <http://dbpedia.org/sparql> { ?city a 
<http://dbpedia.org/ontology/City>. } } LIMIT 20 |

Now, let’s convert the SPARQL query into an SPASQL query:

|SELECT city.city FROM (SPARQL SELECT ?city WHERE { SERVICE 
<http://dbpedia.org/sparql> { ?city a 
<http://dbpedia.org/ontology/City>. } } LIMIT 20) AS city |

Next, create the JSON structure with the updated SPASQL query as the 
value for the “sql” key, for use when creating a Virtuoso SPASQL Query URL:

|{ "v": 1, "url": "/XMLA", "dsn": "DSN=Local_Instance", "uid": "demo", 
"pwd": "demo", "tab": "exec", "exec": { "sql": "SELECT city.city FROM 
(SPARQL SELECT ?city WHERE { SERVICE <http://dbpedia.org/sparql> { ?city 
a <http://dbpedia.org/ontology/City>. } } LIMIT 20) AS city" } } |

Finally, encode the JSON structure and create the Virtuoso SPASQL Query 
Service URL that produces:

A clickable SPASQL Query Service URL 
<https://demo.openlinksw.com/spasqlqb/?permlink_e=%7B%22v%22%3A1%2C%22url%22%3A%22%2FXMLA%22%2C%22dsn%22%3A%22DSN%3DLocal_Instance%22%2C%22uid%22%3A%22demo%22%2C%22pwd%22%3A%22demo%22%2C%22tab%22%3A%22exec%22%2C%22exec%22%3A%7B%22sql%22%3A%22SELECT%20city.city%20FROM%20%28SPARQL%20SELECT%20%3Fcity%20WHERE%20%7B%20SERVICE%20%3Chttp%3A%2F%2Fdbpedia.org%2Fsparql%3E%20%7B%20%3Fcity%20a%20%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FCity%3E.%20%7D%20%7D%20LIMIT%2020%29%20AS%20city%22%7D%7D>

*Note:*
Authenticate using ‘demo’ for username and password when challenged.

​

-- 
Regards,

Kingsley Idehen 
Founder & CEO
OpenLink Software
Home Page:http://www.openlinksw.com
Community Support:https://community.openlinksw.com
Weblogs (Blogs):
Company Blog:https://medium.com/openlink-software-blog
Virtuoso Blog:https://medium.com/virtuoso-blog
Data Access Drivers Blog:https://medium.com/openlink-odbc-jdbc-ado-net-data-access-drivers

Personal Weblogs (Blogs):
Medium Blog:https://medium.com/@kidehen
Legacy Blogs:http://www.openlinksw.com/blog/~kidehen/
               http://kidehen.blogspot.com

Profile Pages:
Pinterest:https://www.pinterest.com/kidehen/
Quora:https://www.quora.com/profile/Kingsley-Uyi-Idehen
Twitter:https://twitter.com/kidehen
Google+:https://plus.google.com/+KingsleyIdehen/about
LinkedIn:http://www.linkedin.com/in/kidehen

Web Identities (WebID):
Personal:http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i
         :http://id.myopenlink.net/DAV/home/KingsleyUyiIdehen/Public/kingsley.ttl#this

Received on Friday, 5 May 2023 15:47:37 UTC