summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2014-10-10 12:05:12 +0200
committermguetlein <martin.guetlein@gmail.com>2014-10-10 12:05:12 +0200
commit8507a8fbf17b65b1cf939e609287177b20599297 (patch)
tree38dac2055e5c54c3e1cf947bdd19f280bc27dc0c
parent33c3a81c903b439ea729e0b1ec915e7524d7345d (diff)
fix cdkdescriptor calculation: find classes with 'descriptor' in the middle of the class name
-rw-r--r--java/CdkDescriptors.java43
1 files changed, 35 insertions, 8 deletions
diff --git a/java/CdkDescriptors.java b/java/CdkDescriptors.java
index a42853e..42a44e1 100644
--- a/java/CdkDescriptors.java
+++ b/java/CdkDescriptors.java
@@ -38,14 +38,7 @@ class CdkDescriptors {
descriptorNames.add(args[i]);
descriptorName = args[i];
}
- String className = "org.openscience.cdk.qsar.descriptors.molecular." + descriptorName + "Descriptor";
- try {
- Class.forName(className);
- } catch (ClassNotFoundException e) {
- System.err.println("Descriptor not found: "+args[i]);
- System.exit(1);
- }
- classNames.add(className);
+ classNames.add(getDescriptorClassName(descriptorName));
}
engine = new DescriptorEngine(new ArrayList<String>(classNames));
@@ -99,4 +92,38 @@ class CdkDescriptors {
}
catch (Exception e) { e.printStackTrace(); }
}
+
+
+ /** HACK to find the class for a descriptor
+ * problem: Descriptor is not always at the end of the class (APolDescriptor), but may be in the middle (AutocorrelationDescriptorPolarizability)
+ * this method makes a class-lookup using trial and error */
+ static String getDescriptorClassName(String descriptorName) {
+ String split = splitCamelCase(descriptorName)+" "; // space mark possible positions for 'Descriptor'
+ for(int i = split.length()-1; i>0; i--) {
+ if (split.charAt(i)==' ') { // iterate over all spaces, starting with the trailing one
+ String test = split.substring(0,i)+"Descriptor"+split.substring(i+1,split.length()); // replace current space with 'Descriptor' ..
+ test = test.replaceAll("\\s",""); // .. and remove other spaces
+ String className = "org.openscience.cdk.qsar.descriptors.molecular." + test;
+ try {
+ Class.forName(className);
+ return className;
+ } catch (ClassNotFoundException e) {}
+ }
+ }
+ System.err.println("Descriptor not found: "+descriptorName);
+ System.exit(1);
+ return null;
+ }
+
+ /** inserts space in between camel words */
+ static String splitCamelCase(String s) {
+ return s.replaceAll(
+ String.format("%s|%s|%s",
+ "(?<=[A-Z])(?=[A-Z][a-z])",
+ "(?<=[^A-Z])(?=[A-Z])",
+ "(?<=[A-Za-z])(?=[^A-Za-z])"
+ ),
+ " "
+ );
+ }
}