/** * Constructs an entity count metric that counts entities of the specified type. * @param rootOntology The project over which the value for the metric is computed. * @param entityType The entity type. */ public EntityCountMetricCalculator(OWLOntology rootOntology, EntityType<?> entityType) { super(rootOntology); this.entityType = entityType; StringBuilder sb = new StringBuilder(); String typeName = entityType.getName(); for(int i = 0; i < typeName.length(); i++) { char ch = typeName.charAt(i); if(Character.isUpperCase(ch)) { sb.append(" "); } sb.append(ch); } metricName = sb.toString().trim() + " count"; }
private Optional<OWLEntity> getEntity(String declaration, EntityType<?> entityType) { if(!declaration.startsWith(entityType.getName() + "(")) { return Optional.empty(); } if(!declaration.endsWith(")")) { return Optional.empty(); } String iriString = declaration.substring(entityType.getName().length() + 1, declaration.length() - 1); if(iriString.startsWith("<")) { iriString = iriString.substring(1); } if(iriString.endsWith(">")) { iriString = iriString.substring(0, iriString.length() - 1); } return Optional.of( dataFactory.getOWLEntity(entityType, IRI.create(iriString)) ); }
@Override public String toString() { return toStringHelper("OWLEntityPrimitive") .add("type", entity.getEntityType().getName()) .add("iri", entity.getIRI().toString()) .toString(); }
public Optional<OWLEntity> parseEntity(String declaration) { if(!declaration.endsWith(")")) { return Optional.empty(); } if(declaration.startsWith(EntityType.CLASS.getName())) { return getEntity(declaration, EntityType.CLASS); } else if(declaration.startsWith(EntityType.OBJECT_PROPERTY.getName())) { return getEntity(declaration, EntityType.OBJECT_PROPERTY); } else if(declaration.startsWith(EntityType.DATA_PROPERTY.getName())) { return getEntity(declaration, EntityType.DATA_PROPERTY); } else if(declaration.startsWith(EntityType.ANNOTATION_PROPERTY.getName())) { return getEntity(declaration, EntityType.ANNOTATION_PROPERTY); } else if(declaration.startsWith(EntityType.NAMED_INDIVIDUAL.getName())) { return getEntity(declaration, EntityType.NAMED_INDIVIDUAL); } else if(declaration.startsWith(EntityType.DATATYPE.getName())) { return getEntity(declaration, EntityType.DATATYPE); } else { return Optional.empty(); } }
/** * Return the entities contained in the current knowledge base. */ protected SortedSet<OWLEntity> getEntities(){ if(entities == null){ entities = new TreeSet<>(); for (EntityType<? extends OWLEntity> entityType : entityTypes) { if(entityType == EntityType.CLASS){ entities.addAll(reasoner.getOWLClasses()); } else if(entityType == EntityType.OBJECT_PROPERTY){ entities.addAll(reasoner.getOWLObjectProperties()); } else if(entityType == EntityType.DATA_PROPERTY){ entities.addAll(reasoner.getOWLDataProperties()); } else { throw new IllegalArgumentException("Entity type " + entityType.getName() + " not supported."); } } } return entities; }
private void renderEntityShortForm(final String shortForm, OWLEntity entity) { StringBuilder classNamesBuilder = new StringBuilder(); final boolean highlighted = highlightChecker.isHighlighted(entity); if (highlighted) { classNamesBuilder.append(" highlight"); } final boolean deprecated = deprecatedChecker.isDeprecated(entity); if (deprecated) { classNamesBuilder.append(" deprecated"); } stringBuilder.append("<span title=\"").append(entity.getEntityType().getName()).append(": "); stringBuilder.append(entity.getIRI()); stringBuilder.append("\" class=\"").append(classNamesBuilder.toString().trim()).append("\">"); stringBuilder.append(new SafeHtmlBuilder().appendEscaped(shortForm).toSafeHtml().asString().replace(" ", " ")); stringBuilder.append("</span>"); }
@Override public void visit(OWLDeclarationAxiom axiom) { stringBuilder.append("<span class=\"section-kw\">"); stringBuilder.append(axiom.getEntity().getEntityType().getName()); stringBuilder.append(": "); stringBuilder.append("</span>"); axiom.getEntity().accept(this); renderAxiomAnnotations(axiom); }
@Override public DBObject convert(OWLEntity entity) { BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("type", entity.getEntityType().getName()); basicDBObject.put("iri", entity.getIRI().toString()); return basicDBObject; } }
@Override public DBObject encodeObject(OWLEntity entity, MappedField optionalExtraInfo) { BasicDBObject document = new BasicDBObject(); document.append(TYPE_PROPERTY_NAME, entity.getEntityType().getName()); document.append(IRI_PROPERTY_NAME, entity.getIRI().toString()); return document; } }
private void writeFrameHeader(OWLEntity entity, StringBuilder builder) { frameHeaderTagRenderer.renderOpeningTag(builder); frameTypeTagRenderer.renderOpeningTag(builder); String frameName = entity.getEntityType().getName(); builder.append(frameName); builder.append(": "); frameTypeTagRenderer.renderClosingTag(builder); frameSubjectTagRenderer.renderOpeningTag(builder); renderEscaped(shortFormProvider.getShortForm(entity), builder); frameSubjectTagRenderer.renderClosingTag(builder); frameHeaderTagRenderer.renderClosingTag(builder); }
logger.warn("Cannot make axiom suggestions for empty " + entity.getEntityType().getName() + " " + entity.toStringID()); return;
if (type.getName().equals(entityTypeGroup)) { entityType = type; break;
/** * Computes the popularity of the given entity. * @param entity the entity * @param <T> the OWL entity type * @return the popularity */ public <T extends OWLEntity> int getPopularity(T entity){ // check if we have the value cached Integer popularity = entityPopularityMap.get(entity); // compute the value if not cached if(popularity == null){ ParameterizedSparqlString queryTemplate; if(entity.isOWLClass()){ queryTemplate = CLASS_POPULARITY_QUERY; } else if(entity.isOWLObjectProperty() || entity.isOWLDataProperty()){ queryTemplate = PROPERTY_POPULARITY_QUERY; } else if(entity.isOWLNamedIndividual()){ queryTemplate = INDIVIDUAL_POPULARITY_QUERY; } else { throw new IllegalArgumentException("Popularity computation not supported for entity type " + entity.getEntityType().getName()); } queryTemplate.setIri("entity", entity.toStringID()); ResultSet rs = executeSelectQuery(queryTemplate.toString()); popularity = rs.next().getLiteral("cnt").getInt(); // put to cache entityPopularityMap.put(entity, popularity); } return popularity; }