void Base::Initialize() { ERROR(Tagger().AnalysisName()); // working_path_ = WorkingPath(); // if (Name() != analysis::Base::Name()) // INFO(working_path_, Name()); mkdir(Name().c_str(), 0700); // else ERROR(Name()); Tagger().Initialize(Name()); _name_ = Name(); }
void Base::RunTrainer() { INFO0; if (Exists(Tagger().WeightFileName())) return; PrepareFiles(Stage::trainer); std::ofstream cout_file(Tagger().FolderName() + ".txt"); auto cout = std::cout.rdbuf(); std::cout.rdbuf(cout_file.rdbuf()); Trainer trainer(Tagger()); std::cout.rdbuf(cout); }
static int TagThread(char *direct, char *search, int type) /* 0: title, 1: owner */ { caddr_t fimage, tail; off_t off; int fd, fsize, count; struct stat stbuf; fileheader *head; char *title; if ((fd = open(direct, O_RDONLY)) < 0) return RC_NONE; fstat(fd, &stbuf); fsize = stbuf.st_size; fimage = NULL; off = count = 0; do { fimage = mmap(fimage, BATCH_SIZE, PROT_READ, MAP_SHARED, fd, off); if (fimage == (char *) -1) { outs("MMAP ERROR!!!!"); close(fd); //hialan:是不是缺少這個..@@"" abort_bbs(); } tail = fimage + BMIN(BATCH_SIZE, fsize - off); for (head = (fileheader *) fimage; (caddr_t) head < tail; head++) { int tmplen; count++; if (type == 1) { title = head->owner; tmplen = IDLEN+1; } else { title = str_ttl(head->title); tmplen = TTLEN; } if (!strncmp(search, title, tmplen)) { if (!Tagger(atoi(head->filename + 2) , count, TAG_INSERT)) { off = fsize; break; } } } off += BATCH_SIZE; // wildcat : 會越吃越多記憶體? munmap(fimage, BATCH_SIZE); } while (off < fsize); close(fd); return RC_DRAW; }
static int delete_range2(char *fpath, int id1, int id2) { fileheader fhdr; nol my; char fullpath[STRLEN], *t; int fdr, fdw, fd; register int count; nolfilename(&my, fpath); if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) < 0) return -1; flock(fd, LOCK_EX); if ((fdr = open(fpath, O_RDONLY, 0)) < 0) { flock(fd, LOCK_UN); close(fd); return -1; } if ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) < 0) { close(fdr); flock(fd, LOCK_UN); close(fd); return -1; } strcpy(fullpath, fpath); t = (char *) strrchr(fullpath, '/') + 1; count = 0; while (read(fdr, &fhdr, sizeof(fileheader)) == sizeof(fileheader)) { count++; if ((fhdr.filemode & FILE_MARKED) || /* 標記 */ (id1 && (count < id1 || count > id2)) || /* range */ (!id1 && Tagger(atoi(fhdr.filename+2), count, TAG_COMP))) /* TagList */ { if ((write(fdw, &fhdr, sizeof(fileheader)) < 0)) { close(fdr); close(fdw); unlink(my.newfn); flock(fd, LOCK_UN); close(fd); return -1; } } else { strcpy(t, fhdr.filename); /* 若為看板就連線砍信 */ if (currstat == READING) { cancel_post(&fhdr, fullpath); } unlink(fullpath); } } close(fdr); close(fdw); count = rename(fpath, my.oldfn); if (!count) { if (count = rename(my.newfn, fpath)) rename(my.oldfn, fpath); /* 萬一出鎚,再救回來 */ } flock(fd, LOCK_UN); close(fd); return count; }
void Base::RunTagger(Stage stage) { INFO0; if (Exists(Tagger().FileName(stage, Tag::signal))) return; AnalysisLoop(stage); }
void Base::ClearFiles() { INFO0; files_.clear(); Tagger().ClearTreeNames(); }
void Base::AddFile(Tag tag, boca::FileInfo const& file) { INFO0; files_.emplace_back(file); Tagger().AddTreeName(file.TaggerTreeName(), tag); }