graphmod::Instances from_conll(vector<string> file_names, vector<string> _keep_verbs, int window, unsigned int limit=0, unsigned int per_verb_limit=0){ Instances instances; set<string> keep_verbs; for(string verb: _keep_verbs){ keep_verbs.insert(verb); } std::map<std::string, unsigned int> verb_counts; ConllLoader sentences(file_names); //boost::regex expr("\\n\\s*\\n", boost::regex::perl); //boost::regex_iterator //int total = 0; while(not sentences.eof() and (limit == 0 or instances.size() < limit)){ auto cs = sentences.next(); for(ConllWord cw: cs){ if(cw.get_fine_tag()[0] == 'V' and (keep_verbs.count(cw.get_lemma()) > 0 or keep_verbs.size() == 0)){ map<string, vector<string> > instance; int verb_index = cw.get_index(); instance["verb"] = {cw.get_lemma()}; if(per_verb_limit > 0 and verb_counts[cw.get_lemma()] > per_verb_limit){ continue; } verb_counts[cw.get_lemma()]++; instance["verb_tag"] = {cw.get_fine_tag()}; instance["tag"].resize(0); instance["gr"].resize(0); instance["lemma"].resize(0); if(window > 0){ for(ConllWord ow: cs.get_near(cw, window)){ string tag = ow.get_fine_tag(); instance["tag"].push_back(ow.get_fine_tag()); instance["lemma"].push_back(ow.get_lemma()); stringstream ss; ss << ow.get_index() - verb_index; instance["gr"].push_back(ss.str()); } } else{ //instance["relation"].resize(0); for(ConllWord ow: cs.get_related(cw)){ stringstream ss; string tag = ow.get_fine_tag(), gr = ow.get_relation(); if(function_tag(tag[0]) == true){ ss << gr << "(" << tag << "-" << ow.get_lemma() << "," << cw.get_fine_tag() << ")"; } else{ ss << gr << "(" << tag << "," << cw.get_fine_tag() << ")"; } instance["tag"].push_back(tag); //instance["gr"].push_back(ss.str()); instance["gr"].push_back(gr); instance["lemma"].push_back(ow.get_lemma()); } } instances.add(instance); } } } return instances; //cout << total << endl; }
void Series::Load3DImage(void* target, Orthanc::PixelFormat format, size_t lineStride, size_t stackStride, Orthanc::ThreadedCommandProcessor::IListener* listener) { using namespace Orthanc; // Choose the extraction mode, depending on the format of the // target image. uint8_t bytesPerPixel; ImageExtractionMode mode; switch (format) { case PixelFormat_RGB24: bytesPerPixel = 3; mode = ImageExtractionMode_Preview; break; case PixelFormat_Grayscale8: bytesPerPixel = 1; mode = ImageExtractionMode_UInt8; // Preview ??? break; case PixelFormat_Grayscale16: bytesPerPixel = 2; mode = ImageExtractionMode_UInt16; break; case PixelFormat_SignedGrayscale16: bytesPerPixel = 2; mode = ImageExtractionMode_UInt16; format = PixelFormat_Grayscale16; break; default: throw OrthancException(ErrorCode_NotImplemented); } // Check that the target image is properly sized unsigned int sx = GetWidth(); unsigned int sy = GetHeight(); if (lineStride < sx * bytesPerPixel || stackStride < sx * sy * bytesPerPixel) { throw OrthancException(ErrorCode_BadRequest); } if (sx == 0 || sy == 0 || GetInstanceCount() == 0) { // Empty image, nothing to do if (listener) listener->SignalSuccess(0); return; } /** * Order the stacks according to their distance along the slice * normal (using the "Image Position Patient" tag). This works * even if the "SliceLocation" tag is absent. **/ SliceLocator locator(GetInstance(0)); typedef std::map<float, Instance*> Instances; Instances instances; for (unsigned int i = 0; i < GetInstanceCount(); i++) { float dist = locator.ComputeSliceLocation(GetInstance(i)); instances[dist] = &GetInstance(i); } if (instances.size() != GetInstanceCount()) { // Several instances have the same Z coordinate throw OrthancException(ErrorCode_NotImplemented); } // Submit the download of each stack as a set of commands ThreadedCommandProcessor processor(connection_.GetThreadCount()); if (listener != NULL) { processor.SetListener(*listener); } uint8_t* stackTarget = reinterpret_cast<uint8_t*>(target); for (Instances::iterator it = instances.begin(); it != instances.end(); it++) { processor.Post(new ImageDownloadCommand(*it->second, format, mode, stackTarget, lineStride)); stackTarget += stackStride; } // Wait for all the stacks to be downloaded if (!processor.Join()) { throw OrthancException(ErrorCode_NetworkProtocol); } }