// generate a ground substitution for a clause int groundSubstitutions(const Clause &clause, Substitutions &subs) { // clear substitutions subs.clear(); // get a string representation String clstring = (String)clause; // list of variables Map<String, String> variables; // find variables in clause StringTokens clst(clstring, " \t"); for ( ; !clst.done(); clst++) { if ((clst()(0,2) == String("_V")) || (clst()(0,3) == String("_RV"))) { String variable(clst()); if (!variables.isInMap(variable)) { variables[variable] = uniqueName("_CONST"); } } } // generate substitutions now MapIterator<String, String> varsIter(variables); for ( ; !varsIter.done(); varsIter++) { Substitution sub(Terms(varsIter.data()), varsIter.key()); subs = subs*sub; } // all done return(OK); }
int main(void) { clst("lower123", "lowerabc", '\0'); clst("higher234", "higher123", '\0'); clst("equal", "equal", '\0'); clst("equal", "equallong", '\0'); clst("equallong", "equal", '\0'); clst("lower1", "lower2", 'w'); // will compare equal return 0; }
/** 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