org.apache.uima.jcas.cas.StringList Java Examples

The following examples show how to use org.apache.uima.jcas.cas.StringList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DictionaryExtractor.java    From newsleak with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Annotate regex patterns (URLs, IPs, email addresses and Phone numbers)
 *
 * @param jcas
 *            the jcas
 * @param pattern
 *            the pattern
 * @param type
 *            the type
 * @return the array list
 */
public ArrayList<DictTerm> annotateRegex(JCas jcas, Pattern pattern, String type) {
	String docText = jcas.getDocumentText();
	ArrayList<DictTerm> regexMatches = new ArrayList<DictTerm>();
	Matcher matcher = pattern.matcher(docText);
	// Check all occurrences
	while (matcher.find()) {
		DictTerm dictTerm = new DictTerm(jcas);
		dictTerm.setBegin(matcher.start());
		dictTerm.setEnd(matcher.end());
		StringList typeList = new StringList(jcas);
		StringList baseFormList = new StringList(jcas);
		typeList = typeList.push(type);
		baseFormList = baseFormList.push(matcher.group());
		dictTerm.setDictType(typeList);
		dictTerm.setDictTerm(baseFormList);
		dictTerm.addToIndexes();
		regexMatches.add(dictTerm);
	}
	return regexMatches;
}
 
Example #2
Source File: DictionaryExtractor.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Annotate dict types.
 *
 * @param jcas
 *            the jcas
 * @param token
 *            the token to annotate
 */
public void annotateDictTypes(JCas jcas, Token token) {

	String tokenStem = dictTermExtractor.stem(token.getCoveredText()).toLowerCase();
	String tokenValue = token.getCoveredText().toLowerCase();

	boolean dictTermFound = false;
	StringList typeList = new StringList(jcas);
	StringList baseFormList = new StringList(jcas);

	for (String dictType : unigramDictionaries.keySet()) {
		HashMap<String, String> dict = unigramDictionaries.get(dictType);
		if (dict.containsKey(tokenStem)) {
			String baseForm = dict.get(tokenStem);
			if (tokenValue.startsWith(baseForm)) {
				typeList = typeList.push(dictType);
				baseFormList = baseFormList.push(baseForm);
				dictTermFound = true;
			}
		}
	}

	// add to cas index
	if (dictTermFound) {
		DictTerm dictTerm = new DictTerm(jcas);
		dictTerm.setBegin(token.getBegin());
		dictTerm.setEnd(token.getEnd());
		dictTerm.setDictType(typeList);
		dictTerm.setDictTerm(baseFormList);
		dictTerm.addToIndexes();
	}

}
 
Example #3
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static List<String> create(StringList aList) {
  List<String> data = new ArrayList<String>();
  StringList i = aList;
  while (i instanceof NonEmptyStringList) {
    NonEmptyStringList l = (NonEmptyStringList) i;
    data.add(l.getHead());
    i = l.getTail();
  }

  return asList(data.toArray(new String[data.size()]));
}
 
Example #4
Source File: JCasTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testStringListAPI() {
  StringList sl = new EmptyStringList(jcas);
  sl = sl.push("2");
  sl = sl.push("1");
  
  String[] sa = new String[2];
  int i = 0;
  for (String s : sl) {
    sa[i++] = s;
  }
  
  String[] expected = {"1",  "2"};
  assert(Arrays.equals(expected, sa));
}
 
Example #5
Source File: DictTerm.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
/** getter for dictType - gets Type of dictionary added
 * @generated
 * @return value of the feature 
 */
public StringList getDictType() {
  if (DictTerm_Type.featOkTst && ((DictTerm_Type)jcasType).casFeat_dictType == null)
    jcasType.jcas.throwFeatMissing("dictType", "uhh_lt.newsleak.types.DictTerm");
  return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((DictTerm_Type)jcasType).casFeatCode_dictType)));}
 
Example #6
Source File: DictTerm.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
/** setter for dictType - sets Type of dictionary added 
 * @generated
 * @param v value to set into the feature 
 */
public void setDictType(StringList v) {
  if (DictTerm_Type.featOkTst && ((DictTerm_Type)jcasType).casFeat_dictType == null)
    jcasType.jcas.throwFeatMissing("dictType", "uhh_lt.newsleak.types.DictTerm");
  jcasType.ll_cas.ll_setRefValue(addr, ((DictTerm_Type)jcasType).casFeatCode_dictType, jcasType.ll_cas.ll_getFSRef(v));}
 
Example #7
Source File: DictTerm.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
/** getter for dictTerm - gets Base word types from dictionary list
 * @generated
 * @return value of the feature 
 */
public StringList getDictTerm() {
  if (DictTerm_Type.featOkTst && ((DictTerm_Type)jcasType).casFeat_dictTerm == null)
    jcasType.jcas.throwFeatMissing("dictTerm", "uhh_lt.newsleak.types.DictTerm");
  return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((DictTerm_Type)jcasType).casFeatCode_dictTerm)));}
 
Example #8
Source File: DictTerm.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
/** setter for dictTerm - sets Base word types from dictionary list 
 * @generated
 * @param v value to set into the feature 
 */
public void setDictTerm(StringList v) {
  if (DictTerm_Type.featOkTst && ((DictTerm_Type)jcasType).casFeat_dictTerm == null)
    jcasType.jcas.throwFeatMissing("dictTerm", "uhh_lt.newsleak.types.DictTerm");
  jcasType.ll_cas.ll_setRefValue(addr, ((DictTerm_Type)jcasType).casFeatCode_dictTerm, jcasType.ll_cas.ll_getFSRef(v));}
 
Example #9
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static StringList createStringList(JCas aJCas, String... aValues) {
  return createStringList(aJCas.getCas(), aValues);
}
 
Example #10
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static StringList createStringList(JCas aJCas, Collection<String> aCollection) {
  return createStringList(aJCas.getCas(), aCollection);
}
 
Example #11
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aListString - gets 
 * @generated
 * @return value of the feature 
 */
public StringList getAListString() { return (StringList)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aListString)));}
 
Example #12
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aListString - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAListString(StringList v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aListString), v);
}
 
Example #13
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aListMrString - gets 
 * @generated
 * @return value of the feature 
 */
public StringList getAListMrString() { return (StringList)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aListMrString)));}
 
Example #14
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aListMrString - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAListMrString(StringList v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aListMrString), v);
}