I want to create a class D which represents any A that contains an
object property P1 whose value is equal to any object property P2
contained by B.
I think you're looking for a class expression like this (in DL and Manchester syntaxes):
D ≡ A ⊓ ∃ p1.(∃ p2-1.B)
D equivalentClass (A and (p1 some (inverse(p2) some B)))
This says that something is a D if and only if it is an A, and has some value for p1 that is the p2 value of some instance of B.
If the domains of p1 and p2 are A and B, respectively, then you can actually simplify that to:
D ≡ ∃ p1.∃ p2-1
D equivalentClass p1 some (inverse(p2) some Thing)
Here's what the first one looks like in the N3 RDF serialization of OWL.
@prefix : <http://stackoverflow.com/q/28506192/1281433/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:A a owl:Class .
:B a owl:Class .
:p a owl:ObjectProperty .
:q a owl:ObjectProperty .
:D a owl:Class ;
owl:equivalentClass [ a owl:Class ;
owl:intersectionOf ( :A _:b0 )
] .
_:b0 a owl:Restriction ;
owl:onProperty :p ;
owl:someValuesFrom [ a owl:Restriction ;
owl:onProperty [ owl:inverseOf :q ] ;
owl:someValuesFrom :B
] .
If you have the domain and range axioms, so that you can use the simpler form, it'd be:
@prefix : <http://stackoverflow.com/q/28506192/1281433/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:A a owl:Class .
:B a owl:Class .
:p a owl:ObjectProperty ;
rdfs:domain :A .
:q a owl:ObjectProperty ;
rdfs:domain :B .
:D a owl:Class ;
owl:equivalentClass [ a owl:Restriction ;
owl:onProperty :p ;
owl:someValuesFrom [ a owl:Restriction ;
owl:onProperty [ owl:inverseOf :q ] ;
owl:someValuesFrom owl:Thing
]
] .