📄 angr_05.cc
字号:
// Anchor* ancr: (input) anchor to be added//// return: logical error status//// method to add an anchor to the graph//boolean AnnotationGraph::addAnchor(Anchor* ancr_a) { // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // insert the anchor id and anchor pair to the anchor mapping // anchorids_d->addAnchorRef(ancr_a->getId(), ancr_a); // insert the anchor to the anchor set // if (!index_d.ancrset_d.contains(ancr_a)) { index_d.addAnchor(ancr_a); } // exit gracefully // return true;}// method: deleteAnchor//// arguments:// Anchor* ancr: (input) anchor to be deleted//// return: logical error status//// method to delete an anchor from the graph//boolean AnnotationGraph::deleteAnchor(Anchor* ancr_a) { // declare local variables // HashKey<Anchor> hashkey; // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // make sure that the anchor has no incoming or outgoing arcs // hashkey.assign(ancr_a); if ((index_d.incoming_d.get(hashkey) == (DoubleLinkedList<Annotation>*)NULL) && (index_d.outgoing_d.get(hashkey) == (DoubleLinkedList<Annotation>*)NULL)) { // remove the anchor for the identifier list // anchorids_d->deleteAnchorRef(ancr_a->getId()); index_d.deleteAnchor(ancr_a); // reclaim the id from the anchor issuer // anchorids_d->reclaimId(ancr_a->getId()); // delete the anchor // delete ancr_a; // exit gracefully // return true; } // exit gracefully // return false;}// method: setAnchorOffset//// arguments:// Anchor* ancr: (input) anchor whose offset is to be changed// float offset: (input) anchor offset//// return: logical error status//// method that sets an anchors offset to the specified value//boolean AnnotationGraph::setAnchorOffset(Anchor* ancr_a, float offset_a) { // delete anchor from indexes // index_d.deleteAnchor(ancr_a); // update the anchor // ancr_a->setOffset(offset_a); // add new anchor to indexes // index_d.addAnchor(ancr_a); // exit gracefully // return true; }// method: splitAnchor//// arguments:// Anchor* ancr: (input) anchor to be split//// return: the new anchor is returned//// method that splits an anchor a in two, creating a new anchor a'// having the same offset as the original one. anchor a has all the// incoming annotations, while anchor a' has all the outgoing annotations.// the new anchor a' is returned.//Anchor* AnnotationGraph::splitAnchor(Anchor* ancr_a) { // declare local variables // String newid; Anchor* ancr = (Anchor*)NULL; DoubleLinkedList<Annotation> annos(DstrBase::USER); // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // generate a new id for the anchor // newid.assign(anchorids_d->registerId()); // clone the anchor // ancr = new Anchor(newid, ancr_a); addAnchor(ancr); // for each outgoing arc from ancr_a, change its start node to ancr // getOutgoingAnnotationSet(ancr_a, annos); for (boolean more = annos.gotoFirst(); more; more = annos.gotoNext()) { setStartAnchor(annos.getCurr(), ancr); } // return the new anchor // return ancr; }// method: add//// arguments:// Annotation* anno: (input) annotation to be added//// return: logical error status//// method that adds a new annotation to the graph//boolean AnnotationGraph::add(Annotation* anno_a) { // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // add annotation to the annotation set // annoseq_d.insert(anno_a); // update index and the identifier issuer // index_d.add(anno_a); annotationids_d->addAnnotationRef(anno_a->getId(), anno_a); // exit gracefully // return true; }// method: createAnnotation//// arguments:// String& id_a: (input) annotation id// Anchor* anchor1_a: (input) start anchor// Anchor* anchor2_a: (input) end anchor// String& type_a: (input) annotation type// long channel; (input) channel//// return: annotation id//// method that create a new annotation//String AnnotationGraph::createAnnotation(String& id_a, Anchor* anchor1_a, Anchor* anchor2_a, String& type_a, long channel_a) { // declare local variables // String newid; Annotation* anno = (Annotation*)NULL; // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } String nspace(annotationids_d->getNamespace(id_a)); if (nspace.eq(String::EMPTY)) { nspace.assign(id_a); } // when the is the same as the graphs id // if (id_a.eq(id_a)) { newid.assign(annotationids_d->registerId()); anno = new Annotation(newid, anchor1_a, anchor2_a, type_a, channel_a); } // when the namespace is the same as the graphs id // else if (nspace.eq(id_a)) { newid.assign(annotationids_d->registerId(id_a)); anno = new Annotation(newid, anchor1_a, anchor2_a, type_a, channel_a); } // the id is not an annotation graph or a valid annotation id // else { return Error::handle(name(), L"createAnnotation", Error::ARG, __FILE__, __LINE__); } // add the annotation to the graph // add(anno); // return the annotation id // return anno->getId();}// method: createAnchor//// arguments:// String& id: (input) anchor id// float offset: (input) anchor offset// String& unit: (input) unit of the offset//// return: anchor id//// method that creates and anchor with specified offset and unit//String AnnotationGraph::createAnchor(String& id_a, String& unit_a) { // declare local variables // String newid; Anchor* ancr = (Anchor*)NULL; // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } String nspace(anchorids_d->getNamespace(id_a)); if (nspace.eq(String::EMPTY)) { nspace.assign(id_a); } // when the id is the same as the graphs id // if (id_a.eq(id_d)) { newid.assign(anchorids_d->registerId()); ancr = new Anchor(newid, unit_a); } // when the name space is the same as the graphs id // else if (nspace.eq(id_a)) { newid.assign(anchorids_d->registerId(id_a)); ancr = new Anchor(newid, unit_a); } // the id is not an annotation graph or a valid anchor id // else { return Error::handle(name(), L"createAnchor", Error::ARG, __FILE__, __LINE__); } // add the anchor to the graph // addAnchor(ancr); // return the anchor id // return ancr->getId();}// method: createAnchor//// arguments:// String& id: (input) anchor id// float offset: (input) anchor offset// String& unit: (input) unit of the offset//// return: anchor id//// method that creates and anchor with specified offset and unit//String AnnotationGraph::createAnchor(String& id_a, float offset_a, String& unit_a) { // declare local variables // String newid; Anchor* ancr = (Anchor*)NULL; // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } String nspace(anchorids_d->getNamespace(id_a)); if (nspace.eq(String::EMPTY)) { nspace.assign(id_a); } // when the id is the same as the graphs id // if (id_a.eq(id_d)) { newid.assign(anchorids_d->registerId()); ancr = new Anchor(newid, offset_a, unit_a); } // when the name space is the same as the graphs id // else if (nspace.eq(id_a)) { newid.assign(anchorids_d->registerId(id_a)); ancr = new Anchor(newid, offset_a, unit_a); } // the id is not an annotation graph or a valid anchor id // else { return Error::handle(name(), L"createAnchor", Error::ARG, __FILE__, __LINE__); } // add the anchor to the graph // addAnchor(ancr); // return the anchor id // return ancr->getId();}// method: getAnchorOffset//// arguments:// Anchor* ancr: (input) graph anchor//// return: anchor offset//// method that returns the offset of the specified anchor//float AnnotationGraph::getAnchorOffset(Anchor* ancr_a) { // declare local variables // float offset = 0.0; // determine the offset of the anchor // if ((ancr_a != (Anchor*)NULL) && (ancr_a->getAnchored())) { offset = ancr_a->getOffset(); } // return the offset // return offset;}// method: copyAnnotation//// arguments:// const Annotation* anno: (input) graph anchor//// return: annotation copy//// method that makes a copy of the specified annotation//Annotation* AnnotationGraph::copyAnnotation(const Annotation* anno_a) { // declare local variables // String newid; Annotation* annotation = (Annotation*)NULL; // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // clone the annotation // newid.assign(annotationids_d->registerId()); annotation = new Annotation(newid, anno_a); // add the cloned annotation to the graph // add(annotation); // return the annotation copy // return annotation;}// method: splitAnnotation//// arguments:// Annotation* anno: (input) annotation to split//// return: split annotation//// method that split an annotation a in two creating a new annotation a'// having the same label data as the original one. the two annotations a,// a' connect head-to-tail at a new anchor. the new annotation and anchor// have identifiers taken from the specified identifier spaces. the new// anchor is unanchored, i.e. has no offset.//Annotation* AnnotationGraph::splitAnnotation(Annotation* anno_a) { // dclare local variables // String newid; String newunit; Anchor* endancr = (Anchor*)NULL; Annotation* newanno = (Annotation*)NULL; Anchor* newancr = (Anchor*)NULL; // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // get the end anchor of the annotation // endancr = anno_a->getEndAnchor(); // clone the annotation // newanno = copyAnnotation(anno_a); // create a new anchor positioned between the split annotations // newunit.assign(endancr->getUnit()); newid.assign(anchorids_d->registerId()); newancr = new Anchor(newid, newunit); // make anno_a end at this anchor // setEndAnchor(anno_a, newancr); // make newanno start at this anchor // setStartAnchor(newanno, newancr); // return the new annotation // return newanno;}// method: nSplitAnnotation//// arguments:// Annotation* anno: (input) annotation to split// long num_split: number of splits// DoubleLinkedList<Annotation> annos: (output) annotation list//// return: split annotations//// method that split an annotation to n annotations. aversion of split// which does the split operation n-1 times, i.e. splits the original// annotation into n annotations.//boolean AnnotationGraph::nSplitAnnotation(Annotation* anno_a, long num_split_a, DoubleLinkedList<Annotation>& annos_a) { // declare local variables // Annotation* anno = anno_a; // clear the list to start with // annos_a.clear(); annos_a.setAllocationMode(DstrBase::USER); // insert the into the list // if (anno != (Annotation*)NULL) { annos_a.insert(anno); } // split the annotation as per the number specified // for (int i=num_split_a; i > 1; i--) { if (anno != (Annotation*)NULL) { anno = splitAnnotation(anno); annos_a.insert(anno); } } // exit gracefully // return true;}// method: deleteAnnotation//// arguments:// Annotation* anno: (input) annotation to delete//// return: logical error status//// method that deletes the annotation from the graph//boolean AnnotationGraph::deleteAnnotation(Annotation* anno_a) { // check for null pointer exceptions // if (anchorids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } if (annotationids_d == (Identifier*)NULL) { return Error::handle(name(), L"null pointer", Error::ARG, __FILE__, __LINE__); } // determine if the annotation is present in the graph // if (getById(anno_a->getId()) != (Annotation*)NULL) { // delete the annotation from the indices and identifier issuer // annotationids_d->deleteAnnotationRef(anno_a->getId()); index_d.deleteAnnotation(anno_a); // remove the annotation from the sequence and reclaim the identifier // if (annoseq_d.find(anno_a)) { annoseq_d.remove(); } annotationids_d->reclaimId(anno_a->getId()); // delete the annotation // delete anno_a; // exit gracefully // return true; } // exit gracefully // return false; }// method: setStartAnchor//// arguments:// Annotation* anno: (input) graph annotation// Anchor* ancr: (input) start anchor//// return: logical error status//// method that sets the start anchor of an annotation to the input anchor//boolean AnnotationGraph::setStartAnchor(Annotation* anno_a, Anchor* ancr_a) { // delete the annotation from the indices // index_d.deleteAnnotation(anno_a); // set the start anchor of the annotation // anno_a->setStartAnchor(ancr_a);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -