E lcs = getLeastCommonSubsumer(sup1, sup2, f);
} ) .forEach(e2 -> { Node lcs = NonStandardReasoningServices.getLeastCommonSubsumer(reasoner, e1, e2, entityType);
return getLeastCommonSubsumer(e1, e2, f);
/** * Computes the least common subsumer (LCS) of the given entities <code>e1</code> and <code>e2</code> if exists, * otherwise <code>null</code> * * @param reasoner the reasoner used to compute the direct parents * @param n1 first entity * @param n2 second entity * @param entityType the entity type * @param <E> the entity type * @return the LCS if exists */ public static <E extends OWLEntity> Node getLeastCommonSubsumer(AbstractReasonerComponent reasoner, Node n1, Node n2, EntityType<E> entityType) { // trivial case if(n1.equals(n2)) { return n1; } E lcs = getLeastCommonSubsumer(reasoner, OwlApiJenaUtils.asOWLEntity(n1, entityType), OwlApiJenaUtils.asOWLEntity(n2, entityType)); if(lcs != null) { return OwlApiJenaUtils.asNode(lcs); } return null; }
Node lcs = NonStandardReasoningServices.getLeastCommonSubsumer(reasoner, tree1.getData(), tree2.getData(), EntityType.CLASS);
@Test public void getLeastCommonSubsumer() throws Exception { OWLProperty lcs = NonStandardReasoningServices.getLeastCommonSubsumer( reasoner, df.getOWLObjectProperty("s3", pm), df.getOWLObjectProperty("s5", pm)); assertTrue(lcs.equals(df.getOWLObjectProperty("p1", pm))); lcs = NonStandardReasoningServices.getLeastCommonSubsumer( reasoner, df.getOWLObjectProperty("s3", pm), df.getOWLObjectProperty("s4", pm)); assertTrue(lcs.equals(df.getOWLObjectProperty("s3", pm))); lcs = NonStandardReasoningServices.getLeastCommonSubsumer( reasoner, df.getOWLObjectProperty("s1", pm), df.getOWLObjectProperty("s2", pm)); assertTrue(lcs.equals(df.getOWLObjectProperty("p1", pm))); lcs = NonStandardReasoningServices.getLeastCommonSubsumer( reasoner, df.getOWLObjectProperty("s3", pm), df.getOWLObjectProperty("p2", pm)); assertTrue(lcs == null); }