Created
February 7, 2012 14:04
-
-
Save hecomi/1759838 to your computer and use it in GitHub Desktop.
文章をカタカナに変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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