Hi,

> On 8. Aug 2024, at 14:22, Raghunath Mahakud <mahakudraghunath...@gmail.com> 
> wrote:
> 
> Can anyone guide me? It's a critical blocker for me.

it would be good if we could reproduce this. So far, I have been unable to 
reproduce
your problem.

The code below creates a CAS with two types whose short name is `Document` and 
does not
throw an exception. I tested this on the Rut 3.3.x branch.

If you could produce a simple example that reproduces your issue, it would help.

Cheers,

-- Richard

```
package org.apache.uima.ruta;

import static java.util.Arrays.asList;

import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.util.CasCreationUtils;

public class RutaScriptExample {
  private static final String DOCUMENT = "org.apache.uima.ruta.type.Document";

  public static void main(String[] args) {
    try {
      // Create a TypeSystemDescription with a type x.y.z.Document
      TypeSystemDescription tsDesc = new TypeSystemDescription_impl();
      tsDesc.addType(DOCUMENT, "", "uima.tcas.Annotation");

      TypeSystemDescription tsDefault = 
TypeSystemDescriptionFactory.createTypeSystemDescription();

      TypeSystemDescription tsAll = 
CasCreationUtils.mergeTypeSystems(asList(tsDesc, tsDefault));

      // Create a CAS with the type system
      CAS cas = CasCreationUtils.createCas(tsAll, null, null);

      // Add some text to the CAS
      cas.setDocumentText("This is a sample document.");

      // Create an annotation of type Document
      Type documentType = cas.getTypeSystem().getType(DOCUMENT);
      AnnotationFS documentAnnotation = cas.createAnnotation(documentType, 0,
              cas.getDocumentText().length());
      cas.addFsToIndexes(documentAnnotation);

      // Define a Ruta script that uses the rule Document{-> ...}
      String rutaScript = "Document{-> NUM};";

      // Apply the Ruta script to the CAS
      Ruta.apply(cas, rutaScript);

    } catch (Exception e) {
      // Catch and handle any exceptions that occur
      System.err.println("An error occurred while applying the Ruta script:");
      e.printStackTrace();
    }
  }
}
```

Reply via email to