void TextEngine::lineWrappedGreedyAlgo(string text) { vector<string> words = getWords(text); int width = 20; int spaceLeft = width; int spaceWidth = 1; bool first = true; for(int i=0; i<words.size(); i++) { int size = words[i].size(); if(size > spaceLeft) { cout << endl; spaceLeft = width - size; cout << words[i]; first = false; } else { if(first) { cout << words[i]; first = false; } else cout << " " << words[i]; spaceLeft = spaceLeft - (size + spaceWidth); } } cout << endl; }
int main (int argc, const char * argv[]) { // insert code here... int choice, count = 0; char right[25] = "\0"; char left[25]; char bottom[25] = "\0"; char target[25]; choice = getWordChoice(); getWords(left, target, choice); displayStrings(left, right, bottom, count); while(strcmp(left, target) != 0){ scanf("%d", &choice); if (choice == 3){ moveCharRight(left, right); }else if (choice == 1){ moveCharLeft(left, right); }else if (choice == 2){ moveCharDown(left, bottom); }else if (choice == 4){ moveCharUp(left, bottom); } count++; displayStrings(left, right, bottom, count); } printf("You did it!\n"); system("pause"); return 0; }
string Word::toString(){ stringstream ss; ss << this->wordAsNr << " " << getWords(); return ss.str(); }
void wordLadder(char* word1, char* word2) { getWords(word1, word2); if (!isValidWord(word1) || !isValidWord(word2)) { printf("a word is not valid\n"); return; } if (!isSameLen(word1, word2)) { printf("not same length\n"); return; } char* w2_ptr = word2; char cur_word[1024], prev_word[1024]; strcpy(cur_word, word1); strcpy(prev_word, word1); while (strcmp(cur_word, word2) != 0) { add_to_wordBank(prev_word); print_wordBank(); checkWithWord(cur_word, word2); if (strcmp(cur_word, prev_word) == 0) { checkWithAlpha(cur_word); } strcpy(prev_word, cur_word); } }
main(){ int a =0,b=0; char wordSearch[R][C] ={"\0"}; char keyword[KEY][KEYLEN] ={"\0"}; srand(time(NULL)); getWords(keyword); fits(wordSearch, keyword); printf("\n"); for(a=0; a<R;a++){ for(b=0;b<C;b++){ printf("%c", wordSearch[a][b]); } printf("\n"); } printf("\n\n\n"); pause; displayPuzzle(wordSearch, keyword); pause; }
int main(int argc, char *argv[]) { readDictionary(); size_t tam; std::ifstream fileStream(argv[1]); if (!fileStream) { std::cerr << "ERROR"; exit(-1); } while (fileStream >> tam >> letters) { std::sort(letters.begin(), letters.end()); char previous = letters[0]; static std::string uniqueLetters; uniqueLetters.push_back(previous); for (char c : letters) { if (c != previous) { uniqueLetters.push_back(c); previous = c; } } std::vector<std::string> candidates = getWords(uniqueLetters, tam); std::vector<std::string> wordSquare = findWordSquare(candidates, tam); for (std::string s : wordSquare) { std::cout << s << std::endl; } std::cout << std::endl; } return 0; }
bool WordDocProcessor::setDocument(const Document &document) { mDocument = document; getWords(mTerms, mDocument); return true; }
TextEditor::TextEditor(QWidget *parent): QPlainTextEdit(parent) { connect(this, SIGNAL(textChanged()), this, SLOT(UpdateDocumentStatus())); LineCountArea = new LineNumberArea(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(UpdateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(UpdateLineNumberArea(QRect,int))); UpdateLineNumberAreaWidth(0); // connect(this, SIGNAL(cursorPositionChanged()), // this, SLOT(Highlight_Current_Line())); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(bracketValidate())); setFont(QFont("Monaco", 12)); setTabSize(4); Size = 0; Counter = 0; Start = 0; End = 0; // Setup autocomplete minCompleterLength = 1; c = new QCompleter(this); // c->setModelSorting(QCompleter::CaseInsensitivelySortedModel); c->setCompletionMode(QCompleter::PopupCompletion); c->setCaseSensitivity(Qt::CaseInsensitive); c->setWrapAround(false); c->setWidget(this); c->popup()->setObjectName("autocomplete"); completerModel = new QStringListModel(getWords(), c); c->setModel(completerModel); connect(this, SIGNAL(textChanged()), this, SLOT(updateCompleterModel())); QTextOption option = document()->defaultTextOption(); bool on = false; if (on) { option.setFlags(option.flags() | QTextOption::ShowTabsAndSpaces); } else { option.setFlags(option.flags() & ~QTextOption::ShowTabsAndSpaces); } option.setFlags(option.flags() | QTextOption::AddSpaceForLineAndParagraphSeparators); document()->setDefaultTextOption(option); setTabsAsSpaces(true); bracketMismatchFormat = currentCharFormat(); bracketMismatchFormat.setBackground(QColor(255, 223, 223)); bracketMatchFormat = currentCharFormat(); bracketMatchFormat.setBackground(QColor(158, 209, 255)); }
bool_t RLKdeterminate(char *labeli, char *labelj, RLK_Line *rlk) { const char routineName[] = "RLKZeeman"; char **words, orbit[2]; bool_t invalid; int count, multiplicity, length, Nread, Ji, Jj; /* --- Get spin and orbital quantum numbers from level labels -- -- */ words = getWords(labeli, " ", &count); if (words[0]) { length = strlen(words[count-1]); Nread = sscanf(words[count-1] + length-2, "%d%1s", &multiplicity, orbit); free(words); if (Nread != 2 || !isupper(orbit[0])) return FALSE; rlk->Li = getOrbital(orbit[0]); rlk->Si = (multiplicity - 1) / 2.0; Ji = (rlk->gi - 1.0) / 2.0; } else return FALSE; words = getWords(labelj, " ", &count); if (words[0]) { length = strlen(words[count-1]); Nread = sscanf(words[count-1] + length-2, "%d%1s", &multiplicity, orbit); free(words); if (Nread != 2 || !isupper(orbit[0])) return FALSE; rlk->Lj = getOrbital(orbit[0]); rlk->Sj = (multiplicity - 1) / 2.0; Jj = (rlk->gj - 1.0) / 2.0; } else return FALSE; /* --- For the moment only allow electronic dipole transitions -- --*/ /* if (fabs(Ji - Jj) > 1.0) return FALSE; else */ return TRUE; }
int main(int argc, char* argv[]) { char buffer[BUFSIZE]; fgets(buffer, sizeof(buffer), stdin); char words[BUFSIZE]; getWords(words, buffer); removeWords(words); printf("%s\n", words); }
bool ObjReader::readFile2(char* name) { fstream file; string line; vector<string> data; Model *mod = new ModelAdv(); scPtr->models.push_back(mod); modPtr = mod; modPtr->implicit= false; Material *mat1= new MaterialPhong; mat1->setDiffuse(ColourRGB(0.5,0.5,0.5)); mat1->setAmbientC(ColourRGB(0.2,0.2,0.2)); mat1->setSpecular(ColourRGB(0.5,0.5,0.5)); mat1->setSpecularExp(2); scPtr->materials.push_back(mat1); modPtr->material = mat1; file.open(name); while(! file.eof()) { getline (file,line); data = getWords(line); if(data.size() >0) { if(data[0] == "v") { storeVertex(data); } if(data[0] == "vt") { storeVertexUV(data); } if(data[0] == "vn") { storeVertexNormal(data); } if(data[0] == "f") { storeModel(data); } } } //invertPolygons(); clear(); file.close(); return true; }
static int think(ModeInfo * mi) { nosestruct *np = &noses[MI_SCREEN(mi)]; if (LRAND() & 1) walk(mi, FRONT); if (LRAND() & 1) { np->words = getWords(MI_SCREEN(mi), MI_NUM_SCREENS(mi)); return 1; } return 0; }
std::vector<std::string> Tokenizer::getKeys(std::string line) { auto words = getWords(line); std::vector<std::string> keys; for (auto x : words) { if (keywords.count(x) != 0) { keys.push_back(x); } } return keys; }
void Differ::computeTextHighlights(QPainterPath *highlighted1, QPainterPath *highlighted2, const PdfPage &page1, const PdfPage &page2, const int DPI) { const bool ComparingWords = comparisonMode == CompareWords; QRectF rect1; QRectF rect2; QRectF rect; if (margins) rect = pointRectForMargins(page1->pageSize()); const TextBoxList list1 = getTextBoxes(page1, rect); const TextBoxList list2 = getTextBoxes(page2, rect); TextItems items1 = ComparingWords ? getWords(list1) : getCharacters(list1); TextItems items2 = ComparingWords ? getWords(list2) : getCharacters(list2); const int ToleranceY = 10; if (debug >= DebugShowTexts) { const bool Yx = debug == DebugShowTextsAndYX; items1.debug(1, ToleranceY, ComparingWords, Yx); items2.debug(2, ToleranceY, ComparingWords, Yx); } SequenceMatcher matcher(items1.texts(), items2.texts()); RangesPair rangesPair = computeRanges(&matcher); rangesPair = invertRanges(rangesPair.first, items1.count(), rangesPair.second, items2.count()); foreach (int index, rangesPair.first) addHighlighting(&rect1, highlighted1, items1.at(index).rect, DPI); if (!rect1.isNull() && !rangesPair.first.isEmpty()) highlighted1->addRect(rect1); foreach (int index, rangesPair.second) addHighlighting(&rect2, highlighted2, items2.at(index).rect, DPI); if (!rect2.isNull() && !rangesPair.second.isEmpty()) highlighted2->addRect(rect2); }
std::vector<std::string> Tokenizer::getVars(std::string line) { auto words = getWords(line); std::vector<std::string> vars; for (auto x : words) { if (keywords.count(x) == 0) { if (!isdigit(x[0])) { vars.push_back(x); } } } return vars; }
LineBreakInfo TextEngine::computeLineBreakInfo(string text, float fontPixelSize, int linePixelWidth) { vector<string> words = getWords(text); int n = words.size(); float spacePixelWidth = getTextWidth(" ", fontPixelSize); vector<vector<int>> lineCosts = computeLineCosts(words, fontPixelSize, n, linePixelWidth, spacePixelWidth); vector<int> startIndices = computeLineBreakStartIndices(lineCosts, n); vector<int> endPositions(n+1, 0); for(int i = startIndices.size()-1; i > 0 ;i--) { int cur = i; int start = startIndices[i]; while( start != i) i--; endPositions[i] = cur; } /// compute LineBreakInfo vector<int> lineBreaks; int curLineWidth = 0, maxLineWidth = 0; int charIndex = 0; for(int i = 0; i<words.size(); i++) { charIndex += (words[i].size()+1); curLineWidth = getTextWidth(words[i], fontPixelSize); int end = endPositions[i+1]; while( (i+1) < end) { i++; charIndex += (words[i].size()+1); curLineWidth += (spacePixelWidth + getTextWidth(words[i], fontPixelSize)); } lineBreaks.push_back(charIndex-1); maxLineWidth = max(maxLineWidth, curLineWidth); } if(!lineBreaks.empty()) lineBreaks.pop_back(); return LineBreakInfo(lineBreaks.size()+1, lineBreaks, maxLineWidth); }
void storeDocsSparse(mxArray *mxStruct, char *name, DOC **docs, int ndocs, int nwords) { mxArray *fieldValue; double *sr; int i,j,k, count,*irs,*jcs, numOcc; SVECTOR *fvec; WORD *words; DOC *doc; if (docs == NULL) return; numOcc = numOccupied(docs,ndocs); printf("Using %d occupied cells\n"); fieldValue = mxCreateSparse(ndocs, nwords, numOcc,mxREAL); sr = mxGetPr(fieldValue); irs = mxGetIr(fieldValue); jcs = mxGetJc(fieldValue); count = 0; /* track # of items added */ for(i = 0; i < nwords; i++) /* rank by column/word */ { for (j = 0; j < ndocs; j++) /* handle each row */ { WORD *w = getWords(docs,j); /* get the word list for this row */ if (w == NULL) continue; /* skip if empty */ for (k = 0; w[k].wnum != 0; k++) /* iterate over each word */ { /* this row contains the word indicated by the outermost loop */ if ((w[k].wnum ) == i) { sr[count] = w[k].weight; irs[count] = j; count++; } } /* end handle word array */ } /* end handle row */ jcs[i+1] = count; jcs[i] = count; } mxSetField(mxStruct,0, name, fieldValue); }
int getWordChoice(void) { int choice; char left[25], correct[25]; int i; do{ printf("Please choose the word\n"); for(i = 0; i < MAX_WORDS; i = i +1) { getWords(left, correct, i); printf("%d %s\n", i, left); } scanf("%d", &choice); eatTheRestOfTheLine(); }while(choice < 0 || choice >= MAX_WORDS); return choice; }
std::vector<std::string> Tokenizer::getLits(std::string line) { auto words = getWords(line); std::vector<std::string> lits; bool isnum; for (auto x : words) { isnum = true; for (unsigned int i = 0; i < x.size(); i++) { if (!isdigit(x[i])) { isnum = false; } } if (isnum) { lits.push_back(x); } } return lits; }
void wordLadder(char* w1, char* w2) { char alphabet[] = "abcdefghijklmnopqrstuvwxyz"; getWords(w1, w2); if (!isValidWord(w1) || !isValidWord(w2)) { printf("a word is not valid\n"); return; } if (!isSameLen(w1, w2)) { printf("not same length\n"); return; } char* t1 = w2; char t2[1024]; strcpy(t2, w1); while (strcmp(t2, w2) != 0) { while (*t1 != '\0') { strncpy(t2, t1, 1); if (isValidWord(t2)) { } t1++; } } printf("$%s$\n$%s$\n", w1, w2); printf("%d, %d\n", isValidWord(w1), isValidWord(w2)); printf("%lu\n", strlen(w1)); }
int main ( int argc , char *argv[] ) { // let's ensure our core file can dump struct rlimit lim; lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; if ( setrlimit(RLIMIT_CORE,&lim) ) log("blaster::setrlimit: %s", mstrerror(errno) ); //g_conf.m_maxMem = 500000000; // init our table for doing zobrist hashing if ( ! hashinit() ) { log("blaster::hashinit failed" ); return 1; } // init the memory class after conf since it gets maxMem from Conf //if ( ! g_mem.init ( 20000000 ) ) { // log("blaster::Mem init failed" ); return 1; } //g_mem.m_maxMem = 200000000; // start up log file if ( ! g_log.init( "/tmp/blasterLog" ) ) { log("blaster::Log open /tmp/blasterLog failed" ); return 1; } // get dns ip from /etc/resolv.conf g_conf.m_dnsIps[0] = 0; FILE *fd = fopen ( "/etc/resolv.conf" , "r" ); if ( ! fd ) { log("blaster::fopen: /etc/resolve.conf %s", mstrerror(errno)); return 1; } char tmp[1024]; while ( fgets ( tmp , 1024 , fd ) ) { // tmp buf ptr char *p = tmp; // skip comments if ( *p == '#' ) continue; // skip nameserver name if ( ! isdigit(*p) ) while ( ! isspace ( *p ) ) p++ ; // skip spaces while ( isspace ( *p ) ) p++; // if this is not a digit, continue if ( ! isdigit(*p) ) continue; // get ip g_conf.m_dnsIps[0] = atoip ( p , gbstrlen(p) ); // done break; } fclose ( fd ); // if no dns server found, bail if ( g_conf.m_dnsIps[0] == 0 ) { log("blaster:: no dns ip found in /etc/resolv.conf");return 1;} // hack # of dns servers g_conf.m_numDns = 1; g_conf.m_dnsPorts[0] = 53; //g_conf.m_dnsIps [0] = atoip ( "192.168.0.1", 11 ); //g_conf.m_dnsClientPort = 9909; g_conf.m_dnsMaxCacheMem = 1024*10; // hack http server port to -1 (none) //g_conf.m_httpPort = 0; g_conf.m_httpMaxSockets = 200; //g_conf.m_httpMaxReadBufSize = 102*1024*1024; g_conf.m_httpMaxSendBufSize = 16*1024; //g_conf.m_httpMaxDownloadSockets = 200; if ( argc != 4 && argc != 5 && argc !=6 ) { printUsage: fprintf(stderr,"USAGE: blaster [fileOfUrls | -r<num random words><server>] [maxNumThreads] [wait in ms] " "<lines to skip> <string to append>\n"); fprintf(stderr,"USAGE: examples:\n"); fprintf(stderr,"USAGE: ./blaster queries.fromlog 10 1\n"); fprintf(stderr,"USAGE: ./blaster -r3http://www.gigablast.com/index.php?q= 1 100\n"); return 1; } fprintf(stderr,"Logging to /tmp/blasterLog\n"); // init the loop if ( ! g_loop.init() ) { log("blaster::Loop init failed" ); return 1; } // . then dns client // . server should listen to a socket and register with g_loop if ( ! g_dns.init(6000) ) { log("blaster::Dns client init failed" ); return 1; } // . then webserver // . server should listen to a socket and register with g_loop for(int32_t i = 0; i < 50; i++) { if ( ! g_httpServer.init( 8333 + i, 9334+i ) ) { log("blaster::HttpServer init failed" ); //return 1; } else break; } // set File class char *fname = argv[1]; int32_t fnameLen = gbstrlen(fname); int32_t fileSize = 0; int32_t bufSize = 0; char *buf = NULL; int32_t n = 0; //should we generate random queries? if(fnameLen > 2 && fname[0] == '-' && fname[1] == 'r') { char *p = fname + 2; s_numRandWords = atoi( p ); while(is_digit(*p)) p++; getWords(); if(*p == '\0') goto printUsage; s_server = p; log("blaster server is %s", s_server); // char x[1024]; // while(1) { // int32_t l = getRandomWords(x, x + 1024, s_numRandWords); // *(x + l) = '\0'; // log("blaster: %s", x); // } // exit(1); } else { //it is a real file File f; f.set ( fname ); // open file if ( ! f.open ( O_RDONLY ) ) { log("blaster::open: %s %s",fname,mstrerror(g_errno)); return 1; } // get file size fileSize = f.getFileSize() ; // store a \0 at the end bufSize = fileSize + 1; // make buffer to hold all buf = (char *) mmalloc ( bufSize , "blaster" ); if ( ! buf) {log("blaster::mmalloc: %s",mstrerror(errno));return 1;} //char *bufEnd = buf + bufSize; // set s_p s_p = buf; s_pend = buf + bufSize - 1; // read em all in if ( ! f.read ( buf , fileSize , 0 ) ) { log("blaster::read: %s %s",fname,mstrerror(g_errno));return 1;} // change \n to \0 //char *p = buf; for ( int32_t i = 0 ; i < bufSize ; i++ ) { if ( buf[i] != '\n' ) continue; buf[i] = '\0'; n++; } f.close(); } // log a msg log(LOG_INIT,"blaster: read %"INT32" urls into memory", n ); int32_t linesToSkip = 0; if ( argc >= 5 ) { linesToSkip = atoi ( argv[4] ); log (LOG_INIT,"blaster: skipping %"INT32" urls",linesToSkip); } for ( int32_t i = 0; i < linesToSkip && s_p < s_pend; i++ ) s_p += gbstrlen(s_p) + 1; if ( argc == 6 ) { int32_t len = gbstrlen ( argv[5] ); if ( len > 512 ) len = 512; strncpy ( s_append , argv[5] , gbstrlen (argv[5]) ); } else s_append[0] = '\0'; // get min time bewteen each spider in milliseconds s_wait = atoi( argv[3] ); // # of threads s_maxNumThreads = 1; s_maxNumThreads = atoi ( argv[2] ); s_portSwitch = 0; //if ( argc == 4 ) s_portSwitch = 1; //else s_portSwitch = 0; // start our spider loop //startSpidering( ); // wakeup wrapper every X ms g_loop.registerSleepCallback ( s_wait , NULL , sleepWrapper ); //msg10.addUrls ( uu , gbstrlen(uu)+1, NULL,0,time(0),4,true,NULL,NULL); // . now start g_loops main interrupt handling loop // . it should block forever // . when it gets a signal it dispatches to a server or db to handle it if ( ! g_loop.runLoop() ) { log("blaster::runLoop failed" ); return 1; } // dummy return (0-->normal exit status for the shell) return 0; }
void TextEditor::updateCompleterModel() { completerModel->setStringList(getWords()); }
void TextEngine::lineWrappedDynamicAlgo1(string text) { vector<string> words = getWords(text); int n = words.size(); int lineWidth = 6; int l[n]; for(int i=0; i<words.size(); i++) l[i] = words[i].size(); int INF = 100; // For simplicity, 1 extra space is used in all below arrays // extras[i][j] will have number of extra spaces if words from i // to j are put in a single line int extras[n+1][n+1]; int lc[n+1][n+1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { extras[i][j] = INF; lc[i][j] = INF; } } // lc[i][j] will have cost of a line which has words from // i to j // c[i] will have total cost of optimal arrangement of words // from 1 to i int c[n+1]; // p[] is used to print the solution. int p[n+1]; int i, j; // calculate extra spaces in a single line. The value extra[i][j] // indicates extra spaces if words from word number i to j are // placed in a single line // the extra -1 is for the "space" for (int y = 1; y <= n; y++) { extras[y][y] = lineWidth - l[y-1]; for (int x = y+1; x <= n; x++) extras[y][x] = extras[y][x-1] - l[x-1] - 1; } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) cout << extras[i][j] << " "; cout << endl; } cout << endl << endl; // Calculate line cost corresponding to the above calculated extra // spaces. The value lc[i][j] indicates cost of putting words from // word number i to j in a single line for (int y = 1; y <= n; y++) { for (int x = y; x <= n; x++) { if (extras[y][x] < 0) lc[y][x] = INF; else if (x == n && extras[y][x] >= 0) lc[y][x] = 0; else lc[y][x] = extras[y][x]*extras[y][x]; } } for (int y = 0; y <= n; y++) { for (int x = 0; x <= n; x++) cout << lc[y][x] << " "; cout << endl; } // Calculate minimum cost and find minimum cost arrangement. // The value c[j] indicates optimized cost to arrange words // from word number 1 to j. c[0] = 0; for (j = 1; j <= n; j++) { c[j] = INF; for (i = 1; i <= j; i++) { // if (c[i-1] != INF && lc[i][j] != INF && (c[i-1] + lc[i][j] < c[j])) if (lc[i][j] != INF && (c[i-1] + lc[i][j] < c[j])) { c[j] = c[i-1] + lc[i][j]; p[j] = i; } } } for (int y = 0; y <= n; y++) { cout << p[y] << " "; } cout << endl; // printSolution(p, n); }
bool compareBlocks(HWND view1, HWND view2, const UserSettings& settings, diff_info& blockDiff1, diff_info& blockDiff2) { diff_info* pBlockDiff1 = &blockDiff1; diff_info* pBlockDiff2 = &blockDiff2; if (blockDiff1.len > blockDiff2.len) { std::swap(view1, view2); std::swap(pBlockDiff1, pBlockDiff2); } chunk_info chunk1(pBlockDiff1->off, pBlockDiff1->len); chunk_info chunk2(pBlockDiff2->off, pBlockDiff2->len); getWords(view1, settings, chunk1); getWords(view2, settings, chunk2); // Compare the two chunks const std::vector<diff_info> chunkDiff = DiffCalc<Word>(chunk1.words, chunk2.words)(); const int chunkDiffSize = static_cast<int>(chunkDiff.size()); if (chunkDiffSize == 0) return false; std::vector<std::vector<int>> linesConvergence(chunk1.lineCount, std::vector<int>(chunk2.lineCount, 0)); // Use the MATCH results to synchronize line numbers (count the match length of each line) int wordOffset = 0; for (int i = 0; i < chunkDiffSize; ++i) { const diff_info& cd = chunkDiff[i]; if (cd.type == diff_type::DIFF_DELETE) { wordOffset -= cd.len; } else if (cd.type == diff_type::DIFF_INSERT) { wordOffset += cd.len; } else // diff_type::DIFF_MATCH { for (int wordIdx = cd.off; wordIdx < (cd.off + cd.len); ++wordIdx) { const Word& word1 = chunk1.words[wordIdx]; const Word& word2 = chunk2.words[wordIdx + wordOffset]; if (word1.type != charType::SPACECHAR) linesConvergence[word1.line][word2.line] += word1.length; } } } // Select the line with the most matches (as length) for (int line1 = 0; line1 < chunk1.lineCount; ++line1) { if (pBlockDiff1->isMoved(line1)) continue; int maxConvergence = 0; int line2 = 0; for (int i = 0; i < chunk2.lineCount; ++i) { if (!pBlockDiff2->isMoved(i) && linesConvergence[line1][i] > maxConvergence) { line2 = i; maxConvergence = linesConvergence[line1][i]; } } // Make sure that the line is matched and the other line is not already matched if (maxConvergence == 0 || chunk2.lineMappings[line2] != -1) continue; int line1Size = 0; for (int i = chunk1.lineStartWordIdx[line1]; i < chunk1.lineEndWordIdx[line1]; ++i) { const Word& word1 = chunk1.words[i]; if (word1.type != charType::SPACECHAR) line1Size += word1.length; } // Is enough portion of the line matched to be significant? if (line1Size && maxConvergence > (line1Size / 3)) { chunk1.lineMappings[line1] = line2; chunk2.lineMappings[line2] = line1; } } compareLines(*pBlockDiff1, *pBlockDiff2, chunk1, chunk2); return true; }
void init_nose(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); XGCValues gcv; nosestruct *np; if (noses == NULL) { if ((noses = (nosestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (nosestruct))) == NULL) return; } np = &noses[MI_SCREEN(mi)]; np->width = MI_WIDTH(mi) + 2; np->height = MI_HEIGHT(mi) + 2; np->tinymode = (np->width + np->height < 4 * PIXMAP_SIZE); np->xs = PIXMAP_SIZE; np->ys = PIXMAP_SIZE; MI_CLEARWINDOW(mi); XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); /* do not want any exposure events from XCopyPlane */ XSetGraphicsExposures(display, gc, False); if (mode_font == None) { #ifdef USE_MB mode_font = getFontSet(display); #else mode_font = getFont(display); #endif } if (np->noseGC[0] == None) if (!pickClothes(mi)) { free_nose(display, np); return; } np->words = getWords(MI_SCREEN(mi), MI_NUM_SCREENS(mi)); if (np->text_fg_gc == None && mode_font != None) { #ifndef USE_MB gcv.font = mode_font->fid; #endif gcv.graphics_exposures = False; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((np->text_fg_gc = XCreateGC(display, window, #ifndef USE_MB GCFont | #endif GCForeground | GCBackground | GCGraphicsExposures, &gcv)) == None) { free_nose(display, np); return; } gcv.foreground = MI_BLACK_PIXEL(mi); gcv.background = MI_WHITE_PIXEL(mi); if ((np->text_bg_gc = XCreateGC(display, window, #ifndef USE_MB GCFont | #endif GCForeground | GCBackground | GCGraphicsExposures, &gcv)) == None) { free_nose(display, np); return; } } np->up = 1; if (np->tinymode) { int pos = NRAND(PIXMAPS); np->x = 0; np->y = 0; XCopyArea(display, np->position[pos], window, np->noseGC[pos], 0, 0, PIXMAP_SIZE, PIXMAP_SIZE, (np->width - PIXMAP_SIZE) / 2, (np->height - PIXMAP_SIZE) / 2); np->state = FREEZE; } else { np->x = np->width / 2; np->y = np->height / 2; np->state = MOVE; } XFlush(display); }
void quantumNumbers(Atom *atom) { register int i; char multiplet[ATOM_LABEL_WIDTH + 1], *ptr, **words; int ic, count; double Z; /* --- Determine the principal quantum number n, the orbital quantum number l, and the effective quantum number n_eff for all levels from the atomic data labels. -- -------------- */ n = (int *) malloc((atom->Nlevel - 1) * sizeof(int)); l = (int *) malloc((atom->Nlevel - 1) * sizeof(int)); n_eff = (double*) malloc((atom->Nlevel - 1) * sizeof(double)); for (i = 0; i < atom->Nlevel-1; i++) { /* --- The principal and orbital quantum numbers n and l -- ----- */ strcpy(multiplet, atom->label[i]); ptr = multiplet + (strlen(multiplet) - 1); while ((*ptr != 'E') && (*ptr != 'O') && (ptr > multiplet)) ptr--; if (ptr > multiplet) *(ptr + 1) = '\0'; else { sprintf(messageStr, "Unable to determine whether level is even or odd", atom->label[i]); Error(ERROR_LEVEL_2, "quantumNumbers", messageStr); } words = getWords(multiplet, " ", &count); n[i] = (int) (words[count-2][0] - '0'); switch (words[count-1][1]) { case 'S': l[i] = 0; break; case 'P': l[i] = 1; break; case 'D': l[i] = 2; break; case 'F': l[i] = 3; break; case 'G': l[i] = 4; break; case 'H': l[i] = 5; break; case 'I': l[i] = 6; break; default: l[i] = n[i] - 1; } /* --- The effective quantum number n_eff -- -------------- */ ic = i + 1; while ((atom->stage[ic] < atom->stage[i]+1) && (ic < atom->Nlevel)) ic++; if (atom->stage[ic] == atom->stage[i]) { sprintf(messageStr, "Found no overlying continuum for level %s", atom->label[i]); Error(ERROR_LEVEL_2, "quantumNumbers", messageStr); } else { Z = (double) (atom->stage[i] + 1); n_eff[i] = Z * sqrt(E_Rydberg / (atom->E[ic] - atom->E[i])); } free(words); } /* --- Print quantum numbers to standard error -- -------------- */ fprintf(stderr, "\n label n_eff n l\n"); fprintf(stderr, "-----------------------------------------\n"); for (i = 0; i < atom->Nlevel-1; i++) { fprintf(stderr, "'%20s' %f %2d %2d\n", atom->label[i], n_eff[i], n[i], l[i]); } fprintf(stderr, "\n"); }
bool compareWords(diff_edit& e1, diff_edit& e2, const DocLines_t& doc1, const DocLines_t& doc2, bool IgnoreSpaces) { unsigned int i, j; chunk_info chunk1(e1.off, e1.len); chunk_info chunk2(e2.off, e2.len); getWords(doc1, chunk1, IgnoreSpaces); getWords(doc2, chunk2, IgnoreSpaces); // Compare the two chunks std::vector<diff_edit> diff = DiffCalc<Word>(chunk1.words, chunk2.words)(); chunk1.changes.reset(new varray<diff_change>); chunk2.changes.reset(new varray<diff_change>); std::vector<std::vector<int>> lineMappings1(chunk1.lineCount); for (i = 0; i < chunk1.lineCount; ++i) lineMappings1[i].resize(chunk2.lineCount, 0); // Use the MATCH results to synchronize line numbers // count how many are on each line, then select the line with the most matches const std::size_t diffSize = diff.size(); int offset = 0; for (i = 0; i < diffSize; ++i) { diff_edit& e = diff[i]; if (e.op == DIFF_DELETE) { offset -= e.len; } else if (e.op == DIFF_INSERT) { offset += e.len; } else { for (unsigned int index = e.off; index < (e.off + e.len); ++index) { Word *word1 = &chunk1.words[index]; Word *word2 = &chunk2.words[index + offset]; if (word1->type != SPACECHAR && word1->type != EOLCHAR) { int line1a = word1->line; int line2a = word2->line; lineMappings1[line1a][line2a] += word1->length; } } } } // go through each line, and select the line with the highest strength for (i = 0; i < chunk1.lineCount; ++i) { int line = -1; int max = 0; for (j = 0; j <chunk2.lineCount; ++j) { if (lineMappings1[i][j] > max && (e2.moves.empty() || e2.moves[j] == -1)) { line = j; max = lineMappings1[i][j]; } } // make sure that the line isn't already matched to another line, // and that enough of the line is matched to be significant const int size = doc1[e1.off + i].size(); if (line != -1 && chunk2.lineMappings[line] == -1 && max > (size / 3) && (e1.moves.empty() || e1.moves[i] == -1)) { chunk1.lineMappings[i] = line; chunk2.lineMappings[line] = i; } } // find all the differences between the lines chunk1.changeCount = 0; chunk2.changeCount = 0; for (i = 0; i < diffSize; ++i) { diff_edit& e = diff[i]; if (e.op == DIFF_DELETE) { // Differences for Doc 1 checkWords(e, chunk1, chunk2); } else if (e.op == DIFF_INSERT) { // Differences for Doc2 checkWords(e, chunk2, chunk1); } } e1.changeCount = chunk1.changeCount; e1.changes = chunk1.changes; e2.changeCount = chunk2.changeCount; e2.changes = chunk2.changes; return (chunk1.changeCount + chunk2.changeCount > 0); }
void TextEngine::lineWrappedDynamicAlgo(string text) { vector<string> words = getWords(text); int n = words.size(); int lineWidth = 20; /// this is 2D cost map (really is diagnol) vector<vector<int>> lineCosts(n+1, vector<int>(n+1, INT_MAX)); for(int y = 1; y <= n; y++) { int cost = lineWidth - words[y-1].size(); lineCosts[y][y] = cost * cost * cost; for(int x = y+1; x <= n; x++) { cost -= (words[x-1].size() + 1); if(cost < 0) break; else lineCosts[y][x] = cost * cost * cost; } } lineCosts[n][n] = 0; Utility::debug<int>("lineCosts", lineCosts); vector<int> startPositions(n+1, 0); vector<int> minCosts(n+1, 0); for(int y = 1; y <= n; y++) { minCosts[y] = INT_MAX; for(int x = 1; x <= y; x++) { /// if from a previous word to a current word /// the cost is INT_MAX, we skip if(lineCosts[x][y] == INT_MAX) continue; if(minCosts[x-1] + lineCosts[x][y] < minCosts[y]) { minCosts[y] = minCosts[x-1] + lineCosts[x][y]; startPositions[y] = x; } } } vector<int> endPositions(n+1, 0); for(int i = startPositions.size()-1; i > 0 ;i--) { int cur = i; int start = startPositions[i]; while( start != i) i--; endPositions[i] = cur; } Utility::debug<int>("endPositions", endPositions); for(int i = 0; i<words.size(); i++) { cout << words[i]; int end = endPositions[i+1]; while( (i + 1)<end) { i++; cout << " " << words[i] ; } cout << endl; } }
void Anagramer::run(void){ // File open failed return message in openDicitionary if( openDictionary() ) return; getWords(); return; }
void init_marquee(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); marqueestruct *mp; XGCValues gcv; int i; if (marquees == NULL) { if ((marquees = (marqueestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (marqueestruct))) == NULL) return; } mp = &marquees[MI_SCREEN(mi)]; mp->win_width = MI_WIDTH(mi); mp->win_height = MI_HEIGHT(mi); if (MI_NPIXELS(mi) > 2) mp->color = NRAND(MI_NPIXELS(mi)); mp->time = 0; mp->t = 0; mp->nonblanks = 0; mp->x = 0; MI_CLEARWINDOW(mi); if (mode_font == None) mode_font = getFont(display); if (mp->gc == NULL && mode_font != None) { gcv.font = mode_font->fid; gcv.graphics_exposures = False; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((mp->gc = XCreateGC(display, MI_WINDOW(mi), GCForeground | GCBackground | GCGraphicsExposures | GCFont, &gcv)) == None) { return; } mp->ascent = mode_font->ascent; mp->height = font_height(mode_font); for (i = 0; i < 256; i++) if ((i >= (int) mode_font->min_char_or_byte2) && (i <= (int) mode_font->max_char_or_byte2)) char_width[i] = font_width(mode_font, (char) i); else char_width[i] = font_width(mode_font, (char) mode_font->default_char); } else if (mode_font == None) { for (i = 0; i < 256; i++) char_width[i] = 8; } mp->words = fixup_back(getWords(MI_SCREEN(mi), MI_NUM_SCREENS(mi))); mp->y = 0; if (isRibbon()) { mp->x = mp->win_width; if (mp->win_height > font_height(mode_font)) mp->y += NRAND(mp->win_height - font_height(mode_font)); else if (mp->win_height < font_height(mode_font)) mp->y -= NRAND(font_height(mode_font) - mp->win_height); } else { int text_ht = text_height(mp->words); int text_font_wid = text_font_width(mp->words); if (mp->win_height > text_ht * font_height(mode_font)) mp->y = NRAND(mp->win_height - text_ht * font_height(mode_font)); if (mp->y < 0) mp->y = 0; mp->x = 0; if (mp->win_width > text_font_wid) mp->x += NRAND(mp->win_width - text_font_wid); /* else if (mp->win_width < text_font_wid) mp->x -= NRAND(text_font_wid - mp->win_width); */ mp->startx = mp->x; } }