Package org.apache.uima.resource.metadata

Examples of org.apache.uima.resource.metadata.FeatureDescription


      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[] {
View Full Code Here


    try {
      super.setUp();

      TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
      TypeDescription type1 = typeSystem.addType("Fake", "<b>Fake</b> Type", "Annotation");
      FeatureDescription feature1 = type1.addFeature("TestFeature", "For Testing Only",
              CAS.TYPE_NAME_STRING);
      TypeDescription enumType = typeSystem.addType("EnumType", "Test Enumerated Type",
              "uima.cas.String");
      enumType.setAllowedValues(new AllowedValue[] { new AllowedValue_impl("One", "First Value"),
          new AllowedValue_impl("Two", "Second Value") });
View Full Code Here

    if (!_Type) {

      FeatureDescription[] fds = td.getFeatures();
      for (int i = 0; i < fds.length; i++) {
        FeatureDescription fd = fds[i];
        if (null != typeSystem) {
          String rangeTypeNameCAS = fd.getRangeTypeName();
          Type rangeCasType = typeSystem.getType(rangeTypeNameCAS);
          if (typeSystem.subsumes(casStringType, rangeCasType))
            continue;
        }
        collectImport(fd.getRangeTypeName(), false);
        if (hasArrayRange(fd)) {
          collectImport(getJavaRangeArrayElementType(fd), false);
        }
      }
    }
View Full Code Here

    EList eFeatures = aEClass.getEStructuralFeatures();
    Iterator iter = eFeatures.iterator();
    List uimaFeatures = new ArrayList();
    while (iter.hasNext()) {
      EStructuralFeature eFeat = (EStructuralFeature) iter.next();
      FeatureDescription uimaFeat = eStructuralFeature2UimaFeature(eFeat, aOptions);
      uimaFeatures.add(uimaFeat);
    }
    // copy down features from additional supertypes
    for (int i = 1; i < supertypes.size(); i++) {
      EClass copyFrom = (EClass) supertypes.get(i);
      EList copyFeatures = copyFrom.getEStructuralFeatures();
      Iterator iter2 = copyFeatures.iterator();
      while (iter2.hasNext()) {
        EStructuralFeature eFeat = (EStructuralFeature) iter2.next();
        // do not copy if this feature is a duplicate of one defined on the class
        // or inherited from its primary supertype
        EList locallyDefinedFeatures = aEClass.getEStructuralFeatures();
        EList firstSupertypesFeatures = ((EClass) supertypes.get(0)).getEAllStructuralFeatures();
        if (!containsNamedElement(locallyDefinedFeatures, eFeat.getName())
                && !containsNamedElement(firstSupertypesFeatures, eFeat.getName())) {
          FeatureDescription uimaFeat = eStructuralFeature2UimaFeature(eFeat, aOptions);
          uimaFeatures.add(uimaFeat);
        }
      }
    }
View Full Code Here

   * @param attr
   * @return
   */
  private static FeatureDescription eStructuralFeature2UimaFeature(
          EStructuralFeature aStructuralFeature, Map aOptions) throws URISyntaxException {
    FeatureDescription feat = uimaFactory.createFeatureDescription();
    feat.setName(aStructuralFeature.getName());
    String rangeTypeName = null;
    String elementTypeName = null;
    EAnnotation eannot = aStructuralFeature.getEAnnotation("http://uima.apache.org");
    if (eannot != null) {
      feat.setDescription((String) eannot.getDetails().get("description"));
      // the UIMA type name to use may be recorded as an EAnnotation; this is
      // particularly important for arrays and lists, since Ecore doesn't distinguish between
      // these two possible implementations for a multi-valued property
      rangeTypeName = (String) eannot.getDetails().get("uimaType");
      // the elemnt type may also be specified as an EAnnotation; this is
      // used for the case where an FSArray or FSList is NOT represented
      // as a multi-valued property
      elementTypeName = (String) eannot.getDetails().get("elementType");
    }
    EClassifier attrRangeType = aStructuralFeature.getEType();

    // if range type wasn't specified in an EAnnotation, compute it ourselves
    if (rangeTypeName == null) {
      rangeTypeName = getUimaTypeName(attrRangeType, aStructuralFeature.isMany(), aOptions);
    }
    feat.setRangeTypeName(rangeTypeName);

    if (aStructuralFeature.isMany()) {
      // set the element type of the array/list to the EType of the structural feature
      // (except primitive, or TOP, which are assumed)
      String uimaElementType = getUimaTypeName(attrRangeType, false, aOptions);
      if (!CAS.TYPE_NAME_INTEGER.equals(uimaElementType)
              && !CAS.TYPE_NAME_FLOAT.equals(uimaElementType)
              && !CAS.TYPE_NAME_STRING.equals(uimaElementType)
              && !CAS.TYPE_NAME_TOP.equals(uimaElementType)
              && !CAS.TYPE_NAME_BYTE.equals(uimaElementType)
              && !CAS.TYPE_NAME_SHORT.equals(uimaElementType)
              && !CAS.TYPE_NAME_LONG.equals(uimaElementType)
              && !CAS.TYPE_NAME_DOUBLE.equals(uimaElementType)
              && !CAS.TYPE_NAME_BOOLEAN.equals(uimaElementType)) {
        feat.setElementType(uimaElementType);
      }
    } else if (!aStructuralFeature.getEType().equals(EcorePackage.eINSTANCE.getEByteArray())) {
      // if in Ecore we have a single-valued property whose range type is an array or list,
      // we need to set "multiple references allowed" to true in the UIMA type system
      // (exception: don't do this for the EByteArray data type, which is implicilty a
      // multi-valued type)
      if (isArrayOrList(rangeTypeName)) {
        feat.setMultipleReferencesAllowed(Boolean.TRUE);
        // also, set element type if one was contained in the EAnnotation
        feat.setElementType(elementTypeName);
      }
    }
    return feat;
  }
View Full Code Here

   * @param aFeature
   *          feature object to convert
   * @return a FeatureDescription that is equivalent to <code>aFeature</code>
   */
  public static FeatureDescription feature2FeatureDescription(Feature aFeature) {
    FeatureDescription featDesc = UIMAFramework.getResourceSpecifierFactory()
            .createFeatureDescription();
    featDesc.setName(aFeature.getShortName());
    featDesc.setRangeTypeName(aFeature.getRange().getName());
    return featDesc;
  }
View Full Code Here

    if (!_Type) {

      FeatureDescription[] fds = td.getFeatures();
      for (int i = 0; i < fds.length; i++) {
        FeatureDescription fd = fds[i];
        if (null != typeSystem) {
          String rangeTypeNameCAS = fd.getRangeTypeName();
          Type rangeCasType = typeSystem.getType(rangeTypeNameCAS);
          if (typeSystem.subsumes(casStringType, rangeCasType))
            continue;
        }
        collectImport(fd.getRangeTypeName(), false);
        if (hasArrayRange(fd)) {
          collectImport(getJavaRangeArrayElementType(fd), false);
        }
      }
    }
View Full Code Here

    stringBuffer.append(".typeIndexID;\n  /** @generated \n     @modifiable */\n  public final static boolean featOkTst = JCasRegistry.getFeatOkTst(\"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
   FeatureDescription [] fds = td.getFeatures();
   for (int i = 0; i < fds.length; i++) {
     FeatureDescription fd = fds[i];

     String featName = fd.getName();
     String featUName = jg.uc1(featName)// upper case first letter

     String rangeType = jg.getJavaRangeType(fd);
     String getSetNamePart = jg.sc(rangeType);
     String returnType = getSetNamePart.equals("Ref") ? "int" : rangeType;
     String getSetArrayNamePart = jg.getGetSetArrayNamePart(fd);
    
     String elemType = jg.getJavaRangeArrayElementType(fd);   
     if (jg.sc(elemType).equals("Ref"))
       elemType = "int";  
     String casFeatCode = "casFeatCode_" + featName;

    stringBuffer.append(" \n  /** @generated */\n  final Feature casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(";\n  /** @generated */\n  final int     ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append(";\n  /** @generated */ \n  public ");
    stringBuffer.append(returnType);
    stringBuffer.append(" get");
    stringBuffer.append(featUName);
    stringBuffer.append("(int addr) {\n    ");
    stringBuffer.append("");
 
/* checks to insure that cas has the feature */

    stringBuffer.append("    if (featOkTst && casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    return ll_cas.ll_get");
    stringBuffer.append(getSetNamePart);
    stringBuffer.append("Value(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append(");\n  }\n  /** @generated */    \n  public void set");
    stringBuffer.append(featUName);
    stringBuffer.append("(int addr, ");
    stringBuffer.append(returnType);
    stringBuffer.append(" v) {\n    ");
    stringBuffer.append("");
 
/* checks to insure that cas has the feature */

    stringBuffer.append("    if (featOkTst && casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    ll_cas.ll_set");
    stringBuffer.append(getSetNamePart);
    stringBuffer.append("Value(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append(", v);}\n    \n ");
  if (jg.hasArrayRange(fd)) {
    stringBuffer.append("  /** @generated */\n  public ");
    stringBuffer.append(elemType);
    stringBuffer.append(" get");
    stringBuffer.append(featUName);
    stringBuffer.append("(int addr, int i) {\n    ");
    stringBuffer.append("");
 
/* checks to insure that cas has the feature */

    stringBuffer.append("    if (featOkTst && casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    if (lowLevelTypeChecks)\n      return ll_cas.ll_get");
    stringBuffer.append(getSetArrayNamePart);
    stringBuffer.append("ArrayValue(ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append("), i, true);\n    jcas.checkArrayBounds(ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append("), i);\n  return ll_cas.ll_get");
    stringBuffer.append(getSetArrayNamePart);
    stringBuffer.append("ArrayValue(ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append("), i);\n  }\n   \n  /** @generated */ \n  public void set");
    stringBuffer.append(featUName);
    stringBuffer.append("(int addr, int i, ");
    stringBuffer.append(elemType);
    stringBuffer.append(" v) {\n    ");
    stringBuffer.append("");
 
/* checks to insure that cas has the feature */

    stringBuffer.append("    if (featOkTst && casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    if (lowLevelTypeChecks)\n      ll_cas.ll_set");
    stringBuffer.append(getSetArrayNamePart);
    stringBuffer.append("ArrayValue(ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append("), i, v, true);\n    jcas.checkArrayBounds(ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append("), i);\n    ll_cas.ll_set");
    stringBuffer.append(getSetArrayNamePart);
    stringBuffer.append("ArrayValue(ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(casFeatCode);
    stringBuffer.append("), i, v);\n  }\n");
   }
    stringBuffer.append(" \n");
   }
    stringBuffer.append("\n");
   if (td.getName().equals("uima.cas.Annotation")) {
    stringBuffer.append("  ");
    stringBuffer.append("  /** @see org.apache.uima.cas.text.AnnotationFS#getCoveredText() \n    * @generated */ \n  public String getCoveredText(int inst) { \n    final CASImpl casView = ll_cas.ll_getSofaCasView(inst);\n    final String text = casView.getDocumentText();\n    if (text == null) {\n      return null;\n    }\n    return text.substring(getBegin(inst), getEnd(inst)); \n  }\n");
    stringBuffer.append("");
   } /* of Annotation if-statement */
    stringBuffer.append("\n\n  /** initialize variables to correspond with Cas Type and Features\n  * @generated */\n  public ");
    stringBuffer.append(typeName_Type);
    stringBuffer.append("(JCas jcas, Type casType) {\n    super(jcas, casType);\n    casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl)this.casType, getFSGenerator());\n\n");
   for (int i = 0; i < fds.length; i++) {
     FeatureDescription fd = fds[i];

     String featName = fd.getName();


    stringBuffer.append(" \n    casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" = jcas.getRequiredFeatureDE(casType, \"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(fd.getRangeTypeName());
    stringBuffer.append("\", featOkTst);\n    casFeatCode_");
    stringBuffer.append(featName);
    stringBuffer.append("  = (null == casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(") ? JCas.INVALID_FEATURE_CODE : ((FeatureImpl)casFeat_");
View Full Code Here

    try {
      super.setUp();

      TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
      TypeDescription type1 = typeSystem.addType("Fake", "<b>Fake</b> Type", "Annotation");
      FeatureDescription feature1 = type1.addFeature("TestFeature", "For Testing Only",
              CAS.TYPE_NAME_STRING);
      TypeDescription enumType = typeSystem.addType("EnumType", "Test Enumerated Type",
              "uima.cas.String");
      enumType.setAllowedValues(new AllowedValue[] { new AllowedValue_impl("One", "First Value"),
          new AllowedValue_impl("Two", "Second Value") });
View Full Code Here

    try {
      super.setUp();

      TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
      TypeDescription type1 = typeSystem.addType("Fake", "A Fake Type", "Annotation");
      FeatureDescription feature1 = type1.addFeature("TestFeature", "For Testing Only",
              CAS.TYPE_NAME_STRING);
      TypeDescription enumType = typeSystem.addType("EnumType", "Test Enumerated Type",
              "uima.cas.String");
      enumType.setAllowedValues(new AllowedValue[] { new AllowedValue_impl("One", "First Value"),
          new AllowedValue_impl("Two", "Second Value") });
View Full Code Here

TOP

Related Classes of org.apache.uima.resource.metadata.FeatureDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.