@@ -23,12 +23,27 @@ public class AxiomRelationshipConversionService {
2323 private final OntologyService ontologyService ;
2424
2525 private static final Logger LOGGER = LoggerFactory .getLogger (AxiomRelationshipConversionService .class );
26+ private Collection <Long > objectAttributes ;
27+ private Collection <Long > dataAttributes ;
2628
2729 public AxiomRelationshipConversionService (Set <Long > ungroupedAttributes ) {
2830 snomedTaxonomyLoader = new SnomedTaxonomyLoader ();
2931 ontologyService = new OntologyService (ungroupedAttributes );
3032 }
3133
34+ /**
35+ * Use this constructor to enable generating SubObjectPropertyOf and SubDataPropertyOf axioms from relationships.
36+ * @param ungroupedAttributes
37+ * @param objectAttributes
38+ * @param dataAttributes
39+ */
40+ public AxiomRelationshipConversionService (Set <Long > ungroupedAttributes , Collection <Long > objectAttributes , Collection <Long > dataAttributes ) {
41+ snomedTaxonomyLoader = new SnomedTaxonomyLoader ();
42+ ontologyService = new OntologyService (ungroupedAttributes );
43+ this .objectAttributes = objectAttributes ;
44+ this .dataAttributes = dataAttributes ;
45+ }
46+
3247 /**
3348 * Converts an OWL Axiom expression String to an AxiomRepresentation containing a concept id or set of relationships for each side of the expression.
3449 * Currently supported axiom types are SubClassOf and EquivalentClasses.
@@ -172,8 +187,31 @@ public Map<Long, Set<AxiomRepresentation>> convertAxiomsToRelationships(Map<Long
172187 }
173188
174189 public String convertRelationshipsToAxiom (AxiomRepresentation representation ) {
175- OWLClassAxiom owlClassAxiom = ontologyService .createOwlClassAxiom (representation );
176- return owlClassAxiom .toString ().replaceAll (CORE_COMPONENT_NAMESPACE_PATTERN , ":$1" ).replace (") )" , "))" );
190+
191+ // Identify and convert object and data property axioms
192+ if (representation .getLeftHandSideNamedConcept () != null && representation .getRightHandSideRelationships () != null ) {
193+ List <Relationship > relationships = representation .getRightHandSideRelationships ().get (0 );
194+ for (Relationship relationship : relationships ) {
195+ if (relationship .getTypeId () == Concepts .IS_A_LONG ) {
196+ if (objectAttributes != null && objectAttributes .contains (relationship .getDestinationId ())) {
197+ // Attributes will only have one parent
198+ return axiomToString (ontologyService .createOwlSubObjectPropertyOfAxiom (representation .getLeftHandSideNamedConcept (), relationship .getDestinationId ()));
199+ } else if (dataAttributes != null && dataAttributes .contains (relationship .getDestinationId ())) {
200+ return axiomToString (ontologyService .createOwlSubDataPropertyOfAxiom (representation .getLeftHandSideNamedConcept (), relationship .getDestinationId ()));
201+ } else {
202+ // If the first parent is not an attribute then the concept is not an attribute.
203+ break ;
204+ }
205+ }
206+ }
207+ }
208+
209+ // Normal axioms and GCI axioms go through here
210+ return axiomToString (ontologyService .createOwlClassAxiom (representation ));
211+ }
212+
213+ public String axiomToString (OWLLogicalAxiom owlAxiom ) {
214+ return owlAxiom .toString ().replaceAll (CORE_COMPONENT_NAMESPACE_PATTERN , ":$1" ).replace (") )" , "))" );
177215 }
178216
179217 /**
0 commit comments