如何查询owl:equivalentClass蕴含的本体隐式属性?
owl:equivalentClass in Virtuoso I get it, you want to avoid hardcoding the FLOPO class URI and instead query based on the implicit "green" characteristic (PATO_0000320) from your ontology's equivalent class definition. Let's break down how to do this with Virtuoso's SPARQL and reasoning capabilities.
First, let's recap your ontology structure to make sure we're aligned:
- The class
FLOPO_0004148("flower green") is defined as equivalent to a restriction: an individual that has a part (BFO_0000051) which is a flower (PO_0009046), and that flower has a characteristic (RO_0000053) of being green (PATO_0000320). - Your goal is to find all plant individuals meeting this implicit condition without referencing the FLOPO class URI directly.
Step 1: Enable Virtuoso's OWL Reasoning
Virtuoso needs explicit instruction to apply OWL inference and expand implicit triples. Add this line at the start of your query to enable standard OWL reasoning:
DEFINE input:inference <http://www.w3.org/2002/07/owl#>
Note: If you loaded your ontology into a specific graph, adjust the inference URI to match your setup (e.g., the graph URI of your ontology with reasoning enabled).
Step 2: Query Based on the Implicit Property Chain
Since the "green" property is attached to the flower part (not the plant directly), we need to traverse this property chain in our query. This version directly mirrors the logic from your owl:equivalentClass definition:
DEFINE input:inference <http://www.w3.org/2002/07/owl#> SELECT ?plant WHERE { # The plant has a part that is a flower ?plant <http://purl.obolibrary.org/obo/BFO_0000051> ?flower . ?flower rdf:type <http://purl.obolibrary.org/obo/PO_0009046> . # That flower has the "green" characteristic ?flower <http://purl.obolibrary.org/obo/RO_0000053> <http://purl.obolibrary.org/obo/PATO_0000320> . }
Virtuoso's reasoning will infer any implicit triples (like individuals belonging to FLOPO_0004148 that match this structure) and return the corresponding plant individuals.
Step 3: Alternative Query (Matching Equivalent Class Definitions)
If you want to avoid writing out the full property chain, you can query for any class that has the equivalent class structure you care about, then fetch its instances. This works well if multiple classes might share this "green flower" condition:
DEFINE input:inference <http://www.w3.org/2002/07/owl#> SELECT ?plant WHERE { # Match any class with your target equivalent class structure ?targetClass owl:equivalentClass [ a owl:Restriction ; owl:onProperty <http://purl.obolibrary.org/obo/BFO_0000051> ; owl:someValuesFrom [ a owl:Class ; owl:intersectionOf ( <http://purl.obolibrary.org/obo/PO_0009046> [ a owl:Restriction ; owl:onProperty <http://purl.obolibrary.org/obo/RO_0000053> ; owl:someValuesFrom <http://purl.obolibrary.org/obo/PATO_0000320> ] ) ] ] . # Get all instances of that class ?plant rdf:type ?targetClass . }
Why Your Initial Query Won't Work
Your original idea of SELECT * { ?s ?p <PATO_0000320> } won't return plants because the PATO_0000320 (green) property isn't directly attached to plant individuals—it's attached to their flower parts. Reasoning is needed to connect the plant to its flower part and infer this implicit relationship.
Quick Virtuoso Checks
- Ensure your ontology is loaded into Virtuoso and reasoning is enabled for the graph containing it.
- Double-check that all property/class URIs exactly match those in your ontology (typos will break the query!).
内容的提问来源于stack exchange,提问作者DoctorZebra

