TyErrorId process(CAS & rCAS, ResultSpecification const & crResultSpecification) { CAS *engTcas, *germTcas; UChar *myLocalSaveState; // Look for english document and "translate" to German cout << "SofaExampleAnnotator: process() begins" << endl; // get English view engTcas = rCAS.getView("EnglishDocument"); DocumentFS adocFS = engTcas->getDocumentAnnotation(); UnicodeStringRef aengText = adocFS.getCoveredText(); cout << " English Input: " << aengText << endl; // Create the output German text Sofa and open CAS view germTcas = rCAS.createView("GermanDocument"); // Get pointer to the English text document DocumentFS docFS = engTcas->getDocumentAnnotation(); UnicodeStringRef engText = docFS.getCoveredText(); // make copy of document for the u_strtok_r function (100 character limit!) UChar uWork[100]; u_strncpy(uWork, engText.getBuffer(), 99); // Setup for translated text int germBegin = 0; int germEnd = 0; UChar translation[400]; translation[0]=0; // get two IR handles for adding annotations to the appropriate view FSIndexRepository & engIndexRep = engTcas->getIndexRepository(); FSIndexRepository & germIndexRep = germTcas->getIndexRepository(); // Parse the English text UChar uDelim[2]; UnicodeString delimUS(" "); u_strncpy(uDelim, delimUS.getBuffer(), 1); uDelim[1] = 0; UChar * next = u_strtok_r(uWork, uDelim, &myLocalSaveState); while (next) { // Create annotation on source text AnnotationFS engAnnot = engTcas->createAnnotation(annot, next-uWork, (next-uWork)+u_strlen(next)); engIndexRep.addFS(engAnnot); // Translate word-by-word const UChar * gword = translate(next); // Accumulate the total translated document if (germBegin > 0) { // if not the first word, add space before u_strncat(translation, uDelim, 1); germBegin += 1; } u_strcat(translation, gword); // Create annotation on output text germEnd = germBegin + u_strlen(gword); AnnotationFS germAnnot = germTcas->createAnnotation(cross, germBegin, germEnd); germIndexRep.addFS(germAnnot); // add link to English text germAnnot.setFSValue(other, engAnnot); germBegin = germEnd; next = u_strtok_r(NULL, uDelim, &myLocalSaveState); } // set documentText with accumulated transation germTcas->setDocumentText( translation, u_strlen(translation), true ); cout << " German(!) Output: " << germTcas->getDocumentText() << endl; cout << "SofaExampleAnnotator: process() ends" << endl; return (TyErrorId)UIMA_ERR_NONE; }