从UIMA FSArray检索值

问题描述:

我有一个具有FSArray类型特征的注释。该功能应包含一个字符串列表。从UIMA FSArray检索值

FSArray fsArray = (FSArray)annotation.getFeatureValue(fe); 

如何从FSArray获取字符串列表?

通过fsArray.toStringArray()循环只返回字符串“FSArray”而不是实际值。

+0

FSArray的元素有哪些类型? – rec

有哪些是重要的内UIMA从FSArray检索值时,了解一些重要概念:

  • org.apache.uima.cas.Type - 的类型描述的数据模型。它的类似于java中的类的概念,它是 。一个类型有一个名字空间 ,它定义了属性(特征)。
  • org.apache.uima.cas.Feature - 是由Type描述的属性。
  • org.apache.uima.jcas.cas.TOP - 是最通用的类​​型,可以用java.lang.Object进行比较。
  • org.apache.uima.cas.FeatureStructure - 一个FeatureStructure最好是 ,它被描述为一个Type的实例。 FeatureStructure是你用来访问数据的东西。

让我们说,我们有以下两种类型:

  • com.abcColoredCar
  • com.abcCar

,我们有下面的句子:

Car A and car B are both blue. 

让我们假设以前的UIMA舞台有一个nnotated使用Type com.abcColoredCar全句如下:

begin: 0 
end: 24 
color: "blue" 
cars: FSArray 

让我们也假设我们从类型定义该功能的汽车是com.abcCar的FSArray已知的,以及汽车包含下列值:

begin: 4 
end: 5 
manufacturer: "Volvo" 

begin: 14 
end: 15 
manufacturer: "Toyota" 

以下代码将演示如何检索汽车FSArray的制造商属性/功能。

public void process(JCas aJCas) throws AnalysisEngineProcessException { 
    List<TOP> tops = new ArrayList<TOP>(JCasUtil.selectAll(aJCas)); 
    List<String> manufacturers = new ArrayList<>(); 
    for (TOP t : tops) { 
     if (t.getType().getName().endsWith("ColoredCar")) { 
      Feature carsFeature = t.getType().getFeatureByBaseName("cars"); 
      FSArray fsArray = (FSArray) t.getFeatureValue(carsFeature); 
      FeatureStructure[] arrayStructures = fsArray.toArray(); 
      for (int i = 0; i < arrayStructures.length; i++) { 
       FeatureStructure fs = arrayStructures[i]; 
       Feature manufacturerFeature = fs.getType().getFeatureByBaseName("cars"); 
       manufacturers.add(fs.getStringValue(manufacturerFeature)); 
      } 
     } 
    } 
} 

要深入了解这一点,最好了解Type系统,堆和索引存储库如何在CAS中工作。