📄 angr_05.cc
字号:
// file: $isip/class/mmedia/AnnotationGraph/angr_5.cc// version: $Id: angr_05.cc,v 1.13 2003/05/12 22:41:59 huang Exp $//// isip include files//#include "AnnotationGraph.h"// method: clear//// arguments:// Integral::CMODE cmode: (input) clear mode//// return: logical error status//// this method clears the content of the current object//boolean AnnotationGraph::clear(Integral::CMODE cmode_a) { // declare local variables // boolean status = false; DoubleLinkedList<Anchor> ancrs(DstrBase::USER); DoubleLinkedList<Annotation> annos(DstrBase::USER); // delete the sequence of annotations // if (getAnnotationSet(annos)) { for (boolean more = annos.gotoFirst(); more; more = annos.gotoNext()) { deleteAnnotation(annos.getCurr()); } } // delete the set of anchors // if (getAnchorSet(ancrs)) { for (boolean more = ancrs.gotoFirst(); more; more = ancrs.gotoNext()) { deleteAnchor(ancrs.getCurr()); } } // clear the member data // status = id_d.clear(cmode_a); status &= type_d.clear(cmode_a); status &= index_d.clear(cmode_a); status &= annoseq_d.clear(cmode_a); // delete the identifiers // if (anchorids_d != (Identifier*)NULL) { delete anchorids_d; anchorids_d = (Identifier*)NULL; } if (annotationids_d != (Identifier*)NULL) { delete annotationids_d; annotationids_d = (Identifier*)NULL; } // return the logical status // return status;}// method: sofSize//// arguments: none//// return: logical error status//// method gets the size of the graph object//long AnnotationGraph::sofSize() const { // declare local variables // DoubleLinkedList<Pair<Long, Anchor> > ancrs; DoubleLinkedList<Triple<Long, Long, Annotation> > annos; // get the annotations and anchors associated with the graph // const_cast<AnnotationGraph*>(this)->get(ancrs, annos); // return the sof size // return ancrs.sofSize() + annos.sofSize() + id_d.sofSize() + type_d.sofSize();} // method: get//// arguments:// DoubleLinkedList<Pair<Long, Anchor> >& ancrs: (output) list of anchors// DoubleLinkedList<Triple<Long, Long, Annotation> >& annos: (output) list// of annotations//// return: logical error status//// method get the annotations and anchors associated with the graph//boolean AnnotationGraph::get(DoubleLinkedList<Pair<Long, Anchor> >& ancrs_a, DoubleLinkedList<Triple<Long, Long, Annotation> >& annos_a) { // declare local variables // Pair<Long, Anchor> ancr_pair; Triple<Long, Long, Annotation> anno_triple; DoubleLinkedList<Anchor> ancrs(DstrBase::USER); DoubleLinkedList<Annotation> annos(DstrBase::USER); // get the list of anchors // getAnchorSet(ancrs); // get the list of annotations // getAnnotationSeqByOffset(annos, 0.0, 0.0); // create a list of annotations and anchors that contain cross indexing // information in order for the annotations to reference the anchors // for (boolean more = ancrs.gotoFirst(); more; more = ancrs.gotoNext()) { // set the index of the anchor // ancr_pair.first().assign(ancrs.getPosition()); // set the anchor object // ancr_pair.second().assign(*ancrs.getCurr()); // inset the anchor pair into the list // ancrs_a.insert(&ancr_pair); } for (boolean more = annos.gotoFirst(); more; more = annos.gotoNext()) { // set the start index of the annotation // anno_triple.first().assign(DEF_INDEX); if (ancrs.find(annos.getCurr()->getStartAnchor())) { anno_triple.first().assign(ancrs.getPosition()); } // set the end index of the annotation // anno_triple.second().assign(DEF_INDEX); if (ancrs.find(annos.getCurr()->getEndAnchor())) { anno_triple.second().assign(ancrs.getPosition()); } // set the annotation object // anno_triple.third().assign(*annos.getCurr()); // insert the annotation pair into the list // annos_a.insert(&anno_triple); } // exit gracefully // return true;}// method: set//// arguments:// DoubleLinkedList<Pair<Long, Anchor> >& ancrs: (input) list of anchors// DoubleLinkedList<Triple<Long, Long, Annotation> >& annos: (input) list// of annotations//// return: logical error status//// method get the annotations and anchors associated with the graph//boolean AnnotationGraph::set(DoubleLinkedList<Pair<Long, Anchor> >& ancrs_a, DoubleLinkedList<Triple<Long, Long, Annotation> >& annos_a) { // declare local variables // long index; long start_index; long end_index; String tmpstr; Anchor anchor; String anchorid; Annotation annotation; Annotation* annotation1; String annotationid; Vector<String> keys; long num_anchors = ancrs_a.length(); Anchor* start_anchor = (Anchor*)NULL; Anchor* end_anchor = (Anchor*)NULL; Anchor* anchors[num_anchors]; // insert the anchors into the graph // for (boolean more=ancrs_a.gotoFirst(); more; more=ancrs_a.gotoNext()) { // get the anchor parameters // index = ancrs_a.getCurr()->first(); anchor = ancrs_a.getCurr()->second(); tmpstr = anchor.getUnit(); // create the anchor object using the parameters // if (anchor.getAnchored()) { anchorid = createAnchor(id_d, anchor.getOffset(), tmpstr); } else { anchorid = createAnchor(id_d, tmpstr); } anchors[index] = getAnchorById(anchorid); } // insert the annotations into the graph // for (boolean more=annos_a.gotoFirst(); more; more=annos_a.gotoNext()) { // get the annotation parameters // start_anchor = (Anchor*)NULL; end_anchor = (Anchor*)NULL; start_index = annos_a.getCurr()->first(); end_index = annos_a.getCurr()->second(); annotation = annos_a.getCurr()->third(); tmpstr = annotation.getType(); // get the start and end anchors // if (start_index != DEF_INDEX) { start_anchor = anchors[start_index]; } if (end_index != DEF_INDEX) { end_anchor = anchors[end_index]; } long channel_index = annotation.getChannel(); // create the annotation object using the parameters // annotationid.assign(annotation.getId()); annotationid = createAnnotation(id_d, start_anchor, end_anchor, tmpstr, channel_index); annotation1 = getById(annotationid); // set the feature map for the annotation // annotation1->setFeatureMap(annotation.getFeatureMap()); // get the features corresponding to the annotation // annotation.getFeatureNames(keys); // add the features to the annotation index // for (long i=0; i<keys.length(); i++) { tmpstr.assign(annotation.getFeature(keys(i))); index_d.addFeature(annotation1, keys(i), tmpstr); } } // exit gracefully // return true;}// method: eq//// arguments:// const AnnotationGraph& arg: (input) annotation graph//// return: logical error status//// method determines if the input annotation graph is equal to the current//boolean AnnotationGraph::eq(const AnnotationGraph& arg_a) const { // declare local variables // boolean status = false; DoubleLinkedList<Pair<Long, Anchor> > ancrs; DoubleLinkedList<Triple<Long, Long, Annotation> > annos; DoubleLinkedList<Pair<Long, Anchor> > ancrs1; DoubleLinkedList<Triple<Long, Long, Annotation> > annos1; // get the structure of the current graph // const_cast<AnnotationGraph*>(this)->get(ancrs, annos); // get the structure of the input graph // const_cast<AnnotationGraph&>(arg_a).get(ancrs1, annos1); // determine if the two graph structures are equal // status = ancrs.eq(ancrs1); status &= annos.eq(annos1); // return the logical status // return status;}// method: assign//// arguments:// const AnnotationGraph& arg: (input) annotation graph//// return: logical error status//// method assigns the input annotation graph to the current one//boolean AnnotationGraph::assign(const AnnotationGraph& arg_a) { // declare local variables // boolean status = false; String anchor(DEF_ANCHOR); String annotation(DEF_ANNOTATION); DoubleLinkedList<Pair<Long, Anchor> > ancrs; DoubleLinkedList<Triple<Long, Long, Annotation> > annos; // clear the current contents of the graph // this->clear(); // assign the member data // status = id_d.assign(arg_a.id_d); status &= type_d.assign(arg_a.type_d); // initialize the identifiers if needed // if (anchorids_d == (Identifier*)NULL) { anchorids_d = new Identifier(id_d, anchor); } if (annotationids_d == (Identifier*)NULL) { annotationids_d = new Identifier(id_d, annotation); } // get the annotations and anchors associated with the input graph // status &= const_cast<AnnotationGraph&>(arg_a).get(ancrs, annos); // initialize the annotations and anchors // status &= set(ancrs, annos); // return the logical status // return status; } // method: setFeature//// arguments:// String& id_a: (input) annotation id// String& fname_a: (input) feature name// String& fvalue_a: (input) feature value//// return: logical error status//// method sets the feature value of the annotation//boolean AnnotationGraph::setFeature(String& id_a, String& fname_a, String& fvalue_a) { // insert the feature value pair to the feature map of the annotation // return setFeature(getById(id_a), fname_a, fvalue_a);}// method: existsFeature//// arguments:// String& id_a: (input) annotation id// String& fname_a: (input) feature name//// return: logical error status//// method to test if a feature exists in the annotation//boolean AnnotationGraph::existsFeature(String& id_a, String& fname_a) { // declare local variables // boolean status = false; Annotation* anno = (Annotation*)NULL; // get the annotation corresponding to the id // anno = getById(id_a); // determine if the feature name exists // if (anno != (Annotation*)NULL) { status = anno->existsFeature(fname_a); } // return the logical status // return status;}// method: deleteFeature//// arguments:// String& id_a: (input) annotation id// String& fname_a: (input) feature name//// return: logical error status//// method that deletes the specified feature from the annotation//boolean AnnotationGraph::deleteFeature(String& id_a, String& fname_a) { // declare local variables // boolean status = false; Annotation* anno = (Annotation*)NULL; // get the annotation corresponding to the id // anno = getById(id_a); // delete the feature from the indeces // if (anno != (Annotation*)NULL) { status = index_d.deleteFeature(anno, fname_a); status &= anno->deleteFeature(fname_a); } // return the logical status // return status; }// method: getFeature//// arguments:// String& id_a: (input) annotation id// String& fname_a: (input) feature name//// return: value of the corresponding feature name//// method that gets the value of specified feature in the annotation//String AnnotationGraph::getFeature(String& id_a, String& fname_a) { // declare local variables // String fvalue; Annotation* anno = (Annotation*)NULL; // get the annotation corresponding to the id // anno = getById(id_a); // retrieve the feature value // if (anno != (Annotation*)NULL) { fvalue.assign(anno->getFeature(fname_a)); } // return the feature value // return fvalue;}// method: getFeatureNames//// arguments:// String& id_a: (input) annotation id// Vector<String>& features: (output) vector of feature names//// return: logical error status//// method that gets the value of specified feature in the annotation//boolean AnnotationGraph::getFeatureNames(String& id_a, Vector<String>& features_a) { // declare local variables // boolean status = false; Annotation* anno = (Annotation*)NULL; // get the annotation corresponding to the id // anno = getById(id_a); // retrieve the feature names // if (anno != (Annotation*)NULL) { status = anno->getFeatureNames(features_a); } // return the logical status // return status;}// method: unsetFeatures//// arguments:// String& id_a: (input) annotation id//// return: logical error status//// method to unset all features in the annotation//boolean AnnotationGraph::unsetFeatures(String& id_a) { // declare local variables // String null; Vector<String> names; Annotation* anno = (Annotation*)NULL; // get the annotation corresponding to the id // anno = getById(id_a); // get the set of feature names // if (anno != (Annotation*)NULL) { if (!anno->getFeatureNames(names)) { return Error::handle(name(), L"getFeature", Error::ARG, __FILE__, __LINE__); } } // loop over all feature names and unset their values // null.assign(String::EMPTY); for (int i=0; i < names.length(); i++) { setFeature(anno, names(i), null); } // exit gracefully // return true; }// method: setFeature//// arguments:// Annotation* anno: (input) annotation// const String& fname_a: (input) feature name// const String& fvalue_a: (input) feature value//// return: logical error status//// method to set the specified feature of the annotation to this value//boolean AnnotationGraph::setFeature(Annotation* anno_a, String& fname_a, String& fvalue_a) { // declare local variables // boolean status = false; // delete the previous feature from the annotation indices // status = index_d.deleteFeature(anno_a, fname_a); if (anno_a->existsFeature(fname_a)) { status &= anno_a->deleteFeature(fname_a); } // insert the feature value pair into the indices // status &= anno_a->setFeature(fname_a, fvalue_a); status &= index_d.addFeature(anno_a, fname_a, fvalue_a); // return the logical status // return status;}// method: getAnnotationSetByFeature//// arguments:// const String& fname_a: (input) feature name// const String& fvalue_a: (input) feature value// DoubleLinkedList<Annotation>& annos_a: (input) annotation list//// return: logical error status//// method to set the specified feature of the annotation to this value//boolean AnnotationGraph::getAnnotationSetByFeature(const String& fname_a, const String& fvalue_a, DoubleLinkedList<Annotation>& annos_a) { // declare local variables // String index; // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // generate the hash index // index.assign(fname_a); index.concat(fvalue_a); // get the list of annotations corresponding to the feature-value pair // if (index_d.by_feature_d.get(index) != (DoubleLinkedList<Annotation>*)NULL) { annos_a.assign(*index_d.by_feature_d.get(index)); } // return error // else { return Error::handle(name(), L"null pointer - no annotation for this feature and the value", Error::ARG, __FILE__, __LINE__); } // exit gracefully // return true; }// method: addAnchor//// arguments:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -