org.apache.uima.cas.CASRuntimeException Java Examples
The following examples show how to use
org.apache.uima.cas.CASRuntimeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JCasTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testUndefinedType() throws Exception { //create jcas with no type system JCas localJcas = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null).getJCas(); localJcas.setDocumentText("This is a test."); try { //this should throw an exception localJcas.getCasType(Sentence.type); fail(); } catch(CASRuntimeException e) { assertEquals(CASRuntimeException.JCAS_TYPE_NOT_IN_CAS, e.getMessageKey()); } //check that this does not leave JCAS in an inconsistent state //(a check for bug UIMA-738) Iterator<Annotation> iter = localJcas.getAnnotationIndex().iterator(); assertTrue(iter.hasNext()); Annotation annot = iter.next(); assertEquals("This is a test.", annot.getCoveredText()); }
Example #2
Source File: StringSubtypeTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testLowLevelCas() { LowLevelCAS cas = this.jcas.getLowLevelCas(); LowLevelTypeSystem ts = cas.ll_getTypeSystem(); final int annotType = ts.ll_getCodeForTypeName(annotationTypeName); final int addr = cas.ll_createFS(annotType); final int stringSetFeat = ts.ll_getCodeForFeatureName(annotationTypeName + TypeSystem.FEATURE_SEPARATOR + stringSetFeatureName); cas.ll_setStringValue(addr, stringSetFeat, definedValue1); cas.ll_setStringValue(addr, stringSetFeat, definedValue2); cas.ll_setStringValue(addr, stringSetFeat, definedValue3); // next should be ok https://issues.apache.org/jira/browse/UIMA-1839 cas.ll_setStringValue(addr, stringSetFeat, null); boolean exCaught = false; try { cas.ll_setStringValue(addr, stringSetFeat, undefinedValue); } catch (CASRuntimeException e) { exCaught = true; } assertTrue(exCaught); }
Example #3
Source File: CasUtil.java From uima-uimafit with Apache License 2.0 | 6 votes |
/** * Convenience method to get the specified view or create a new view if the requested view does * not exist. * * @param cas * a CAS * @param viewName * the requested view. * @param create * the view is created if it does not exist. * @return the requested view * @throws IllegalArgumentException * if the view does not exist and is not to be created. */ public static CAS getView(CAS cas, String viewName, boolean create) { CAS view; try { view = cas.getView(viewName); } catch (CASRuntimeException e) { // View does not exist if (create) { view = cas.createView(viewName); } else { throw new IllegalArgumentException("No view with name [" + viewName + "]"); } } return view; }
Example #4
Source File: FSClassRegistry.java From uima-uimaj with Apache License 2.0 | 6 votes |
public static JCasClassInfo createJCasClassInfo( TypeImpl ti, ClassLoader cl, Lookup lookup) { Class<? extends TOP> clazz = maybeLoadJCas(ti, cl); if (null == clazz || ! TOP.class.isAssignableFrom(clazz)) { return null; } int jcasType = -1; if (!Modifier.isAbstract(clazz.getModifiers())) { // skip next for abstract classes jcasType = Misc.getStaticIntFieldNoInherit(clazz, "typeIndexID"); // if jcasType is negative, this means there's no value for this field if (jcasType == -1) { add2errors(errorSet, /** The Class "{0}" matches a UIMA Type, and is a subtype of uima.cas.TOP, but is missing the JCas typeIndexId.*/ new CASRuntimeException(CASRuntimeException.JCAS_MISSING_TYPEINDEX, clazz.getName()), false); // not a fatal error return null; } } return createJCasClassInfo(clazz, ti, jcasType, lookup); }
Example #5
Source File: SelectFSs_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
@Override public T singleOrNull() { FSIterator<T> it = fsIterator(); if (it.isValid()) { T v = it.getNvc(); if (shift >= 0) { it.moveToNext(); } else { it.moveToPrevious(); } if (it.isValid()) { throw new CASRuntimeException(CASRuntimeException.SELECT_GET_TOO_MANY_INSTANCES, ti.getName(), maybeMsgPosition()); } return v; } return null; }
Example #6
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void _check_feature_range_is_FeatureStructure(Feature feat, FeatureStructureImplC fs) { Type range = feat.getRange(); if (range.isPrimitive()) { throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE_NOT_FS, feat.getName(), fs.getType().getName(), feat.getRange().getName() ); } }
Example #7
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
/************************************* * Validation checking *************************************/ private void _Check_feature_defined_for_this_type(Feature feat) { if (!(((TypeImpl) (feat.getDomain()) ).subsumes(_typeImpl))) { /* Feature "{0}" is not defined for type "{1}". */ throw new CASRuntimeException(CASRuntimeException.INAPPROP_FEAT, feat.getName(), _typeImpl.getName()); } }
Example #8
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * All 3 checks for long * @param fi - the feature * @param v - the value */ protected void _setLongValueCJ(FeatureImpl fi, long v) { if (!fi.isInInt) { /** Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "long or double", fi.getRange().getName()); } if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) _Check_feature_defined_for_this_type(fi); _casView.setLongValue(this, fi, v); }
Example #9
Source File: FSClassRegistry.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Return a Functional Interface for a generator for creating instances of a type. * Function takes a casImpl arg, and returning an instance of the JCas type. * @param jcasClass the class of the JCas type to construct * @param typeImpl the UIMA type * @return a Functional Interface whose createFS method takes a casImpl * and when subsequently invoked, returns a new instance of the class */ private static FsGenerator3 createGenerator(Class<?> jcasClass, Lookup lookup) { try { MethodHandle mh = lookup.findConstructor(jcasClass, findConstructorJCasCoverType); MethodType mtThisGenerator = methodType(jcasClass, TypeImpl.class, CASImpl.class); CallSite callSite = LambdaMetafactory.metafactory( lookup, // lookup context for the constructor "createFS", // name of the method in the Function Interface callsiteFsGenerator, // signature of callsite, return type is functional interface, args are captured args if any fsGeneratorType, // samMethodType signature and return type of method impl by function object mh, // method handle to constructor mtThisGenerator); return (FsGenerator3) callSite.getTarget().invokeExact(); } catch (Throwable e) { if (e instanceof NoSuchMethodException) { String classname = jcasClass.getName(); add2errors(errorSet, new CASRuntimeException(e, CASRuntimeException.JCAS_CAS_NOT_V3, classname, jcasClass.getClassLoader().getResource(classname.replace('.', '/') + ".class").toString() )); return null; } /** An internal error occurred, please report to the Apache UIMA project; nested exception if present: {0} */ throw new UIMARuntimeException(e, UIMARuntimeException.INTERNAL_ERROR); } }
Example #10
Source File: MarkerImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public boolean isNew(FeatureStructure fs) { //check if same CAS instance if (!isValid || !cas.isInCAS(fs)) { throw new CASRuntimeException(CASRuntimeException.CAS_MISMATCH, "FS and Marker are not from the same CAS."); } return isNew(fs._id()); }
Example #11
Source File: SerDesTest4.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void tstPrevGenV2(Runnable m) { tearDown(); setUp(); boolean caught = false; try { m.run(); } catch (CASRuntimeException e) { caught = e.hasMessageKey(CASRuntimeException.DESERIALIZING_V2_DELTA_V3); } assertTrue("Should have thrown exception serializing v2 into v3", caught); }
Example #12
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
SofaFS getSofa(int sofaRef) { SofaFS aSofa = (SofaFS) this.ll_getFSForRef(sofaRef); if (aSofa == null) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFAREF_NOT_FOUND); throw e; } return aSofa; }
Example #13
Source File: IteratorTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testInvalidIndexRequest() { boolean exc = false; try { this.cas.getIndexRepository().getIndex(CASTestSetup.ANNOT_BAG_INDEX, this.stringType); } catch (CASRuntimeException e) { exc = true; } assertTrue(exc); }
Example #14
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
protected void _setRefValueCJ(FeatureImpl fi, Object v) { if (fi.isInInt) { /** Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "int", fi.getRange().getName()); } if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) _Check_feature_defined_for_this_type(fi); _casView.setWithCheckAndJournal((TOP)this, fi.getCode(), () -> _setRefValueCommon(fi, v)); }
Example #15
Source File: FeaturePathImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void setTargetFeature(TOP currentFs, int i) { targetFeature = currentFs._getTypeImpl().getFeatureByBaseName(featurePathElementNames.get(i)); if (targetFeature == null) { throw new CASRuntimeException(MESSAGE_DIGEST, "INVALID_FEATURE_PATH_FEATURE_NOT_DEFINED", new Object[] { getFeaturePathString(), currentFs._getTypeImpl().getName(), this.featurePathElementNames.get(i) }); } boundFeatures.add(targetFeature); // cache for future use }
Example #16
Source File: JCasTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void checkOkMissingImport(Exception e1) { if (e1 instanceof CASRuntimeException) { System.out.print("setup caught CAS Exception with message: "); String m = e1.getMessage(); System.out.println(m); assertEquals("The JCas cannot be initialized. The following errors occurred: " + "\nUnable to find required getPlainRef method for JCAS type aa.Root with return type of org.apache.uima.jcas.cas.TOP." + "\nUnable to find required setPlainRef method for JCAS type aa.Root with argument type of org.apache.uima.jcas.cas.TOP.\n", m); // if (!m // .equals("Error initializing JCas: Error: can't access feature information from CAS in initializing JCas type: aa.Root, feature: testMissingImport\n")) { // assertTrue(false); // } } else assertTrue(false); }
Example #17
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public void setDocumentLanguage(String languageCode) { if (this == this.svd.baseCAS) { throw new CASRuntimeException(CASRuntimeException.INVALID_BASE_CAS_METHOD, "setDocumentLanguage(String)"); } Annotation docAnnot = getDocumentAnnotation(); FeatureImpl languageFeature = getTypeSystemImpl().langFeat; languageCode = Language.normalize(languageCode); boolean wasRemoved = this.checkForInvalidFeatureSetting(docAnnot, languageFeature.getCode(), this.getAddbackSingle()); docAnnot.setStringValue(getTypeSystemImpl().langFeat, languageCode); addbackSingleIfWasRemoved(wasRemoved, docAnnot); }
Example #18
Source File: AnnotationTreeNodeImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public AnnotationTreeNode<T> getChild(int i) throws CASRuntimeException { try { return this.dtrs.get(i); } catch (IndexOutOfBoundsException e) { throw new CASRuntimeException(CASRuntimeException.CHILD_INDEX_OOB, null); } }
Example #19
Source File: CasCopier.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Gets the named view; if the view doesn't exist it will be created. */ private static CASImpl getOrCreateView(CASImpl aCas, String aViewName) { //TODO: there should be some way to do this without the try...catch try { // throws if view doesn't exist return (CASImpl) aCas.getView(aViewName).getLowLevelCAS(); } catch(CASRuntimeException e) { //create the view return (CASImpl) aCas.createView(aViewName).getLowLevelCAS(); } }
Example #20
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
Sofa createSofa(int sofaNum, String sofaName, String mimeType) { if (this.svd.sofaNameSet.contains(sofaName)) { throw new CASRuntimeException(CASRuntimeException.SOFANAME_ALREADY_EXISTS, sofaName); } final boolean viewAlreadyExists = sofaNum == this.svd.viewCount; if (!viewAlreadyExists) { if (sofaNum == 1) { // skip the test for sofaNum == 1 - this can be set "later" if (this.svd.viewCount == 0) { this.svd.viewCount = 1; } // else it is == or higher, so don't reset it down } else { // sofa is not initial sofa - is guaranteed to be set when view created // if (sofaNum != this.svd.viewCount + 1) { // System.out.println("debug"); // } assert (sofaNum == this.svd.viewCount + 1); this.svd.viewCount = sofaNum; } } Sofa sofa = new Sofa( getTypeSystemImpl().sofaType, this.getBaseCAS(), // view for a sofa is the base cas to correspond to where it gets indexed sofaNum, sofaName, mimeType); this.getBaseIndexRepository().addFS(sofa); this.svd.sofaNameSet.add(sofaName); if (!viewAlreadyExists) { getView(sofa); // create the view that goes with this Sofa } return sofa; }
Example #21
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * All 3 checks * @param fi - the feature * @param v - the value */ protected void _setIntValueCJ(FeatureImpl fi, int v) { if (!fi.isInInt) { /** Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/ throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, fi.getName(), "boolean, byte, short, int, or float", fi.getRange().getName()); } if (IS_ENABLE_RUNTIME_FEATURE_VALIDATION) _Check_feature_defined_for_this_type(fi); _casView.setWithCheckAndJournal((TOP)this, fi.getCode(), () -> _setIntValueCommon(fi, v)); }
Example #22
Source File: FeaturePathImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Method that throws the CASRuntimeException for an unsupported built-in * function * * @param typeName * type name that does not support the built-in function */ private void throwBuiltInFunctionException(String typeName) { // get built-in function name String functionName = null; if (this.builtInFunction == FUNCTION_COVERED_TEXT) { functionName = FUNCTION_NAME_COVERED_TEXT; } else if (this.builtInFunction == FUNCTION_ID) { functionName = FUNCTION_NAME_ID; } else if (this.builtInFunction == FUNCTION_TYPE_NAME) { functionName = FUNCTION_NAME_TYPE_NAME; } // throw runtime exception throw new CASRuntimeException(MESSAGE_DIGEST, "BUILT_IN_FUNCTION_NOT_SUPPORTED", new Object[] { functionName, typeName }); }
Example #23
Source File: FeatureStructureTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testErrorDerefDifferentCAS() { CAS cas2 = CASInitializer.initCas(new CASTestSetup(), null); Type tokenType1 = this.ts.getType(CASTestSetup.TOKEN_TYPE); Feature tokenTypeFeature = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_TYPE + ":" + CASTestSetup.TOKEN_TYPE_FEAT); FeatureStructure fs1 = cas2.createFS(tokenType1); FeatureStructure fs = cas.createFS(tokenType1); boolean caught = false; try { fs.setFeatureValue(tokenTypeFeature, fs1); } catch (Exception e) { assertTrue( e instanceof CASRuntimeException); caught = true; } assertTrue(caught); }
Example #24
Source File: FeatureValuePathImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Checks whether the feature snippet denotes array access (i.e., has [..] attached to it). If so, * determines the arrayIndex to use within evaluation, which can be a number, the special element * "last" or simple [], which means "all elements" * * @throws CASRuntimeException * If the closing ] is missing, or the number is not an integer */ private final void determineArray() throws CASRuntimeException { int startIndex = this.featureName.indexOf('['); if (startIndex == -1) { return; } int endIndex = this.featureName.indexOf(']'); if (endIndex == -1) { // we're missing the ending bracket throw new CASRuntimeException(CASRuntimeException.INVALID_FEATURE_PATH, this.toString()); } this.isArrayOrList = true; String arrayIndexString = this.featureName.substring(startIndex + 1, endIndex); // cut off the array markers from the actual feature name this.featureName = this.featureName.substring(0, startIndex); // determine the array index to use if (arrayIndexString.equals("")) { // empty brackets, denotes "all // elements" this.arrayIndex = USE_ALL_ENTRIES; } else if (LAST_ARRAY_ENTRY_MARKER.equalsIgnoreCase(arrayIndexString)) { // [last],denotes "take the last array element" this.arrayIndex = LAST_ARRAY_ENTRY; } else { try { this.arrayIndex = Integer.parseInt(arrayIndexString); } catch (NumberFormatException e) { throw new CASRuntimeException(CASRuntimeException.INVALID_FEATURE_PATH, this.toString()); } } }
Example #25
Source File: SelectFSs_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void forceAnnotationIndex() { if (index == null) { index = (LowLevelIndex<T>) ( (ti == null) ? view.getAnnotationIndex() : view.getAnnotationIndex(ti)); } else { if (!(index instanceof AnnotationIndex)) { /** Index "{0}" must be an AnnotationIndex. */ throw new CASRuntimeException(CASRuntimeException.ANNOTATION_INDEX_REQUIRED, index); } } }
Example #26
Source File: SelectFSs_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public T single() { T v = singleOrNull(); if (v == null && !isNullOK) { throw new CASRuntimeException(CASRuntimeException.SELECT_GET_NO_INSTANCES, ti.getName(), maybeMsgPosition()); } return v; }
Example #27
Source File: IndexRepositoryTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testMissingSofaRef() throws Exception { JCas jcas = cas.getJCas(); Annotation a = new Annotation(jcas, 0, 4); FeatureImpl feat = (FeatureImpl) cas.getTypeSystem().getType(CAS.TYPE_NAME_ANNOTATION_BASE) .getFeatureByBaseName(CAS.FEATURE_BASE_NAME_SOFA); a._setFeatureValueNcNj(feat, null); try { jcas.addFsToIndexes(a); } catch (CASRuntimeException e) { assertEquals("SOFAREF_NOT_SET", e.getMessageKey()); return; } fail("required exception not thrown"); // fail }
Example #28
Source File: NonEmptyStringList.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void setTail(StringList v) { if (v != null && _casView.getBaseCAS() != v._casView.getBaseCAS()) { /** Feature Structure {0} belongs to CAS {1}, may not be set as the value of an array or list element in a different CAS {2}.*/ throw new CASRuntimeException(CASRuntimeException.FS_NOT_MEMBER_OF_CAS, v, v._casView, _casView); } _setFeatureValueNcWj(wrapGetIntCatchException(_FH_tail), v); }
Example #29
Source File: XCASDeserializer.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Common code run at finalize time, to set ref values and handle out-of-typesystem data * * @param extId the external ID identifying either a deserialized FS or an out-of-typesystem instance * @param fs Feature Structure whose fi reference feature is to be set with a value derived from extId and FSinfo * @param fi the featureImpl */ private void finalizeRefValue(int extId, TOP fs, FeatureImpl fi) { FSInfo fsInfo = fsTree.get(extId); if (fsInfo == null) { // this feature may be a ref to an out-of-typesystem FS. // add it to the Out-of-typesystem features list (APL) if (extId != 0 && outOfTypeSystemData != null) { List<Pair<String, Object>> ootsAttrs = outOfTypeSystemData.extraFeatureValues.computeIfAbsent(fs, k -> new ArrayList<>()); String featFullName = fi.getName(); int separatorOffset = featFullName.indexOf(TypeSystem.FEATURE_SEPARATOR); String featName = "_ref_" + featFullName.substring(separatorOffset + 1); ootsAttrs.add(new Pair(featName, Integer.toString(extId))); } CASImpl.setFeatureValueMaybeSofa(fs, fi, null); } else { // the sofa ref in annotationBase is set when the fs is created, not here if (fi.getCode() != TypeSystemConstants.annotBaseSofaFeatCode) { if (fs instanceof Sofa) { // special setters for sofa values Sofa sofa = (Sofa) fs; switch (fi.getRangeImpl().getCode()) { case TypeSystemConstants.sofaArrayFeatCode: sofa.setLocalSofaData(fsInfo.fs); break; default: throw new CASRuntimeException(UIMARuntimeException.INTERNAL_ERROR); } return; } // handle case where feature is xyz[] (an array ref, not primitive) but the value of fs is FSArray ts.fixupFSArrayTypes(fi.getRangeImpl(), fsInfo.fs); CASImpl.setFeatureValueMaybeSofa(fs, fi, fsInfo.fs); } } }
Example #30
Source File: NonEmptyFloatList.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void setTail(FloatList v) { if (v != null && _casView.getBaseCAS() != v._casView.getBaseCAS()) { /** Feature Structure {0} belongs to CAS {1}, may not be set as the value of an array or list element in a different CAS {2}.*/ throw new CASRuntimeException(CASRuntimeException.FS_NOT_MEMBER_OF_CAS, v, v._casView, _casView); } _setFeatureValueNcWj(wrapGetIntCatchException(_FH_tail), v); }