static void deco (Display *dpy, Window window, struct state *st, int x, int y, int w, int h, int depth) { if (((random() % st->max_depth) < depth) || (w < st->min_width) || (h < st->min_height)) { if (!mono_p) { if (++st->current_color >= st->ncolors) st->current_color = 0; XSetForeground(dpy, st->bgc, st->colors[st->current_color].pixel); } XFillRectangle (dpy, window, st->bgc, x, y, w, h); XDrawRectangle (dpy, window, st->fgc, x, y, w, h); } else { if ((st->goldenRatio || st->mondrian) ? (w > h) : (random() & 1)) { /* Divide the rectangle side-by-side */ int wnew = (st->goldenRatio ? (w * (random() & 1 ? PHI1 : PHI2)) : w/2); deco (dpy, window, st, x, y, wnew, h, depth+1); deco (dpy, window, st, x+wnew, y, w-wnew, h, depth+1); } else { /* Divide the rectangle top-to-bottom */ int hnew = (st->goldenRatio ? (h * (random() & 1 ? PHI1 : PHI2)) : h/2); deco (dpy, window, st, x, y, w, hnew, depth+1); deco (dpy, window, st, x, y+hnew, w, h-hnew, depth+1); } } }
int segment(const char * str, std::vector<std::string> & words) { ltp::segmentor::Instance * inst = new ltp::segmentor::Instance; // ltp::strutils::codecs::decode(str, inst->forms); int ret = ltp::segmentor::rulebase::preprocess(str, inst->raw_forms, inst->forms, inst->chartypes); if (-1 == ret) { delete inst; words.clear(); return 0; } ltp::segmentor::Segmentor::extract_features(inst); ltp::segmentor::Segmentor::calculate_scores(inst, true); // allocate a new decoder so that the segmentor support multithreaded // decoding. this modification was committed by niuox ltp::segmentor::Decoder deco(model->num_labels(), *baseAll); deco.decode(inst); ltp::segmentor::Segmentor::build_words(inst, inst->predicted_tagsidx, words, beg_tag0, beg_tag1); delete inst; return words.size(); }
void DecorationTest::testSection() { MockBridge bridge; auto decoSettings = QSharedPointer<KDecoration2::DecorationSettings>::create(&bridge); MockDecoration deco(&bridge); deco.setSettings(decoSettings); MockSettings *settings = bridge.lastCreatedSettings(); settings->setLargeSpacing(0); MockClient *client = bridge.lastCreatedClient(); client->setWidth(100); client->setHeight(100); QCOMPARE(deco.size(), QSize(100, 100)); QCOMPARE(deco.borderLeft(), 0); QCOMPARE(deco.borderTop(), 0); QCOMPARE(deco.borderRight(), 0); QCOMPARE(deco.borderBottom(), 0); QCOMPARE(deco.titleBar(), QRect()); QCOMPARE(deco.sectionUnderMouse(), Qt::NoSection); QFETCH(QRect, titleBar); QFETCH(QMargins, margins); deco.setBorders(margins); QCOMPARE(deco.borderLeft(), margins.left()); QCOMPARE(deco.borderTop(), margins.top()); QCOMPARE(deco.borderRight(), margins.right()); QCOMPARE(deco.borderBottom(), margins.bottom()); deco.setTitleBar(titleBar); QCOMPARE(deco.titleBar(), titleBar); QCOMPARE(deco.size(), QSize(100 + deco.borderLeft() + deco.borderRight(), 100 + deco.borderTop() + deco.borderBottom())); QSignalSpy spy(&deco, SIGNAL(sectionUnderMouseChanged(Qt::WindowFrameSection))); QVERIFY(spy.isValid()); QFETCH(QPoint, pos); QHoverEvent event(QEvent::HoverMove, QPointF(pos), QPointF(pos)); QCoreApplication::sendEvent(&deco, &event); QFETCH(Qt::WindowFrameSection, expected); QCOMPARE(deco.sectionUnderMouse(), expected); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().value<Qt::WindowFrameSection>(), expected); QHoverEvent event2(QEvent::HoverMove, QPointF(50, 50), QPointF(50, 50)); QCoreApplication::sendEvent(&deco, &event2); QCOMPARE(deco.sectionUnderMouse(), Qt::NoSection); QCOMPARE(spy.count(), 2); QCOMPARE(spy.first().first().value<Qt::WindowFrameSection>(), expected); QCOMPARE(spy.last().first().value<Qt::WindowFrameSection>(), Qt::NoSection); }
static unsigned long deco_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; XFillRectangle (dpy, window, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); if (st->mondrian) { mondrian_set_sizes(st, st->xgwa.width, st->xgwa.height); if (st->line_width != st->old_line_width) { XSetLineAttributes(dpy, st->fgc, st->line_width, LineSolid, CapButt, JoinBevel); st->old_line_width = st->line_width; } } deco (dpy, window, st, 0, 0, st->xgwa.width, st->xgwa.height, 0); return 1000000 * st->delay; }
void testUtf8BlockIndexDecoder(std::string const & fn) { ::libmaus::util::Utf8BlockIndex::unique_ptr_type index = (::libmaus::util::Utf8BlockIndex::constructFromUtf8File(fn)); std::string const idxfn = fn + ".idx"; ::libmaus::aio::CheckedOutputStream COS(idxfn); index->serialise(COS); COS.flush(); COS.close(); ::libmaus::util::Utf8BlockIndexDecoder deco(idxfn); assert ( deco.numblocks+1 == index->blockstarts.size() ); for ( uint64_t i = 0; i < deco.numblocks; ++i ) assert ( deco[i] == index->blockstarts[i] ); assert ( index->blockstarts[deco.numblocks] == ::libmaus::util::GetFileSize::getFileSize(fn) ); assert ( deco[deco.numblocks] == ::libmaus::util::GetFileSize::getFileSize(fn) ); }
void DecorationTest::testOpaque() { MockBridge bridge; MockDecoration deco(&bridge); QSignalSpy opaqueChangedSpy(&deco, SIGNAL(opaqueChanged(bool))); QVERIFY(opaqueChangedSpy.isValid()); QCOMPARE(deco.isOpaque(), false); deco.setOpaque(false); QVERIFY(opaqueChangedSpy.isEmpty()); deco.setOpaque(true); QCOMPARE(opaqueChangedSpy.count(), 1); QCOMPARE(opaqueChangedSpy.first().first().toBool(), true); QCOMPARE(deco.isOpaque(), true); deco.setOpaque(true); QCOMPARE(opaqueChangedSpy.count(), 1); deco.setOpaque(false); QCOMPARE(opaqueChangedSpy.count(), 2); QCOMPARE(opaqueChangedSpy.first().first().toBool(), true); QCOMPARE(opaqueChangedSpy.last().first().toBool(), false); QCOMPARE(deco.isOpaque(), false); }
int recognize(const std::vector<std::string> & words, const std::vector<std::string> & postags, std::vector<std::string> & tags) { ltp::ner::rulebase::RuleBase base(model->labels); ltp::ner::Decoder deco(model->num_labels(), base); ltp::ner::Instance * inst = new ltp::ner::Instance; for (int i = 0; i < words.size(); ++ i) { inst->forms.push_back(ltp::strutils::chartypes::sbc2dbc_x(words[i])); inst->postags.push_back(postags[i]); } ltp::ner::NER::extract_features(inst); ltp::ner::NER::calculate_scores(inst, true); deco.decode(inst); for (int i = 0; i < words.size(); ++ i) { tags.push_back(model->labels.at(inst->predicted_tagsidx[i])); } delete inst; return tags.size(); }