IdentifierBuilder { public String lowercaseIdentifier(ResourceObject resource, OntGenerationConfig config) throws RepositoryException { StringBuilder rawName; String rdfsLabel = getPreferredRDFSLabel(resource, config); if(rdfsLabel != null && (!config.isRDFSLabelAmbiguityChecked() || isRDFSLabelUnique(resource, rdfsLabel))) { rawName = new StringBuilder(rdfsLabel); } else if(!config.isFileOrFragmentAmbiguityChecked() || isFileOrFragmentNameUnique(resource)){ rawName = new StringBuilder(getFileOrFragmentName(resource)); } else { rawName = new StringBuilder(getFileOrFragmentName(resource)).append(resource.getResourceAsString().hashCode()); } int pivotUnderscore = -1, pivotWhitespace = -1; do { pivotUnderscore = rawName.indexOf("_", pivotUnderscore); pivotWhitespace = rawName.indexOf(" ", pivotWhitespace); if(pivotUnderscore != -1) { if(pivotUnderscore + 1 < rawName.length() && Character.isLowerCase(rawName.charAt(pivotUnderscore + 1))) { rawName.setCharAt(pivotUnderscore + 1, Character.toUpperCase(rawName.charAt(pivotUnderscore + 1))); } rawName.deleteCharAt(pivotUnderscore); if(pivotUnderscore < pivotWhitespace) { pivotWhitespace--; } } if(pivotWhitespace != -1) { if(pivotWhitespace + 1 < rawName.length() && Character.isLowerCase(rawName.charAt(pivotWhitespace + 1))) { rawName.setCharAt(pivotWhitespace + 1, Character.toUpperCase(rawName.charAt(pivotWhitespace + 1))); } rawName.deleteCharAt(pivotWhitespace); if(pivotUnderscore > pivotWhitespace) { pivotUnderscore--; } } } while (pivotUnderscore != -1 || pivotWhitespace != -1); if(rawName.length() > 0) { rawName.setCharAt(0, Character.toLowerCase(rawName.charAt(0))); } return toJavaName(rawName.toString()); } IdentifierBuilder(ObjectConnection connection); static IdentifierBuilder forObjectRepository(ObjectRepository repository); static IdentifierBuilder forObjectRepository(ObjectConnection connection); String packageName(ResourceObject object, OntGenerationConfig config); String lowercaseIdentifier(ResourceObject resource, OntGenerationConfig config); String capitalizedIdentifier(ResourceObject resource, OntGenerationConfig config); String lowercasePluralIdentifier(ResourceObject resource, OntGenerationConfig config); String capitalizedPluralIdentifier(ResourceObject resource, OntGenerationConfig config);  }
@Test public void testLowercaseIdentifier() throws Exception { IdentifierBuilder builder = IdentifierBuilder.forObjectRepository(anno4j.getObjectRepository()); assertEquals("mboxSha1sum", builder.lowercaseIdentifier(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl(FOAF.MBOX_SHA1SUM)), config)); assertEquals("person", builder.lowercaseIdentifier(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl(FOAF.PERSON)), config)); RDFSClazz person = anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl(FOAF.PERSON)); person.setLabels(Sets.<CharSequence>newHashSet(new LangString("A living person", "de"))); assertEquals("aLivingPerson", builder.lowercaseIdentifier(person, config)); assertEquals("someClazz", builder.lowercaseIdentifier(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl("urn:test:some_clazz")), config)); }