HowTo — Using CHAT-GPT to generate a Knowledge Graph from a Mermaid Entity Relationship Model

Kingsley Uyi Idehen
OpenLink Software Blog
14 min readApr 5, 2023
DALL-E generated image depicting: The Global Mind Meld Enabled by a Semantic Web

This post showcases the use of Mermaid’s visual notation for presenting an Entity Relationship Model Diagram that’s ultimately used as the basis for generating a Knowledge Graph deployed using Linked Data Principles that’s immediately viewable and browsable from any web browser that includes the OpenLink Structured Data Sniffer Browser Extension.

Here are the steps for achieving the goal outlined above.

Create Entity Relationship Model using Mermaid’s Visual Notation.

Here’s a simple entity relationship model example covering the following classes: Customer, Delivery Address, Order, Order Item, Invoice, Product, and Product-Category.

CUSTOMER }|…|{ DELIVERY-ADDRESS : has
CUSTOMER ||–o{ ORDER : places
CUSTOMER ||–o{ INVOICE : “liable for”
DELIVERY-ADDRESS ||–o{ ORDER : receives
INVOICE ||–|{ ORDER : covers
ORDER ||–|{ ORDER-ITEM : includes
PRODUCT-CATEGORY ||–|{ PRODUCT : contains
PRODUCT ||–o{ ORDER-ITEM : “ordered in”

Model Visualization

Mermaid Entity Relationship Graph Visualization

CHAT-GPT Session Transcript

Q: Generate an ontology using RDF-Turtle for the text that follows, using the following guidelines:

  1. Denote subjects and objects using relative hash-based hyperlinks i.e., negating the use of example.com
  2. Output response to a code-block
  3. Place ## Turtle Start ## and ## Turtle End ## around the code within the code-block

CUSTOMER }|…|{ DELIVERY-ADDRESS : has
CUSTOMER ||–o{ ORDER : places
CUSTOMER ||–o{ INVOICE : “liable for”
DELIVERY-ADDRESS ||–o{ ORDER : receives
INVOICE ||–|{ ORDER : covers
ORDER ||–|{ ORDER-ITEM : includes
PRODUCT-CATEGORY ||–|{ PRODUCT : contains
PRODUCT ||–o{ ORDER-ITEM : “ordered in”

A:

@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Customer rdfs:subClassOf :Customer .
:DeliveryAddress rdfs:subClassOf :DeliveryAddress .
:Order rdfs:subClassOf :Order .
:Invoice rdfs:subClassOf :Invoice .
:OrderItem rdfs:subClassOf :OrderItem .
:ProductCategory rdfs:subClassOf :ProductCategory .
:Product rdfs:subClassOf :Product .
:has rdfs:domain :Customer ;
rdfs:range :DeliveryAddress .
:places rdfs:domain :Customer ;
rdfs:range :Order .
:liableFor rdfs:domain :Customer ;
rdfs:range :Invoice .
:receives rdfs:domain :DeliveryAddress ;
rdfs:range :Order .
:covers rdfs:domain :Invoice ;
rdfs:range :Order .
:includes rdfs:domain :Order ;
rdfs:range :OrderItem .
:contains rdfs:domain :ProductCategory ;
rdfs:range :Product .
:orderedIn rdfs:domain :Product ;
rdfs:range :OrderItem .

Q: Are the rdfs:subClassOf triples necessary?
A:
Apologies for the confusion. You are correct; the rdfs:subClassOf triples are not necessary in this case. They are used to define a class hierarchy, which is not needed for this specific ontology. Here’s the corrected Turtle syntax without the rdfs:subClassOf triples:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:has rdfs:domain :Customer ;
rdfs:range :DeliveryAddress .

:places rdfs:domain :Customer ;
rdfs:range :Order .

:liableFor rdfs:domain :Customer ;
rdfs:range :Invoice .

:receives rdfs:domain :DeliveryAddress ;
rdfs:range :Order .

:covers rdfs:domain :Invoice ;
rdfs:range :Order .

:includes rdfs:domain :Order ;
rdfs:range :OrderItem .

:contains rdfs:domain :ProductCategory ;
rdfs:range :Product .

:orderedIn rdfs:domain :Product ;
rdfs:range :OrderItem .
## Turtle End ##

Q: Can you generate 3 sample product class instances?
A:
Certainly! Here are three sample product class instances in Turtle syntax:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Product1 a :Product ;
rdfs:label "Laptop" ;
:price 1200 ;
:category "Electronics" .
:Product2 a :Product ;
rdfs:label "Mountain Bike" ;
:price 800 ;
:category "Sports Equipment" .
:Product3 a :Product ;
rdfs:label "Novel: The Catcher in the Rye" ;
:price 15 ;
:category "Books" .
## Turtle End ##

In this example, I have created three instances of the :Product class, each with a label, price, and category. You can customize the properties and values as needed for your specific use case.

Q: Can you generate 3 Customer instances?
A:
Certainly! Here are three sample customer instances in Turtle syntax:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Customer1 a :Customer ;
rdfs:label "Alice" ;
:email "alice@example.com" ;
:phone "555-123-4567" .

:Customer2 a :Customer ;
rdfs:label "Bob" ;
:email "bob@example.com" ;
:phone "555-987-6543" .

:Customer3 a :Customer ;
rdfs:label "Charlie" ;
:email "charlie@example.com" ;
:phone "555-246-8101" .
## Turtle End ##

In this example, I have created three instances of the :Customer class, each with a label, email, and phone number. You can customize the properties and values as needed for your specific use case.

Q: Can you generate product category instances for each of the sample products?
A:
Sure! Here are the :ProductCategory instances for each of the sample products:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:ElectronicsCategory a :ProductCategory ;
rdfs:label "Electronics" .

:SportsEquipmentCategory a :ProductCategory ;
rdfs:label "Sports Equipment" .

:BooksCategory a :ProductCategory ;
rdfs:label "Books" .

:Product1 a :Product ;
rdfs:label "Laptop" ;
:price 1200 ;
:category :ElectronicsCategory .

:Product2 a :Product ;
rdfs:label "Mountain Bike" ;
:price 800 ;
:category :SportsEquipmentCategory .

:Product3 a :Product ;
rdfs:label "Novel: The Catcher in the Rye" ;
:price 15 ;
:category :BooksCategory .
## Turtle End ##

In this example, I have created three instances of the :ProductCategory class and assigned them to the sample products using the :category property.

Q: Can you create a delivery address for each sample Customer?
A:
Certainly! Here’s the Turtle syntax with :DeliveryAddress instances for each sample customer:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Customer1 a :Customer ;
rdfs:label "Alice" ;
:email "alice@example.com" ;
:phone "555-123-4567" ;
:has :DeliveryAddress1 .

:Customer2 a :Customer ;
rdfs:label "Bob" ;
:email "bob@example.com" ;
:phone "555-987-6543" ;
:has :DeliveryAddress2 .

:Customer3 a :Customer ;
rdfs:label "Charlie" ;
:email "charlie@example.com" ;
:phone "555-246-8101" ;
:has :DeliveryAddress3 .

:DeliveryAddress1 a :DeliveryAddress ;
rdfs:label "Alice's Address" ;
:street "123 Main St" ;
:city "New York" ;
:state "NY" ;
:postalCode "10001" .

:DeliveryAddress2 a :DeliveryAddress ;
rdfs:label "Bob's Address" ;
:street "456 Oak St" ;
:city "Los Angeles" ;
:state "CA" ;
:postalCode "90001" .

:DeliveryAddress3 a :DeliveryAddress ;
rdfs:label "Charlie's Address" ;
:street "789 Pine St" ;
:city "Chicago" ;
:state "IL" ;
:postalCode "60601" .
## Turtle End ##

In this example, I have created three instances of the :DeliveryAddress class and assigned them to the sample customers using the :has property.

Q: Can you generate a sample product order for each sample customer?
A:
Sure! Here’s the Turtle syntax with :Order instances for each sample customer:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Customer1 a :Customer ;
rdfs:label "Alice" ;
:email "alice@example.com" ;
:phone "555-123-4567" ;
:has :DeliveryAddress1 ;
:places :Order1 .
:Customer2 a :Customer ;
rdfs:label "Bob" ;
:email "bob@example.com" ;
:phone "555-987-6543" ;
:has :DeliveryAddress2 ;
:places :Order2 .
:Customer3 a :Customer ;
rdfs:label "Charlie" ;
:email "charlie@example.com" ;
:phone "555-246-8101" ;
:has :DeliveryAddress3 ;
:places :Order3 .
:Order1 a :Order ;
rdfs:label "Order 1" ;
:includes :OrderItem1 ;
:receives :DeliveryAddress1 .
:Order2 a :Order ;
rdfs:label "Order 2" ;
:includes :OrderItem2 ;
:receives :DeliveryAddress2 .
:Order3 a :Order ;
rdfs:label "Order 3" ;
:includes :OrderItem3 ;
:receives :DeliveryAddress3 .
:OrderItem1 a :OrderItem ;
rdfs:label "Order Item 1" ;
:orderedIn :Product1 ;
:quantity 1 .
:OrderItem2 a :OrderItem ;
rdfs:label "Order Item 2" ;
:orderedIn :Product2 ;
:quantity 1 .
:OrderItem3 a :OrderItem ;
rdfs:label "Order Item 3" ;
:orderedIn :Product3 ;
:quantity 1 .
## Turtle End ##

In this example, I have created three instances of the :Order class and assigned them to the sample customers using the :places property. Each order includes one :OrderItem instance that corresponds to a sample product. The :receives property links the orders to the delivery addresses.

Q: Can you generate an invoice for each sample order?
A:
Certainly! Here’s the Turtle syntax with :Invoice instances for each sample order:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Customer1 a :Customer ;
rdfs:label "Alice" ;
:email "alice@example.com" ;
:phone "555-123-4567" ;
:has :DeliveryAddress1 ;
:places :Order1 ;
:liableFor :Invoice1 .
:Customer2 a :Customer ;
rdfs:label "Bob" ;
:email "bob@example.com" ;
:phone "555-987-6543" ;
:has :DeliveryAddress2 ;
:places :Order2 ;
:liableFor :Invoice2 .
:Customer3 a :Customer ;
rdfs:label "Charlie" ;
:email "charlie@example.com" ;
:phone "555-246-8101" ;
:has :DeliveryAddress3 ;
:places :Order3 ;
:liableFor :Invoice3 .
:Invoice1 a :Invoice ;
rdfs:label "Invoice 1" ;
:covers :Order1 ;
:totalAmount 1200 .
:Invoice2 a :Invoice ;
rdfs:label "Invoice 2" ;
:covers :Order2 ;
:totalAmount 800 .
:Invoice3 a :Invoice ;
rdfs:label "Invoice 3" ;
:covers :Order3 ;
:totalAmount 15 .
## Turtle End ##

In this example, I have created three instances of the :Invoice class and assigned them to the sample customers using the :liableFor property. Each invoice covers one of the sample orders, linked with the :covers property, and has a total amount based on the price of the products in the orders.

Q: Enhance the generated ontology by adding owl:equivalentProperty and owl:equivalentClass triples cross-referencing schema.org terms, where appropriate.
A:
Certainly! Here’s the Turtle syntax with owl:equivalentProperty and owl:equivalentClass triples cross-referencing relevant schema.org terms:

@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix schema: <http://schema.org/> .

:Customer a owl:Class ;
owl:equivalentClass schema:Person .
:DeliveryAddress a owl:Class ;
owl:equivalentClass schema:PostalAddress .
:Order a owl:Class ;
owl:equivalentClass schema:Order .
:Invoice a owl:Class ;
owl:equivalentClass schema:Invoice .
:Product a owl:Class ;
owl:equivalentClass schema:Product .
:ProductCategory a owl:Class ;
owl:equivalentClass schema:CategoryCode .
:OrderItem a owl:Class ;
owl:equivalentClass schema:OrderItem .
:has a owl:ObjectProperty ;
owl:equivalentProperty schema:address .
:places a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:liableFor a owl:ObjectProperty ;
owl:equivalentProperty schema:billingAddress .
:receives a owl:ObjectProperty ;
owl:equivalentProperty schema:deliveryAddress .
:covers a owl:ObjectProperty ;
owl:equivalentProperty schema:referencesOrder .
:includes a owl:ObjectProperty ;
owl:equivalentProperty schema:itemOffered .
:category a owl:ObjectProperty ;
owl:equivalentProperty schema:category .
:orderedIn a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:price a owl:DatatypeProperty ;
owl:equivalentProperty schema:price .
:email a owl:DatatypeProperty ;
owl:equivalentProperty schema:email .
:phone a owl:DatatypeProperty ;
owl:equivalentProperty schema:telephone .
:street a owl:DatatypeProperty ;
owl:equivalentProperty schema:streetAddress .
:city a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressLocality .
:state a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressRegion .
:postalCode a owl:DatatypeProperty ;
owl:equivalentProperty schema:postalCode .
:quantity a owl:DatatypeProperty ;
owl:equivalentProperty schema:orderQuantity .
:totalAmount a owl:DatatypeProperty ;
owl:equivalentProperty schema:totalPaymentDue .

In this example, I have added owl:equivalentClass and owl:equivalentProperty triples to map the terms from the original ontology to corresponding schema.org terms, where applicable. This allows for better interoperability between different data sources using schema.org vocabulary.

Q: Are you sure that a Customer Class is equivalent to schema:Person?
A:
You are correct; my previous response was too general by suggesting that the :Customer class is equivalent to schema:Person. In fact, schema:Person is a more general class, while :Customer is a specific type of person in the context of this ontology. A better choice would be to use rdfs:subClassOf to indicate that :Customer is a subclass of schema:Person. Here’s the corrected Turtle syntax:

@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix schema: <http://schema.org/> .

:Customer a owl:Class ;
rdfs:subClassOf schema:Person .
:DeliveryAddress a owl:Class ;
owl:equivalentClass schema:PostalAddress .
:Order a owl:Class ;
owl:equivalentClass schema:Order .
:Invoice a owl:Class ;
owl:equivalentClass schema:Invoice .
:Product a owl:Class ;
owl:equivalentClass schema:Product .
:ProductCategory a owl:Class ;
owl:equivalentClass schema:CategoryCode .
:OrderItem a owl:Class ;
owl:equivalentClass schema:OrderItem .
:has a owl:ObjectProperty ;
owl:equivalentProperty schema:address .
:places a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:liableFor a owl:ObjectProperty ;
owl:equivalentProperty schema:billingAddress .
:receives a owl:ObjectProperty ;
owl:equivalentProperty schema:deliveryAddress .
:covers a owl:ObjectProperty ;
owl:equivalentProperty schema:referencesOrder .
:includes a owl:ObjectProperty ;
owl:equivalentProperty schema:itemOffered .
:category a owl:ObjectProperty ;
owl:equivalentProperty schema:category .
:orderedIn a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:price a owl:DatatypeProperty ;
owl:equivalentProperty schema:price .
:email a owl:DatatypeProperty ;
owl:equivalentProperty schema:email .
:phone a owl:DatatypeProperty ;
owl:equivalentProperty schema:telephone .
:street a owl:DatatypeProperty ;
owl:equivalentProperty schema:streetAddress .
:city a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressLocality .
:state a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressRegion .
:postalCode a owl:DatatypeProperty ;
owl:equivalentProperty schema:postalCode .
:quantity a owl:DatatypeProperty ;
owl:equivalentProperty schema:orderQuantity .
:totalAmount a owl:DatatypeProperty ;
owl:equivalentProperty schema:totalPaymentDue .

This updated Turtle syntax now correctly represents the :Customer class as a subclass of schema:Person.

Q: If :Customer Class is a subclassOf schema:Person, how do we handle organizations who are the more typical targets of an invoice?
A:
You’re right. In many cases, invoices are issued to organizations rather than individual customers. To accommodate both individual customers and organizations, we can create separate subclasses for individuals and organizations under the :Customer class. Then, we can make the :Customer class a subclass of both schema:Person and schema:Organization. Here’s the updated Turtle syntax:

@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix schema: <http://schema.org/> .

:Customer a owl:Class ;
rdfs:subClassOf schema:Person, schema:Organization .
:IndividualCustomer a owl:Class ;
rdfs:subClassOf :Customer ;
rdfs:subClassOf schema:Person .
:OrganizationCustomer a owl:Class ;
rdfs:subClassOf :Customer ;
rdfs:subClassOf schema:

Q: Shouldn’t that be inverted?
A:
You are correct. My previous response was inaccurate. To better model this situation, we should create a :Customer class that is a superclass of both schema:Person and schema:Organization. Then, we can create separate subclasses for individuals and organizations under the :Customer class. Here’s the corrected Turtle syntax:

@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix schema: <http://schema.org/> .

:Customer a owl:Class .
:IndividualCustomer a owl:Class ;
rdfs:subClassOf :Customer, schema:Person .
:OrganizationCustomer a owl:Class ;
rdfs:subClassOf :Customer, schema:Organization .

This updated Turtle syntax now correctly represents the :Customer class as a superclass of both schema:Person and schema:Organization. The :IndividualCustomer class is a subclass of both :Customer and schema:Person, while the :OrganizationCustomer class is a subclass of both :Customer and schema:Organization.

Q: How about simply making schema:Organization the :Customer subclass since this ontology is business centric?
A:
Sure, that’s a valid approach if you want to focus on business-centric use cases where customers are primarily organizations. In this case, we can make :Customer a subclass of schema:Organization. Here’s the updated Turtle syntax:

@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix schema: <http://schema.org/> .

:Customer a owl:Class ;
rdfs:subClassOf schema:Organization .

Now, the :Customer class is a subclass of schema:Organization, which means customers in this ontology are primarily organizations.

Q: Okay, regenerate the entire ontology with these corrections.
A:
Here’s the complete ontology with the requested corrections, where :Customer is a subclass of schema:Organization:

## Turtle Start ##
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix schema: <http://schema.org/> .

:Customer a owl:Class ;
rdfs:subClassOf schema:Organization .
:DeliveryAddress a owl:Class ;
owl:equivalentClass schema:PostalAddress .
:Order a owl:Class ;
owl:equivalentClass schema:Order .
:Invoice a owl:Class ;
owl:equivalentClass schema:Invoice .
:Product a owl:Class ;
owl:equivalentClass schema:Product .
:ProductCategory a owl:Class ;
owl:equivalentClass schema:CategoryCode .
:OrderItem a owl:Class ;
owl:equivalentClass schema:OrderItem .
:has a owl:ObjectProperty ;
owl:equivalentProperty schema:address .
:places a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:liableFor a owl:ObjectProperty ;
owl:equivalentProperty schema:billingAddress .
:receives a owl:ObjectProperty ;
owl:equivalentProperty schema:deliveryAddress .
:covers a owl:ObjectProperty ;
owl:equivalentProperty schema:referencesOrder .
:includes a owl:ObjectProperty ;
owl:equivalentProperty schema:itemOffered .
:category a owl:ObjectProperty ;
owl:equivalentProperty schema:category .
:orderedIn a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:price a owl:DatatypeProperty ;
owl:equivalentProperty schema:price .
:email a owl:DatatypeProperty ;
owl:equivalentProperty schema:email .
:phone a owl:DatatypeProperty ;
owl:equivalentProperty schema:telephone .
:street a owl:DatatypeProperty ;
owl:equivalentProperty schema:streetAddress .
:city a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressLocality .
:state a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressRegion .
:postalCode a owl:DatatypeProperty ;
owl:equivalentProperty schema:postalCode .
:quantity a owl:DatatypeProperty ;
owl:equivalentProperty schema:orderQuantity .
:totalAmount a owl:DatatypeProperty ;
owl:equivalentProperty schema:totalPaymentDue .
## Turtle End ##

This ontology now has :Customer as a subclass of schema:Organization, making it more business-centric. The other classes, properties, and equivalent mappings to schema.org terms remain unchanged.

Knowledge Graph Visualization & Export Using Nanotation

At this juncture, courtesy of the ## Turtle Start ## and ## Turtle End ## comments placed around the RDF-Turtle statements generated by CHAT-GPT, simply invoke OSDS (by clicking on the “doggie” icon) to see a visualization of the graph represented in the text of this post.

Ontology Visualization using a Property Sheet Layout
Instance Data using a Property Sheet Layout

In addition, the data expressed in the graph can also be uploaded directly to an Knowledge Graph or DBMS platform that supports SPARQL INSERTs e.g., the live Virtuoso instance behind our URIBurner Service. You simply select the “Upload to SPARQL Endpoint” option from the download option drop-down associated with the download action (depicted by the cloud+download arrow).

Export to SPARQL Endpoint Feature for Data Upload from current document

Once the data is uploaded it lays the foundation for the next stage which focuses on applying SPARQL Queries to the data that leverage reasoning and inference.

Reasoning & Inference

At this juncture, there’s a working Entity Relationship Graph that’s been constructed using Linked Data principles whereby entities, entity types, and entity relationship types are denoted using hyperlinks and described using entity->attribute-value or subject->predicate->object triples. Fundamentally, this is a Knowledge Graph about Products, Customers, Orders etc., defined by classes and properties described in an Ontology that ultimately manifests a Semantic Web.

As a Semantic Web, the meaning (or semantics) of relationship types are both human- and machine-computable which can be demonstrated by adding a few more relationships to the Ontology that cross-reference classes described by the Schema.org vocabulary.

-- a SPASQL (SPARQL integrated into SPARQL) snippet that added owl:equivalentClass relationship types to the Ontology.
-- <urn:rdfs:subclas
s:subproperty:mappings> denotes the Named Graph associated an existing Built-In Inference Rule denoted by <urn:rdfs:subclass:subproperty:inference:rules>
SPARQL
PREFIX : <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX schema: <http://schema.org/>
WITH <urn:rdfs:subclass:subproperty:mappings>
INSERT {
:Customer a owl:Class ;
rdfs:subClassOf schema:Organization .
:DeliveryAddress a owl:Class ;
owl:equivalentClass schema:PostalAddress .
:Order a owl:Class ;
owl:equivalentClass schema:Order .
:Invoice a owl:Class ;
owl:equivalentClass schema:Invoice .
:Product a owl:Class ;
owl:equivalentClass schema:Product .
:ProductCategory a owl:Class ;
owl:equivalentClass schema:CategoryCode .
:OrderItem a owl:Class ;
owl:equivalentClass schema:OrderItem .
:has a owl:ObjectProperty ;
owl:equivalentProperty schema:address .
:places a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:liableFor a owl:ObjectProperty ;
owl:equivalentProperty schema:billingAddress .
:receives a owl:ObjectProperty ;
owl:equivalentProperty schema:deliveryAddress .
:covers a owl:ObjectProperty ;
owl:equivalentProperty schema:referencesOrder .
:includes a owl:ObjectProperty ;
owl:equivalentProperty schema:itemOffered .
:category a owl:ObjectProperty ;
owl:equivalentProperty schema:category .
:orderedIn a owl:ObjectProperty ;
owl:equivalentProperty schema:orderedItem .
:price a owl:DatatypeProperty ;
owl:equivalentProperty schema:price .
:email a owl:DatatypeProperty ;
owl:equivalentProperty schema:email .
:phone a owl:DatatypeProperty ;
owl:equivalentProperty schema:telephone .
:street a owl:DatatypeProperty ;
owl:equivalentProperty schema:streetAddress .
:city a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressLocality .
:state a owl:DatatypeProperty ;
owl:equivalentProperty schema:addressRegion .
:postalCode a owl:DatatypeProperty ;
owl:equivalentProperty schema:postalCode .
:quantity a owl:DatatypeProperty ;
owl:equivalentProperty schema:orderQuantity .
:totalAmount a owl:DatatypeProperty ;
owl:equivalentProperty schema:totalPaymentDue .
} ;
-- refreshes existing rule with newly added data
RDFS_RULE_SET ('urn:rdfs:subclass:subproperty:inference:rules', 'urn:rdfs:subclass:subproperty:mappings')

SPARQL Queries with Inference Context Enabled

These queries showcasing reasoning & inference informed by Ontology can be executed against the live Virtuoso instance behind the URIBurner Query Services Endpoint at: https://linkeddata.uriburner.com/sparql

Orders Sample

DEFINE input:inference "urn:rdfs:subclass:subproperty:inference:rules"
SELECT (SAMPLE(?s) AS ?EntityID)
(COUNT(*) AS ?count)
(?o AS ?EntityTypeID)
FROM <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#osds>
WHERE {
?s a ?o
FILTER ( ?o = schema:Order)
}
GROUP BY ?o
ORDER BY DESC (?count)

Live Query Results Page Link.

Orders Dump

DEFINE input:inference "urn:rdfs:subclass:subproperty:inference:rules"

SELECT *
FROM <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#osds>
WHERE {
?s a schema:Order .
}

Live Query Results Page Link.

Products Dump

DEFINE input:inference "urn:rdfs:subclass:subproperty:inference:rules"

SELECT *
FROM <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#osds>
WHERE {
?s a schema:Product .
}

Live Query Results Page Link.

Organizations Dump

DEFINE input:inference "urn:rdfs:subclass:subproperty:inference:rules"

SELECT *
FROM <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#osds>
WHERE {
?s a schema:Organization .
}

Live Query Results Page Link.

Invoices Dump

DEFINE input:inference "urn:rdfs:subclass:subproperty:inference:rules"

SELECT *
FROM <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#osds>
WHERE {
?s a schema:Invoice .
}

Live Query Results Page Link.

Postal Addresses Dump

DEFINE input:inference "urn:rdfs:subclass:subproperty:inference:rules"

SELECT *
FROM <https://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Playground/gptChat/nanotations/gpt4-related/ontology-and-instance-data-example1.txt#osds>
WHERE {
?s a schema:PostalAddress .
}

Live Query Results Page Link.

When clicking on a hyperlink, courtesy of Linked Data Principles, your browser will resolve to an detailed Entity Description Page that also comprises inverse links (a/k/a backlinks) that are automatically generated by the Virtuoso’s native faceted search and browsing engine.

Entity Description Page comprising inverse-links for bi-directional exploration

Related

OpenLink Data Sniffer (OSDS) Browser Extension Links

Additional Information

--

--

Kingsley Uyi Idehen
OpenLink Software Blog

CEO, OpenLink Software —High-Performance Data Centric Technology Providers.