You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/02/03 17:54:11 UTC
svn commit: r503248 [2/8] - /incubator/uima/uimacpp/trunk/src/cas/
Added: incubator/uima/uimacpp/trunk/src/cas/featurestructure.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/featurestructure.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/featurestructure.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/featurestructure.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,597 @@
+/** \file featurestructure.cpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+#include "uima/featurestructure.hpp"
+#include "uima/lowlevel_fsheap.hpp"
+#include "uima/msg.h"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/internal_typeshortcuts.hpp"
+#include "uima/listfs.hpp"
+#include "uima/arrayfs.hpp"
+#include "uima/cas.hpp"
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+
+ /*
+ Most of the methods in here are thin wrappers over then lowlevel API
+ but also include error checking.
+ */
+
+ /* ----------------------------------------------------------------------- */
+ /* Exceptions Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ UIMA_EXC_CLASSIMPLEMENT(InvalidFSObjectException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(FeatureNotAppropriateException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(IncompatibleValueTypeException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(FSIsNotStringException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(WrongStringValueException, CASException);
+
+ /* ----------------------------------------------------------------------- */
+ /* Tool Functions Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ /**
+ * Checks if this FS is valid and throws an appropriate exeption
+ * with the passed context if not.
+ */
+ void FeatureStructure::checkValidity(TyMessageId tyContext) const {
+ if (!isValid()) {
+ UIMA_EXC_THROW_NEW(InvalidFSObjectException,
+ UIMA_ERR_INVALID_FS_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_FS_OBJECT,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ /**
+ * Checks whether the passed feature is defined on the type of this FS.
+ * Throws an appropriate if not.
+ */
+ void FeatureStructure::checkFeature(Feature const & f, TyMessageId tyContext) const {
+ if (!f.isValid()) {
+ UIMA_EXC_THROW_NEW(InvalidFSFeatureObjectException,
+ UIMA_ERR_INVALID_FSFEATURE_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_FSFEATURE_OBJECT,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ assert(EXISTS(iv_cas));
+ if (! iv_cas->getHeap()->getTypeSystem()
+ .isAppropriateFeature( iv_cas->getHeap()->getType(iv_tyFS),
+ internal::FSPromoter::demoteFeature(f)) ) {
+ ErrorMessage msg(UIMA_MSG_ID_EXC_FEATURE_NOT_APPROPRIATE);
+ UnicodeStringRef ref = f.getName();
+ icu::UnicodeString usFeatureName( ref.getBuffer(), ref.length() );
+ msg.addParam( usFeatureName );
+ msg.addParam( getType().getName() );
+
+ UIMA_EXC_THROW_NEW(FeatureNotAppropriateException,
+ UIMA_ERR_FEATURE_NOT_APPROPRIATE,
+ msg,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ /**
+ * checks if the range type of the feature is not built-in.
+ */
+ void FeatureStructure::checkNonBuiltinFeature(Feature const & crFeature, TyMessageId tyContext) const {
+ assert(EXISTS(iv_cas));
+ lowlevel::TypeSystem const & rTS = iv_cas->getHeap()->getTypeSystem();
+ uima::lowlevel::TyFSType rangeType = rTS.getRangeType(internal::FSPromoter::demoteFeature(crFeature));
+ if ( rangeType == uima::internal::gs_tyIntegerType
+ || rangeType == uima::internal::gs_tyFloatType
+ || rangeType == uima::internal::gs_tyStringType
+ || rTS.getParentType(rangeType) == uima::internal::gs_tyStringType ) {
+ ErrorMessage msg( UIMA_MSG_ID_EXC_INCOMPATIBLE_RANGE_TYPE);
+ msg.addParam( rTS.getFeatureName( internal::FSPromoter::demoteFeature(crFeature) ) );
+ Type t;
+ crFeature.getRangeType(t);
+ msg.addParam( t.getName() );
+ UIMA_EXC_THROW_NEW(FeatureNotAppropriateException,
+ UIMA_ERR_INCOMPATIBLE_RANGE_TYPE,
+ msg,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ /**
+ * checks if the range type of the feature subsumes the aType.
+ * In other words, checks if an FS of aType is an appropriate value for f.
+ */
+ void FeatureStructure::checkAppropFeature(Feature const & f, lowlevel::TyFSType aType, TyMessageId tyContext) const {
+ checkFeature(f, tyContext);
+ assert(EXISTS(iv_cas));
+ uima::lowlevel::TypeSystem const & ts = iv_cas->getHeap()->getTypeSystem();
+
+ //This to deal with FS array type with <elementType> tag
+ //which results in a feature range type that is a subtype of
+ //FS array. FSs of type FSArray are allowed values.
+ if (aType == uima::internal::gs_tyFSArrayType) {
+ Type featType;
+ f.getRangeType(featType);
+ lowlevel::TyFSType featTypeCode = internal::FSPromoter::demoteType(featType);
+ if (aType != featTypeCode && !ts.subsumes(aType,featTypeCode) ) {
+ ErrorMessage msg( UIMA_MSG_ID_EXC_INCOMPATIBLE_RANGE_TYPE);
+ msg.addParam( ts.getFeatureName(internal::FSPromoter::demoteFeature(f)) );
+ msg.addParam( ts.getTypeName(aType) );
+ UIMA_EXC_THROW_NEW(IncompatibleValueTypeException,
+ UIMA_ERR_INCOMPATIBLE_RANGE_TYPE,
+ msg,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ } else if ( !ts.subsumes(ts.getRangeType(internal::FSPromoter::demoteFeature(f)), aType ) ) {
+ ErrorMessage msg( UIMA_MSG_ID_EXC_INCOMPATIBLE_RANGE_TYPE);
+ msg.addParam( ts.getFeatureName(internal::FSPromoter::demoteFeature(f)) );
+ msg.addParam( ts.getTypeName(aType) );
+ UIMA_EXC_THROW_NEW(IncompatibleValueTypeException,
+ UIMA_ERR_INCOMPATIBLE_RANGE_TYPE,
+ msg,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ /**
+ * checks if anFS is an appropriate value for f.
+ */
+ void FeatureStructure::checkAppropFeature(Feature const & f, FeatureStructure const & anFS, TyMessageId tyContext) const {
+ if ( (&iv_cas->getHeap()->getTypeSystem()) != (&anFS.iv_cas->getHeap()->getTypeSystem()) ) {
+ UIMA_EXC_THROW_NEW(InvalidFSObjectException,
+ UIMA_ERR_INVALID_FS_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_FS_OBJECT,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ checkAppropFeature(f, iv_cas->getHeap()->getType(anFS.iv_tyFS), tyContext );
+ }
+
+ /* ----------------------------------------------------------------------- */
+ /* General FeatureStructure Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ FeatureStructure::FeatureStructure(lowlevel::TyFS anFS, CAS & cas)
+ : iv_tyFS(anFS),
+ iv_cas(&cas) {}
+
+
+ FeatureStructure::FeatureStructure()
+ : iv_tyFS(0),
+ iv_cas(NULL) {}
+
+
+ CAS & FeatureStructure::getCAS() {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FSTYPE);
+ assert(EXISTS(iv_cas));
+ return *iv_cas;
+ }
+
+ CAS const & FeatureStructure::getCAS() const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FSTYPE);
+ assert(EXISTS(iv_cas));
+ return *iv_cas;
+ }
+
+ bool FeatureStructure::isValid() const {
+ if (! EXISTS(iv_cas) ) {
+ return false;
+ }
+ return iv_tyFS != 0 && ( iv_cas->getHeap()->isValid(iv_tyFS));
+ }
+
+ Type FeatureStructure::getType() const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FSTYPE);
+ return uima::internal::FSPromoter::promoteType(iv_cas->getHeap()->getType(iv_tyFS), iv_cas->getHeap()->getTypeSystem() );
+ }
+
+ FeatureStructure FeatureStructure::clone() {
+ checkValidity(UIMA_MSG_ID_EXCON_CREATING_FS);
+ FeatureStructure newFS = getCAS().createFS(getType());
+ iv_cas->getHeap()->copyFeatures(newFS.iv_tyFS, iv_tyFS);
+ return newFS;
+ }
+
+ FeatureStructure FeatureStructure::clone(Type const & t) {
+ checkValidity(UIMA_MSG_ID_EXCON_CREATING_FS);
+ uima::lowlevel::TypeSystem const & ts = iv_cas->getHeap()->getTypeSystem();
+ FeatureStructure newFS = getCAS().createFS(t);
+ lowlevel::TyFSType mcst = ts.getMostSpecificCommonSupertype( uima::internal::FSPromoter::demoteType(getType()),
+ uima::internal::FSPromoter::demoteType(t) );
+ lowlevel::TyFeatureOffset featNum = ts.getFeatureNumber( mcst );
+ iv_cas->getHeap()->copyFeatures(newFS.iv_tyFS, iv_tyFS, featNum);
+ return newFS;
+ }
+
+ FeatureStructure FeatureStructure::getFeatureValue(Feature const & f) const {
+ return getFSValue(f);
+ }
+
+ FeatureStructure FeatureStructure::getFSValue(Feature const & f) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkFeature(f, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkNonBuiltinFeature(f, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( f );
+ lowlevel::TyFS resultAddr = iv_cas->getHeap()->getFSValue(iv_tyFS, tyFeat);
+ if (resultAddr != uima::lowlevel::FSHeap::INVALID_FS &&
+ iv_cas->getHeap()->getTypeSystem().subsumes(internal::gs_tyAnnotationType,
+ internal::FSPromoter::demoteType(internal::FSPromoter::promoteFS(resultAddr, *iv_cas).getType()))) {
+ // an annotation. Check that sofaNum agrees with current CAS
+ lowlevel::TyFS annSofaAddr = iv_cas->getHeap()->getFSValue(resultAddr, internal::gs_tySofaRefFeature);
+ if ( annSofaAddr != internal::FSPromoter::demoteFS(iv_cas->getSofa())) {
+ // does not agree. Get appropriate View for annotation Sofa
+ int annSofaNum = iv_cas->getHeap()->getIntValue(annSofaAddr, internal::gs_tySofaNumFeature);
+ CAS* annTcas = iv_cas->getViewBySofaNum(annSofaNum);
+ return FeatureStructure(resultAddr, (CAS &)*annTcas);
+ }
+ }
+ return FeatureStructure(resultAddr, *iv_cas);
+ }
+
+ bool FeatureStructure::isUntouchedFSValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkFeature(crFeature, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->isUntouchedFSValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ int FeatureStructure::getIntValue(Feature const & f) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(f, uima::internal::gs_tyIntegerType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getIntValue(iv_tyFS, internal::FSPromoter::demoteFeature(f));
+ }
+
+ void FeatureStructure::setFSValue(Feature const & f, FeatureStructure const & anFS) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(f, anFS, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ iv_cas->getHeap()->setFSValue(iv_tyFS, internal::FSPromoter::demoteFeature(f), anFS.iv_tyFS);
+ }
+
+ void FeatureStructure::setFeatureValue(Feature const & f, FeatureStructure const & anFS) {
+ setFSValue(f, anFS);
+ }
+
+ void FeatureStructure::setIntValue(Feature const & f, int i) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(f, uima::internal::gs_tyIntegerType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ iv_cas->getHeap()->setIntValue(iv_tyFS, internal::FSPromoter::demoteFeature(f), i);
+ }
+
+ float FeatureStructure::getFloatValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyFloatType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getFloatValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ void FeatureStructure::setFloatValue(Feature const & crFeature, float f) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyFloatType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ iv_cas->getHeap()->setFloatValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature), f);
+ }
+
+ bool FeatureStructure::getBooleanValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyBooleanType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getBooleanValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ void FeatureStructure::setBooleanValue(Feature const & crFeature, bool b ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyBooleanType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+
+ //add byte to 8bit heap
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( crFeature );
+ iv_cas->getHeap()->setBooleanValue( iv_tyFS, tyFeat, b);
+ }
+
+
+ char FeatureStructure::getByteValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyByteType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getByteValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ void FeatureStructure::setByteValue(Feature const & crFeature, char b ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyByteType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+
+ //add byte to 8bit heap
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( crFeature );
+ iv_cas->getHeap()->setByteValue( iv_tyFS, tyFeat, b );
+ }
+
+ short FeatureStructure::getShortValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyShortType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getShortValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ void FeatureStructure::setShortValue(Feature const & crFeature, short s ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyShortType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+
+ //add byte to 8bit heap
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( crFeature );
+ iv_cas->getHeap()->setShortValue( iv_tyFS, tyFeat, s );
+ }
+
+
+ INT64 FeatureStructure::getLongValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyLongType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getLongValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ void FeatureStructure::setLongValue(Feature const & crFeature, INT64 l ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyLongType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+
+ //add byte to 8bit heap
+ //int aRef = iv_cas->getHeap()->addLong(l);
+
+ //set the 8bit heap offset in main heap
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( crFeature );
+ iv_cas->getHeap()->setLongValue( iv_tyFS, tyFeat, l );
+ }
+
+
+ double FeatureStructure::getDoubleValue(Feature const & crFeature) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyDoubleType, UIMA_MSG_ID_EXCON_GETTING_FEATURE_VALUE);
+ return iv_cas->getHeap()->getDoubleValue(iv_tyFS, internal::FSPromoter::demoteFeature(crFeature));
+ }
+
+ void FeatureStructure::setDoubleValue(Feature const & crFeature, double d ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+ checkAppropFeature(crFeature, uima::internal::gs_tyDoubleType, UIMA_MSG_ID_EXCON_SETTING_FEATURE_VALUE);
+
+ //add byte to 8bit heap
+ //int aRef = iv_cas->getHeap()->addDouble(d);
+
+ //set the 8bit heap offset in main heap
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( crFeature );
+ iv_cas->getHeap()->setDoubleValue( iv_tyFS, tyFeat, d );
+ }
+
+
+
+
+
+ /* ----------------------------------------------------------------------- */
+ /* String-oriented FeatureStructure Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ void FeatureStructure::checkRangeIsString(Feature const & f, TyMessageId tyContext) const {
+ assert(EXISTS(iv_cas));
+ uima::lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ uima::lowlevel::TyFSType tyType = crHeap.getTypeSystem().getRangeType(internal::FSPromoter::demoteFeature( f ));
+ if ( ! crHeap.getTypeSystem().subsumes( uima::internal::gs_tyStringType, tyType) ) {
+ UIMA_EXC_THROW_NEW(FSIsNotStringException,
+ UIMA_ERR_FS_IS_NOT_STRING,
+ UIMA_MSG_ID_EXC_FS_IS_NOT_STRING,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+
+ );
+ }
+ }
+
+ UnicodeStringRef FeatureStructure::getStringValue(Feature const & f) const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_STRINGVALUE_FROM_FS);
+ checkRangeIsString(f, UIMA_MSG_ID_EXCON_GETTING_STRINGVALUE_FROM_FS);
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( f );
+ lowlevel::TyFS tyStringFS = iv_cas->getHeap()->getFSValue(iv_tyFS, tyFeat);
+ if (tyStringFS == uima::lowlevel::FSHeap::INVALID_FS) {
+ return UnicodeStringRef();
+ }
+ return iv_cas->getHeap()->getFSAsString( tyStringFS );
+ }
+
+ void FeatureStructure::setStringValue(Feature const & f, UnicodeStringRef uls) {
+ setStringValueExternal( f, uls );
+ }
+
+ void FeatureStructure::setStringValueExternal(Feature const & f, UnicodeStringRef uls) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_STRINGVALUE_IN_FS);
+ checkRangeIsString(f, UIMA_MSG_ID_EXCON_SETTING_STRINGVALUE_IN_FS);
+
+ //!!! Not supporting External at this time. All strings added to StringHeap.
+ int ulsRef = iv_cas->getHeap()->addString(uls);
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( f );
+
+ uima::lowlevel::TypeSystem const & crTypeSystem = iv_cas->getHeap()->getTypeSystem();
+ // if string sub type
+ uima::lowlevel::TyFSType tyRangeType = crTypeSystem.getRangeType(tyFeat);
+ if ( tyRangeType != uima::internal::gs_tyStringType) {
+ vector<icu::UnicodeString> const & crStringSet = crTypeSystem.getStringsForStringSubtype(tyRangeType);
+ vector<icu::UnicodeString>::const_iterator cit;
+ bool bStringFound = false;
+ for (cit = crStringSet.begin(); cit != crStringSet.end(); ++cit) {
+ UnicodeStringRef ref(*cit);
+ if ( ref == uls ) {
+ bStringFound = true;
+ break;
+ }
+ }
+ if (! bStringFound) {
+ UnicodeString us(uls.getBuffer(), uls.length() );
+ ErrorMessage errMess(UIMA_MSG_ID_EXC_WRONG_STRING_VALUE);
+ errMess.addParam(us);
+ errMess.addParam(crTypeSystem.getTypeName(tyRangeType) );
+ UIMA_EXC_THROW_NEW(WrongStringValueException,
+ UIMA_ERR_WRONG_STRING_VALUE,
+ errMess,
+ ErrorMessage(UIMA_MSG_ID_EXCON_SETTING_STRINGVALUE_IN_FS),
+ ErrorInfo::recoverable);
+ }
+ }
+
+
+
+ iv_cas->getHeap()->setStringValue( iv_tyFS, tyFeat, ulsRef );
+ }
+
+ /* ----------------------------------------------------------------------- */
+ /* Array-oriented FeatureStructure Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ ArrayFS FeatureStructure::getArrayFSValue( Feature const & fArray ) const {
+ return ArrayFS(getFSValue(fArray));
+ }
+
+ FloatArrayFS FeatureStructure::getFloatArrayFSValue( Feature const & fArray ) const {
+ return FloatArrayFS(getFSValue(fArray));
+ }
+
+ IntArrayFS FeatureStructure::getIntArrayFSValue( Feature const & fArray ) const {
+ return IntArrayFS(getFSValue(fArray));
+ }
+
+ StringArrayFS FeatureStructure::getStringArrayFSValue( Feature const & fArray ) const {
+ return StringArrayFS(getFSValue(fArray));
+ }
+
+ BooleanArrayFS FeatureStructure::getBooleanArrayFSValue( Feature const & fArray ) const {
+ return BooleanArrayFS(getFSValue(fArray));
+ }
+
+ ByteArrayFS FeatureStructure::getByteArrayFSValue( Feature const & fArray ) const {
+ return ByteArrayFS(getFSValue(fArray));
+ }
+
+ ShortArrayFS FeatureStructure::getShortArrayFSValue( Feature const & fArray ) const {
+ return ShortArrayFS(getFSValue(fArray));
+ }
+
+ LongArrayFS FeatureStructure::getLongArrayFSValue( Feature const & fArray ) const {
+ return LongArrayFS(getFSValue(fArray));
+ }
+ DoubleArrayFS FeatureStructure::getDoubleArrayFSValue( Feature const & fArray ) const {
+ return DoubleArrayFS(getFSValue(fArray));
+ }
+
+
+ /* ----------------------------------------------------------------------- */
+ /* List-oriented FeatureStructure Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ bool FeatureStructure::hasListElements(Feature const & f) const {
+ Type tRangeType;
+ f.getRangeType(tRangeType);
+ lowlevel::TyFSFeature tyRangeType = internal::FSPromoter::demoteType(tRangeType);
+ switch (tyRangeType) {
+ case uima::internal::gs_tyFSListType :
+ case uima::internal::gs_tyEListType :
+ case uima::internal::gs_tyNEListType :
+ return ListFS::hasListElements(*this, f);
+ case uima::internal::gs_tyFloatListType :
+ case uima::internal::gs_tyEFloatListType :
+ case uima::internal::gs_tyNEFloatListType :
+ return FloatListFS::hasListElements(*this, f);
+ case uima::internal::gs_tyIntListType :
+ case uima::internal::gs_tyEIntListType :
+ case uima::internal::gs_tyNEIntListType :
+ return IntListFS::hasListElements(*this, f);
+ case uima::internal::gs_tyStringListType :
+ case uima::internal::gs_tyEStringListType :
+ case uima::internal::gs_tyNEStringListType:
+ return StringListFS::hasListElements(*this, f);
+ }
+ UIMA_EXC_THROW_NEW(FSIsNotListException,
+ UIMA_ERR_FS_IS_NOT_LIST,
+ UIMA_MSG_ID_EXC_FS_IS_NOT_LIST,
+ ErrorMessage(UIMA_MSG_ID_EXCON_GETTING_LIST_ISEMPTY),
+ ErrorInfo::recoverable
+ );
+ return false;
+ }
+
+ ListFS FeatureStructure::getListFSValue( Feature const & f ) const {
+ return ListFS::getListFSValue(*this, f);
+ }
+
+ FloatListFS FeatureStructure::getFloatListFSValue( Feature const & f ) const {
+ return FloatListFS::getListFSValue(*this, f);
+ }
+
+ IntListFS FeatureStructure::getIntListFSValue( Feature const & f ) const {
+ return IntListFS::getListFSValue(*this, f);
+ }
+
+ StringListFS FeatureStructure::getStringListFSValue( Feature const & f ) const {
+ return StringListFS::getListFSValue(*this, f);
+ }
+
+
+ /* ----------------------------------------------------------------------- */
+ /* Operator FeatureStructure Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ bool FeatureStructure::operator==(FeatureStructure const & crFS) const {
+ return (iv_cas == crFS.iv_cas) && (iv_tyFS == crFS.iv_tyFS);
+ }
+
+ bool FeatureStructure::operator<(FeatureStructure const & crFS) const {
+ return (iv_cas == crFS.iv_cas) && (iv_tyFS < crFS.iv_tyFS);
+ }
+
+} // namespace uima
+
+/* ----------------------------------------------------------------------- */
+/* <EOF> */
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/featurestructure.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/fsfilterbuilder.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/fsfilterbuilder.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/fsfilterbuilder.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/fsfilterbuilder.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,348 @@
+/** \file filterbuilder.cpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+#include "uima/fsfilterbuilder.hpp"
+#include "uima/fsindex.hpp"
+#include "uima/internal_fspromoter.hpp"
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/*
+Here are straightforward implementations of FSFilters.
+Nothing exciting.
+*/
+
+namespace uima {
+ namespace internal {
+
+ //////////////////////////////////////////////////////
+ class NOTFilter : public FSFilter {
+ private:
+ FSFilter * iv_pFilter;
+ public:
+ NOTFilter(FSFilter* pFilter)
+ : iv_pFilter(pFilter) {
+ assert(EXISTS(iv_pFilter));
+ }
+
+ bool isFiltered(FeatureStructure const & fs) const {
+ assert(EXISTS(iv_pFilter));
+ return ! iv_pFilter->isFiltered(fs);
+ }
+
+ void deInit() {
+ assert(EXISTS(iv_pFilter));
+ iv_pFilter->deInit();
+ delete iv_pFilter;
+ }
+ };
+
+ //////////////////////////////////////////////////////
+ class BoolBinaryOperationFilter : public FSFilter {
+ protected:
+ FSFilter * iv_pFilter1;
+ FSFilter * iv_pFilter2;
+
+ BoolBinaryOperationFilter(FSFilter * pFilter1, FSFilter * pFilter2)
+ : iv_pFilter1(pFilter1),
+ iv_pFilter2(pFilter2) {
+ assert(EXISTS(iv_pFilter1));
+ assert(EXISTS(iv_pFilter2));
+ }
+ public:
+ void deInit() {
+ assert(EXISTS(iv_pFilter1));
+ iv_pFilter1->deInit();
+ delete iv_pFilter1;
+ assert(EXISTS(iv_pFilter2));
+ iv_pFilter2->deInit();
+ delete iv_pFilter2;
+ }
+ };
+
+ //////////////////////////////////////////////////////
+ class ANDFilter : public BoolBinaryOperationFilter {
+ public:
+ ANDFilter(FSFilter * pFilter1, FSFilter * pFilter2)
+ : BoolBinaryOperationFilter(pFilter1, pFilter2) {}
+
+ bool isFiltered(FeatureStructure const & fs) const {
+ assert(EXISTS(iv_pFilter1));
+ assert(EXISTS(iv_pFilter2));
+ // ensure that filter 2 is not used when filter 1 already returns false
+ bool bResult1 = iv_pFilter1->isFiltered(fs);
+ if (!bResult1) {
+ return false;
+ }
+ // cerr << __FILE__ << ", " << __LINE__ << ": value of filter1: " << iv_pFilter1->isFiltered(fs) << ", value of filter2: " << iv_pFilter2->isFiltered(fs) << endl;
+ return iv_pFilter2->isFiltered(fs);
+ }
+ };
+
+ //////////////////////////////////////////////////////
+ class ORFilter : public BoolBinaryOperationFilter {
+ public:
+ ORFilter(FSFilter * pFilter1, FSFilter * pFilter2)
+ : BoolBinaryOperationFilter(pFilter1, pFilter2) {}
+
+ bool isFiltered(FeatureStructure const & fs) const {
+ assert(EXISTS(iv_pFilter1));
+ assert(EXISTS(iv_pFilter2));
+ bool bResult1 = iv_pFilter1->isFiltered(fs);
+ if (bResult1) {
+ return true;
+ }
+ return iv_pFilter2->isFiltered(fs);
+ }
+ };
+
+ //////////////////////////////////////////////////////
+ class TypeFilter : public FSFilter {
+ private:
+ Type iv_type;
+ bool iv_bUseSusumption;
+ public:
+ TypeFilter(Type const & crType, bool bUseSubsumption)
+ : iv_type(crType),
+ iv_bUseSusumption(bUseSubsumption) {}
+
+ bool isFiltered(FeatureStructure const & fs) const {
+ if (iv_bUseSusumption) {
+ return iv_type.subsumes(fs.getType());
+ }
+ return iv_type == fs.getType();
+ }
+
+ };
+
+ //////////////////////////////////////////////////////
+ FeatureStructure getPath(FeatureStructure const & crFS, vector<Feature> const & crFeatures, size_t uiStep) {
+ FeatureStructure result = crFS;
+ size_t i;
+ for (i=0; i<uiStep; ++i) {
+ result = result.getFSValue(crFeatures[i]);
+ }
+ return result;
+ }
+
+ //////////////////////////////////////////////////////
+ template<class T>
+ class BuiltinFeatureValueFilter : public FSFilter {
+ private:
+ vector<Feature> iv_features;
+ FSFilterBuilder::EnComparisonOperator iv_enOp;
+ T iv_val;
+
+ bool compare(FSFilterBuilder::EnComparisonOperator enOp, T val1, T val2) const {
+ switch (enOp) {
+ case FSFilterBuilder::EQUALS:
+ return val1 == val2;
+ case FSFilterBuilder::GREATER:
+ return val1 > val2;
+ case FSFilterBuilder::LESS:
+ return val1 < val2;
+ };
+ assert(false);
+ return false;
+ }
+
+ protected:
+ virtual T getFeature(FeatureStructure const &, Feature const &) const = 0;
+ public:
+ BuiltinFeatureValueFilter(vector<Feature> const & crFeatures, FSFilterBuilder::EnComparisonOperator enOp, T val)
+ : iv_features(crFeatures),
+ iv_enOp(enOp),
+ iv_val(val) {}
+
+ bool isFiltered(FeatureStructure const & crFS) const {
+ size_t uiLast = iv_features.size() - 1;
+ FeatureStructure fs = getPath(crFS, iv_features, uiLast);
+ T val = getFeature(fs, iv_features[uiLast]);
+ return compare(iv_enOp, val, iv_val);
+ }
+
+ };
+
+ //////////////////////////////////////////////////////
+ class IntFeatureFilter : public BuiltinFeatureValueFilter<int> {
+ protected:
+ int getFeature(FeatureStructure const & crFS, Feature const & crFeat) const {
+ return crFS.getIntValue(crFeat);
+ }
+ public:
+ IntFeatureFilter(vector<Feature> const & crFeatures, FSFilterBuilder::EnComparisonOperator enOp, int val)
+ : BuiltinFeatureValueFilter<int>(crFeatures, enOp, val) {}
+ };
+
+ //////////////////////////////////////////////////////
+ class FloatFeatureFilter : public BuiltinFeatureValueFilter<float> {
+ protected:
+ float getFeature(FeatureStructure const & crFS, Feature const & crFeat) const {
+ return crFS.getFloatValue(crFeat);
+ }
+ public:
+ FloatFeatureFilter(vector<Feature> const & crFeatures, FSFilterBuilder::EnComparisonOperator enOp, float val)
+ : BuiltinFeatureValueFilter<float>(crFeatures, enOp, val) {}
+ };
+ /////////////////////////////////////////////////////////////
+ class UnicodeStringRefFeatureFilter : public BuiltinFeatureValueFilter<UnicodeStringRef> {
+ protected:
+ UnicodeStringRef getFeature(FeatureStructure const & crFS, Feature const & crFeat) const {
+ return crFS.getStringValue(crFeat);
+ }
+ public:
+ UnicodeStringRefFeatureFilter(vector<Feature> const & crFeaturePath, UnicodeStringRef const & crUStr)
+ : BuiltinFeatureValueFilter<UnicodeStringRef>(crFeaturePath, FSFilterBuilder::EQUALS, crUStr ) {}
+ };
+
+ class StringFeatureFilter : public FSFilter {
+ private:
+ UnicodeStringRefFeatureFilter * iv_pUnicodeStringRefFeatureFilter;
+ icu::UnicodeString iv_string;
+ public:
+ StringFeatureFilter(vector<Feature> const & crFeaturePath, UChar const * cpUTFBuffer, size_t uiLength)
+ : iv_pUnicodeStringRefFeatureFilter(NULL) {
+ iv_string = icu::UnicodeString( cpUTFBuffer, uiLength );
+ UnicodeStringRef up(iv_string.getBuffer(), iv_string.length() );
+ iv_pUnicodeStringRefFeatureFilter = new UnicodeStringRefFeatureFilter(crFeaturePath, up);
+ assert( EXISTS( iv_pUnicodeStringRefFeatureFilter ) );
+ }
+
+ ~StringFeatureFilter() {
+ if (iv_pUnicodeStringRefFeatureFilter != NULL) {
+ delete iv_pUnicodeStringRefFeatureFilter;
+ iv_pUnicodeStringRefFeatureFilter = NULL;
+ }
+ }
+
+ virtual bool isFiltered(FeatureStructure const &crFS) const {
+ assert( EXISTS( iv_pUnicodeStringRefFeatureFilter ) );
+ return iv_pUnicodeStringRefFeatureFilter->isFiltered(crFS);
+ }
+
+ virtual void deInit() {
+ assert( EXISTS( iv_pUnicodeStringRefFeatureFilter ) );
+ iv_pUnicodeStringRefFeatureFilter->deInit();
+ }
+
+ };
+
+
+ //////////////////////////////////////////////////////
+ class MatchFilter : public FSFilter {
+ private:
+ vector<Feature> iv_features;
+ FSFilter * iv_pFilter;
+ public:
+ MatchFilter(vector<Feature> const & crFeaturePath, FSFilter * pFilter)
+ : iv_features(crFeaturePath),
+ iv_pFilter(pFilter) {
+ assert(EXISTS(iv_pFilter));
+ }
+
+ bool isFiltered(FeatureStructure const & crFS) const {
+ FeatureStructure fs = getPath(crFS, iv_features, iv_features.size());
+ assert(EXISTS(iv_pFilter));
+ return iv_pFilter->isFiltered(fs);
+ }
+
+ void deInit() {
+ assert(EXISTS(iv_pFilter));
+ iv_pFilter->deInit();
+ delete iv_pFilter;
+ }
+ };
+
+
+ }
+} // namespace uima
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+
+ FSFilterBuilder::FSFilterBuilder() {}
+
+ FSFilterBuilder::~FSFilterBuilder() {}
+
+ FSFilter * FSFilterBuilder::createNOTFilter(FSFilter * pFilter) const {
+ return new internal::NOTFilter(pFilter);
+ }
+
+ FSFilter * FSFilterBuilder::createANDFilter(FSFilter * pFilter1, FSFilter * pFilter2) const {
+ return new internal::ANDFilter(pFilter1, pFilter2);
+ }
+
+ FSFilter * FSFilterBuilder::createORFilter(FSFilter * pFilter1, FSFilter * pFilter2) const {
+ return new internal::ORFilter(pFilter1, pFilter2);
+ }
+
+ FSFilter * FSFilterBuilder::createTypeFilter(Type const & crType, bool bUseSubsumption) const {
+ return new internal::TypeFilter(crType, bUseSubsumption);
+ }
+
+ FSFilter * FSFilterBuilder::createIntFeatureFilter(vector<Feature> const & crFeatures, EnComparisonOperator enOp, int iVal) const {
+ return new internal::IntFeatureFilter(crFeatures, enOp, iVal);
+ }
+
+ FSFilter * FSFilterBuilder::createFloatFeatureFilter(vector<Feature> const & crFeatures, EnComparisonOperator enOp, float fVal) const {
+ return new internal::FloatFeatureFilter(crFeatures, enOp, fVal);
+ }
+
+ FSFilter * FSFilterBuilder::createMatchFilter(vector<Feature> const & crFeaturePath, FSFilter * pFilter) const {
+ return new internal::MatchFilter(crFeaturePath, pFilter);
+ }
+
+ FSFilter * FSFilterBuilder::createStringFeatureFilter(vector<Feature> const & crFeaturePath, UChar const * cpUTFBuffer, size_t uiLength) const {
+ return new internal::StringFeatureFilter(crFeaturePath, cpUTFBuffer, uiLength);
+ }
+
+
+} // namespace uima
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/fsfilterbuilder.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/fsindex.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/fsindex.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/fsindex.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/fsindex.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,187 @@
+/** \file fsindex.cpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+
+#include "uima/fsindex.hpp"
+#include "uima/msg.h"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/lowlevel_fsfilter.hpp"
+#include "uima/lowlevel_index.hpp"
+#include "uima/lowlevel_indexrepository.hpp"
+#include "uima/fsfilterbuilder.hpp"
+
+using namespace uima::internal;
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+/*
+Those implementations are thin wrappers on top of the lowlevel API.
+*/
+
+namespace uima {
+
+ UIMA_EXC_CLASSIMPLEMENT(InvalidIndexObjectException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(WrongFSTypeForIndexException, CASException);
+
+ void FSIndex::checkValidity() const {
+ if (!isValid()) {
+ UIMA_EXC_THROW_NEW(InvalidIndexObjectException,
+ UIMA_ERR_INVALID_INDEX_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_INDEX_OBJECT,
+ ErrorMessage(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ FSIndex::FSIndex(lowlevel::IndexABase const * anIndex, lowlevel::IndexRepository const & rFSSystem)
+ : iv_pIndex(anIndex),
+ iv_indexRepository(& CONST_CAST(uima::lowlevel::IndexRepository &, rFSSystem) ) {}
+
+ FSIndex::FSIndex(lowlevel::IndexABase const * anIndex, lowlevel::IndexRepository & rFSSystem)
+ : iv_pIndex(anIndex),
+ iv_indexRepository(& rFSSystem) {}
+
+ FSIndex::FSIndex()
+ : iv_pIndex(NULL),
+ iv_indexRepository(NULL) {}
+
+ bool FSIndex::isValid() const {
+ return(iv_pIndex != NULL) && (iv_indexRepository != NULL);
+ }
+
+ size_t FSIndex::getSize() const {
+ checkValidity();
+ return iv_pIndex->getSize();
+ }
+
+ FeatureStructure FSIndex::find(FeatureStructure const & anFS) const {
+ checkValidity();
+ if (!anFS.isValid()) {
+ UIMA_EXC_THROW_NEW(InvalidFSObjectException,
+ UIMA_ERR_INVALID_FS_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_FS_OBJECT,
+ ErrorMessage(UIMA_MSG_ID_EXCON_FINDING_FS_IN_INDEX),
+ ErrorInfo::recoverable
+ );
+ }
+ lowlevel::TyFS result = iv_pIndex->find( internal::FSPromoter::demoteFS( anFS ) );
+ return internal::FSPromoter::promoteFS( result, iv_indexRepository->getCas() );
+ }
+
+ FSIterator FSIndex::iterator() const {
+ checkValidity();
+ lowlevel::IndexIterator* it = iv_pIndex->createIterator();
+ return FSIterator( it, &iv_indexRepository->getCas() );
+ }
+
+
+ FSIterator FSIndex::typeSetIterator(set<uima::Type> const & crTypes) const {
+ checkValidity();
+ uima::lowlevel::TyFSType tyIndexType = iv_pIndex->getType();
+ set<uima::lowlevel::TyFSType> setLowlevelTypes;
+ set<uima::Type>::const_iterator cit;
+ for (cit = crTypes.begin(); cit != crTypes.end(); ++cit) {
+ uima::lowlevel::TyFSType tyType = uima::internal::FSPromoter::demoteType(*cit);
+ if ( ! iv_indexRepository->getFSHeap().getTypeSystem().subsumes(tyIndexType, tyType) ) {
+ UIMA_EXC_THROW_NEW(WrongFSTypeForIndexException,
+ UIMA_ERR_WRONG_FSTYPE_FOR_INDEX,
+ UIMA_MSG_ID_EXC_WRONG_FSTYPE_FOR_INDEX,
+ ErrorMessage(UIMA_MSG_ID_EXCON_CREATING_ITERATOR),
+ ErrorInfo::recoverable
+ );
+
+ }
+ setLowlevelTypes.insert(tyType);
+ }
+
+ uima::lowlevel::IndexIterator * it = iv_pIndex->createTypeSetIterator( setLowlevelTypes );
+ return FSIterator( it, &iv_indexRepository->getCas() );
+ }
+
+
+
+///////////////////////////////////////////////////////////////
+
+ /**
+ * This class wraps an OO API filter to obey the lowlevel::FSFilter interface.
+ */
+ namespace internal {
+ class FSFilterWrapper : public lowlevel::FSFilter {
+ private:
+ uima::FSFilter const * iv_cpFilter;
+ uima::CAS const * iv_cas;
+ public:
+ FSFilterWrapper(uima::FSFilter const * cpFilter, uima::CAS const * cas)
+ : iv_cpFilter(cpFilter),
+ iv_cas(cas) {
+ assert(EXISTS(iv_cpFilter));
+ assert(EXISTS(iv_cas));
+ }
+
+ bool isFiltered(lowlevel::TyFS anFS) const {
+ assert(EXISTS(iv_cpFilter));
+ assert(EXISTS(iv_cas));
+ // const cast is OK here since anFS will not be changed
+ // since it is passed as const parameters to isFiltered
+ FeatureStructure fs = internal::FSPromoter::promoteFS(anFS, *iv_cas);
+ return iv_cpFilter->isFiltered(fs);
+ }
+ };
+ }
+
+
+ FSIterator FSIndex::filteredIterator(uima::FSFilter const * cpFilter) const {
+ checkValidity();
+ internal::FSFilterWrapper* pFilterWrapper = new internal::FSFilterWrapper( cpFilter, & iv_indexRepository->getCas() );
+ lowlevel::IndexIterator* it = iv_pIndex->createFilteredIterator(pFilterWrapper);
+ return FSIterator(it, & iv_indexRepository->getCas() );
+ }
+
+}
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/fsindex.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/fsindexrepository.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/fsindexrepository.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/fsindexrepository.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/fsindexrepository.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,161 @@
+/** \file fsindexrepository.cpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+#include "uima/fsindexrepository.hpp"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/lowlevel_indexrepository.hpp"
+#include "uima/msg.h"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+
+ UIMA_EXC_CLASSIMPLEMENT(InvalidIndexIDException, CASException);
+
+ FSIndexRepository::FSIndexRepository() {}
+
+ FSIndexRepository::~FSIndexRepository() {}
+
+ FSIndex FSIndexRepository::getIndex(icu::UnicodeString const & crLabel) const {
+ return getIndex(crLabel, getTypeForIndex(crLabel));
+ }
+
+ std::vector<icu::UnicodeString> FSIndexRepository::getAllIndexIDs() const {
+ vector<icu::UnicodeString> ids;
+ getLowlevelIndexRepository().getIndexDefinition().getAllIndexIDs(ids);
+ return ids;
+ }
+
+ FSIndex FSIndexRepository::getIndex(icu::UnicodeString const & crLabel, Type const & crType) const {
+ uima::lowlevel::TyFSType tyType = uima::internal::FSPromoter::demoteType(crType);
+ if (! isValidIndexID( crLabel ) ) {
+ ErrorMessage msg(UIMA_MSG_ID_EXCON_GETTING_INDEX);
+ msg.addParam(crLabel);
+
+ UIMA_EXC_THROW_NEW(InvalidIndexIDException,
+ UIMA_ERR_INVALID_INDEX_ID,
+ UIMA_MSG_ID_EXC_INVALID_INDEX_ID,
+ msg,
+ ErrorInfo::recoverable
+ );
+ }
+ if ( ! getTypeForIndex(crLabel).subsumes( crType) ) {
+ ErrorMessage msg(UIMA_MSG_ID_EXCON_GETTING_INDEX);
+ msg.addParam(crLabel);
+ UIMA_EXC_THROW_NEW(WrongFSTypeForIndexException,
+ UIMA_ERR_WRONG_FSTYPE_FOR_INDEX,
+ UIMA_MSG_ID_EXC_WRONG_FSTYPE_FOR_INDEX,
+ msg,
+ ErrorInfo::recoverable
+ );
+ }
+
+ uima::lowlevel::IndexABase const * cpIx = & getLowlevelIndexRepository().getLowlevelIndex(crLabel, tyType);
+ return FSIndex(cpIx, getLowlevelIndexRepository());
+ }
+
+ int FSIndexRepository::getIndexSize(Type const & crType) const {
+ assertWithMsg(false, "Not implemented yet!");
+ UIMA_EXC_THROW_NEW(NotYetImplementedException,
+ UIMA_ERR_NOT_YET_IMPLEMENTED,
+ UIMA_MSG_ID_EXC_NOT_YET_IMPLEMENTED,
+ ErrorMessage(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT),
+ ErrorInfo::unrecoverable
+ );
+
+ return -1;
+ }
+
+ Type FSIndexRepository::getTypeForIndex(icu::UnicodeString const & crLabel) const {
+ uima::lowlevel::TyFSType tyType = getLowlevelIndexRepository().getIndexDefinition().getTypeForIndex(crLabel);
+ return uima::internal::FSPromoter::promoteType(tyType, getLowlevelIndexRepository().getFSHeap().getTypeSystem() );
+ }
+
+ bool FSIndexRepository::isValidIndexID(icu::UnicodeString const & crLabel) const {
+ return getLowlevelIndexRepository().getIndexDefinition().isValidIndexId(crLabel);
+ }
+
+ bool FSIndexRepository::isValidIndexID(icu::UnicodeString const & crLabel, Type const & crType) const {
+ if (!isValidIndexID(crLabel) ) {
+ return false;
+ }
+ return getTypeForIndex(crLabel).subsumes(crType);
+ }
+
+
+ void FSIndexRepository::addFS(FeatureStructure const & crFS) {
+ if (!crFS.isValid()) {
+ UIMA_EXC_THROW_NEW(InvalidFSObjectException,
+ UIMA_ERR_INVALID_FSTYPE_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_FSTYPE_OBJECT,
+ ErrorMessage(UIMA_MSG_ID_EXCON_ADDING_FS_TO_INDEX),
+ ErrorInfo::recoverable
+ );
+ }
+ getLowlevelIndexRepository().add( internal::FSPromoter::demoteFS( crFS ) );
+ }
+
+ void FSIndexRepository::removeFS(FeatureStructure const & crFS) {
+ if (!crFS.isValid()) {
+ UIMA_EXC_THROW_NEW(InvalidFSObjectException,
+ UIMA_ERR_INVALID_FSTYPE_OBJECT,
+ UIMA_MSG_ID_EXC_INVALID_FSTYPE_OBJECT,
+ ErrorMessage(UIMA_MSG_ID_EXCON_REMOVING_FS_FROM_INDEX),
+ ErrorInfo::recoverable
+ );
+ }
+ getLowlevelIndexRepository().remove( internal::FSPromoter::demoteFS( crFS ) );
+ }
+
+
+}
+
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/fsindexrepository.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/fsiterator.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/fsiterator.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/fsiterator.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/fsiterator.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,168 @@
+/** \file fsiterator.cpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+#include "uima/fsiterator.hpp"
+#include "uima/lowlevel_indexiterator.hpp"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/lowlevel_fsheap.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+
+ FSIterator::FSIterator(uima::lowlevel::IndexIterator* pIt,
+ uima::CAS * pFSSystem)
+ : iv_pIterator( pIt),
+ iv_cas( pFSSystem ) {
+ assert(EXISTS(iv_pIterator));
+ iv_pIterator->moveToFirst();
+ }
+
+ FSIterator::FSIterator()
+ : iv_pIterator(NULL),
+ iv_cas(NULL) {}
+
+ FSIterator & FSIterator::operator=(FSIterator const & crOther) {
+ if (this == &crOther) {
+ return *this;
+ }
+ if (iv_pIterator != NULL) {
+ delete iv_pIterator;
+ }
+ iv_pIterator = NULL;
+ iv_cas = crOther.iv_cas;
+ iv_pIterator = crOther.iv_pIterator->clone();
+ return *this;
+ }
+
+ FSIterator::FSIterator(FSIterator const & crOther)
+ : iv_pIterator(NULL),
+ iv_cas(NULL) {
+ *this = crOther;
+ }
+
+ FSIterator::~FSIterator() {
+ if (iv_pIterator != NULL) {
+ delete iv_pIterator;
+ }
+ }
+
+
+ bool FSIterator::isValid() const {
+ if (iv_pIterator == NULL) {
+ return false;
+ }
+ assert( EXISTS(iv_pIterator) );
+ return iv_pIterator->isValid();
+ }
+
+ void FSIterator::moveTo(FeatureStructure fs) {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveTo(uima::internal::FSPromoter::demoteFS(fs) );
+ }
+
+ void FSIterator::moveToFirst() {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveToFirst();
+ }
+
+ void FSIterator::moveToLast() {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveToLast();
+ }
+
+ void FSIterator::moveToNext() {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveToNext();
+ }
+
+ void FSIterator::moveToPrevious() {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveToPrevious();
+ }
+
+ FeatureStructure FSIterator::get() const {
+ assert( EXISTS(iv_pIterator) );
+ assert( EXISTS(iv_cas) );
+ return uima::internal::FSPromoter::promoteFS( iv_pIterator->get(), *iv_cas );
+ }
+
+
+ FeatureStructure FSIterator::peekNext() const {
+ FeatureStructure result;
+ iv_pIterator->moveToNext();
+ if (iv_pIterator->isValid()) {
+ result = uima::internal::FSPromoter::promoteFS( iv_pIterator->get(), *iv_cas );
+ iv_pIterator->moveToPrevious();
+ } else {
+ iv_pIterator->moveToLast();
+ }
+ return result;
+ }
+
+ FeatureStructure FSIterator::peekPrevious() const {
+ FeatureStructure result;
+ iv_pIterator->moveToPrevious();
+ if (iv_pIterator->isValid()) {
+ result = uima::internal::FSPromoter::promoteFS( iv_pIterator->get(), *iv_cas );
+ iv_pIterator->moveToNext();
+ } else {
+ iv_pIterator->moveToFirst();
+ }
+ return result;
+ }
+
+
+}
+
+
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/fsiterator.cpp
------------------------------------------------------------------------------
svn:eol-style = native