void MorphemeDisambiguatorClass::test(const string &testFilename) const { ifstream ifs(testFilename); size_t correctCount = 0; size_t allCount = 0; while (true) { vector<string> sequence = Utility::readSequence(ifs); if (!ifs) { break; } vector<string> sentence; vector<vector<string>> correctResultList; splitSentenceAndResult(sequence, &sentence, &correctResultList); auto inferredResultList = tag(sentence); assert(inferredResultList.size() == correctResultList.size()); for (size_t i = 0; i < inferredResultList.size(); ++i) { if (inferredResultList[i].size() == correctResultList[i].size() + 2 && equal(inferredResultList[i].begin() + 2, inferredResultList[i].end(), correctResultList[i].begin())) { ++correctCount; } ++allCount; } } ifs.close(); printf("Accuracy: %d / %d (%1.4f)\n", correctCount, allCount, correctCount / (double)allCount); }
bool sensor_plugin_loader::get_paths_from_dir(const string &dir_path, vector<string> &hal_paths, vector<string> &sensor_paths) { const string PLUGIN_POSTFIX = ".so"; const string HAL_POSTFIX = "_hal.so"; DIR *dir = NULL; struct dirent *dir_entry = NULL; dir = opendir(dir_path.c_str()); if (!dir) { ERR("Failed to open dir: %s", dir_path.c_str()); return false; } string name; while (dir_entry = readdir(dir)) { name = string(dir_entry->d_name); if (equal(PLUGIN_POSTFIX.rbegin(), PLUGIN_POSTFIX.rend(), name.rbegin())) { if (equal(HAL_POSTFIX.rbegin(), HAL_POSTFIX.rend(), name.rbegin())) hal_paths.push_back(dir_path + "/" + name); else sensor_paths.push_back(dir_path + "/" + name); } } closedir(dir); return true; }
int main(int argc, char* argv[]) { // 3 // 2 5 // 1 4 6 unique_ptr<BinaryTreeNode<int>> root = unique_ptr<BinaryTreeNode<int>>( new BinaryTreeNode<int>{3, nullptr, nullptr}); root->left = unique_ptr<BinaryTreeNode<int>>( new BinaryTreeNode<int>{2, nullptr, nullptr}); root->left->left = unique_ptr<BinaryTreeNode<int>>( new BinaryTreeNode<int>{1, nullptr, nullptr}); root->right = unique_ptr<BinaryTreeNode<int>>( new BinaryTreeNode<int>{5, nullptr, nullptr}); root->right->left = unique_ptr<BinaryTreeNode<int>>( new BinaryTreeNode<int>{4, nullptr, nullptr}); root->right->right = unique_ptr<BinaryTreeNode<int>>( new BinaryTreeNode<int>{6, nullptr, nullptr}); // should output 3 // 2 5 // 1 4 6 PrintBinaryTreeDepthOrder(root); vector<vector<int>> golden_res = {{3}, {2, 5}, {1, 4, 6}}; assert(golden_res.size() == results.size() && equal(golden_res.begin(), golden_res.end(), results.begin())); return 0; }
static bool apply(alps::numeric::matrix<T,MemoryBlock> const& m) { typedef typename alps::numeric::matrix<T,MemoryBlock>::const_col_element_iterator col_iterator; using alps::hdf5::get_extent; using alps::hdf5::is_vectorizable; using std::equal; if(boost::is_scalar<typename alps::numeric::matrix<T,MemoryBlock>::value_type>::value || m.empty()) return true; else { std::vector<std::size_t> first_element_extent(get_extent(m(0,0))); for(std::size_t j=0; j < num_cols(m); ++j) { for(std::pair<col_iterator,col_iterator> r = col(m,j); r.first != r.second; ++r.first) { if(!is_vectorizable(*r.first)) { return false; } else { std::vector<std::size_t> element_extent(get_extent(*r.first)); if( first_element_extent.size() != element_extent.size() || !equal(first_element_extent.begin(), first_element_extent.end(), element_extent.begin()) ) return false; } } } return true; } }
static std::vector<std::size_t> apply(alps::numeric::matrix<T,MemoryBlock> const& m) { using alps::hdf5::get_extent; using std::copy; using std::equal; typedef typename alps::numeric::matrix<T,MemoryBlock>::const_col_element_iterator col_iterator; std::vector<std::size_t> extent(2); extent[0] = num_cols(m); extent[1] = num_rows(m); if(num_rows(m) && num_cols(m) ) { // Get the extent of the first element std::vector<std::size_t> first(get_extent(m(0,0))); // We require that all elements of the matrix have the same size // These loops will check that. for(std::size_t j=0; j < num_cols(m); ++j) for(std::pair<col_iterator,col_iterator> r = col(m,j); r.first != r.second; ++r.first) { std::vector<std::size_t> size(get_extent(*r.first)); if( first.size() != size.size() || !equal(first.begin(),first.end(), size.begin()) ) throw archive_error("Matrix elements have different sizes." + ALPS_STACKTRACE); } copy(first.begin(),first.end(), std::back_inserter(extent)); } return extent; }
END_TEST START_TEST(should_overwrite_destination_file) { Process_dir_fixture f; string src(f.get_path() + "/src"); create_emptyfile(src); vector<char> content(dummy_content()); write_to_file(src, content); vector<char> dest_content(content); dest_content.insert(dest_content.end(), content.begin(), content.end()); random_shuffle(dest_content.begin(), dest_content.end()); string dest(f.get_path() + "/dest"); write_to_file(dest, dest_content); Io io; int r(copy(io, src.c_str(), dest.c_str())); fail_unless(r == 0, "result value"); vector<char> copied; read_file(dest, copied); fail_unless(content.size() == copied.size(), "size"); fail_unless(equal(content.begin(), content.end(), copied.begin()), "value"); }
bool SyntaxNode::operator==( const SyntaxNode& node ) const { return node_type_ == node.node_type_ && lexeme_ == node.lexeme_ && nodes_.size() == node.nodes_.size() && equal( nodes_.begin(), nodes_.end(), node.nodes_.begin(), indirect_equal() ) ; }
inline bool is_palindrome(string word) { return equal(word.begin(), word.end(), word.rbegin()); }
bool is_palindrome(const string& s) { return equal(s.begin(), s.end(), s.rbegin()); }