001 /*
002 Copyright (c) 2012, Regents of the University of Colorado
003 All rights reserved.
004
005 Redistribution and use in source and binary forms, with or without modification,
006 are permitted provided that the following conditions are met:
007
008 * Redistributions of source code must retain the above copyright notice, this
009 list of conditions and the following disclaimer.
010
011 * Redistributions in binary form must reproduce the above copyright notice,
012 this list of conditions and the following disclaimer in the documentation
013 and/or other materials provided with the distribution.
014
015 * Neither the name of the University of Colorado nor the names of its
016 contributors may be used to endorse or promote products derived from this
017 software without specific prior written permission.
018
019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
023 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030 package edu.ucdenver.ccp.nlp.biolemmatizer.uima;
031
032 import org.apache.uima.jcas.JCas;
033 import org.apache.uima.jcas.cas.FSArray;
034 import org.apache.uima.jcas.cas.StringArray;
035 import org.apache.uima.jcas.cas.TOP;
036
037 /**
038 * This class contains a few simple utility methods related to UIMA
039 *
040 * @author Colorado Computational Pharmacology, UC Denver; ccpsupport@ucdenver.edu
041 *
042 */
043 public class UimaUtil {
044
045 /**
046 * Adds a single feature structure to the input {@link FSArray}. IF the input {@link FSArray} is
047 * null, a new one is initialized
048 *
049 * @param fsArray
050 * @param featureStructureToAdd
051 * @param jcas
052 * @return a copy of the input {@link FSArray} with the input featureStructureToAdd added to it
053 */
054 public static FSArray addToFSArray(FSArray fsArray, TOP featureStructureToAdd, JCas jcas) {
055 FSArray fsArrayToReturn;
056 if (fsArray == null) {
057 fsArrayToReturn = new FSArray(jcas, 1);
058 } else {
059 fsArrayToReturn = new FSArray(jcas, fsArray.size() + 1);
060 for (int i = 0; i < fsArray.size(); i++) {
061 fsArrayToReturn.set(i, fsArray.get(i));
062 }
063 }
064
065 fsArrayToReturn.set(fsArrayToReturn.size() - 1, featureStructureToAdd);
066 return fsArrayToReturn;
067 }
068
069 /**
070 * Adds a single String to the input {@link StringArray}. If the input {@link StringArray} is
071 * null, a new one is initialized
072 *
073 * @param stringArray
074 * @param stringToAdd
075 * @param jcas
076 * @return a copy of the input {@link StringArray} with the input stringToAdd added to it
077 */
078 public static StringArray addToStringArray(StringArray stringArray, String stringToAdd, JCas jcas) {
079 StringArray stringArrayToReturn;
080 if (stringArray == null) {
081 stringArrayToReturn = new StringArray(jcas, 1);
082 } else {
083 stringArrayToReturn = new StringArray(jcas, stringArray.size() + 1);
084 for (int i = 0; i < stringArray.size(); i++) {
085 stringArrayToReturn.set(i, stringArray.get(i));
086 }
087 }
088
089 stringArrayToReturn.set(stringArrayToReturn.size() - 1, stringToAdd);
090 return stringArrayToReturn;
091 }
092
093 }