Skip to content

Commit

Permalink
Simplify owl entity finder
Browse files Browse the repository at this point in the history
because stripAndEscapeRendering() should already return a canonical
(unique) rendering representation, e.g., ['foo\'bar'] => [foo\'bar]
  • Loading branch information
ykazakov committed Jun 12, 2024
1 parent 36ff6f3 commit a25f9be
Showing 1 changed file with 10 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,15 @@ public OWLEntityFinderImpl(OWLModelManagerImpl mngr, OWLEntityRenderingCache ren
this.renderingCache = renderingCache;
}


private static final String ESCAPE_CHAR = "'";


private String stripAndEscapeRendering(String rendering) {
String strippedRendering;
if(rendering.startsWith("'") && rendering.endsWith("'") && rendering.length() > 1) {
strippedRendering = rendering.substring(1, rendering.length() - 1);
if (rendering.startsWith("'") && rendering.endsWith("'") && rendering.length() > 1) {
rendering = rendering.substring(1, rendering.length() - 1);
}
else {
strippedRendering = rendering;
}
return RenderingEscapeUtils.getEscapedRendering(strippedRendering);
return RenderingEscapeUtils.getEscapedRendering(rendering);
}

public OWLClass getOWLClass(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLClass cls = renderingCache.getOWLClass(rendering);
if (cls == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)) {
cls = renderingCache.getOWLClass(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return cls;
return renderingCache.getOWLClass(stripAndEscapeRendering(rendering));
}

@Override
Expand All @@ -71,62 +58,32 @@ public Set<OWLEntity> getOWLEntities(String rendering) {
}

public OWLObjectProperty getOWLObjectProperty(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLObjectProperty prop = renderingCache.getOWLObjectProperty(rendering);
if (prop == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)){
prop = renderingCache.getOWLObjectProperty(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return prop;
return renderingCache.getOWLObjectProperty(stripAndEscapeRendering(rendering));
}


public OWLDataProperty getOWLDataProperty(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLDataProperty prop = renderingCache.getOWLDataProperty(rendering);
if (prop == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)){
prop = renderingCache.getOWLDataProperty(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return prop;
return renderingCache.getOWLDataProperty(stripAndEscapeRendering(rendering));
}


public OWLAnnotationProperty getOWLAnnotationProperty(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLAnnotationProperty prop = renderingCache.getOWLAnnotationProperty(rendering);
if (prop == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)){
prop = renderingCache.getOWLAnnotationProperty(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return prop;
return renderingCache.getOWLAnnotationProperty(stripAndEscapeRendering(rendering));
}


public OWLNamedIndividual getOWLIndividual(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLNamedIndividual individual = renderingCache.getOWLIndividual(rendering);
if (individual == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)){
individual = renderingCache.getOWLIndividual(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return individual;
return renderingCache.getOWLIndividual(stripAndEscapeRendering(rendering));
}


public OWLDatatype getOWLDatatype(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLDatatype dataType = renderingCache.getOWLDatatype(rendering);
if (dataType == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)){
dataType = renderingCache.getOWLDatatype(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return dataType;
return renderingCache.getOWLDatatype(stripAndEscapeRendering(rendering));
}


public OWLEntity getOWLEntity(String rendering) {
rendering = stripAndEscapeRendering(rendering);
OWLEntity entity = renderingCache.getOWLEntity(rendering);
if (entity == null && !rendering.startsWith(ESCAPE_CHAR) && !rendering.endsWith(ESCAPE_CHAR)){
entity = renderingCache.getOWLEntity(RenderingEscapeUtils.getEscapedRendering(rendering));
}
return entity;
return renderingCache.getOWLEntity(stripAndEscapeRendering(rendering));
}


Expand Down

0 comments on commit a25f9be

Please sign in to comment.