1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties.classify.feature;
23
24 import de.fu_berlin.ties.ProcessingException;
25 import de.fu_berlin.ties.TiesConfiguration;
26 import de.fu_berlin.ties.util.Util;
27
28 /***
29 * Static factory for initializing {@linkplain
30 * de.fu_berlin.ties.classify.feature.FeatureExtractor feature extractors}.
31 *
32 * @author Christian Siefkes
33 * @version $Revision: 1.4 $, $Date: 2006/10/21 16:03:57 $, $Author: siefkes $
34 */
35 public final class FeatureExtractorFactory {
36
37
38 /***
39 * Factory method that creates a feature extractor based on the
40 * provided configuration. The "feature.extractor" key in the configuration
41 * (optionally adapted by appending the provided <code>suffix</code>) must
42 * give the qualified name of a {@link FeatureExtractor} implementation
43 * accepting a {@link TiesConfiguration} as first argument and a
44 * <code>suffix</code> String as second argument.
45 *
46 * @param conf used to configure this instance
47 * @param suffix optional suffix for
48 * {@linkplain de.fu_berlin.ties.TiesConfiguration#adaptKey(String, String)
49 * adapting configuration keys} if not <code>null</code>
50 * @return the created extractor
51 * @throws ProcessingException if an error occurred while creating the
52 * extractor
53 */
54 public static FeatureExtractor createExtractor(final TiesConfiguration conf,
55 final String suffix) throws ProcessingException {
56 final FeatureExtractor result;
57 final String className =
58 conf.getString(conf.adaptKey("feature.extractor", suffix));
59
60
61
62
63 try {
64 result = (FeatureExtractor) Util.createObject(
65 Class.forName(className),
66 new Object[] {conf, suffix},
67 new Class[] {TiesConfiguration.class, String.class});
68 } catch (ClassNotFoundException cnfe) {
69
70 throw new ProcessingException(
71 "Cannot create feature extractor for class "
72 + className + ": " + cnfe.toString());
73 } catch (InstantiationException ie) {
74
75 throw new ProcessingException(
76 "Cannot create feature extractor for class "
77 + className, ie);
78 }
79 return result;
80 }
81
82
83 /***
84 * Private constructor prevents creation of instances.
85 */
86 private FeatureExtractorFactory() {
87 super();
88 }
89
90 }