Java Code Examples for org.apache.uima.resource.metadata.TypeDescription#addFeature()

The following examples show how to use org.apache.uima.resource.metadata.TypeDescription#addFeature() . 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: TypeSystemUtilTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testTypeSystem2TypeSystemDescription() throws Exception {
  //create a CAS with example type system
  File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml");
  TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(typeSystemFile));
  
  //add an example type to test FSArrays with and without elementTypes
  TypeDescription type = tsDesc.addType("example.TestType", "", "uima.tcas.Annotation");
  type.addFeature("testFeat", "", "uima.cas.FSArray","uima.tcas.Annotation", null);
  TypeDescription type2 = tsDesc.addType("example.TestType2", "", "uima.tcas.Annotation");
  type2.addFeature("testFeat", "", "uima.cas.FSArray");

  
  CAS cas = CasCreationUtils.createCas(tsDesc, null, null);    
  //convert that CAS's type system back to a TypeSystemDescription
  TypeSystemDescription tsDesc2 = TypeSystemUtil.typeSystem2TypeSystemDescription(cas.getTypeSystem());
  //test that this is valid by creating a new CAS
  CasCreationUtils.createCas(tsDesc2, null, null);
  
  // Check that can be written (without cluttering up the console)
  StringWriter out = new StringWriter();
  tsDesc2.toXML(out);
}
 
Example 2
Source File: AgreementTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem(String... aFeatures)
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
    for (String feature : aFeatures) {
        hostTD.addFeature(feature, "", CAS.TYPE_NAME_STRING);
    }

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 3
Source File: AgreementTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 4
Source File: RelationLayerSupport.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public void generateTypes(TypeSystemDescription aTsd, AnnotationLayer aLayer,
        List<AnnotationFeature> aAllFeaturesInProject)
{
    TypeDescription td = aTsd.addType(aLayer.getName(), aLayer.getDescription(),
            TYPE_NAME_ANNOTATION);
    AnnotationLayer attachType = aLayer.getAttachType();

    td.addFeature(FEAT_REL_TARGET, "", attachType.getName());
    td.addFeature(FEAT_REL_SOURCE, "", attachType.getName());

    List<AnnotationFeature> featureForLayer = aAllFeaturesInProject.stream()
            .filter(feature -> aLayer.equals(feature.getLayer()))
            .collect(toList());
    generateFeatures(aTsd, td, featureForLayer);
}
 
Example 5
Source File: DiffTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem(String... aFeatures)
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
    for (String feature : aFeatures) {
        hostTD.addFeature(feature, "", CAS.TYPE_NAME_STRING);
    }

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 6
Source File: DiffTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 7
Source File: CurationTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSystem(String... aFeatures)
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", CAS.TYPE_NAME_ANNOTATION);

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
    for (String feature : aFeatures) {
        hostTD.addFeature(feature, "", CAS.TYPE_NAME_STRING);
    }

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 8
Source File: CurationTestUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", CAS.TYPE_NAME_ANNOTATION);

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
Example 9
Source File: SubjectObjectFeatureSupport.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
    AnnotationFeature aFeature)
{
    // Link type
    TypeDescription linkTD = aTSD.addType(aFeature.getLinkTypeName(), "",
        CAS.TYPE_NAME_TOP);
    linkTD.addFeature(aFeature.getLinkTypeRoleFeatureName(), "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature(aFeature.getLinkTypeTargetFeatureName(), "", aFeature.getType());
    
    // Link feature
    aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(),
        false);
}
 
Example 10
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
public CAS cloneAndMonkeyPatchCAS(Project aProject, CAS aSourceCas, CAS aTargetCas)
    throws UIMAException, IOException
{
    try (StopWatch watch = new StopWatch(log, "adding score features")) {
        TypeSystemDescription tsd = annoService.getFullProjectTypeSystem(aProject);

        for (AnnotationLayer layer : annoService.listAnnotationLayer(aProject)) {
            TypeDescription td = tsd.getType(layer.getName());

            if (td == null) {
                log.trace("Could not monkey patch type [{}]", layer.getName());
                continue;
            }

            for (FeatureDescription feature : td.getFeatures()) {
                String scoreFeatureName = feature.getName() + FEATURE_NAME_SCORE_SUFFIX;
                td.addFeature(scoreFeatureName, "Score feature", CAS.TYPE_NAME_DOUBLE);
                
                String scoreExplanationFeatureName = feature.getName() + 
                        FEATURE_NAME_SCORE_EXPLANATION_SUFFIX;
                td.addFeature(scoreExplanationFeatureName, "Score explanation feature", 
                        CAS.TYPE_NAME_STRING);
            }

            td.addFeature(FEATURE_NAME_IS_PREDICTION, "Is Prediction", CAS.TYPE_NAME_BOOLEAN);
        }

        annoService.upgradeCas(aSourceCas, aTargetCas, tsd);
    }

    return aTargetCas;
}
 
Example 11
Source File: SlotFeatureSupport.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
        AnnotationFeature aFeature)
{
    // Link type
    TypeDescription linkTD = aTSD.addType(aFeature.getLinkTypeName(), "",
            CAS.TYPE_NAME_TOP);
    linkTD.addFeature(aFeature.getLinkTypeRoleFeatureName(), "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature(aFeature.getLinkTypeTargetFeatureName(), "", aFeature.getType());
    
    // Link feature
    aTD.addFeature(aFeature.getName(), aFeature.getDescription(), CAS.TYPE_NAME_FS_ARRAY,
            linkTD.getName(), false);
}
 
Example 12
Source File: CasCreationUtils.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts a TypeSystem definition from a CasData.
 * 
 * @param aCasData
 *                the CAS Data from which to extract the type system
 * 
 * @return a description of a TypeSystem to which the CAS Data conforms
 */
public static TypeSystemDescription convertData2TypeSystem(CasData aCasData) {
  TypeSystemDescription result = UIMAFramework.getResourceSpecifierFactory()
      .createTypeSystemDescription();
  Iterator<FeatureStructure> iter = aCasData.getFeatureStructures();
  List<TypeDescription> typesArr = new ArrayList<>();
  while (iter.hasNext()) {
    FeatureStructure casFS = iter.next();
    TypeDescription newType = UIMAFramework.getResourceSpecifierFactory().createTypeDescription();
    newType.setName(casFS.getType());
    newType.setSupertypeName("uima.tcas.annotation");
    newType.setDescription("CasData Type");
    String features[] = casFS.getFeatureNames();
    if (features != null) {
      for (int i = 0; i < features.length; i++) {
        String featName = features[i];
        String rangeName = "";
        String description = "";
        PrimitiveValue pVal = (PrimitiveValue) casFS.getFeatureValue(featName);
        if (pVal.get().getClass().getName().equals("java.lang.String")) {
          System.out.println(" the feature is a String ");
          rangeName = "uima.cas.String";
          description = " featue of the casDataType";
        }
        newType.addFeature(featName, description, rangeName);
      }
    }
    typesArr.add(newType);
  }
  TypeDescription td[] = new TypeDescription[typesArr.size()];
  for (int j = 0; j < typesArr.size(); j++) {
    td[j] = typesArr.get(j);
  }
  result.setTypes(td);
  return result;
}
 
Example 13
Source File: CasIOUtilsTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testDocumentAnnotationIsNotResurrected() throws Exception {
  String refererAnnoTypeName = "org.apache.uima.testing.Referer";
  String customDocAnnoTypeName = "org.apache.uima.testing.CustomDocumentAnnotation";
    
  TypeSystemDescription tsd = UIMAFramework.getResourceSpecifierFactory().createTypeSystemDescription();
  tsd.addType(customDocAnnoTypeName, "", CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
  TypeDescription refererType = tsd.addType(refererAnnoTypeName, "", CAS.TYPE_NAME_TOP);
  refererType.addFeature("ref", "", CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
  
  CAS cas = CasCreationUtils.createCas(tsd, null, null);
  
  // Initialize the default document annotation
  // ... then immediately remove it from the indexes.
  FeatureStructure da = cas.getDocumentAnnotation();

  assertThat(cas.select(cas.getTypeSystem().getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION)).asList())
      .extracting(fs -> fs.getType().getName())
      .containsExactly(CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
  
  // Add a feature structure that references the original document annotation before we remove
  // it from the indexes
  FeatureStructure referer = cas.createFS(cas.getTypeSystem().getType(refererAnnoTypeName));
  referer.setFeatureValue(referer.getType().getFeatureByBaseName("ref"), da);
  cas.addFsToIndexes(referer);
  
  cas.removeFsFromIndexes(da);
  
  // Now add a new document annotation of our custom type
  FeatureStructure cda = cas.createFS(cas.getTypeSystem().getType(customDocAnnoTypeName));
  cas.addFsToIndexes(cda);

  assertThat(cas.select(cas.getTypeSystem().getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION)).asList())
      .extracting(fs -> fs.getType().getName())
      .containsExactly(customDocAnnoTypeName);
  
  // Serialize to a buffer
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  CasIOUtils.save(cas, bos, SerialFormat.SERIALIZED_TSI);
  
  // Deserialize from the buffer
  ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
  CasIOUtils.load(bis, cas);
  
  assertThat(cas.select(cas.getTypeSystem().getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION)).asList())
      .extracting(fs -> fs.getType().getName())
      .containsExactly(customDocAnnoTypeName);
}
 
Example 14
Source File: PropertyFeatureSupport.java    From inception with Apache License 2.0 4 votes vote down vote up
@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
    AnnotationFeature aFeature)
{
    aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_STRING);
}
 
Example 15
Source File: CasCreationUtils.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Merges features into a TypeDescription.
 * 
 * @param aType
 *                TypeDescription into which to merge the features
 * @param aFeatures
 *                array of features to merge
 * 
 * @throws ResourceInitializationException
 *                 if an incompatibility exists
 */
protected static void mergeFeatures(TypeDescription aType, FeatureDescription[] aFeatures)
    throws ResourceInitializationException {
  FeatureDescription[] existingFeatures = aType.getFeatures();
  if (existingFeatures == null) {
    existingFeatures = EMPTY_FEAT_DESC_ARRAY;
  }

  for (int i = 0; i < aFeatures.length; i++) {
    String featName = aFeatures[i].getName();
    String rangeTypeName = aFeatures[i].getRangeTypeName();
    String elementTypeName = aFeatures[i].getElementType();
    Boolean multiRefsAllowed = aFeatures[i].getMultipleReferencesAllowed();

    // see if a feature already exists with this name
    FeatureDescription feat = null;
    for (int j = 0; j < existingFeatures.length; j++) {
      if (existingFeatures[j].getName().equals(featName)) {
        feat = existingFeatures[j];
        break;
      }
    }

    if (feat == null) {
      // doesn't exist; add it
      FeatureDescription featDesc = aType.addFeature(featName, aFeatures[i].getDescription(),
          rangeTypeName, elementTypeName, multiRefsAllowed);
      featDesc.setSourceUrl(aFeatures[i].getSourceUrl());
    } else {// feature does exist
      // check that the range types match
      if (!feat.getRangeTypeName().equals(rangeTypeName)) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_RANGE_TYPES, new Object[] {
                aType.getName() + ":" + feat.getName(), rangeTypeName, feat.getRangeTypeName(),
                aType.getSourceUrlString() });
      }
      Boolean mra1 = feat.getMultipleReferencesAllowed();
      Boolean mra2 = multiRefsAllowed;

      // the logic here:
      // OK if both null
      // OK if both not-null, and are equals()
      // OK if one is null, the other has boolean-value of false (false is the default)
      // not ok otherwise

      if (!(((mra1 == null) && (mra2 == null)) || ((mra1 != null) && mra1.equals(mra2))
          || ((mra1 == null) && !mra2) || ((mra2 == null) && !mra1))) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_MULTI_REFS, new Object[] {
                aType.getName() + ":" + feat.getName(), aType.getSourceUrlString() });
      }

      if (!elementTypesCompatible(feat.getElementType(), elementTypeName)) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_ELEMENT_RANGE_TYPES, new Object[] {
                aType.getName() + TypeSystem.FEATURE_SEPARATOR + feat.getName(), elementTypeName,
                feat.getElementType(), aType.getSourceUrlString() });
      }
    }
  }
}
 
Example 16
Source File: XmiCasDeserializerTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testOutOfTypeSystemArrayElement() throws Exception {
  //add to type system an annotation type that has an FSArray feature
  TypeDescription testAnnotTypeDesc = typeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
  testAnnotTypeDesc.addFeature("arrayFeat", "", "uima.cas.FSArray");
  //populate a CAS with such an array
  CAS cas = CasCreationUtils.createCas(typeSystem, null, null);
  Type testAnnotType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
  Type orgType = cas.getTypeSystem().getType(
    "org.apache.uima.testTypeSystem.Organization");
  AnnotationFS orgAnnot1 = cas.createAnnotation(orgType, 0, 10);
  cas.addFsToIndexes(orgAnnot1);
  AnnotationFS orgAnnot2 = cas.createAnnotation(orgType, 10, 20);
  cas.addFsToIndexes(orgAnnot2);
  AnnotationFS testAnnot = cas.createAnnotation(testAnnotType, 0, 20);
  cas.addFsToIndexes(testAnnot);
  ArrayFS arrayFs = cas.createArrayFS(2);
  arrayFs.set(0, orgAnnot1);
  arrayFs.set(1, orgAnnot2);
  Feature arrayFeat = testAnnotType.getFeatureByBaseName("arrayFeat");
  testAnnot.setFeatureValue(arrayFeat, arrayFs);
  
  //serialize to XMI
  String xmiStr = serialize(cas, null);
  
  //deserialize into a CAS that's missing the Organization type
  File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml");
  TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(partialTypeSystemFile));
  testAnnotTypeDesc = partialTypeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
  testAnnotTypeDesc.addFeature("arrayFeat", "", "uima.cas.FSArray");
  CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, null);
  XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
  deserialize(xmiStr, partialTsCas, sharedData, true, -1);
  
  //check out of type system data
  Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
  FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get(); 
  Feature arrayFeat2 = testAnnotType2.getFeatureByBaseName("arrayFeat");
  FeatureStructure arrayFs2 = testAnnot2.getFeatureValue(arrayFeat2);
  List ootsElems = sharedData.getOutOfTypeSystemElements();
  assertEquals(2, ootsElems.size());
  List ootsArrayElems = sharedData.getOutOfTypeSystemArrayElements((FSArray) arrayFs2);
  assertEquals(2, ootsArrayElems.size());
  for (int i = 0; i < 2; i++) {
    OotsElementData oed = (OotsElementData)ootsElems.get(i);
    XmiArrayElement arel = (XmiArrayElement)ootsArrayElems.get(i);
    assertEquals(oed.xmiId, arel.xmiId);      
  }
  
  //reserialize along with out of type system data
  String xmiStr2 = serialize(partialTsCas, sharedData);
  
  //deserialize into a new CAS and compare
  CAS cas2 = CasCreationUtils.createCas(typeSystem, null, null);
  deserialize(xmiStr2, cas2, null, false, -1);
  
  CasComparer.assertEquals(cas, cas2);    
}
 
Example 17
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Handle add feature.
 *
 * @param parent the parent
 */
// disabled unless type is selected
public void handleAddFeature(TreeItem parent) {

  TypeDescription td = getTypeDescriptionFromTableTreeItem(parent);
  // guaranteed non-null - otherwise add button disabled
  TypeDescription localTd = getLocalTypeDefinition(td);
  //
  AddFeatureDialog dialog = new AddFeatureDialog(this, td, null);
  if (dialog.open() == Window.CANCEL) {
    return;
  }

  FeatureDescription fd = localTd.addFeature(null, null, null);
  featureUpdate(fd, dialog);

  editor.addDirtyTypeName(td.getName());

  // update the GUI

  // if this type is merged with an import or with a built-in,
  // need to "refresh"
  if (isImportedType(td) || isBuiltInType(td)) {
    if (!isImportedFeature(dialog.featureName, td)) {
      // don't need to check builtin Feature because gui doesn't let you
      // define a built-in feature again
      fd = td.addFeature(null, null, null);
      featureUpdate(fd, dialog);
    }
    refresh();

    selectTypeInGui(td);

    finishAction();
  } else {
    fd = td.addFeature(null, null, null);
    featureUpdate(fd, dialog);
    TreeItem item = new TreeItem(parent, SWT.NONE);
    updateGuiFeature(item, fd, td);
    parent.setExpanded(true);
    finishActionPack();
  }
}
 
Example 18
Source File: UimaPrimitiveFeatureSupport_ImplBase.java    From webanno with Apache License 2.0 4 votes vote down vote up
@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
        AnnotationFeature aFeature)
{
    aTD.addFeature(aFeature.getName(), aFeature.getDescription(), aFeature.getType());
}
 
Example 19
Source File: XmiCasDeserializerTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testOutOfTypeSystemListElement() throws Exception {
    //add to type system an annotation type that has an FSList feature
    TypeDescription testAnnotTypeDesc = typeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
    testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList");
    
    //populate a CAS with such an list
    CAS cas = CasCreationUtils.createCas(typeSystem, null, null);
    Type testAnnotType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
    Type orgType       = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.Organization");
    
    AnnotationFS orgAnnot1 = cas.createAnnotation(orgType, 0, 10);
                             cas.addFsToIndexes(orgAnnot1);
    AnnotationFS orgAnnot2 = cas.createAnnotation(orgType, 10, 20);
                             cas.addFsToIndexes(orgAnnot2);
    AnnotationFS testAnnot = cas.createAnnotation(testAnnotType, 0, 20);
                             cas.addFsToIndexes(testAnnot);
                             
    Type nonEmptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
    Type emptyFsListType    = cas.getTypeSystem().getType(CAS.TYPE_NAME_EMPTY_FS_LIST);
    Feature headFeat = nonEmptyFsListType.getFeatureByBaseName("head");
    Feature tailFeat = nonEmptyFsListType.getFeatureByBaseName("tail");
    
    FeatureStructure emptyNode  = cas.createFS(emptyFsListType);
    
    FeatureStructure secondNode = cas.createFS(nonEmptyFsListType);
    secondNode.setFeatureValue(headFeat, orgAnnot2);
    secondNode.setFeatureValue(tailFeat, emptyNode);
    
    FeatureStructure firstNode = cas.createFS(nonEmptyFsListType);
    firstNode.setFeatureValue(headFeat, orgAnnot1);
    firstNode.setFeatureValue(tailFeat, secondNode);
    
    Feature listFeat = testAnnotType.getFeatureByBaseName("listFeat");
    testAnnot.setFeatureValue(listFeat, firstNode);
    
    //serialize to XMI
    String xmiStr = serialize(cas, null);
//    System.out.println(xmiStr);
    
    //deserialize into a CAS that's missing the Organization type
    File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml");
    TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(partialTypeSystemFile));
    testAnnotTypeDesc = partialTypeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
    testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList");
    CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, null);
    XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
    deserialize(xmiStr, partialTsCas, sharedData, true, -1);
    
    //check out of type system data
    Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
    FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get(); 
    Feature listFeat2 = testAnnotType2.getFeatureByBaseName("listFeat");
    FeatureStructure listFs = testAnnot2.getFeatureValue(listFeat2);
    List ootsElems = sharedData.getOutOfTypeSystemElements();
    assertEquals(2, ootsElems.size());
    
    OotsElementData oed = sharedData.getOutOfTypeSystemFeatures((TOP) listFs);
    XmlAttribute attr = oed.attributes.get(0);
    assertNotNull(attr);
    assertEquals(CAS.FEATURE_BASE_NAME_HEAD, attr.name);
    assertEquals(attr.value, ((OotsElementData)ootsElems.get(0)).xmiId);
    
    //reserialize along with out of type system data
    String xmiStr2 = serialize(partialTsCas, sharedData);
//    System.out.println(xmiStr2);
    
    //deserialize into a new CAS and compare
    CAS cas2 = CasCreationUtils.createCas(typeSystem, null, null);
    deserialize(xmiStr2, cas2, null, false, -1);
    
    CasComparer.assertEquals(cas, cas2);    
  }
 
Example 20
Source File: ImageFeatureSupport.java    From inception with Apache License 2.0 4 votes vote down vote up
@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
        AnnotationFeature aFeature)
{
    aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_STRING);
}