Skip to content

Instantly share code, notes, and snippets.

@hecomi
Created February 7, 2012 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hecomi/1759838 to your computer and use it in GitHub Desktop.
Save hecomi/1759838 to your computer and use it in GitHub Desktop.
文章をカタカナに変換
#include <iostream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <mecab.h>
namespace qi = boost::spirit::qi;
using qi::standard_wide::char_;
using qi::_1;
int main(int argc, char* argv[])
{
// MeCab による形態素解析
std::string input = "今日は良い天気ですなぁ。";
boost::shared_ptr<MeCab::Tagger> tagger(MeCab::createTagger(""));
const MeCab::Node* node = tagger->parseToNode(input.c_str());
// 結果をコンテナに突っ込む
std::vector<std::string> features;
for (node = node->next; node->next; node = node->next) {
features.push_back(node->feature);
}
// 発音箇所だけ取り出す
std::string s = "";
for (const std::string& x : features) {
std::vector<std::string> v;
std::string::const_iterator
first = x.begin(),
last = x.end();
qi::parse(first, last, +(char_-',')%',', v);
s += v[8];
}
std::cout << s << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment