You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/01/11 00:12:37 UTC
svn commit: r1431721 [9/19] - in /uima/sandbox/uimafit/trunk:
uimafit-examples/src/main/java/org/apache/uima/fit/examples/experiment/pos/
uimafit-examples/src/main/java/org/apache/uima/fit/examples/getstarted/
uimafit-examples/src/main/java/org/apache/...
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/FsIndexFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/FsIndexFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/FsIndexFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/FsIndexFactory.java Thu Jan 10 23:12:33 2013
@@ -47,220 +47,210 @@ import org.apache.uima.util.XMLInputSour
/**
*/
public final class FsIndexFactory {
- public static final int STANDARD_COMPARE = FsIndexKeyDescription.STANDARD_COMPARE;
+ public static final int STANDARD_COMPARE = FsIndexKeyDescription.STANDARD_COMPARE;
- public static final int REVERSE_STANDARD_COMPARE = FsIndexKeyDescription.STANDARD_COMPARE;
+ public static final int REVERSE_STANDARD_COMPARE = FsIndexKeyDescription.STANDARD_COMPARE;
- private FsIndexFactory() {
- // Factory class
- }
-
- /**
- * Create index configuration data for a given class definition using reflection and the
- * configuration parameter annotation.
- */
- public static FsIndexCollection createFsIndexCollection(Class<?> componentClass) {
- List<FsIndex> anFsIndexList = new ArrayList<FsIndex>();
-
- // Check FsIndexCollection annotation
- org.apache.uima.fit.descriptor.FsIndexCollection anIndexCollection =
- getInheritableAnnotation(org.apache.uima.fit.descriptor.FsIndexCollection.class, componentClass);
- if (anIndexCollection != null) {
- anFsIndexList.addAll(asList(anIndexCollection.fsIndexes()));
- }
-
- // Check FsIndex annotation
- org.apache.uima.fit.descriptor.FsIndex anFsIndex =
- getInheritableAnnotation(FsIndex.class, componentClass);
- if (anFsIndex != null) {
- if (anIndexCollection != null) {
- throw new IllegalStateException("Class ["+componentClass.getName()+"] must not " +
- "declare "+org.apache.uima.fit.descriptor.FsIndexCollection.class.getSimpleName() +
- " and "+FsIndex.class.getSimpleName()+" at the same time.");
- }
-
- anFsIndexList.add(anFsIndex);
- }
-
- FsIndexCollection_impl fsIndexCollection = new FsIndexCollection_impl();
-
- // Process collected FsIndex annotations
- for (FsIndex anIdx : anFsIndexList) {
- // Collect index keys
- List<FsIndexKeyDescription> keys = new ArrayList<FsIndexKeyDescription>();
- for (FsIndexKey anIndexKey : anIdx.keys()) {
- keys.add(createFsIndexKeyDescription(anIndexKey.featureName(),
- anIndexKey.comparator()));
- }
-
- // type and typeName must not be set at the same time
- if (!anIdx.typeName().equals(FsIndex.NO_NAME_TYPE_SET)
- && anIdx.type() != FsIndex.NoClassSet.class){
- throw new IllegalStateException("Class ["+componentClass.getName()+"] must not " +
- "declare an "+org.apache.uima.fit.descriptor.FsIndex.class.getSimpleName() +
- " with type and typeName both set at the same time.");
- }
-
- String typeName;
- if (!anIdx.typeName().equals(FsIndex.NO_NAME_TYPE_SET)) {
- typeName = anIdx.typeName();
- }
- else if (anIdx.type() != FsIndex.NoClassSet.class) {
- typeName = anIdx.type().getName();
- }
- else {
- throw new IllegalStateException("Class ["+componentClass.getName()+"] must not " +
- "declare an "+org.apache.uima.fit.descriptor.FsIndex.class.getSimpleName() +
- " with neither type nor typeName set.");
- }
-
- fsIndexCollection.addFsIndex(createFsIndexDescription(anIdx.label(), anIdx.kind(),
- typeName, anIdx.typePriorities(),
- keys.toArray(new FsIndexKeyDescription[keys.size()])));
- }
-
- return fsIndexCollection;
- }
-
- public static FsIndexDescription createFsIndexDescription(String label, String kind,
- String typeName, boolean useTypePriorities, FsIndexKeyDescription... keys) {
- FsIndexDescription_impl fsIndexDescription = new FsIndexDescription_impl();
- fsIndexDescription.setLabel(label);
- fsIndexDescription.setKind(kind);
- fsIndexDescription.setTypeName(typeName);
- fsIndexDescription.setKeys(keys);
- return fsIndexDescription;
- }
-
- public static FsIndexCollection createFsIndexCollection(FsIndexDescription...descriptions) {
- FsIndexCollection_impl fsIndexCollection = new FsIndexCollection_impl();
- fsIndexCollection.setFsIndexes(descriptions);
- return fsIndexCollection;
- }
-
- public static FsIndexKeyDescription createFsIndexKeyDescription(String featureName) {
- return createFsIndexKeyDescription(featureName, STANDARD_COMPARE);
- }
-
- public static FsIndexKeyDescription createFsIndexKeyDescription(String featureName,
- int comparator) {
- FsIndexKeyDescription_impl key = new FsIndexKeyDescription_impl();
- key.setFeatureName(featureName);
- key.setComparator(comparator);
- key.setTypePriority(false);
- return key;
- }
-
- /**
- * System property indicating which locations to scan for index descriptions. A list of
- * locations may be given separated by ";".
- */
- public static final String FS_INDEX_IMPORT_PATTERN = "org.uimafit.fsindex.import_pattern";
-
- /**
- * Index manifest location.
- */
- public static final String FS_INDEX_MANIFEST_PATTERN = "classpath*:META-INF/org.uimafit/fsindexes.txt";
-
- private static String[] indexDescriptorLocations;
-
- /**
- * Creates a {@link FsIndexCollection} from descriptor names.
- *
- * @param descriptorNames
- * The fully qualified, Java-style, dotted descriptor names.
- * @return a {@link FsIndexCollection} that includes the indexes from all of the specified files.
- */
- public static FsIndexCollection createFsIndexCollection(String... descriptorNames) {
- List<Import> imports = new ArrayList<Import>();
- for (String descriptorName : descriptorNames) {
- Import imp = new Import_impl();
- imp.setName(descriptorName);
- imports.add(imp);
- }
- Import[] importArray = new Import[imports.size()];
-
- FsIndexCollection fsIndexCollection = new FsIndexCollection_impl();
- fsIndexCollection.setImports(imports.toArray(importArray));
- return fsIndexCollection;
- }
-
- /**
- * Creates a {@link FsIndexCollection} from a descriptor file
- *
- * @param descriptorURIs
- * The descriptor file paths.
- * @return A {@link FsIndexCollection} that includes the indexes from all of the specified files.
- */
- public static FsIndexCollection createTypeSystemDescriptionFromPath(
- String... descriptorURIs) {
- List<Import> imports = new ArrayList<Import>();
- for (String descriptorURI : descriptorURIs) {
- Import imp = new Import_impl();
- imp.setLocation(descriptorURI);
- imports.add(imp);
- }
- Import[] importArray = new Import[imports.size()];
-
- FsIndexCollection fsIndexCollection = new FsIndexCollection_impl();
- fsIndexCollection.setImports(imports.toArray(importArray));
- return fsIndexCollection;
- }
-
- /**
- * Creates a {@link FsIndexCollection} from all index descriptions that can be found via the
- * {@link #FS_INDEX_IMPORT_PATTERN} or via the {@code META-INF/org.uimafit/fsindexes.txt} files
- * in the classpath.
- *
- * @return the auto-scanned indexes.
- */
- public static FsIndexCollection createFsIndexCollection()
- throws ResourceInitializationException {
- List<FsIndexDescription> fsIndexList = new ArrayList<FsIndexDescription>();
- for (String location : scanIndexDescriptors()) {
- try {
- XMLInputSource xmlInput = new XMLInputSource(location);
- FsIndexCollection fsIdxCol = getXMLParser().parseFsIndexCollection(xmlInput);
- fsIdxCol.resolveImports();
- fsIndexList.addAll(asList(fsIdxCol.getFsIndexes()));
- LogFactory.getLog(FsIndexFactory.class).debug(
- "Detected index at [" + location + "]");
- }
- catch (IOException e) {
- throw new ResourceInitializationException(e);
- }
- catch (InvalidXMLException e) {
- LogFactory.getLog(TypeSystemDescription.class).warn(
- "[" + location + "] is not a index descriptor file. Ignoring.", e);
- }
- }
-
- return createFsIndexCollection(fsIndexList.toArray(new FsIndexDescription[fsIndexList
- .size()]));
- }
-
- /**
- * Get all currently accessible index descriptor locations. A scan is actually only
- * performed on the first call and the locations are cached. To force a re-scan use
- * {@link #forceIndexDescriptorsScan()}.
- *
- * @return an array of locations.
- * @throws ResourceInitializationException
- * if the locations could not be resolved.
- */
- public static String[] scanIndexDescriptors() throws ResourceInitializationException {
- if (indexDescriptorLocations == null) {
- indexDescriptorLocations = resolve(scanImportsAndManifests(FS_INDEX_MANIFEST_PATTERN,
- FS_INDEX_IMPORT_PATTERN));
- }
- return indexDescriptorLocations;
- }
-
- /**
- * Force rescan of type descriptors. The next call to {@link #scanIndexDescriptors()} will rescan
- * all auto-import locations.
- */
- public static void forceIndexDescriptorsScan() {
- indexDescriptorLocations = null;
- }
+ private FsIndexFactory() {
+ // Factory class
+ }
+
+ /**
+ * Create index configuration data for a given class definition using reflection and the
+ * configuration parameter annotation.
+ */
+ public static FsIndexCollection createFsIndexCollection(Class<?> componentClass) {
+ List<FsIndex> anFsIndexList = new ArrayList<FsIndex>();
+
+ // Check FsIndexCollection annotation
+ org.apache.uima.fit.descriptor.FsIndexCollection anIndexCollection = getInheritableAnnotation(
+ org.apache.uima.fit.descriptor.FsIndexCollection.class, componentClass);
+ if (anIndexCollection != null) {
+ anFsIndexList.addAll(asList(anIndexCollection.fsIndexes()));
+ }
+
+ // Check FsIndex annotation
+ org.apache.uima.fit.descriptor.FsIndex anFsIndex = getInheritableAnnotation(FsIndex.class,
+ componentClass);
+ if (anFsIndex != null) {
+ if (anIndexCollection != null) {
+ throw new IllegalStateException("Class [" + componentClass.getName() + "] must not "
+ + "declare "
+ + org.apache.uima.fit.descriptor.FsIndexCollection.class.getSimpleName() + " and "
+ + FsIndex.class.getSimpleName() + " at the same time.");
+ }
+
+ anFsIndexList.add(anFsIndex);
+ }
+
+ FsIndexCollection_impl fsIndexCollection = new FsIndexCollection_impl();
+
+ // Process collected FsIndex annotations
+ for (FsIndex anIdx : anFsIndexList) {
+ // Collect index keys
+ List<FsIndexKeyDescription> keys = new ArrayList<FsIndexKeyDescription>();
+ for (FsIndexKey anIndexKey : anIdx.keys()) {
+ keys.add(createFsIndexKeyDescription(anIndexKey.featureName(), anIndexKey.comparator()));
+ }
+
+ // type and typeName must not be set at the same time
+ if (!anIdx.typeName().equals(FsIndex.NO_NAME_TYPE_SET)
+ && anIdx.type() != FsIndex.NoClassSet.class) {
+ throw new IllegalStateException("Class [" + componentClass.getName() + "] must not "
+ + "declare an " + org.apache.uima.fit.descriptor.FsIndex.class.getSimpleName()
+ + " with type and typeName both set at the same time.");
+ }
+
+ String typeName;
+ if (!anIdx.typeName().equals(FsIndex.NO_NAME_TYPE_SET)) {
+ typeName = anIdx.typeName();
+ } else if (anIdx.type() != FsIndex.NoClassSet.class) {
+ typeName = anIdx.type().getName();
+ } else {
+ throw new IllegalStateException("Class [" + componentClass.getName() + "] must not "
+ + "declare an " + org.apache.uima.fit.descriptor.FsIndex.class.getSimpleName()
+ + " with neither type nor typeName set.");
+ }
+
+ fsIndexCollection.addFsIndex(createFsIndexDescription(anIdx.label(), anIdx.kind(), typeName,
+ anIdx.typePriorities(), keys.toArray(new FsIndexKeyDescription[keys.size()])));
+ }
+
+ return fsIndexCollection;
+ }
+
+ public static FsIndexDescription createFsIndexDescription(String label, String kind,
+ String typeName, boolean useTypePriorities, FsIndexKeyDescription... keys) {
+ FsIndexDescription_impl fsIndexDescription = new FsIndexDescription_impl();
+ fsIndexDescription.setLabel(label);
+ fsIndexDescription.setKind(kind);
+ fsIndexDescription.setTypeName(typeName);
+ fsIndexDescription.setKeys(keys);
+ return fsIndexDescription;
+ }
+
+ public static FsIndexCollection createFsIndexCollection(FsIndexDescription... descriptions) {
+ FsIndexCollection_impl fsIndexCollection = new FsIndexCollection_impl();
+ fsIndexCollection.setFsIndexes(descriptions);
+ return fsIndexCollection;
+ }
+
+ public static FsIndexKeyDescription createFsIndexKeyDescription(String featureName) {
+ return createFsIndexKeyDescription(featureName, STANDARD_COMPARE);
+ }
+
+ public static FsIndexKeyDescription createFsIndexKeyDescription(String featureName, int comparator) {
+ FsIndexKeyDescription_impl key = new FsIndexKeyDescription_impl();
+ key.setFeatureName(featureName);
+ key.setComparator(comparator);
+ key.setTypePriority(false);
+ return key;
+ }
+
+ /**
+ * System property indicating which locations to scan for index descriptions. A list of locations
+ * may be given separated by ";".
+ */
+ public static final String FS_INDEX_IMPORT_PATTERN = "org.uimafit.fsindex.import_pattern";
+
+ /**
+ * Index manifest location.
+ */
+ public static final String FS_INDEX_MANIFEST_PATTERN = "classpath*:META-INF/org.uimafit/fsindexes.txt";
+
+ private static String[] indexDescriptorLocations;
+
+ /**
+ * Creates a {@link FsIndexCollection} from descriptor names.
+ *
+ * @param descriptorNames
+ * The fully qualified, Java-style, dotted descriptor names.
+ * @return a {@link FsIndexCollection} that includes the indexes from all of the specified files.
+ */
+ public static FsIndexCollection createFsIndexCollection(String... descriptorNames) {
+ List<Import> imports = new ArrayList<Import>();
+ for (String descriptorName : descriptorNames) {
+ Import imp = new Import_impl();
+ imp.setName(descriptorName);
+ imports.add(imp);
+ }
+ Import[] importArray = new Import[imports.size()];
+
+ FsIndexCollection fsIndexCollection = new FsIndexCollection_impl();
+ fsIndexCollection.setImports(imports.toArray(importArray));
+ return fsIndexCollection;
+ }
+
+ /**
+ * Creates a {@link FsIndexCollection} from a descriptor file
+ *
+ * @param descriptorURIs
+ * The descriptor file paths.
+ * @return A {@link FsIndexCollection} that includes the indexes from all of the specified files.
+ */
+ public static FsIndexCollection createTypeSystemDescriptionFromPath(String... descriptorURIs) {
+ List<Import> imports = new ArrayList<Import>();
+ for (String descriptorURI : descriptorURIs) {
+ Import imp = new Import_impl();
+ imp.setLocation(descriptorURI);
+ imports.add(imp);
+ }
+ Import[] importArray = new Import[imports.size()];
+
+ FsIndexCollection fsIndexCollection = new FsIndexCollection_impl();
+ fsIndexCollection.setImports(imports.toArray(importArray));
+ return fsIndexCollection;
+ }
+
+ /**
+ * Creates a {@link FsIndexCollection} from all index descriptions that can be found via the
+ * {@link #FS_INDEX_IMPORT_PATTERN} or via the {@code META-INF/org.uimafit/fsindexes.txt} files in
+ * the classpath.
+ *
+ * @return the auto-scanned indexes.
+ */
+ public static FsIndexCollection createFsIndexCollection() throws ResourceInitializationException {
+ List<FsIndexDescription> fsIndexList = new ArrayList<FsIndexDescription>();
+ for (String location : scanIndexDescriptors()) {
+ try {
+ XMLInputSource xmlInput = new XMLInputSource(location);
+ FsIndexCollection fsIdxCol = getXMLParser().parseFsIndexCollection(xmlInput);
+ fsIdxCol.resolveImports();
+ fsIndexList.addAll(asList(fsIdxCol.getFsIndexes()));
+ LogFactory.getLog(FsIndexFactory.class).debug("Detected index at [" + location + "]");
+ } catch (IOException e) {
+ throw new ResourceInitializationException(e);
+ } catch (InvalidXMLException e) {
+ LogFactory.getLog(TypeSystemDescription.class).warn(
+ "[" + location + "] is not a index descriptor file. Ignoring.", e);
+ }
+ }
+
+ return createFsIndexCollection(fsIndexList.toArray(new FsIndexDescription[fsIndexList.size()]));
+ }
+
+ /**
+ * Get all currently accessible index descriptor locations. A scan is actually only performed on
+ * the first call and the locations are cached. To force a re-scan use
+ * {@link #forceIndexDescriptorsScan()}.
+ *
+ * @return an array of locations.
+ * @throws ResourceInitializationException
+ * if the locations could not be resolved.
+ */
+ public static String[] scanIndexDescriptors() throws ResourceInitializationException {
+ if (indexDescriptorLocations == null) {
+ indexDescriptorLocations = resolve(scanImportsAndManifests(FS_INDEX_MANIFEST_PATTERN,
+ FS_INDEX_IMPORT_PATTERN));
+ }
+ return indexDescriptorLocations;
+ }
+
+ /**
+ * Force rescan of type descriptors. The next call to {@link #scanIndexDescriptors()} will rescan
+ * all auto-import locations.
+ */
+ public static void forceIndexDescriptorsScan() {
+ indexDescriptorLocations = null;
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasBuilder.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasBuilder.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasBuilder.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasBuilder.java Thu Jan 10 23:12:33 2013
@@ -29,97 +29,98 @@ import org.apache.uima.jcas.JCas;
*
*/
public class JCasBuilder {
- private final StringBuilder documentText = new StringBuilder();
- private final JCas jcas;
+ private final StringBuilder documentText = new StringBuilder();
- /**
- * Create a new JCas builder working on the specified JCas. The JCas must not have any content
- * yet.
- *
- * @param aJCas
- * the working JCas.
- */
- public JCasBuilder(JCas aJCas) {
- jcas = aJCas;
- }
-
- /**
- * Append a text.
- *
- * @param aText
- * the text to append.
- */
- public void add(String aText) {
- documentText.append(aText);
- }
-
- /**
- * Append a text annotated with the specified annotation. The created annotation is returned and
- * further properties can be set on it. The annotation is already added to the indexes.
- *
- * @param aText
- * covered text
- * @param aClass
- * annotation type
- * @param <T>
- * annotation type
- * @return annotation instance - can be used to set features or determine offsets
- */
- @SuppressWarnings("unchecked")
- public <T> T add(String aText, Class<T> aClass) {
- Type type = getType(jcas, aClass);
- int begin = documentText.length();
- add(aText);
- int end = documentText.length();
- AnnotationFS fs = jcas.getCas().createAnnotation(type, begin, end);
- jcas.addFsToIndexes(fs);
- return (T) fs;
- }
-
- /**
- * Add an annotation starting at the specified position and ending at the current end of the
- * text. The created annotation is returned and further properties can be set on it. The
- * annotation is already added to the indexes.
- *
- * @param <T>
- * annotation type
- * @param aBegin
- * begin offset.
- * @param aClass
- * annotation type
- * @return annotation instance - can be used to set features or determine offsets
- */
- @SuppressWarnings("unchecked")
- public <T> T add(int aBegin, Class<T> aClass) {
- Type type = getType(jcas, aClass);
- int end = documentText.length();
- AnnotationFS fs = jcas.getCas().createAnnotation(type, aBegin, end);
- jcas.addFsToIndexes(fs);
- return (T) fs;
- }
-
- /**
- * Get the current "cursor" position (current text length).
- *
- * @return current text length.
- */
- public int getPosition() {
- return documentText.length();
- }
-
- /**
- * Get the JCas.
- *
- * @return the JCas.
- */
- public JCas getJCas() {
- return jcas;
- }
-
- /**
- * Complete the building process by writing the text into the CAS. This can only be called once.
- */
- public void close() {
- jcas.setDocumentText(documentText.toString());
- }
+ private final JCas jcas;
+
+ /**
+ * Create a new JCas builder working on the specified JCas. The JCas must not have any content
+ * yet.
+ *
+ * @param aJCas
+ * the working JCas.
+ */
+ public JCasBuilder(JCas aJCas) {
+ jcas = aJCas;
+ }
+
+ /**
+ * Append a text.
+ *
+ * @param aText
+ * the text to append.
+ */
+ public void add(String aText) {
+ documentText.append(aText);
+ }
+
+ /**
+ * Append a text annotated with the specified annotation. The created annotation is returned and
+ * further properties can be set on it. The annotation is already added to the indexes.
+ *
+ * @param aText
+ * covered text
+ * @param aClass
+ * annotation type
+ * @param <T>
+ * annotation type
+ * @return annotation instance - can be used to set features or determine offsets
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T add(String aText, Class<T> aClass) {
+ Type type = getType(jcas, aClass);
+ int begin = documentText.length();
+ add(aText);
+ int end = documentText.length();
+ AnnotationFS fs = jcas.getCas().createAnnotation(type, begin, end);
+ jcas.addFsToIndexes(fs);
+ return (T) fs;
+ }
+
+ /**
+ * Add an annotation starting at the specified position and ending at the current end of the text.
+ * The created annotation is returned and further properties can be set on it. The annotation is
+ * already added to the indexes.
+ *
+ * @param <T>
+ * annotation type
+ * @param aBegin
+ * begin offset.
+ * @param aClass
+ * annotation type
+ * @return annotation instance - can be used to set features or determine offsets
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T add(int aBegin, Class<T> aClass) {
+ Type type = getType(jcas, aClass);
+ int end = documentText.length();
+ AnnotationFS fs = jcas.getCas().createAnnotation(type, aBegin, end);
+ jcas.addFsToIndexes(fs);
+ return (T) fs;
+ }
+
+ /**
+ * Get the current "cursor" position (current text length).
+ *
+ * @return current text length.
+ */
+ public int getPosition() {
+ return documentText.length();
+ }
+
+ /**
+ * Get the JCas.
+ *
+ * @return the JCas.
+ */
+ public JCas getJCas() {
+ return jcas;
+ }
+
+ /**
+ * Complete the building process by writing the text into the CAS. This can only be called once.
+ */
+ public void close() {
+ jcas.setDocumentText(documentText.toString());
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/JCasFactory.java Thu Jan 10 23:12:33 2013
@@ -38,147 +38,144 @@ import org.xml.sax.SAXException;
/**
*/
public final class JCasFactory {
- private JCasFactory() {
- // This class is not meant to be instantiated
- }
-
- /**
- * Creates a new JCas for the automatically derived type system. See
- * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}
- */
- public static JCas createJCas() throws UIMAException {
- return CasCreationUtils.createCas(createTypeSystemDescription(), null, null).getJCas();
-
- }
-
- /**
- * Creates a new JCas from type system descriptor files found by name
- */
- public static JCas createJCas(String... typeSystemDescriptorNames) throws UIMAException {
- return CasCreationUtils.createCas(createTypeSystemDescription(typeSystemDescriptorNames),
- null, null).getJCas();
- }
-
- /**
- * Creates a new JCas from type system descriptor files.
- *
- * @param typeSystemDescriptorPaths
- * paths to type system descriptor files
- */
- public static JCas createJCasFromPath(String... typeSystemDescriptorPaths) throws UIMAException {
- return createJCas(createTypeSystemDescriptionFromPath(typeSystemDescriptorPaths));
- }
-
- /**
- * Create a new JCas with a new type system defined by the classes provided
- *
- * @param typeSystemClasses
- * should be classes generated by JCasGen
- *
- * @deprecated This is not the method you want to use. If you declare only one type per XML type
- * descriptor, you'll end up with LOTS of these. Use
- * {@link TypeSystemDescriptionFactory#createTypeSystemDescription(String...)} or
- * automatic type system detection with
- * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}.
- */
- @Deprecated
- public static JCas createJCas(Class<?>... typeSystemClasses) throws UIMAException {
- return createJCas(createTypeSystemDescription(typeSystemClasses));
- }
-
- /**
- * Create a new JCas for the given type system description
- */
- public static JCas createJCas(TypeSystemDescription typeSystemDescription) throws UIMAException {
- return CasCreationUtils.createCas(typeSystemDescription, null, null).getJCas();
- }
-
- /**
- * This method creates a new JCas and loads the contents of an XMI file into it.
- *
- * @param xmiFileName
- * a file name for an XMI file.
- */
- public static JCas createJCas(String xmiFileName, TypeSystemDescription typeSystemDescription)
- throws UIMAException, IOException {
- return createJCas(xmiFileName, typeSystemDescription, true);
- }
-
- /**
- * This method creates a new JCas and loads the contents of an XMI or XCAS file into it.
- *
- * @param xmlFileName
- * a file name for an XML file containing XMI or XCAS content.
- * @param isXmi
- * if true, than assume XMI format. Otherwise, assume XCAS.
- */
- public static JCas createJCas(String xmlFileName, TypeSystemDescription typeSystemDescription,
- boolean isXmi) throws UIMAException, IOException {
- JCas jCas = createJCas(typeSystemDescription);
- loadJCas(jCas, xmlFileName, isXmi);
- return jCas;
- }
-
- /**
- * This method passes through to {@link #loadJCas(JCas, String, boolean)}
- *
- * @param xmiFileName
- * a file name for an XMI file
- */
- public static void loadJCas(JCas jCas, String xmiFileName) throws IOException {
- loadJCas(jCas, xmiFileName, true);
- }
-
- /**
- * This method takes a JCas, resets it, and loads it with the contents of an XMI or XCAS file
- *
- * @param xmlFileName
- * a file name for an XML file containing XMI or XCAS content.
- * @param isXmi
- * if true, than assume XMI format. Otherwise, assume XCAS.
- */
- public static void loadJCas(JCas jCas, String xmlFileName, boolean isXmi) throws IOException {
- FileInputStream inputStream = new FileInputStream(xmlFileName);
- loadJCas(jCas, inputStream, isXmi);
- }
-
- /**
- * This method passes through to {@link #loadJCas(JCas, InputStream, boolean)}
- */
- public static void loadJCas(JCas jCas, InputStream xmiInputStream) throws IOException {
- loadJCas(jCas, xmiInputStream, true);
- }
-
- /**
- * This method takes a JCas, resets it, and loads it with the contents of an XMI or XCAS input
- * stream
- *
- * @param xmlInputStream
- * should contain the contents of a serialized CAS in the form of XMI or XCAS XML
- * @param isXmi
- * if true, than assume XMI format. Otherwise, assume XCAS.
- */
- public static void loadJCas(JCas jCas, InputStream xmlInputStream, boolean isXmi)
- throws IOException {
- jCas.reset();
- try {
- CAS cas = jCas.getCas();
- if (isXmi) {
- XmiCasDeserializer.deserialize(xmlInputStream, cas);
- }
- else {
- XCASDeserializer.deserialize(xmlInputStream, cas);
- }
- }
- catch (SAXException e) {
- IOException ioe = new IOException(e.getMessage());
- ioe.initCause(e);
- throw ioe; // NOPMD
- // If we were using Java 1.6 and add the wrapped exception to the IOException
- // constructor, we would not get a warning here
- }
- finally {
- IOUtils.closeQuietly(xmlInputStream);
- }
- }
+ private JCasFactory() {
+ // This class is not meant to be instantiated
+ }
+
+ /**
+ * Creates a new JCas for the automatically derived type system. See
+ * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}
+ */
+ public static JCas createJCas() throws UIMAException {
+ return CasCreationUtils.createCas(createTypeSystemDescription(), null, null).getJCas();
+
+ }
+
+ /**
+ * Creates a new JCas from type system descriptor files found by name
+ */
+ public static JCas createJCas(String... typeSystemDescriptorNames) throws UIMAException {
+ return CasCreationUtils.createCas(createTypeSystemDescription(typeSystemDescriptorNames), null,
+ null).getJCas();
+ }
+
+ /**
+ * Creates a new JCas from type system descriptor files.
+ *
+ * @param typeSystemDescriptorPaths
+ * paths to type system descriptor files
+ */
+ public static JCas createJCasFromPath(String... typeSystemDescriptorPaths) throws UIMAException {
+ return createJCas(createTypeSystemDescriptionFromPath(typeSystemDescriptorPaths));
+ }
+
+ /**
+ * Create a new JCas with a new type system defined by the classes provided
+ *
+ * @param typeSystemClasses
+ * should be classes generated by JCasGen
+ *
+ * @deprecated This is not the method you want to use. If you declare only one type per XML type
+ * descriptor, you'll end up with LOTS of these. Use
+ * {@link TypeSystemDescriptionFactory#createTypeSystemDescription(String...)} or
+ * automatic type system detection with
+ * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}.
+ */
+ @Deprecated
+ public static JCas createJCas(Class<?>... typeSystemClasses) throws UIMAException {
+ return createJCas(createTypeSystemDescription(typeSystemClasses));
+ }
+
+ /**
+ * Create a new JCas for the given type system description
+ */
+ public static JCas createJCas(TypeSystemDescription typeSystemDescription) throws UIMAException {
+ return CasCreationUtils.createCas(typeSystemDescription, null, null).getJCas();
+ }
+
+ /**
+ * This method creates a new JCas and loads the contents of an XMI file into it.
+ *
+ * @param xmiFileName
+ * a file name for an XMI file.
+ */
+ public static JCas createJCas(String xmiFileName, TypeSystemDescription typeSystemDescription)
+ throws UIMAException, IOException {
+ return createJCas(xmiFileName, typeSystemDescription, true);
+ }
+
+ /**
+ * This method creates a new JCas and loads the contents of an XMI or XCAS file into it.
+ *
+ * @param xmlFileName
+ * a file name for an XML file containing XMI or XCAS content.
+ * @param isXmi
+ * if true, than assume XMI format. Otherwise, assume XCAS.
+ */
+ public static JCas createJCas(String xmlFileName, TypeSystemDescription typeSystemDescription,
+ boolean isXmi) throws UIMAException, IOException {
+ JCas jCas = createJCas(typeSystemDescription);
+ loadJCas(jCas, xmlFileName, isXmi);
+ return jCas;
+ }
+
+ /**
+ * This method passes through to {@link #loadJCas(JCas, String, boolean)}
+ *
+ * @param xmiFileName
+ * a file name for an XMI file
+ */
+ public static void loadJCas(JCas jCas, String xmiFileName) throws IOException {
+ loadJCas(jCas, xmiFileName, true);
+ }
+
+ /**
+ * This method takes a JCas, resets it, and loads it with the contents of an XMI or XCAS file
+ *
+ * @param xmlFileName
+ * a file name for an XML file containing XMI or XCAS content.
+ * @param isXmi
+ * if true, than assume XMI format. Otherwise, assume XCAS.
+ */
+ public static void loadJCas(JCas jCas, String xmlFileName, boolean isXmi) throws IOException {
+ FileInputStream inputStream = new FileInputStream(xmlFileName);
+ loadJCas(jCas, inputStream, isXmi);
+ }
+
+ /**
+ * This method passes through to {@link #loadJCas(JCas, InputStream, boolean)}
+ */
+ public static void loadJCas(JCas jCas, InputStream xmiInputStream) throws IOException {
+ loadJCas(jCas, xmiInputStream, true);
+ }
+
+ /**
+ * This method takes a JCas, resets it, and loads it with the contents of an XMI or XCAS input
+ * stream
+ *
+ * @param xmlInputStream
+ * should contain the contents of a serialized CAS in the form of XMI or XCAS XML
+ * @param isXmi
+ * if true, than assume XMI format. Otherwise, assume XCAS.
+ */
+ public static void loadJCas(JCas jCas, InputStream xmlInputStream, boolean isXmi)
+ throws IOException {
+ jCas.reset();
+ try {
+ CAS cas = jCas.getCas();
+ if (isXmi) {
+ XmiCasDeserializer.deserialize(xmlInputStream, cas);
+ } else {
+ XCASDeserializer.deserialize(xmlInputStream, cas);
+ }
+ } catch (SAXException e) {
+ IOException ioe = new IOException(e.getMessage());
+ ioe.initCause(e);
+ throw ioe; // NOPMD
+ // If we were using Java 1.6 and add the wrapped exception to the IOException
+ // constructor, we would not get a warning here
+ } finally {
+ IOUtils.closeQuietly(xmlInputStream);
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactory.java Thu Jan 10 23:12:33 2013
@@ -34,132 +34,130 @@ import org.apache.uima.util.XMLParser;
/**
*/
public final class ResourceCreationSpecifierFactory {
- private ResourceCreationSpecifierFactory() {
- // This class is not meant to be instantiated
- }
-
- /**
- * Parse a ResourceCreationSpecifier from the URL of an XML descriptor file, setting additional
- * configuration parameters as necessary.
- *
- * @param descriptorURL
- * The URL of the XML descriptor file.
- * @param parameters
- * Any additional configuration parameters to be set. These should be supplied as
- * (name, value) pairs, so there should always be an even number of parameters.
- * @return The ResourceCreationSpecifier for the XML descriptor with all the configuration
- * parameters set.
- */
- public static ResourceCreationSpecifier createResourceCreationSpecifier(URL descriptorURL,
- Object[] parameters) throws UIMAException, IOException {
- return createResourceCreationSpecifier(new XMLInputSource(descriptorURL), parameters);
- }
-
- /**
- * Parse a ResourceCreationSpecifier from XML descriptor file input, setting additional
- * configuration parameters as necessary.
- *
- * @param xmlInput
- * The descriptor file as an XMLInputSource.
- * @param parameters
- * Any additional configuration parameters to be set. These should be supplied as
- * (name, value) pairs, so there should always be an even number of parameters.
- * @return The ResourceCreationSpecifier for the XML descriptor with all the configuration
- * parameters set.
- */
- public static ResourceCreationSpecifier createResourceCreationSpecifier(
- XMLInputSource xmlInput, Object[] parameters) throws UIMAException, IOException {
- ConfigurationParameterFactory.ensureParametersComeInPairs(parameters);
-
- ResourceCreationSpecifier specifier;
- XMLParser parser = UIMAFramework.getXMLParser();
- specifier = (ResourceCreationSpecifier) parser.parseResourceSpecifier(xmlInput);
- setConfigurationParameters(specifier, parameters);
-
- return specifier;
- }
-
- /**
- * Parse a ResourceCreationSpecifier from an XML descriptor file, setting additional
- * configuration parameters as necessary.
- *
- * @param descriptorPath
- * The path to the XML descriptor file.
- * @param parameters
- * Any additional configuration parameters to be set. These should be supplied as
- * (name, value) pairs, so there should always be an even number of parameters.
- * @return The ResourceCreationSpecifier for the XML descriptor with all the configuration
- * parameters set.
- */
- public static ResourceCreationSpecifier createResourceCreationSpecifier(String descriptorPath,
- Object[] parameters) throws UIMAException, IOException {
- return createResourceCreationSpecifier(new XMLInputSource(descriptorPath), parameters);
- }
-
- /**
- * Create configuration parameter declarations and settings from a list of (name, value) pairs.
- *
- * @param specifier
- * The ResourceCreationSpecifier whose parameters are to be set.
- * @param configurationData
- * The configuration parameters to be set. These should be supplied as (name, value)
- * pairs, so there should always be an even number of parameters.
- */
- public static void setConfigurationParameters(ResourceCreationSpecifier specifier,
- Object... configurationData) {
- if (configurationData == null || configurationData.length == 0) {
- return;
- }
-
- ConfigurationParameterFactory.ensureParametersComeInPairs(configurationData);
-
- ConfigurationParameter[] configurationParameters = new ConfigurationParameter[configurationData.length / 2];
- Object[] configurationValues = new Object[configurationData.length / 2];
-
- for (int i = 0; i < configurationValues.length; i++) {
- String name = (String) configurationData[i * 2];
- Object value = configurationData[i * 2 + 1];
- ConfigurationParameter param = ConfigurationParameterFactory.createPrimitiveParameter(
- name, value.getClass(), null, false);
- configurationParameters[i] = param;
- configurationValues[i] = ConfigurationParameterFactory.convertParameterValue(param, value);
- }
- setConfigurationParameters(specifier, configurationParameters, configurationValues);
- }
-
- /**
- * This method passes through to
- * {@link #setConfigurationParameters(ResourceMetaData, ConfigurationParameter[], Object[])}
- */
- public static void setConfigurationParameters(ResourceCreationSpecifier specifier,
- ConfigurationParameter[] configurationParameters, Object[] configurationValues) {
- setConfigurationParameters(specifier.getMetaData(), configurationParameters,
- configurationValues);
- }
-
- /**
- * This method sets the configuration parameters of a resource. The length of
- * configurationParameters and configurationValues should be equal
- *
- * @param configurationParameters
- * an array of configuration parameters
- * @param configurationValues
- * an array of configuration parameter values
- */
- public static void setConfigurationParameters(ResourceMetaData metaData,
- ConfigurationParameter[] configurationParameters, Object[] configurationValues) {
- ConfigurationParameterDeclarations paramDecls = metaData
- .getConfigurationParameterDeclarations();
- ConfigurationParameterSettings paramSettings = metaData.getConfigurationParameterSettings();
- for (int i = 0; i < configurationParameters.length; i++) {
- if (paramDecls != null
- && paramDecls.getConfigurationParameter(null,
- configurationParameters[i].getName()) == null) {
- paramDecls.addConfigurationParameter(configurationParameters[i]);
- }
- paramSettings.setParameterValue(configurationParameters[i].getName(),
- configurationValues[i]);
- }
- }
+ private ResourceCreationSpecifierFactory() {
+ // This class is not meant to be instantiated
+ }
+
+ /**
+ * Parse a ResourceCreationSpecifier from the URL of an XML descriptor file, setting additional
+ * configuration parameters as necessary.
+ *
+ * @param descriptorURL
+ * The URL of the XML descriptor file.
+ * @param parameters
+ * Any additional configuration parameters to be set. These should be supplied as (name,
+ * value) pairs, so there should always be an even number of parameters.
+ * @return The ResourceCreationSpecifier for the XML descriptor with all the configuration
+ * parameters set.
+ */
+ public static ResourceCreationSpecifier createResourceCreationSpecifier(URL descriptorURL,
+ Object[] parameters) throws UIMAException, IOException {
+ return createResourceCreationSpecifier(new XMLInputSource(descriptorURL), parameters);
+ }
+
+ /**
+ * Parse a ResourceCreationSpecifier from XML descriptor file input, setting additional
+ * configuration parameters as necessary.
+ *
+ * @param xmlInput
+ * The descriptor file as an XMLInputSource.
+ * @param parameters
+ * Any additional configuration parameters to be set. These should be supplied as (name,
+ * value) pairs, so there should always be an even number of parameters.
+ * @return The ResourceCreationSpecifier for the XML descriptor with all the configuration
+ * parameters set.
+ */
+ public static ResourceCreationSpecifier createResourceCreationSpecifier(XMLInputSource xmlInput,
+ Object[] parameters) throws UIMAException, IOException {
+ ConfigurationParameterFactory.ensureParametersComeInPairs(parameters);
+
+ ResourceCreationSpecifier specifier;
+ XMLParser parser = UIMAFramework.getXMLParser();
+ specifier = (ResourceCreationSpecifier) parser.parseResourceSpecifier(xmlInput);
+ setConfigurationParameters(specifier, parameters);
+
+ return specifier;
+ }
+
+ /**
+ * Parse a ResourceCreationSpecifier from an XML descriptor file, setting additional configuration
+ * parameters as necessary.
+ *
+ * @param descriptorPath
+ * The path to the XML descriptor file.
+ * @param parameters
+ * Any additional configuration parameters to be set. These should be supplied as (name,
+ * value) pairs, so there should always be an even number of parameters.
+ * @return The ResourceCreationSpecifier for the XML descriptor with all the configuration
+ * parameters set.
+ */
+ public static ResourceCreationSpecifier createResourceCreationSpecifier(String descriptorPath,
+ Object[] parameters) throws UIMAException, IOException {
+ return createResourceCreationSpecifier(new XMLInputSource(descriptorPath), parameters);
+ }
+
+ /**
+ * Create configuration parameter declarations and settings from a list of (name, value) pairs.
+ *
+ * @param specifier
+ * The ResourceCreationSpecifier whose parameters are to be set.
+ * @param configurationData
+ * The configuration parameters to be set. These should be supplied as (name, value)
+ * pairs, so there should always be an even number of parameters.
+ */
+ public static void setConfigurationParameters(ResourceCreationSpecifier specifier,
+ Object... configurationData) {
+ if (configurationData == null || configurationData.length == 0) {
+ return;
+ }
+
+ ConfigurationParameterFactory.ensureParametersComeInPairs(configurationData);
+
+ ConfigurationParameter[] configurationParameters = new ConfigurationParameter[configurationData.length / 2];
+ Object[] configurationValues = new Object[configurationData.length / 2];
+
+ for (int i = 0; i < configurationValues.length; i++) {
+ String name = (String) configurationData[i * 2];
+ Object value = configurationData[i * 2 + 1];
+ ConfigurationParameter param = ConfigurationParameterFactory.createPrimitiveParameter(name,
+ value.getClass(), null, false);
+ configurationParameters[i] = param;
+ configurationValues[i] = ConfigurationParameterFactory.convertParameterValue(param, value);
+ }
+ setConfigurationParameters(specifier, configurationParameters, configurationValues);
+ }
+
+ /**
+ * This method passes through to
+ * {@link #setConfigurationParameters(ResourceMetaData, ConfigurationParameter[], Object[])}
+ */
+ public static void setConfigurationParameters(ResourceCreationSpecifier specifier,
+ ConfigurationParameter[] configurationParameters, Object[] configurationValues) {
+ setConfigurationParameters(specifier.getMetaData(), configurationParameters,
+ configurationValues);
+ }
+
+ /**
+ * This method sets the configuration parameters of a resource. The length of
+ * configurationParameters and configurationValues should be equal
+ *
+ * @param configurationParameters
+ * an array of configuration parameters
+ * @param configurationValues
+ * an array of configuration parameter values
+ */
+ public static void setConfigurationParameters(ResourceMetaData metaData,
+ ConfigurationParameter[] configurationParameters, Object[] configurationValues) {
+ ConfigurationParameterDeclarations paramDecls = metaData
+ .getConfigurationParameterDeclarations();
+ ConfigurationParameterSettings paramSettings = metaData.getConfigurationParameterSettings();
+ for (int i = 0; i < configurationParameters.length; i++) {
+ if (paramDecls != null
+ && paramDecls.getConfigurationParameter(null, configurationParameters[i].getName()) == null) {
+ paramDecls.addConfigurationParameter(configurationParameters[i]);
+ }
+ paramSettings.setParameterValue(configurationParameters[i].getName(), configurationValues[i]);
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/SofaMappingFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/SofaMappingFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/SofaMappingFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/SofaMappingFactory.java Thu Jan 10 23:12:33 2013
@@ -25,45 +25,45 @@ import org.apache.uima.analysis_engine.m
/**
*/
public final class SofaMappingFactory {
- private SofaMappingFactory() {
- // This class is not meant to be instantiated
- }
+ private SofaMappingFactory() {
+ // This class is not meant to be instantiated
+ }
- /**
- * This method creates a sofa mapping which is useful for mapping view names in individual
- * components used in aggregate analysis engines to the view names used by the aggregate.
- *
- * WARNING: in version 0.9.12 the ordering of the parameters was changed! The order used to be
- * aggregateSofaName, componentKey, componentSofaName. This was changed because it seemed an
- * unnatural ordering.
- *
- * @param componentKey
- * the key/name used by the aggregate analysis engine for the component whose view is
- * being mapped.
- * @param componentSofaName
- * the sofa name used by the the component
- * @param aggregateSofaName
- * the view name that the component name is mapped to and used by the aggregate
- * analysis engine
- * @return a sofa mapping with the componentSofaName mapped to the aggregateSofaName
- */
- public static SofaMapping createSofaMapping(String componentKey, String componentSofaName,
- String aggregateSofaName) {
+ /**
+ * This method creates a sofa mapping which is useful for mapping view names in individual
+ * components used in aggregate analysis engines to the view names used by the aggregate.
+ *
+ * WARNING: in version 0.9.12 the ordering of the parameters was changed! The order used to be
+ * aggregateSofaName, componentKey, componentSofaName. This was changed because it seemed an
+ * unnatural ordering.
+ *
+ * @param componentKey
+ * the key/name used by the aggregate analysis engine for the component whose view is
+ * being mapped.
+ * @param componentSofaName
+ * the sofa name used by the the component
+ * @param aggregateSofaName
+ * the view name that the component name is mapped to and used by the aggregate analysis
+ * engine
+ * @return a sofa mapping with the componentSofaName mapped to the aggregateSofaName
+ */
+ public static SofaMapping createSofaMapping(String componentKey, String componentSofaName,
+ String aggregateSofaName) {
- SofaMapping sofaMapping = new SofaMapping_impl();
- sofaMapping.setComponentKey(componentKey);
- sofaMapping.setComponentSofaName(componentSofaName);
- sofaMapping.setAggregateSofaName(aggregateSofaName);
- return sofaMapping;
- }
+ SofaMapping sofaMapping = new SofaMapping_impl();
+ sofaMapping.setComponentKey(componentKey);
+ sofaMapping.setComponentSofaName(componentSofaName);
+ sofaMapping.setAggregateSofaName(aggregateSofaName);
+ return sofaMapping;
+ }
- /**
- * create a sofa mapping using the component class rather than the component name
- */
- public static SofaMapping createSofaMapping(Class<? extends AnalysisComponent> componentClass,
- String componentSofaName, String aggregateSofaName) {
+ /**
+ * create a sofa mapping using the component class rather than the component name
+ */
+ public static SofaMapping createSofaMapping(Class<? extends AnalysisComponent> componentClass,
+ String componentSofaName, String aggregateSofaName) {
- return createSofaMapping(componentClass.getName(), componentSofaName, aggregateSofaName);
- }
+ return createSofaMapping(componentClass.getName(), componentSofaName, aggregateSofaName);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypePrioritiesFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypePrioritiesFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypePrioritiesFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypePrioritiesFactory.java Thu Jan 10 23:12:33 2013
@@ -18,51 +18,51 @@
*/
package org.apache.uima.fit.factory;
+import static org.apache.uima.fit.util.CasUtil.UIMA_BUILTIN_JCAS_PREFIX;
+
import org.apache.uima.resource.metadata.TypePriorities;
import org.apache.uima.resource.metadata.TypePriorityList;
import org.apache.uima.resource.metadata.impl.TypePriorities_impl;
-import static org.apache.uima.fit.util.CasUtil.UIMA_BUILTIN_JCAS_PREFIX;
-
/**
*/
public final class TypePrioritiesFactory {
- private TypePrioritiesFactory() {
- // This class is not meant to be instantiated
- }
-
- /**
- * Create a TypePriorities given a sequence of ordered type classes
- *
- * @param prioritizedTypes
- * a sequence of ordered type classes
- */
- public static TypePriorities createTypePriorities(Class<?>... prioritizedTypes) {
- String[] typeNames = new String[prioritizedTypes.length];
- for (int i = 0; i < prioritizedTypes.length; i++) {
- String typeName = prioritizedTypes[i].getName();
- if (typeName.startsWith(UIMA_BUILTIN_JCAS_PREFIX)) {
- typeName = "uima." + typeName.substring(UIMA_BUILTIN_JCAS_PREFIX.length());
- }
-
- typeNames[i] = typeName;
- }
- return createTypePriorities(typeNames);
- }
-
- /**
- * Create a TypePriorities given a sequence of ordered type names
- *
- * @param prioritizedTypeNames
- * a sequence of ordered type names
- */
- public static TypePriorities createTypePriorities(String... prioritizedTypeNames) {
- TypePriorities typePriorities = new TypePriorities_impl();
- TypePriorityList typePriorityList = typePriorities.addPriorityList();
- for (String typeName : prioritizedTypeNames) {
- typePriorityList.addType(typeName);
- }
- return typePriorities;
- }
+ private TypePrioritiesFactory() {
+ // This class is not meant to be instantiated
+ }
+
+ /**
+ * Create a TypePriorities given a sequence of ordered type classes
+ *
+ * @param prioritizedTypes
+ * a sequence of ordered type classes
+ */
+ public static TypePriorities createTypePriorities(Class<?>... prioritizedTypes) {
+ String[] typeNames = new String[prioritizedTypes.length];
+ for (int i = 0; i < prioritizedTypes.length; i++) {
+ String typeName = prioritizedTypes[i].getName();
+ if (typeName.startsWith(UIMA_BUILTIN_JCAS_PREFIX)) {
+ typeName = "uima." + typeName.substring(UIMA_BUILTIN_JCAS_PREFIX.length());
+ }
+
+ typeNames[i] = typeName;
+ }
+ return createTypePriorities(typeNames);
+ }
+
+ /**
+ * Create a TypePriorities given a sequence of ordered type names
+ *
+ * @param prioritizedTypeNames
+ * a sequence of ordered type names
+ */
+ public static TypePriorities createTypePriorities(String... prioritizedTypeNames) {
+ TypePriorities typePriorities = new TypePriorities_impl();
+ TypePriorityList typePriorityList = typePriorities.addPriorityList();
+ for (String typeName : prioritizedTypeNames) {
+ typePriorityList.addType(typeName);
+ }
+ return typePriorities;
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactory.java Thu Jan 10 23:12:33 2013
@@ -20,6 +20,7 @@ package org.apache.uima.fit.factory;
import static org.apache.uima.UIMAFramework.getXMLParser;
import static org.apache.uima.util.CasCreationUtils.mergeTypeSystems;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -45,207 +46,202 @@ import org.springframework.core.io.suppo
/**
*/
public final class TypeSystemDescriptionFactory {
- private TypeSystemDescriptionFactory() {
- // This class is not meant to be instantiated
- }
-
- /**
- * System property indicating which locations to scan for type descriptions. A list of locations
- * may be given separated by ";".
- */
- public static final String TYPE_IMPORT_PATTERN = "org.apache.uima.fit.type.import_pattern";
-
- /**
- * Type manifest location.
- */
- public static final String TYPE_MANIFEST_PATTERN = "classpath*:META-INF/org.uimafit/types.txt";
-
- private static String[] typeDescriptorLocations;
-
- /**
- * Creates a TypeSystemDescription from a list of classes belonging to a type system - i.e.
- * classes generated by JCasGen. It is expected that for each of the classes passed to this
- * method, an XML type description exists with the same name as the class and in the same
- * package. It is further expected, that each of these type system descriptors declares
- * a single type, for which a JCas wrapper class has been generated, which has been passed to
- * this method.
- *
- * @param typeSystemClasses
- * The type system class objects. Should be classes generated by JCasGen.
- * @return A TypeSystemDescription that includes all of the specified Annotation types.
- * @deprecated This is not the method you want to use. If you declare only one type per
- * XML type descriptor, you'll end up with LOTS of these. Use {@link
- * #createTypeSystemDescription(String...)} or automatic type system detection with
- * {@link #createTypeSystemDescription()}.
- */
- @Deprecated
- public static TypeSystemDescription createTypeSystemDescription(Class<?>... typeSystemClasses) {
- TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
- List<Import> imports = new ArrayList<Import>();
- for (Class<?> typeSystemClass : typeSystemClasses) {
- Import imprt = new Import_impl();
- imprt.setName(typeSystemClass.getName());
- imports.add(imprt);
- }
- Import[] importArray = new Import[imports.size()];
- typeSystem.setImports(imports.toArray(importArray));
- return typeSystem;
- }
-
- /**
- * Creates a TypeSystemDescription from descriptor names.
- *
- * @param descriptorNames
- * The fully qualified, Java-style, dotted descriptor names.
- * @return A TypeSystemDescription that includes the types from all of the specified files.
- */
- public static TypeSystemDescription createTypeSystemDescription(String... descriptorNames) {
- TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
- List<Import> imports = new ArrayList<Import>();
- for (String descriptorName : descriptorNames) {
- Import imp = new Import_impl();
- imp.setName(descriptorName);
- imports.add(imp);
- }
- Import[] importArray = new Import[imports.size()];
- typeSystem.setImports(imports.toArray(importArray));
- return typeSystem;
- }
-
- /**
- * Creates a TypeSystemDescription from a descriptor file
- *
- * @param descriptorURIs
- * The descriptor file paths.
- * @return A TypeSystemDescription that includes the types from all of the specified files.
- */
- public static TypeSystemDescription createTypeSystemDescriptionFromPath(
- String... descriptorURIs) {
- TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
- List<Import> imports = new ArrayList<Import>();
- for (String descriptorURI : descriptorURIs) {
- Import imp = new Import_impl();
- imp.setLocation(descriptorURI);
- imports.add(imp);
- }
- Import[] importArray = new Import[imports.size()];
- typeSystem.setImports(imports.toArray(importArray));
- return typeSystem;
- }
-
- /**
- * Creates a {@link TypeSystemDescription} from all type descriptions that can be found via the
- * {@link #TYPE_IMPORT_PATTERN} or via the {@code META-INF/org.uimafit/types.txt} files in the
- * classpath.
- *
- * @return the auto-scanned type system.
- */
- public static TypeSystemDescription createTypeSystemDescription()
- throws ResourceInitializationException {
- List<TypeSystemDescription> tsdList = new ArrayList<TypeSystemDescription>();
- for (String location : scanTypeDescriptors()) {
- try {
- XMLInputSource xmlInputType1 = new XMLInputSource(location);
- tsdList.add(getXMLParser().parseTypeSystemDescription(xmlInputType1));
- LogFactory.getLog(TypeSystemDescription.class).debug(
- "Detected type system at [" + location + "]");
- }
- catch (IOException e) {
- throw new ResourceInitializationException(e);
- }
- catch (InvalidXMLException e) {
- LogFactory.getLog(TypeSystemDescription.class).warn(
- "[" + location + "] is not a type file. Ignoring.", e);
- }
- }
-
- return mergeTypeSystems(tsdList);
- }
-
- /**
- * Get all currently accessible type system descriptor locations. A scan is actually only
- * performed on the first call and the locations are cached. To force a re-scan use
- * {@link #forceTypeDescriptorsScan()}.
- *
- * @return an array of locations.
- * @throws ResourceInitializationException
- * if the locations could not be resolved.
- */
- public static String[] scanTypeDescriptors() throws ResourceInitializationException {
- if (typeDescriptorLocations == null) {
- typeDescriptorLocations = resolve(scanImportsAndManifests(TYPE_MANIFEST_PATTERN,
- TYPE_IMPORT_PATTERN));
- }
- return typeDescriptorLocations;
- }
-
- /**
- * Force rescan of type descriptors. The next call to {@link #scanTypeDescriptors()} will rescan
- * all auto-import locations.
- */
- public static void forceTypeDescriptorsScan() {
- typeDescriptorLocations = null;
- }
-
- /**
- * Scan patterns from manifest files and from the specified system property.
- *
- * @param manifestPatterns pattern matching the manifest files.
- * @param importProperty system property containing additional patterns.
- * @return array or all patterns found.
- */
- public static String[] scanImportsAndManifests(String manifestPatterns, String importProperty)
- throws ResourceInitializationException {
- ArrayList<String> patterns = new ArrayList<String>();
-
- // Scan auto-import locations
- patterns.addAll(Arrays.asList(System.getProperty(importProperty, "").split(";")));
-
- // Scan manifest
- for (String mfUrl : resolve(manifestPatterns)) {
- InputStream is = null;
- try {
- is = new URL(mfUrl).openStream();
- @SuppressWarnings("unchecked")
- List<? extends String> lines = IOUtils.readLines(is);
- patterns.addAll(lines);
- }
- catch (IOException e) {
- throw new ResourceInitializationException(e);
- }
- finally {
- IOUtils.closeQuietly(is);
- }
- }
-
- return patterns.toArray(new String[patterns.size()]);
- }
-
- /**
- * Resolve a list of patterns to a set of URLs.
- *
- * @return an array of locations.
- * @throws ResourceInitializationException
- * if the locations could not be resolved.
- */
- public static String[] resolve(String... patterns) throws ResourceInitializationException {
- Set<String> locations = new HashSet<String>();
- PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
- try {
- // Scan auto-import locations. Using a set to avoid scanning a pattern twice.
- for (String pattern : new TreeSet<String>(Arrays.asList(patterns))) {
- String p = pattern.trim();
- if (p.length() == 0) {
- continue;
- }
- for (Resource r : resolver.getResources(pattern)) {
- locations.add(r.getURL().toString());
- }
- }
- return locations.toArray(new String[locations.size()]);
- }
- catch (IOException e) {
- throw new ResourceInitializationException(e);
- }
- }
+ private TypeSystemDescriptionFactory() {
+ // This class is not meant to be instantiated
+ }
+
+ /**
+ * System property indicating which locations to scan for type descriptions. A list of locations
+ * may be given separated by ";".
+ */
+ public static final String TYPE_IMPORT_PATTERN = "org.apache.uima.fit.type.import_pattern";
+
+ /**
+ * Type manifest location.
+ */
+ public static final String TYPE_MANIFEST_PATTERN = "classpath*:META-INF/org.uimafit/types.txt";
+
+ private static String[] typeDescriptorLocations;
+
+ /**
+ * Creates a TypeSystemDescription from a list of classes belonging to a type system - i.e.
+ * classes generated by JCasGen. It is expected that for each of the classes passed to this
+ * method, an XML type description exists with the same name as the class and in the same package.
+ * It is further expected, that each of these type system descriptors declares a single type, for
+ * which a JCas wrapper class has been generated, which has been passed to this method.
+ *
+ * @param typeSystemClasses
+ * The type system class objects. Should be classes generated by JCasGen.
+ * @return A TypeSystemDescription that includes all of the specified Annotation types.
+ * @deprecated This is not the method you want to use. If you declare only one type per XML type
+ * descriptor, you'll end up with LOTS of these. Use
+ * {@link #createTypeSystemDescription(String...)} or automatic type system detection
+ * with {@link #createTypeSystemDescription()}.
+ */
+ @Deprecated
+ public static TypeSystemDescription createTypeSystemDescription(Class<?>... typeSystemClasses) {
+ TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
+ List<Import> imports = new ArrayList<Import>();
+ for (Class<?> typeSystemClass : typeSystemClasses) {
+ Import imprt = new Import_impl();
+ imprt.setName(typeSystemClass.getName());
+ imports.add(imprt);
+ }
+ Import[] importArray = new Import[imports.size()];
+ typeSystem.setImports(imports.toArray(importArray));
+ return typeSystem;
+ }
+
+ /**
+ * Creates a TypeSystemDescription from descriptor names.
+ *
+ * @param descriptorNames
+ * The fully qualified, Java-style, dotted descriptor names.
+ * @return A TypeSystemDescription that includes the types from all of the specified files.
+ */
+ public static TypeSystemDescription createTypeSystemDescription(String... descriptorNames) {
+ TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
+ List<Import> imports = new ArrayList<Import>();
+ for (String descriptorName : descriptorNames) {
+ Import imp = new Import_impl();
+ imp.setName(descriptorName);
+ imports.add(imp);
+ }
+ Import[] importArray = new Import[imports.size()];
+ typeSystem.setImports(imports.toArray(importArray));
+ return typeSystem;
+ }
+
+ /**
+ * Creates a TypeSystemDescription from a descriptor file
+ *
+ * @param descriptorURIs
+ * The descriptor file paths.
+ * @return A TypeSystemDescription that includes the types from all of the specified files.
+ */
+ public static TypeSystemDescription createTypeSystemDescriptionFromPath(String... descriptorURIs) {
+ TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
+ List<Import> imports = new ArrayList<Import>();
+ for (String descriptorURI : descriptorURIs) {
+ Import imp = new Import_impl();
+ imp.setLocation(descriptorURI);
+ imports.add(imp);
+ }
+ Import[] importArray = new Import[imports.size()];
+ typeSystem.setImports(imports.toArray(importArray));
+ return typeSystem;
+ }
+
+ /**
+ * Creates a {@link TypeSystemDescription} from all type descriptions that can be found via the
+ * {@link #TYPE_IMPORT_PATTERN} or via the {@code META-INF/org.uimafit/types.txt} files in the
+ * classpath.
+ *
+ * @return the auto-scanned type system.
+ */
+ public static TypeSystemDescription createTypeSystemDescription()
+ throws ResourceInitializationException {
+ List<TypeSystemDescription> tsdList = new ArrayList<TypeSystemDescription>();
+ for (String location : scanTypeDescriptors()) {
+ try {
+ XMLInputSource xmlInputType1 = new XMLInputSource(location);
+ tsdList.add(getXMLParser().parseTypeSystemDescription(xmlInputType1));
+ LogFactory.getLog(TypeSystemDescription.class).debug(
+ "Detected type system at [" + location + "]");
+ } catch (IOException e) {
+ throw new ResourceInitializationException(e);
+ } catch (InvalidXMLException e) {
+ LogFactory.getLog(TypeSystemDescription.class).warn(
+ "[" + location + "] is not a type file. Ignoring.", e);
+ }
+ }
+
+ return mergeTypeSystems(tsdList);
+ }
+
+ /**
+ * Get all currently accessible type system descriptor locations. A scan is actually only
+ * performed on the first call and the locations are cached. To force a re-scan use
+ * {@link #forceTypeDescriptorsScan()}.
+ *
+ * @return an array of locations.
+ * @throws ResourceInitializationException
+ * if the locations could not be resolved.
+ */
+ public static String[] scanTypeDescriptors() throws ResourceInitializationException {
+ if (typeDescriptorLocations == null) {
+ typeDescriptorLocations = resolve(scanImportsAndManifests(TYPE_MANIFEST_PATTERN,
+ TYPE_IMPORT_PATTERN));
+ }
+ return typeDescriptorLocations;
+ }
+
+ /**
+ * Force rescan of type descriptors. The next call to {@link #scanTypeDescriptors()} will rescan
+ * all auto-import locations.
+ */
+ public static void forceTypeDescriptorsScan() {
+ typeDescriptorLocations = null;
+ }
+
+ /**
+ * Scan patterns from manifest files and from the specified system property.
+ *
+ * @param manifestPatterns
+ * pattern matching the manifest files.
+ * @param importProperty
+ * system property containing additional patterns.
+ * @return array or all patterns found.
+ */
+ public static String[] scanImportsAndManifests(String manifestPatterns, String importProperty)
+ throws ResourceInitializationException {
+ ArrayList<String> patterns = new ArrayList<String>();
+
+ // Scan auto-import locations
+ patterns.addAll(Arrays.asList(System.getProperty(importProperty, "").split(";")));
+
+ // Scan manifest
+ for (String mfUrl : resolve(manifestPatterns)) {
+ InputStream is = null;
+ try {
+ is = new URL(mfUrl).openStream();
+ @SuppressWarnings("unchecked")
+ List<? extends String> lines = IOUtils.readLines(is);
+ patterns.addAll(lines);
+ } catch (IOException e) {
+ throw new ResourceInitializationException(e);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ return patterns.toArray(new String[patterns.size()]);
+ }
+
+ /**
+ * Resolve a list of patterns to a set of URLs.
+ *
+ * @return an array of locations.
+ * @throws ResourceInitializationException
+ * if the locations could not be resolved.
+ */
+ public static String[] resolve(String... patterns) throws ResourceInitializationException {
+ Set<String> locations = new HashSet<String>();
+ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+ try {
+ // Scan auto-import locations. Using a set to avoid scanning a pattern twice.
+ for (String pattern : new TreeSet<String>(Arrays.asList(patterns))) {
+ String p = pattern.trim();
+ if (p.length() == 0) {
+ continue;
+ }
+ for (Resource r : resolver.getResources(pattern)) {
+ locations.add(r.getURL().toString());
+ }
+ }
+ return locations.toArray(new String[locations.size()]);
+ } catch (IOException e) {
+ throw new ResourceInitializationException(e);
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/UimaContextFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/UimaContextFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/UimaContextFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/UimaContextFactory.java Thu Jan 10 23:12:33 2013
@@ -26,24 +26,24 @@ import org.apache.uima.resource.Resource
/**
*/
public final class UimaContextFactory {
- private UimaContextFactory() {
- // This class is not meant to be instantiated
- }
+ private UimaContextFactory() {
+ // This class is not meant to be instantiated
+ }
- /**
- * Create a new UimaContext with the given configuration parameters set.
- *
- * @param configurationParameters
- * The parameters to be set.
- * @return The new UimaContext.
- * @throws ResourceInitializationException
- * If the context could not be created.
- */
- public static UimaContext createUimaContext(Object... configurationParameters)
- throws ResourceInitializationException {
- AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(NoOpAnnotator.class,
- null, configurationParameters);
- return engine.getUimaContext();
- }
+ /**
+ * Create a new UimaContext with the given configuration parameters set.
+ *
+ * @param configurationParameters
+ * The parameters to be set.
+ * @return The new UimaContext.
+ * @throws ResourceInitializationException
+ * If the context could not be created.
+ */
+ public static UimaContext createUimaContext(Object... configurationParameters)
+ throws ResourceInitializationException {
+ AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(NoOpAnnotator.class, null,
+ configurationParameters);
+ return engine.getUimaContext();
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/Initializable.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/Initializable.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/Initializable.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/Initializable.java Thu Jan 10 23:12:33 2013
@@ -33,7 +33,7 @@ import org.apache.uima.resource.Resource
* is instantiated, it is useful to provide it a {@code UimaContext} so that it can initialize
* itself based on configuration parameters.
* </p>
- *
+ *
* <p>
* As an example, consider the component {@link XWriter} which has a member variable of type
* {@link XWriterFileNamer} which is an interface that provides a way for {@code XWriter} to come up
@@ -48,13 +48,13 @@ import org.apache.uima.resource.Resource
* {@code XWriterFileNamer} does not have to implement {@code Initializable} if it has no need for
* the initialize method.
* </p>
- *
+ *
*/
public interface Initializable {
- /**
- * This method will be called automatically if the implementing class is instantiated with
- * InitializableFactory.
- */
- public void initialize(UimaContext context) throws ResourceInitializationException;
+ /**
+ * This method will be called automatically if the implementing class is instantiated with
+ * InitializableFactory.
+ */
+ public void initialize(UimaContext context) throws ResourceInitializationException;
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/InitializableFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/InitializableFactory.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/InitializableFactory.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/initializable/InitializableFactory.java Thu Jan 10 23:12:33 2013
@@ -23,55 +23,53 @@ import org.apache.uima.resource.Resource
/**
* Please see {@link Initializable} for a description of how this class is intended to be used.
- *
- *
+ *
+ *
* @see Initializable
*/
public final class InitializableFactory {
- private InitializableFactory() {
- // This class is not meant to be instantiated
- }
-
- /**
- * Provides a way to create an instance of T. If the class specified by className implements
- * Initializable, then the UimaContext provided here will be passed to its initialize method.
- */
- public static <T> T create(UimaContext context, String className, Class<T> superClass)
- throws ResourceInitializationException {
- Class<? extends T> cls = getClass(className, superClass);
- return create(context, cls);
- }
-
- public static <T> Class<? extends T> getClass(String className, Class<T> superClass)
- throws ResourceInitializationException {
- try {
- Class<? extends T> cls = Class.forName(className).asSubclass(superClass);
- return cls;
- }
- catch (Exception e) {
- throw new ResourceInitializationException(new IllegalStateException("classname = "
- + className + " superClass = " + superClass.getName(), e));
- }
- }
-
- public static <T> T create(UimaContext context, Class<? extends T> cls)
- throws ResourceInitializationException {
- T instance;
- try {
- instance = cls.newInstance();
- }
- catch (Exception e) {
- throw new ResourceInitializationException(e);
- }
- initialize(instance, context);
- return instance;
- }
-
- public static void initialize(Object object, UimaContext context)
- throws ResourceInitializationException {
- if (object instanceof Initializable) {
- ((Initializable) object).initialize(context);
- }
- }
+ private InitializableFactory() {
+ // This class is not meant to be instantiated
+ }
+
+ /**
+ * Provides a way to create an instance of T. If the class specified by className implements
+ * Initializable, then the UimaContext provided here will be passed to its initialize method.
+ */
+ public static <T> T create(UimaContext context, String className, Class<T> superClass)
+ throws ResourceInitializationException {
+ Class<? extends T> cls = getClass(className, superClass);
+ return create(context, cls);
+ }
+
+ public static <T> Class<? extends T> getClass(String className, Class<T> superClass)
+ throws ResourceInitializationException {
+ try {
+ Class<? extends T> cls = Class.forName(className).asSubclass(superClass);
+ return cls;
+ } catch (Exception e) {
+ throw new ResourceInitializationException(new IllegalStateException("classname = "
+ + className + " superClass = " + superClass.getName(), e));
+ }
+ }
+
+ public static <T> T create(UimaContext context, Class<? extends T> cls)
+ throws ResourceInitializationException {
+ T instance;
+ try {
+ instance = cls.newInstance();
+ } catch (Exception e) {
+ throw new ResourceInitializationException(e);
+ }
+ initialize(instance, context);
+ return instance;
+ }
+
+ public static void initialize(Object object, UimaContext context)
+ throws ResourceInitializationException {
+ if (object instanceof Initializable) {
+ ((Initializable) object).initialize(context);
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/locator/JndiResourceLocator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/locator/JndiResourceLocator.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/locator/JndiResourceLocator.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/locator/JndiResourceLocator.java Thu Jan 10 23:12:33 2013
@@ -31,34 +31,34 @@ import org.apache.uima.resource.Resource
/**
* Locate an object via JNDI.
- *
+ *
*/
public class JndiResourceLocator extends Resource_ImplBase implements ExternalResourceLocator {
- public static final String PARAM_NAME = "Name";
- @ConfigurationParameter(name = PARAM_NAME, mandatory = true)
- private String jndiName;
-
- private Object resource;
-
- @SuppressWarnings("rawtypes")
- @Override
- public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams)
- throws ResourceInitializationException {
- if (!super.initialize(aSpecifier, aAdditionalParams)) {
- return false;
- }
-
- try {
- InitialContext ctx = new InitialContext();
- resource = ctx.lookup(jndiName);
- }
- catch (NamingException e) {
- throw new ResourceInitializationException(e);
- }
- return true;
- }
-
- public Object getResource() {
- return resource;
- }
+ public static final String PARAM_NAME = "Name";
+
+ @ConfigurationParameter(name = PARAM_NAME, mandatory = true)
+ private String jndiName;
+
+ private Object resource;
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams)
+ throws ResourceInitializationException {
+ if (!super.initialize(aSpecifier, aAdditionalParams)) {
+ return false;
+ }
+
+ try {
+ InitialContext ctx = new InitialContext();
+ resource = ctx.lookup(jndiName);
+ } catch (NamingException e) {
+ throw new ResourceInitializationException(e);
+ }
+ return true;
+ }
+
+ public Object getResource() {
+ return resource;
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/package-info.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/package-info.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/package-info.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/factory/package-info.java Thu Jan 10 23:12:33 2013
@@ -20,3 +20,4 @@
* Factories to create different kinds of UIMA resource specifiers.
*/
package org.apache.uima.fit.factory;
+
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/pipeline/CpePipeline.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/pipeline/CpePipeline.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/pipeline/CpePipeline.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/pipeline/CpePipeline.java Thu Jan 10 23:12:33 2013
@@ -39,100 +39,91 @@ import org.xml.sax.SAXException;
/**
*/
public class CpePipeline {
- /**
- * Run the CollectionReader and AnalysisEngines as a multi-threaded pipeline.
- *
- * @param readerDesc
- * The CollectionReader that loads the documents into the CAS.
- * @param descs
- * Primitive AnalysisEngineDescriptions that process the CAS, in order. If you have a
- * mix of primitive and aggregate engines, then please create the AnalysisEngines
- * yourself and call the other runPipeline method.
- */
- public static void runPipeline(final CollectionReaderDescription readerDesc,
- final AnalysisEngineDescription... descs) throws UIMAException, SAXException,
- CpeDescriptorException, IOException {
- // Create AAE
- final AnalysisEngineDescription aaeDesc = createAggregateDescription(descs);
-
- CpeBuilder builder = new CpeBuilder();
- builder.setReader(readerDesc);
- builder.setAnalysisEngine(aaeDesc);
-
- StatusCallbackListenerImpl status = new StatusCallbackListenerImpl();
- CollectionProcessingEngine engine = builder.createCpe(status);
-
- engine.process();
- try {
- synchronized (status) {
- while (status.isProcessing) {
- status.wait();
- }
- }
- }
- catch (InterruptedException e) {
- // Do nothing
- }
-
- if (status.exceptions.size() > 0) {
- throw new AnalysisEngineProcessException(status.exceptions.get(0));
- }
- }
-
- private static class StatusCallbackListenerImpl
- implements StatusCallbackListener
- {
-
- private final List<Exception> exceptions = new ArrayList<Exception>();
- private boolean isProcessing = true;
-
- public void entityProcessComplete(CAS arg0, EntityProcessStatus arg1)
- {
- if (arg1.isException()) {
- for (Exception e : arg1.getExceptions()) {
- exceptions.add(e);
- }
- }
- }
-
- public void aborted()
- {
- synchronized (this) {
- if (isProcessing) {
- isProcessing = false;
- notify();
- }
- }
- }
-
- public void batchProcessComplete()
- {
- // Do nothing
- }
-
- public void collectionProcessComplete()
- {
- synchronized (this) {
- if (isProcessing) {
- isProcessing = false;
- notify();
- }
- }
- }
-
- public void initializationComplete()
- {
- // Do nothing
- }
-
- public void paused()
- {
- // Do nothing
- }
-
- public void resumed()
- {
- // Do nothing
- }
- }
+ /**
+ * Run the CollectionReader and AnalysisEngines as a multi-threaded pipeline.
+ *
+ * @param readerDesc
+ * The CollectionReader that loads the documents into the CAS.
+ * @param descs
+ * Primitive AnalysisEngineDescriptions that process the CAS, in order. If you have a mix
+ * of primitive and aggregate engines, then please create the AnalysisEngines yourself
+ * and call the other runPipeline method.
+ */
+ public static void runPipeline(final CollectionReaderDescription readerDesc,
+ final AnalysisEngineDescription... descs) throws UIMAException, SAXException,
+ CpeDescriptorException, IOException {
+ // Create AAE
+ final AnalysisEngineDescription aaeDesc = createAggregateDescription(descs);
+
+ CpeBuilder builder = new CpeBuilder();
+ builder.setReader(readerDesc);
+ builder.setAnalysisEngine(aaeDesc);
+
+ StatusCallbackListenerImpl status = new StatusCallbackListenerImpl();
+ CollectionProcessingEngine engine = builder.createCpe(status);
+
+ engine.process();
+ try {
+ synchronized (status) {
+ while (status.isProcessing) {
+ status.wait();
+ }
+ }
+ } catch (InterruptedException e) {
+ // Do nothing
+ }
+
+ if (status.exceptions.size() > 0) {
+ throw new AnalysisEngineProcessException(status.exceptions.get(0));
+ }
+ }
+
+ private static class StatusCallbackListenerImpl implements StatusCallbackListener {
+
+ private final List<Exception> exceptions = new ArrayList<Exception>();
+
+ private boolean isProcessing = true;
+
+ public void entityProcessComplete(CAS arg0, EntityProcessStatus arg1) {
+ if (arg1.isException()) {
+ for (Exception e : arg1.getExceptions()) {
+ exceptions.add(e);
+ }
+ }
+ }
+
+ public void aborted() {
+ synchronized (this) {
+ if (isProcessing) {
+ isProcessing = false;
+ notify();
+ }
+ }
+ }
+
+ public void batchProcessComplete() {
+ // Do nothing
+ }
+
+ public void collectionProcessComplete() {
+ synchronized (this) {
+ if (isProcessing) {
+ isProcessing = false;
+ notify();
+ }
+ }
+ }
+
+ public void initializationComplete() {
+ // Do nothing
+ }
+
+ public void paused() {
+ // Do nothing
+ }
+
+ public void resumed() {
+ // Do nothing
+ }
+ }
}