📄 angr_05.cc
字号:
// add the annotation to the indices // index_d.add(anno_a); // exit gracefully // return true; }// method: setEndAnchor//// arguments:// Annotation* anno: (input) graph annotation// Anchor* ancr: (input) end anchor//// return: logical error status//// method that sets the end anchor of an annotation to the specified anchor//boolean AnnotationGraph::setEndAnchor(Annotation* anno_a, Anchor* ancr_a) { // delete the annotation from the indices // index_d.deleteAnnotation(anno_a); // set the end anchor of the annotation // anno_a->setEndAnchor(ancr_a); // add the annotation to the indices // index_d.add(anno_a); // exit gracefully // return true; }// method: unsetAnchorOffset//// arguments:// Anchor* ancr: (input) graph anchor//// return: logical error status//// method that unsets the offset of the specified anchor//boolean AnnotationGraph::unsetAnchorOffset(Anchor* ancr_a) { // delete anchor from indices // index_d.deleteAnchor(ancr_a); // update the anchor offset // ancr_a->unsetOffset(); // add new anchor to indices // index_d.addAnchor(ancr_a); // exit gracefully // return true; }// method: getAnchorSet//// arguments:// DoubleLinkedList<Anchor>& ancrs: (output) anchors list//// return: graph anchor set//// metod that gets the set of anchors, sorted by offsets//boolean AnnotationGraph::getAnchorSet(DoubleLinkedList<Anchor>& ancrs_a) { // clear the list to start with // ancrs_a.clear(); ancrs_a.setAllocationMode(DstrBase::USER); // assign the anchor set to the input list // ancrs_a.assign(index_d.ancrset_d); // exit gracefully // return true; }// method: getById//// arguments:// const String& id: (input) annotation id//// return: annotation//// method that gets the annotation reference by its id//Annotation* AnnotationGraph::getById(const String& id_a) { // declare local variables // Annotation* annotation = (Annotation*)NULL; // check if the annotation exists // if(index_d.existsAnnotation(id_a)) { annotation = index_d.anno_by_id_d.get(id_a); } // return the annotation // return annotation;}// method://// arguments:// const String& id: (input) anchor id//// return: anchor//// method that gets the anchor reference by its id//Anchor* AnnotationGraph::getAnchorById(const String& id_a) { // declare local variables // Anchor* anchor = (Anchor*)NULL; // check if the anchor exists // if(index_d.existsAnchor(id_a)) { anchor = index_d.ancr_by_id_d.get(id_a); } // return the annotation // return anchor;}// method: getAnchorSetByOffset//// arguments:// float offset: (input) anchor offset// DoubleLinkedList<Anchor> ancrs: (output) anchors list// double esp: (input) epsilon value //// return: anchor set//// method that gets anchors with the specified offset//boolean AnnotationGraph::getAnchorSetByOffset(float offset_a, DoubleLinkedList<Anchor>& ancrs_a, double eps_a) { // d eclare local variables // double delta; Float offset; DoubleLinkedList<Anchor> ancrset(DstrBase::USER); // clear the list to start with // ancrs_a.clear(); ancrs_a.setAllocationMode(DstrBase::USER); // epsilon should not be a negative number // eps_a = eps_a > 0.0 ? eps_a : -eps_a; // when the specified epsilon is zero // if (eps_a == 0.0) { offset.assign(offset_a); if (index_d.ancrset_by_offset_d.get(offset) != (DoubleLinkedList<Anchor>*)NULL) { ancrs_a.assign(*(index_d.ancrset_by_offset_d.get(offset))); } } // when the specified epsilon is greater than zero // else { // get the list of anchors // getAnchorSet(ancrset); // loop over all anchors in the set // for(boolean more = ancrset.gotoFirst(); more; more = ancrset.gotoNext()) { // determine the variance between the current and input offsets // delta = ancrset.getCurr()->getOffset() - offset_a; delta = delta > 0.0 ? delta : -delta; // insert the anchor into the list if the variance is within epsilon // if (delta <= eps_a) { ancrs_a.insert(ancrset.getCurr()); } } } // exit gracefully // return true; }// method: getAnnotationSetByType//// arguments:// const String& type: (input) annotation type// DoubleLinkedList<Annotation>& annos: (output) annotation list//// return: annotation set//// method that gets the annotations using the type//boolean AnnotationGraph::getAnnotationSetByType(const String& type_a, DoubleLinkedList<Annotation>& annos_a) { // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); DoubleLinkedList<Annotation>* list; // assign the annotation set // if (index_d.anno_by_type_d.get(type_a) != (DoubleLinkedList<Annotation>*)NULL) { list = index_d.anno_by_type_d.get(type_a); annos_a.assign(*(index_d.anno_by_type_d.get(type_a))); } // exit gracefully // return true; }// method: getAnnotationSetByOffset//// arguments:// float offset: (input) annotation offset// DoubleLinkedList<Annotation>& annos: (input) annotation list//// return: annotation set//// method that gets the annotations that overlap a particular time offset.// gets all annotations whose start anchor offset is smaller than or// equal to the given offset AND end anchor offset is greater than // or equal to the given offet//boolean AnnotationGraph::getAnnotationSetByOffset(float offset_a, DoubleLinkedList<Annotation>& annos_a) { // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // get the annotation set by offset // index_d.getByOffset(offset_a, annos_a); // exit gracefully // return true; }// method: getIncomingAnnotationSet//// arguments:// Anchor* ancr: (input) graph anchor// DoubleLinkedList<Annotation>& annos: (input) annotation list//// return: annotation set//// method that gets the incoming annotations to the specified node//boolean AnnotationGraph::getIncomingAnnotationSet(Anchor* ancr_a, DoubleLinkedList<Annotation>& annos_a) { // define local variables // HashKey<Anchor> hashkey; // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // get the incoming annotation set // hashkey.assign(ancr_a); if (index_d.incoming_d.get(hashkey) != (DoubleLinkedList<Annotation>*)NULL) { annos_a.assign(*(index_d.incoming_d.get(hashkey))); } // exit gracefully // return true; }// method: getOutgoingAnnotationSet//// arguments:// Anchor* ancr: (input) graph anchor// DoubleLinkedList<Annotation>& annos: (input) annotation list//// return: annotation set//// method that gets the outgoing annotations from the specified node//boolean AnnotationGraph::getOutgoingAnnotationSet(Anchor* ancr_a, DoubleLinkedList<Annotation>& annos_a) { // define local variables // HashKey<Anchor> hashkey; // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // get the outgoing annotation set // hashkey.assign(ancr_a); if (index_d.outgoing_d.get(hashkey) != (DoubleLinkedList<Annotation>*)NULL) { annos_a.assign(*(index_d.outgoing_d.get(hashkey))); } // exit gracefully // return true; }// method: getNearestOffset//// arguments:// float offset: (input) offset target//// return: nearest offset//// method that gets the nearest used offset to the specified offset//float AnnotationGraph::getNearestOffset(float offset_a) { // get the nearest offset // return index_d.getNearestOffset(offset_a);}// method: getAnnotationSeqByOffset//// arguments:// DoubleLinkedList<Annotation>& annos: (output) annotation list// float begin: (input) start offset// float end: (input) end offset//// return: annotation set//// method that get all annotations with its start anchor offset in between// the specified values. gets all annotations with its start anchor offset// in between the specified values. if both values are 0, return all// annotations in the graph//boolean AnnotationGraph::getAnnotationSeqByOffset(DoubleLinkedList<Annotation>& annos_a, float begin_a, float end_a) { // declate local variables // Annotation* anno; // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // determine if the annotation sequence is not empty // if (!annoseq_d.isEmpty()) { // when the begin and end times are zero return the annotation sequence // if ((begin_a == 0.0) && (end_a == 0.0)) { annos_a.assign(annoseq_d); } // determine which annotations in the sequence lie in the specified range // else { // loop over all annotations in the sequence // for (boolean more = annoseq_d.gotoFirst(); more; more = annoseq_d.gotoNext()) { // get the current annotation // anno = annoseq_d.getCurr(); // check if the annotation start anchor is within bounds // if (anno->getStartAnchor()->getOffset() >= begin_a) { // check if the annotation start anchor is within bounds // if (anno->getStartAnchor()->getOffset() <= end_a) { // insert the annotation into the list // annos_a.insert(anno); } } } } } // exit gracefully // return true; }// method: getAnnotationByOffset//// arguments:// float offset: (input) annotation offset//// return: annotation//// method that gets one of the annotations which overlap a particular time// offset. same as getByOffset except that getAnnotationByOffset returns only// one qualified annotation while getByOffset returns all of them//Annotation* AnnotationGraph::getAnnotationByOffset(float offset_a) { // get the annotation by offset // return index_d.getAnnotationByOffset(offset_a);}// method: getAnchorSetNearestOffset//// arguments:// float offset: (input) anchor offset// DoubleLinkedList<Anchor>& ancrs: (output) anchots list//// return: anchor set//// method that gets all anchors whose offset is the nearest to the// specified offset//boolean AnnotationGraph::getAnchorSetNearestOffset(float offset_a, DoubleLinkedList<Anchor>& ancrs_a) { // determine the nearest offset // float offset = getNearestOffset(offset_a); // get the anchor set corresponding to the nearest offset // getAnchorSetByOffset(offset, ancrs_a); // exit gracefully // return true; }// method: getAnnotationSet//// arguments:// DoubleLinkedList<Annotation>& annos_a: (output) annotation list//// return: logical error status//// method to get all the annotations in the graph//boolean AnnotationGraph::getAnnotationSet(DoubleLinkedList<Annotation>& annos_a) { // declare local variables // String index; // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // get the list of annotations // annos_a.assign(annoseq_d); // exit gracefully // return true; }// method: deleteAnnotationSetByFeature//// arguments:// const String& fname_a: (input) feature name// const String& fvalue_a: (input) feature value//// return: logical error status//// method to delete the annotations and the corresponding redundant// anchors with the feature-value pair//boolean AnnotationGraph::deleteAnnotationSetByFeature(const String& fname_a, const String& fvalue_a) { // declare local variables // DoubleLinkedList<Annotation> annos(DstrBase::USER); Annotation* anno = (Annotation*)NULL; // get the list of annotations corresponding to the feature-value pair // if (!getAnnotationSetByFeature(fname_a, fvalue_a, annos)) { return Error::handle(name(), L"no annotation for this feature and the value", Error::ARG, __FILE__, __LINE__); } // loop over the list of annotations and delete them // for (boolean more = annos.gotoFirst(); more; more = annos.gotoNext()) { // get the annotation // anno = annos.getCurr(); // check for null annotation // if (anno == (Annotation*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // delete the annotation // if (!deleteAnnotation(anno)) { return Error::handle(name(), L"can't delete this Annotation", Error::ARG, __FILE__, __LINE__); } } // get all the anchors and purge the redundant anchors // if (!purgeAnchors()) { return Error::handle(name(), L"can't purge the Anchors", Error::ARG, __FILE__, __LINE__); } // exit gracefully // return true; }// method: purgeAnchors//// arguments:// none//// return: logical error status//// method to purge all the redundant anchors in the graph//boolean AnnotationGraph::purgeAnchors() { // local variables // DoubleLinkedList<Anchor> ancrs(DstrBase::USER); Anchor* ancr = (Anchor*)NULL; DoubleLinkedList<Annotation> in_annos(DstrBase::USER); DoubleLinkedList<Annotation> out_annos(DstrBase::USER); // get all the anchors // if (!getAnchorSet(ancrs)) { return Error::handle(name(), L"no Anchors in this AnnotationGraph", Error::ARG, __FILE__, __LINE__); } // delete the redundant anchors // for (boolean morea = ancrs.gotoFirst(); morea; morea = ancrs.gotoNext()) { // get the anchor // ancr = ancrs.getCurr(); // check for null anchor // if (ancr == (Anchor*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // clear the memory // in_annos.clear(); out_annos.clear(); // get the incoming and the outgoing annotations at this anchor // if (!getIncomingAnnotationSet(ancr, in_annos)) { return Error::handle(name(), L"no annotation in this AnnotationGraph", Error::ARG, __FILE__, __LINE__); } if (!getOutgoingAnnotationSet(ancr, out_annos)) { return Error::handle(name(), L"no annotation in this AnnotationGraph", Error::ARG, __FILE__, __LINE__); } // delete this anchor if both the incoming and the outgoig // annotations are zero // if ((in_annos.length() == (long)0) && (out_annos.length() == (long)0)) { // delete the annotation // if (!deleteAnchor(ancr)) { return Error::handle(name(), L"can't delete this Anchor", Error::ARG, __FILE__, __LINE__); } } } // exit gracefully // return true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -