Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document is ambiguous error on executing ruta script. #168

Open
raghu298 opened this issue Aug 7, 2024 · 2 comments
Open

Document is ambiguous error on executing ruta script. #168

raghu298 opened this issue Aug 7, 2024 · 2 comments
Labels
🦟 Bug Something isn't working Needs confirmation

Comments

@raghu298
Copy link

raghu298 commented Aug 7, 2024

I am using below versions:

versions used:
[uimaj-3.4.1]
[uimafit-3.4.0]
[ruta-3.3.0]
[cleartk-3.0.0]

java.lang.IllegalArgumentException: Document is ambiguous, use one of the following instead : org.apache.uima.ruta.type.Document uima.tcas.DocumentAnnotation

@raghu298
Copy link
Author

raghu298 commented Aug 7, 2024

@pkluegl Could you please help out what is going wrong and mostly its occurring when it runs in batch.
I don't have any multiple versions too.
and why Ruta thinks that "Document" should be a valid name for "Document" annotation.

@reckart
Copy link
Member

reckart commented Aug 9, 2024

I am unable to reproduce the issue on the 3.3.x branch

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();
   }
 }
}

@viorell91 suggested on the mailing list to try disambiguating the type in the scripts:

TYPE Document1 = org.apache.uima.ruta.type.Document;
TYPE Document2 = uima.tcas.DocumentAnnotation;

Document1{ -> CREATE(MyAnnotation)};

@reckart reckart added 🦟 Bug Something isn't working Needs confirmation labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦟 Bug Something isn't working Needs confirmation
Projects
None yet
Development

No branches or pull requests

2 participants