void build_dict() { int edges_count = 0; for (auto& l : words) for (auto& r : words) { if (l == r) continue; auto& lw = dict[l->word_id]; auto& rw = dict[r->word_id]; if (is_similar(lw, rw)) { edges_count++; l->similar.insert(r); } } std::cout << "edges count: " << edges_count << std::endl; //for (auto& w : words) //{ // std::cout << "item: " << w->word << std::endl; // for (auto& s : w->similar) // std::cout << "\t -> " << s->word << std::endl; //} }
// A value of type T1 can be converted to a type T2 if they are // similar and... something about the cv-signature. // // Note that the top-level cv-qualifiers can be removed by this // conversion since it applies to values (i.e., copies). Expr& convert_qualifier(Expr& e, Type& t) { if (is_similar(e.type(), t)) { Qualifier_list sa = get_qualification_signature(e.type()); Qualifier_list sb = get_qualification_signature(t); if (can_convert_signature(sa, sb)) return *new Qualification_conv(t, e); } return e; }
void mysql__add_row_to_model(MYSQL_ROW row, unsigned long* lengths) { GdkPixbuf* iconbuf = NULL; char length[64]; char keywords[256]; char name[256]; float samplerate; char samplerate_s[32]; unsigned channels, colour; gboolean online = FALSE; GtkTreeIter iter; //db__iter_to_result(result); //deserialise the pixbuf field: GdkPixdata pixdata; GdkPixbuf* pixbuf = NULL; if(row[MYSQL_PIXBUF]){ if(gdk_pixdata_deserialize(&pixdata, lengths[MYSQL_PIXBUF], (guint8*)row[MYSQL_PIXBUF], NULL)){ pixbuf = gdk_pixbuf_from_pixdata(&pixdata, TRUE, NULL); } } format_time(length, row[MYSQL_LENGTH]); if(row[MYSQL_KEYWORDS]) snprintf(keywords, 256, "%s", row[MYSQL_KEYWORDS]); else keywords[0] = 0; if(!row[MYSQL_SAMPLERATE]) samplerate = 0; else samplerate = atoi(row[MYSQL_SAMPLERATE]); samplerate_format(samplerate_s, samplerate); if(row[7]==NULL) channels = 0; else channels = atoi(row[7]); if(row[MYSQL_ONLINE]==NULL) online = 0; else online = atoi(row[MYSQL_ONLINE]); if(row[MYSQL_COLOUR]==NULL) colour = 0; else colour = atoi(row[MYSQL_COLOUR]); strncpy(name, row[MYSQL_NAME], 255); //TODO markup should be set in cellrenderer, not model! #if 0 if(GTK_WIDGET_REALIZED(app.view)){ //check colours dont clash: long c_num = strtol(app.config.colour[colour], NULL, 16); dbg(2, "rowcolour=%s", app.config.colour[colour]); GdkColor row_colour; color_rgba_to_gdk(&row_colour, c_num << 8); if(is_similar(&row_colour, &app.fg_colour, 0x60)){ snprintf(name, 255, "%s%s%s", "<span foreground=\"blue\">", row[MYSQL_NAME], "</span>"); } } #endif #ifdef USE_AYYI //is the file loaded in the current Ayyi song? if(ayyi.got_song){ gchar* fullpath = g_build_filename(row[MYSQL_DIR], name, NULL); if(pool__file_exists(fullpath)) dbg(0, "exists"); else dbg(0, "doesnt exist"); g_free(fullpath); } #endif //icon (only shown if the sound file is currently available): if(online){ MIME_type* mime_type = mime_type_lookup(row[MYSQL_MIMETYPE]); type_to_icon(mime_type); if ( ! mime_type->image ) dbg(0, "no icon."); iconbuf = mime_type->image->sm_pixbuf; } else iconbuf = NULL; #if 0 //strip the homedir from the dir string: char* path = strstr(row[MYSQL_DIR], g_get_home_dir()); path = path ? path + strlen(g_get_home_dir()) + 1 : row[MYSQL_DIR]; #endif gtk_list_store_append(app.store, &iter); gtk_list_store_set(app.store, &iter, COL_ICON, iconbuf, #ifdef USE_AYYI COL_AYYI_ICON, ayyi_icon, #endif COL_IDX, atoi(row[MYSQL_ID]), COL_NAME, name, COL_FNAME, row[MYSQL_DIR], COL_KEYWORDS, keywords, COL_OVERVIEW, pixbuf, COL_LENGTH, length, COL_SAMPLERATE, samplerate_s, COL_CHANNELS, channels, COL_MIMETYPE, row[MYSQL_MIMETYPE], COL_NOTES, row[MYSQL_NOTES], COL_COLOUR, colour, -1); if(pixbuf) g_object_unref(pixbuf); #if 0 if(app.no_gui){ printf(" %s\n", name); } #endif }
/** Function make_cluster() * * Given a list of fragments denoted by seeds, make pairwise comparison * and clustering conforming max_mismatch criteria * * Output: clusters in 2d vector format, where each row of the vector * stores the clustered fragment IDs. */ void make_cluster (iivec_t& clusters, const ii64vec_t& list_seeds, const ivec_t& init_cluster, int max_mismatch, const ivec_t& uf_clst) { if (list_seeds.size() == 0) { abording ("DuplRm.cpp -- make_cluster(): SC failed"); } //--------- union find: (1) initialize the cluster --------- int sz = init_cluster.size(); bvec_t visited (sz, false); ivec_t clst (sz); for (int i = 0; i < sz; ++ i) clst[i] = i; //--------- pairwise comparison --------- for (int i = 0; i < sz - 1; ++ i) { if (visited[i]) continue; // to speed up int idx_i = init_cluster[i]; for (int j = i + 1; j < sz; ++ j) { if (visited[j]) continue; // to speed up, avoid of comparison // if this is already clustered int idx_j = init_cluster[j]; // check global uf structure according to fragID int root_uf_i = uf_clsfind ((int) list_seeds[idx_i].back(), uf_clst), root_uf_j = uf_clsfind ((int) list_seeds[idx_j].back(), uf_clst); if (root_uf_i != root_uf_j) { int root_i = uf_find (i, clst), root_j = uf_find (j, clst); if (root_i != root_j) { if (is_similar (list_seeds[idx_i], list_seeds[idx_j], max_mismatch)) { clst[root_j] = root_i; visited[j] = true; } } } // if } // for (int j = i + 1 } // for (int i = 0 //----- generate final cluster { clusterID --> fragment IDs } ------ std::map<int, ivec_t> clstID_fragIDs; std::map<int, ivec_t>::iterator it; for (int i = 0; i < sz; ++ i) { int idx_i = init_cluster[i]; int fragID = list_seeds[idx_i].back(); int root_i = uf_clsfind (i, clst); it = clstID_fragIDs.find (root_i); if (it != clstID_fragIDs.end()) it->second.push_back(fragID); else clstID_fragIDs[root_i] = ivec_t (1, fragID); } // for (int i = 0 // go through the map and produce clusters in sorted vector format for (it = clstID_fragIDs.begin(); it != clstID_fragIDs.end(); ++ it) { if (it->second.size() > 1) { std::sort (it->second.begin(), it->second.end()); clusters.push_back(it->second); } } // for (it } // make_cluster
int main() { FILE *fp, *fpd, *fpo; char c; char buffer[MAXS]; char outbuffer[MAXS2] = ""; char dictionary[DICS]; char* token; double flag; int isreplaced=0; int numcount=1; /* Open file for both reading and writing */ fprintf(stderr, "Opening files ...\n"); fp = fopen("input.txt", "r+"); fpd = fopen("dictionary.txt", "r+"); fpo = fopen("output.txt", "w+"); /* Write data to the file */ //fwrite(c, strlen(c) + 1, 1, fp); /* Seek to the beginning of the file */ //fseek(fp, SEEK_SET, 0); /* Read and display data */ //fread(buffer, sizeof(buffer)+1, 1, fp); fgets(buffer, sizeof(buffer), fp); remove_newline_ch(buffer); printf("Input paragraph;\n%s\n", buffer); /* while(!feof(fpd)) { fgets(dictionary, sizeof(dictionary), fpd); printf("%s\n", dictionary); }*/ token = strtok(buffer, " "); while (token) { remove_punct_and_make_lower_case(token); // printf("\n\ntoken: %s, lenght: %d\n\n\n", token, strlen(token)); // checking for numbers if(is_valid_int(token)){ printf("\nNumber %d: %s",numcount, token); numcount++; convert_to_words(token); strcat(outbuffer, token); strcat(outbuffer, " "); } else { if(strlen(token) >= 4){ // checking for spelling fseek(fpd, SEEK_SET, 0); isreplaced = 0; while(!feof(fpd)) { flag = 0.0; fgets(dictionary, sizeof(dictionary), fpd); remove_punct_and_make_lower_case(dictionary); remove_newline_ch(dictionary); // printf("%s\n", dictionary); if(strlen(token) >= 4){ flag = is_similar(token, dictionary); /*{ strcat(outbuffer, token); strcat(outbuffer, " "); }if(flag == 0.0){ strcat(outbuffer, token); strcat(outbuffer, " "); } else */ if(isreplaced != 1){ if(flag > 0.6){ strcat(outbuffer, dictionary); strcat(outbuffer, " "); isreplaced = 1; } else if(flag == 1.0){ strcat(outbuffer, token); strcat(outbuffer, " "); isreplaced = 1; } } } } if(isreplaced == 0){ strcat(outbuffer, token); strcat(outbuffer, " "); } } else { strcat(outbuffer, token); strcat(outbuffer, " "); } } token = strtok(NULL, " "); } fwrite(outbuffer, strlen(outbuffer) + 1, 1, fpo); fclose(fp); fclose(fpd); fclose(fpo); return(0); }
bool operator()(Array_type const& a) { return is_similar(a, cast<Array_type>(b)); }
bool operator()(Sequence_type const& a) { return is_similar(a, cast<Sequence_type>(b)); }
bool operator()(Pointer_type const& a) { return is_similar(a, cast<Pointer_type>(b)); }
bool is_similar(Sequence_type const& a, Sequence_type const& b) { return is_similar(a.type(), b.type()); }
bool is_similar(Pointer_type const& a, Pointer_type const& b) { return is_similar(a.type(), b.type()); }
bool operator()(Tuple_type const& a) { return is_similar(a, cast<Tuple_type>(b)); }
// FIXME: Arrays are only similar when they have the same extent. bool is_similar(Array_type const& a, Array_type const& b) { return is_similar(a.element_type(), b.element_type()); }