本文整理汇总了Java中org.apache.uima.jcas.cas.StringArray类的典型用法代码示例。如果您正苦于以下问题:Java StringArray类的具体用法?Java StringArray怎么用?Java StringArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringArray类属于org.apache.uima.jcas.cas包,在下文中一共展示了StringArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readCast
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
public static void readCast(JCas jcas, Drama drama, Document doc) {
Map<String, CastFigure> idFigureMap = new HashMap<String, CastFigure>();
Elements castEntries = doc.select("profileDesc > particDesc > listPerson > person");
// castEntries.addAll(doc.select("profileDesc > particDesc > listPerson
// > personGrp"));
FSArray castListArray = new FSArray(jcas, castEntries.size());
for (int i = 0; i < castEntries.size(); i++) {
Element castEntry = castEntries.get(i);
String id = castEntry.attr("xml:id");
StringArray arr = new StringArray(jcas, 1);
arr.set(0, castEntry.text());
CastFigure figure = new CastFigure(jcas);
figure.setXmlId(id);
figure.setNames(arr);
idFigureMap.put(id, figure);
castListArray.set(i, figure);
}
drama.setCastList(castListArray);
for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
speaker.setCastFigure(new FSArray(jcas, speaker.getXmlId().size()));
for (int i = 0; i < speaker.getXmlId().size(); i++)
speaker.setCastFigure(i, idFigureMap.get(speaker.getXmlId(i)));
}
}
示例2: readCast
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
private static void readCast(JCas jcas, Drama drama, Document doc) {
Map<String, CastFigure> idFigureMap = new HashMap<String, CastFigure>();
Elements castEntries = doc.select("castList > castItem > role");
// castEntries.addAll(doc.select("profileDesc > particDesc > listPerson
// > personGrp"));
FSArray castListArray = new FSArray(jcas, castEntries.size());
for (int i = 0; i < castEntries.size(); i++) {
Element castEntry = castEntries.get(i);
String id = castEntry.attr("xml:id");
StringArray arr = new StringArray(jcas, 1);
arr.set(0, castEntry.text());
CastFigure figure = new CastFigure(jcas);
figure.setXmlId(id);
figure.setNames(arr);
idFigureMap.put(id, figure);
castListArray.set(i, figure);
}
drama.setCastList(castListArray);
for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
speaker.setCastFigure(new FSArray(jcas, speaker.getXmlId().size()));
for (int i = 0; i < speaker.getXmlId().size(); i++)
speaker.setCastFigure(i, idFigureMap.get(speaker.getXmlId(i)));
}
}
示例3: testStringArray
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
@Test
public void testStringArray(){
DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
StringArray rel = new StringArray(jCas, 3);
rel.set(0, "ENG");
rel.set(1, "WAL");
rel.set(2, "SCO");
da.setDocumentReleasability(rel);
Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);
Object[] o = FeatureUtils.featureToArray(f, da);
assertEquals(3, o.length);
assertTrue(o[0] instanceof String);
assertEquals("ENG", (String)o[0]);
assertTrue(o[1] instanceof String);
assertEquals("WAL", (String)o[1]);
assertTrue(o[2] instanceof String);
assertEquals("SCO", (String)o[2]);
}
示例4: testStringArrayToObject
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
@Test
public void testStringArrayToObject(){
DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
StringArray rel = new StringArray(jCas, 3);
rel.set(0, "true");
rel.set(1, "2");
rel.set(2, "0.45");
da.setDocumentReleasability(rel);
Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);
Object[] o = FeatureUtils.featureToArray(f, da);
assertEquals(3, o.length);
assertTrue(o[0] instanceof Boolean);
assertTrue((Boolean)o[0]);
assertTrue(o[1] instanceof Integer);
assertEquals(new Integer(2), (Integer)o[1]);
assertTrue(o[2] instanceof Double);
assertEquals(new Double(0.45), (Double)o[2]);
}
示例5: testStringArrayToList
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
@Test
public void testStringArrayToList(){
DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
StringArray rel = new StringArray(jCas, 3);
rel.set(0, "ENG");
rel.set(1, "WAL");
rel.set(2, "SCO");
da.setDocumentReleasability(rel);
Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);
List<Object> o = FeatureUtils.featureToList(f, da);
assertEquals(3, o.size());
assertTrue(o.get(0) instanceof String);
assertEquals("ENG", (String)o.get(0));
assertTrue(o.get(1) instanceof String);
assertEquals("WAL", (String)o.get(1));
assertTrue(o.get(2) instanceof String);
assertEquals("SCO", (String)o.get(2));
}
示例6: testToList
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
@Test
public void testToList() {
assertTrue(UimaTypesUtils.toList((StringArray)null).isEmpty());
assertTrue(UimaTypesUtils.toList((FSArray)null).isEmpty());
// Empty list
FSArray array = new FSArray(jCas, 2);
assertEquals(2, UimaTypesUtils.toList(array).size());
// Populate
array.set(0, new Entity(jCas));
array.set(1, new Entity(jCas));
List<Entity> list = UimaTypesUtils.toList(array);
assertEquals(2, list.size());
assertSame(array.get(0), list.get(0));
assertSame(array.get(0), list.get(0));
}
示例7: process
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
/**
* @see org.apache.uima.analysis_component.JCasAnnotator_ImplBase#process(org.apache.uima.jcas.JCas)
*/
@Override
public void process(JCas cas) throws AnalysisEngineProcessException {
// we need the nouns and their word stem annotations here.
FSIterator nounAnnotIter = cas.getAnnotationIndex(Noun.type).iterator();
while(nounAnnotIter.hasNext()) {
Noun noun = (Noun)nounAnnotIter.next();
List<String> matchingConceptURIs = ontologyIndex.getExactMatches(noun.getWordStem());
int length = matchingConceptURIs.size();
if (length != 0) {
// OntologyConcept concept = new OntologyConcept(cas);
// concept.setBegin(noun.getBegin());
// concept.setEnd(noun.getEnd());
StringArray conceptURIs = new StringArray(cas, length);
conceptURIs.copyFromArray(matchingConceptURIs.toArray(new String[length]), 0, 0, length);
noun.setConceptURIs(conceptURIs);
conceptURIs.addToIndexes();
// concept.setConceptURIs(conceptURIs);
// concept.addToIndexes();
}
}
}
示例8: writeFieldToDb
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
static void writeFieldToDb(String range, BasicDBObject o, Annotation a,
String dbKey, Feature f) {
if (range.equals("String")) {
o.put(dbKey, a.getStringValue(f));
} else if (range.equals("StringArray")) {
StringArray sa = (StringArray) a.getFeatureValue(f);
if (sa != null) {
String[] vals = sa.toArray();
o.put(dbKey, Lists.newArrayList(vals));
}
} else if (range.equals("Integer")) {
o.put(dbKey, a.getIntValue(f));
} else if (range.equals("Float")) {
o.put(dbKey, a.getFloatValue(f));
} else if (range.equals("Boolean")) {
o.put(dbKey, a.getBooleanValue(f));
} else {
LOG.warn("range not supported " + range);
}
}
示例9: readFieldFromDb
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
public static void readFieldFromDb(String fieldKey, String range,
Annotation a, Feature f, BasicDBObject dbO, JCas jCas) {
if (dbO.containsField(fieldKey)) {
if (range.equals("String")) {
a.setStringValue(f, dbO.getString(fieldKey));
} else if (range.equals("StringArray")) {
BasicDBList vals = (BasicDBList) dbO.get(fieldKey);
StringArray sa = new StringArray(jCas, vals.size());
for (int i = 0; i < vals.size(); i++) {
sa.set(i, vals.get(i).toString());
}
a.setFeatureValue(f, sa);
} else if (range.equals("Integer")) {
a.setIntValue(f, dbO.getInt(fieldKey));
} else if (range.equals("Float")) {
a.setFloatValue(f, (float) dbO.getDouble(fieldKey));
} else if (range.equals("Boolean")) {
a.setBooleanValue(f, dbO.getBoolean(fieldKey));
} else {
LOG.warn("range not supported " + range);
}
}
}
示例10: getSlotValues
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
public Collection<String> getSlotValues() {
Collection<String> slotValuesToReturn = new ArrayList<String>();
StringArray slotValues = wrappedSM.getSlotValues();
for (int i = 0; i < slotValues.size(); i++) {
slotValuesToReturn.add(slotValues.get(i));
}
return slotValuesToReturn;
}
示例11: setSlotValues
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
public void setSlotValues(Collection<String> slotValues) throws InvalidInputException {
List<String> slotValuesList = new ArrayList<String>(slotValues);
StringArray stringArray = new StringArray(jcas, slotValues.size());
for (int i = 0; i < slotValues.size(); i++) {
stringArray.set(i, slotValuesList.get(i));
}
wrappedSM.setSlotValues(stringArray);
}
示例12: initializeStringSlotMention
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
/**
* Initializes a new CCPStringSlotMention
*
* @param slotMentionName
* @param slotValue
* @param jcas
* @return
*/
private static CCPStringSlotMention initializeStringSlotMention(String slotMentionName,
Collection<String> slotValues, JCas jcas) {
StringArray slotValuesArray = new StringArray(jcas, slotValues.size());
int index = 0;
for (String slotValue : slotValues) {
slotValuesArray.set(index++, slotValue);
}
CCPStringSlotMention ccpSSM = new CCPStringSlotMention(jcas);
ccpSSM.setSlotValues(slotValuesArray);
ccpSSM.setMentionName(slotMentionName);
return ccpSSM;
}
示例13: swapDocumentInfo
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
public static void swapDocumentInfo(JCas fromJcas, GenericDocument toGD) {
FSIterator docInfoIter = fromJcas.getJFSIndexRepository().getAnnotationIndex(CCPDocumentInformation.type)
.iterator();
// print document information
String docID = "-1";
int docCollectionID = -1;
if (docInfoIter.hasNext()) {
CCPDocumentInformation docInfo = (CCPDocumentInformation) docInfoIter.next();
docID = docInfo.getDocumentID();
docCollectionID = docInfo.getDocumentCollectionID();
/* Get any secondary document IDs */
StringArray secondaryIDsArray = docInfo.getSecondaryDocumentIDs();
if (secondaryIDsArray != null) {
for (int i = 0; i < secondaryIDsArray.size(); i++) {
toGD.addSecondaryDocumentID(secondaryIDsArray.get(i));
}
}
}
toGD.setDocumentID(docID);
toGD.setDocumentCollectionID(docCollectionID);
// set the document text
toGD.setDocumentText(fromJcas.getDocumentText());
// add the annotations to the Generic Document
// UIMA_Util uimaUtil = new UIMA_Util();
List<TextAnnotation> annotations = getAnnotationsFromCas(fromJcas);
toGD.setAnnotations(annotations);
}
示例14: convertToCollection
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
private static Collection<String> convertToCollection(StringArray iArray) {
Collection<String> iCollection = new ArrayList<String>();
for (int i = 0; i < iArray.size(); i++) {
iCollection.add(iArray.get(i));
}
return iCollection;
}
示例15: indexOf
import org.apache.uima.jcas.cas.StringArray; //导入依赖的package包/类
public static int indexOf(StringArray strArray, String strValue) {
if (strArray == null) {
return -1;
}
for (int i = 0; i < strArray.size(); i++) {
if (strArray.get(i).equals(strValue)) {
return i;
}
}
return -1;
}