Package org.apache.uima.resource.metadata

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


    CasComparer.assertEquals(newCas1, newCas2);   
}
 
  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
View Full Code Here


    CasComparer.assertEquals(cas, cas2);   
  }
 
  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
View Full Code Here

    TypeDescription[] oldTypes = (null == oldTsd || null == oldTsd.getTypes()) ? new TypeDescription[0]
            : oldTsd.getTypes();
    HashMap oldTypeHash = new HashMap(oldTypes.length);

    for (int i = 0, length = oldTypes.length; i < length; i++) {
      TypeDescription oldType = oldTypes[i];
      oldTypeHash.put(oldType.getName(), oldType);
    }

    TypeDescription[] newTypes = mergedTypeSystemDescription.getTypes();
    for (int i = 0; i < newTypes.length; i++) {
      TypeDescription newType = newTypes[i];
      TypeDescription oldType = (TypeDescription) oldTypeHash.get(newType.getName());

      if (newType.equals(oldType)) {
        oldTypeHash.remove(oldType.getName());
      } else {
        addDirtyTypeName(newType.getName());
        if (oldType != null) {
          oldTypeHash.remove(oldType.getName());
        }
      }
    }

    Set deletedTypes = oldTypeHash.keySet();
View Full Code Here

    this.typeSystem = cas.getTypeSystem();
    this.casStringType = typeSystem.getType(CAS.TYPE_NAME_STRING);
    this.tcasAnnotationType = typeSystem.getType(CAS.TYPE_NAME_ANNOTATION);

    for (int i = 0; i < tds.length; i++) {
      TypeDescription td = tds[i];
      // System.out.println("Description: " + td.getDescription() );
      if (noGenTypes.contains(td.getName()))
        continue;
      if (td.getSupertypeName().equals("uima.cas.String"))
        continue;
      if (limitJCasGenToProjectScope &&
          isOutOfScope(td, projectPathDir)) {
        Set<String> mt = mergedTypesAddingFeatures.get(td.getName());
        if (null == mt) {
          continue;
        }
        StringBuilder sb = new StringBuilder("\n");
        for (String p : mt) {
          sb.append("  ").append(p).append('\n');
        }
        error.newError(IError.ERROR, getString("limitingButTypeWasExtended", new Object[] { td.getName(), sb.toString()}), null);
        continue;
      }

      // if the type is built-in - augment it with the built-in's features
      FeatureDescription[] builtInFeatures = (FeatureDescription[]) extendableBuiltInTypes.get(td
              .getName());
      if (null != builtInFeatures) {
        generatedBuiltInTypes.add(td.getName());
        List newFeatures = setDifference(td.getFeatures(), builtInFeatures);
        int newFeaturesSize = newFeatures.size();
        if (newFeaturesSize > 0) {
          int newSize = builtInFeatures.length + newFeaturesSize;
          FeatureDescription[] newFds = new FeatureDescription[newSize];
          System.arraycopy(builtInFeatures, 0, newFds, 0, builtInFeatures.length);
          for (int j = builtInFeatures.length, k = 0; k < newFeaturesSize; j++, k++)
            newFds[j] = (FeatureDescription) newFeatures.get(k);
          td.setFeatures(newFds);
        } else {
          // The only built-in type which is extensible is DocumentAnnotation.
          // If we get here, the user defined DocumentAnnotation, but did not add any features
          //   In this case, skip generation
          continue;
View Full Code Here

    StringBuffer stringBuffer = new StringBuffer();

    stringBuffer.append("\n\n");
    Object [] args = (Object [])argument;
    Jg jg = (Jg)args[0];
    TypeDescription td = (TypeDescription)args[1];
   jg.packageName = jg.getJavaPkg(td);
    stringBuffer.append("/* First created by JCasGen ");
    stringBuffer.append(jg.getDate());
    stringBuffer.append(" */\n");
   if (0 != jg.packageName.length()) {
    stringBuffer.append("package ");
    stringBuffer.append(jg.packageName);
    stringBuffer.append(";\n");
   }
   else
     jg.error.newError(IError.WARN,
    jg.getString("pkgMissing", new Object[] {td.getName()}), null);
    stringBuffer.append("\nimport org.apache.uima.jcas.JCas; \nimport org.apache.uima.jcas.JCasRegistry;\nimport org.apache.uima.jcas.cas.TOP_Type;\n\n");
   for(Iterator i=jg.collectImports(td, false).iterator(); i.hasNext();) {
    stringBuffer.append("import ");
    stringBuffer.append((String)i.next());
    stringBuffer.append(";\n");
   }
    stringBuffer.append("\n\n");
   String typeName = jg.getJavaName(td);
   String typeName_Type = typeName + "_Type";
   String jcasTypeCasted = "((" + typeName_Type + ")jcasType)";

    stringBuffer.append("/** ");
    stringBuffer.append(jg.nullBlank(td.getDescription()));
    stringBuffer.append("\n * Updated by JCasGen ");
    stringBuffer.append(jg.getDate());
    stringBuffer.append("\n * XML source: ");
    stringBuffer.append(jg.xmlSourceFileName);
    stringBuffer.append("\n * @generated */\npublic class ");
    stringBuffer.append(typeName);
    stringBuffer.append(" extends ");
    stringBuffer.append(jg.getJavaName(td.getSupertypeName()));
    stringBuffer.append(" {\n  /** @generated\n   * @ordered \n   */\n  @SuppressWarnings (\"hiding\")\n  public final static int typeIndexID = JCasRegistry.register(");
    stringBuffer.append(typeName);
    stringBuffer.append(".class);\n  /** @generated\n   * @ordered \n   */\n  @SuppressWarnings (\"hiding\")\n  public final static int type = typeIndexID;\n  /** @generated\n   * @return index of the type  \n   */\n  @Override\n  public              int getTypeIndexID() {return typeIndexID;}\n \n  /** Never called.  Disable default constructor\n   * @generated */\n  protected ");
    stringBuffer.append(typeName);
    stringBuffer.append("() {/* intentionally empty block */}\n    \n  /** Internal - constructor used by generator \n   * @generated\n   * @param addr low level Feature Structure reference\n   * @param type the type of this Feature Structure \n   */\n  public ");
    stringBuffer.append(typeName);
    stringBuffer.append("(int addr, TOP_Type type) {\n    super(addr, type);\n    readObject();\n  }\n  \n  /** @generated\n   * @param jcas JCas to which this Feature Structure belongs \n   */\n  public ");
    stringBuffer.append(typeName);
    stringBuffer.append("(JCas jcas) {\n    super(jcas);\n    readObject();   \n  } \n");
  if (jg.isSubTypeOfAnnotation(td)) {
    stringBuffer.append("\n  /** @generated\n   * @param jcas JCas to which this Feature Structure belongs\n   * @param begin offset to the begin spot in the SofA\n   * @param end offset to the end spot in the SofA \n  */  \n  public ");
    stringBuffer.append(typeName);
    stringBuffer.append("(JCas jcas, int begin, int end) {\n    super(jcas);\n    setBegin(begin);\n    setEnd(end);\n    readObject();\n  }   \n");
  }
    stringBuffer.append("\n  /** \n   * <!-- begin-user-doc -->\n   * Write your own initialization here\n   * <!-- end-user-doc -->\n   *\n   * @generated modifiable \n   */\n  private void readObject() {/*default - does nothing empty block */}\n     \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
   if (Jg.reservedFeatureNames.contains(featUName))
     jg.error.newError(IError.ERROR,
     jg.getString("reservedNameUsed", new Object[] { featName, td.getName() }),
     null);

     String featDesc = jg.nullBlank(fd.getDescription());
     String featDescCmt = featDesc;

     String rangeType = jg.getJavaRangeType(fd);
     String elemType = jg.getJavaRangeArrayElementType(fd);   

    stringBuffer.append(" \n    \n  //*--------------*\n  //* Feature: ");
    stringBuffer.append(featName);
    stringBuffer.append("\n\n  /** getter for ");
    stringBuffer.append(featName);
    stringBuffer.append(" - gets ");
    stringBuffer.append(featDescCmt);
    stringBuffer.append("\n   * @generated\n   * @return value of the feature \n   */\n  public ");
    stringBuffer.append(rangeType);
    stringBuffer.append(" get");
    stringBuffer.append(featUName);
    stringBuffer.append("() {\n    ");
    stringBuffer.append("if (");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".featOkTst && ");
    stringBuffer.append(jcasTypeCasted);
    stringBuffer.append(".casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcasType.jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    return ");
    stringBuffer.append(jg.getFeatureValue(fd, td));
    stringBuffer.append(";}\n    \n  /** setter for ");
    stringBuffer.append(featName);
    stringBuffer.append(" - sets ");
    stringBuffer.append(featDescCmt);
    stringBuffer.append(" \n   * @generated\n   * @param v value to set into the feature \n   */\n  public void set");
    stringBuffer.append(featUName);
    stringBuffer.append("(");
    stringBuffer.append(rangeType);
    stringBuffer.append(" v) {\n    ");
    stringBuffer.append("if (");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".featOkTst && ");
    stringBuffer.append(jcasTypeCasted);
    stringBuffer.append(".casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcasType.jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    ");
    stringBuffer.append(jg.setFeatureValue(fd, td));
    stringBuffer.append(";}    \n  ");
  if (jg.hasArrayRange(fd)) {
    stringBuffer.append("  \n  /** indexed getter for ");
    stringBuffer.append(featName);
    stringBuffer.append(" - gets an indexed value - ");
    stringBuffer.append(featDescCmt);
    stringBuffer.append("\n   * @generated\n   * @param i index in the array to get\n   * @return value of the element at index i \n   */\n  public ");
    stringBuffer.append(elemType);
    stringBuffer.append(" get");
    stringBuffer.append(featUName);
    stringBuffer.append("(int i) {\n    ");
    stringBuffer.append("if (");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".featOkTst && ");
    stringBuffer.append(jcasTypeCasted);
    stringBuffer.append(".casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcasType.jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    ");
    stringBuffer.append("jcasType.jcas.checkArrayBounds(jcasType.ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(jcasTypeCasted);
    stringBuffer.append(".casFeatCode_");
    stringBuffer.append(featName);
    stringBuffer.append("), i);\n");
    stringBuffer.append("    return ");
    stringBuffer.append(jg.getArrayFeatureValue(fd, td));
    stringBuffer.append(";}\n\n  /** indexed setter for ");
    stringBuffer.append(featName);
    stringBuffer.append(" - sets an indexed value - ");
    stringBuffer.append(featDescCmt);
    stringBuffer.append("\n   * @generated\n   * @param i index in the array to set\n   * @param v value to set into the array \n   */\n  public void set");
    stringBuffer.append(featUName);
    stringBuffer.append("(int i, ");
    stringBuffer.append(elemType);
    stringBuffer.append(" v) { \n    ");
    stringBuffer.append("if (");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".featOkTst && ");
    stringBuffer.append(jcasTypeCasted);
    stringBuffer.append(".casFeat_");
    stringBuffer.append(featName);
    stringBuffer.append(" == null)\n      jcasType.jcas.throwFeatMissing(\"");
    stringBuffer.append(featName);
    stringBuffer.append("\", \"");
    stringBuffer.append(td.getName());
    stringBuffer.append("\");\n");
    stringBuffer.append("    ");
    stringBuffer.append("jcasType.jcas.checkArrayBounds(jcasType.ll_cas.ll_getRefValue(addr, ");
    stringBuffer.append(jcasTypeCasted);
    stringBuffer.append(".casFeatCode_");
    stringBuffer.append(featName);
    stringBuffer.append("), i);\n");
    stringBuffer.append("    ");
    stringBuffer.append(jg.setArrayFeatureValue(fd, td));
    stringBuffer.append(";}\n  ");
   } /* of hasArray */
    stringBuffer.append("");
   } /* of Features iteration */
    stringBuffer.append("");
   if (td.getName().equals("uima.cas.Annotation")) {
    stringBuffer.append("  ");
    stringBuffer.append("  /** Constructor with begin and end passed as arguments \n    * @generated\n    * @param jcas JCas this Annotation is in\n    * @param begin the begin offset\n    * @param end the end offset\n    */\n  public Annotation(JCas jcas, int begin, int end) { \n    this(jcas); // forward to constructor \n    this.setBegin(begin); \n    this.setEnd(end); \n  } \n  \n  /** @see org.apache.uima.cas.text.AnnotationFS#getCoveredText() \n    * @generated\n    * @return the covered Text \n    */ \n  public String getCoveredText() { \n    final CAS casView = this.getView();\n    final String text = casView.getDocumentText();\n    if (text == null) {\n      return null;\n    }\n    return text.substring(getBegin(), getEnd());\n  } \n  \n  /** @deprecated \n    * @generated\n    * @return the begin offset \n    */\n  public int getStart() {return getBegin();}\n");
    stringBuffer.append("");
   } /* of Annotation if-statement */
    stringBuffer.append("}\n\n    ");
View Full Code Here

    stringBuffer.append("\n");
 
    Object [] args = (Object [])argument;
    Jg jg = (Jg)args[0];
    TypeDescription td = (TypeDescription)args[1];
   jg.packageName = jg.getJavaPkg(td);
    stringBuffer.append("/* First created by JCasGen ");
    stringBuffer.append(jg.getDate());
    stringBuffer.append(" */\n");
   if (0 != jg.packageName.length()) {
    stringBuffer.append("package ");
    stringBuffer.append(jg.packageName);
    stringBuffer.append(";\n");
   }
    stringBuffer.append("\nimport org.apache.uima.jcas.JCas;\nimport org.apache.uima.jcas.JCasRegistry;\nimport org.apache.uima.cas.impl.CASImpl;\nimport org.apache.uima.cas.impl.FSGenerator;\nimport org.apache.uima.cas.FeatureStructure;\nimport org.apache.uima.cas.impl.TypeImpl;\nimport org.apache.uima.cas.Type;\n");
   if (td.getFeatures().length > 0) {
    stringBuffer.append("import org.apache.uima.cas.impl.FeatureImpl;\nimport org.apache.uima.cas.Feature;\n");
   }
    stringBuffer.append("");
   for(Iterator i=jg.collectImports(td, true).iterator(); i.hasNext();) {
String imp = (String)i.next();
  if (!imp.equals(jg.getJavaNameWithPkg(td.getName()+"_Type"))) {
    stringBuffer.append("import ");
    stringBuffer.append(imp);
    stringBuffer.append(";\n");
   }}
    stringBuffer.append("\n");
   String typeName = jg.getJavaName(td);
   String typeName_Type = typeName + "_Type";
    stringBuffer.append("/** ");
    stringBuffer.append(jg.nullBlank(td.getDescription()));
    stringBuffer.append("\n * Updated by JCasGen ");
    stringBuffer.append(jg.getDate());
    stringBuffer.append("\n * @generated */\npublic class ");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(" extends ");
    stringBuffer.append(jg.getJavaName(td.getSupertypeName()) + "_Type");
    stringBuffer.append(" {\n  /** @generated \n   * @return the generator for this type\n   */\n  @Override\n  protected FSGenerator getFSGenerator() {return fsGenerator;}\n  /** @generated */\n  private final FSGenerator fsGenerator = \n    new FSGenerator() {\n      public FeatureStructure createFS(int addr, CASImpl cas) {\n         if (");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".this.useExistingInstance) {\n           // Return eq fs instance if already created\n           FeatureStructure fs = ");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".this.jcas.getJfsFromCaddr(addr);\n           if (null == fs) {\n             fs = new ");
    stringBuffer.append(typeName);
    stringBuffer.append("(addr, ");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".this);\n           ");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".this.jcas.putJfsFromCaddr(addr, fs);\n           return fs;\n           }\n           return fs;\n        } else return new ");
    stringBuffer.append(typeName);
    stringBuffer.append("(addr, ");
    stringBuffer.append(typeName_Type);
    stringBuffer.append(".this);\n      }\n    };\n  /** @generated */\n  @SuppressWarnings (\"hiding\")\n  public final static int typeIndexID = ");
    stringBuffer.append(typeName);
    stringBuffer.append(".typeIndexID;\n  /** @generated \n     @modifiable */\n  @SuppressWarnings (\"hiding\")\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   * @param addr low level Feature Structure reference\n   * @return the feature value \n   */ \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   * @param addr low level Feature Structure reference\n   * @param v value to set \n   */    \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   * @param addr low level Feature Structure reference\n   * @param i index of item in the array\n   * @return value at index i in the array \n   */\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   * @param addr low level Feature Structure reference\n   * @param i index of item in the array\n   * @param v value to set\n   */ \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    * @param inst the low level Feature Structure reference \n    * @return the covered text \n    */ \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   * @param jcas JCas\n   * @param casType Type \n   */\n  public ");
View Full Code Here

      desc.setPrimitive(true);
      desc.getMetaData().setName("Test Primitive TAE");
      desc.setAnnotatorImplementationName("org.apache.uima.analysis_engine.impl.TestAnnotator");

      TypeSystemDescription typeSystem = new TypeSystemDescription_impl();
      TypeDescription type1 = typeSystem.addType("Type1", "Test Type One",
              CAS.TYPE_NAME_ANNOTATION);
      FeatureDescription feat1 = new FeatureDescription_impl();
      feat1.setName("Feature1");
      feat1.setRangeTypeName(CAS.TYPE_NAME_INTEGER);
      type1.setFeatures(new FeatureDescription[] { feat1 });
      TypeDescription type2 = typeSystem.addType("Type2", "Test Type Two",
              CAS.TYPE_NAME_ANNOTATION);
      FeatureDescription feat2 = new FeatureDescription_impl();
      feat2.setName("Feature2");
      feat2.setRangeTypeName("EnumType");
      type2.setFeatures(new FeatureDescription[] { feat2 });
      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") });
      desc.getAnalysisEngineMetaData().setTypeSystem(typeSystem);

      TypePriorities typePriorities = new TypePriorities_impl();
      TypePriorityList priorityList = typePriorities.addPriorityList();
View Full Code Here

      // test results of merge
      // TypeSystem
      TypeSystemDescription typeSys = ae.getAnalysisEngineMetaData().getTypeSystem();
      Assert.assertEquals(8, typeSys.getTypes().length);

      TypeDescription type0 = typeSys.getType("NamedEntity");
      Assert.assertNotNull(type0);
      Assert.assertEquals("uima.tcas.Annotation", type0.getSupertypeName());
      Assert.assertEquals(1, type0.getFeatures().length);

      TypeDescription type1 = typeSys.getType("Person");
      Assert.assertNotNull(type1);
      Assert.assertEquals("NamedEntity", type1.getSupertypeName());
      Assert.assertEquals(1, type1.getFeatures().length);

      TypeDescription type2 = typeSys.getType("Place");
      Assert.assertNotNull(type2);
      Assert.assertEquals("NamedEntity", type2.getSupertypeName());
      Assert.assertEquals(3, type2.getFeatures().length);

      TypeDescription type3 = typeSys.getType("Org");
      Assert.assertNotNull(type3);
      Assert.assertEquals("uima.tcas.Annotation", type3.getSupertypeName());
      Assert.assertEquals(0, type3.getFeatures().length);

      TypeDescription type4 = typeSys.getType("DocumentStructure");
      Assert.assertNotNull(type4);
      Assert.assertEquals("uima.tcas.Annotation", type4.getSupertypeName());
      Assert.assertEquals(0, type4.getFeatures().length);

      TypeDescription type5 = typeSys.getType("Paragraph");
      Assert.assertNotNull(type5);
      Assert.assertEquals("DocumentStructure", type5.getSupertypeName());
      Assert.assertEquals(0, type5.getFeatures().length);

      TypeDescription type6 = typeSys.getType("Sentence");
      Assert.assertNotNull(type6);
      Assert.assertEquals("DocumentStructure", type6.getSupertypeName());
      Assert.assertEquals(0, type6.getFeatures().length);

      TypeDescription type7 = typeSys.getType("test.flowController.Test");
      Assert.assertNotNull(type7);
      Assert.assertEquals("uima.tcas.Annotation", type7.getSupertypeName());
      Assert.assertEquals(1, type7.getFeatures().length);

      // TypePriorities
      TypePriorities pri = ae.getAnalysisEngineMetaData().getTypePriorities();
      Assert.assertNotNull(pri);
      TypePriorityList[] priLists = pri.getPriorityLists();
View Full Code Here

   * @param aTypeSystem
   *          the TypeSystem that contains <code>aType</code>
   * @return a TypeDescription that is equivalent to <code>aType</code>
   */
  public static TypeDescription type2TypeDescription(Type aType, TypeSystem aTypeSystem) {
    TypeDescription typeDesc = UIMAFramework.getResourceSpecifierFactory().createTypeDescription();
    typeDesc.setName(aType.getName());
    Type superType = aTypeSystem.getParent(aType);
    typeDesc.setSupertypeName(superType.getName());
    // special handling for string subtypes (which have "allowed values", rather than features)
    Type stringType = aTypeSystem.getType("uima.cas.String");
    if (aTypeSystem.subsumes(stringType, aType)) {
      String[] allowedValues = getAllowedValuesForType(aType, aTypeSystem);
      AllowedValue[] avObjs = new AllowedValue[allowedValues.length];
      for (int i = 0; i < allowedValues.length; i++) {
        AllowedValue av = UIMAFramework.getResourceSpecifierFactory().createAllowedValue();
        av.setString(allowedValues[i]);
        avObjs[i] = av;
      }
      typeDesc.setAllowedValues(avObjs);
    } else {
      ArrayList<FeatureDescription> featDescs = new ArrayList<FeatureDescription>();
      for (Feature feat : aType.getFeatures()){
        if (!superType.getFeatures().contains(feat)) {
          featDescs.add(feature2FeatureDescription(feat));
        }
      }
      FeatureDescription[] featDescArr = new FeatureDescription[featDescs.size()];
      featDescs.toArray(featDescArr);
      typeDesc.setFeatures(featDescArr);
    }
    return typeDesc;
  }
View Full Code Here

  /**
   * @see TypeSystemDescription#addType(String, String, String)
   */
  public TypeDescription addType(String aTypeName, String aDescription, String aSupertypeName) {
    // create new type description
    TypeDescription newType = new TypeDescription_impl(aTypeName, aDescription, aSupertypeName);

    // add to array
    TypeDescription[] types = getTypes();
    if (types == null) {
      setTypes(new TypeDescription[] { newType });
View Full Code Here

TOP

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

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.