vagrantにxpdfを入れる

yumコマンドで入れます。
[pre]
yum install xpdf
[/pre]

依存性関連をインストールしました:
desktop-file-utils.x86_64 0:0.15-9.el6
lcms-libs.x86_64 0:1.19-1.el6
libXmu.x86_64 0:1.1.1-2.el6
libXp.x86_64 0:1.0.2-2.1.el6
libpaper.x86_64 0:1.1.23-6.1.el6
openjpeg-libs.x86_64 0:1.3-16.el6_8
openmotif.x86_64 0:2.3.3-9.el6
poppler.x86_64 0:0.12.4-12.el6_9
poppler-data.noarch 0:0.4.0-1.el6
poppler-utils.x86_64 0:0.12.4-12.el6_9
urw-fonts.noarch 0:2.4-11.el6
xdg-utils.noarch 0:1.0.2-17.20091016cvs.el6
xorg-x11-fonts-ISO8859-1-100dpi.noarch 0:7.2-11.el6
xorg-x11-fonts-ISO8859-1-75dpi.noarch 0:7.2-11.el6

完了しました!

etcのディレクトリの xpdfrcを編集します。

# Choose a text encoding for copy-and-paste and for pdftotext output.
# The Latin1, ASCII7, and UTF-8 encodings are built into Xpdf. Other
# encodings are available in the language support packages.

textEncoding UTF-8

コマンドラインから、pdftotext origin.pdf create.txt でtxtファイルを作成する。

[vagrant@localhost translator]$ pdftotext boj.pdf boj.txt

うおおおおおおおおおおおおおおおおおお
テキストファイルになってる!!!!!!!!!!!
ヘッダーの「日本銀行」とフッターの「以上」が改行されているが、他は問題なさそう。すげー

xpdfをazureのvmに入れられるのかわからんが、まずはvagrantで構築していきましょう。
pdftotextはcrontabでやるにしても、コマンドラインではなく、phpファイルから実行できるんだろうか?

azure phpで翻訳してonclickで喋らせる

text apiから返ってきたjsonをdocument.getElementById(“text1”).innerHTMLで取得して、speechSynthesisを使います。

<?php

$key = 'hoge';

$host = "https://api.cognitive.microsofttranslator.com";
$path = "/translate?api-version=3.0";
$params = "&to=en";
$text = "当社は中長期的かつ持続的な企業価値の向上を目指しており、そのためには、将来の成長を見据えた
サービスへの先行投資や設備投資、資本業務提携を積極的に行うことが重要だと認識しています。同時
に、利益還元を通じて株主の皆さまに報いることが上場会社としての責務と捉えています。
上記方針のもと、当期の期末配当金につきましては、1 株当たり8.86 円(配当金総額は504 億円)と
いたしました。
当社はこれからも、将来の成長のための投資を継続しながら、株主の皆さまへの適切な利益還元を行
うことにより、企業価値の向上を目指していきます。";

if(!function_exists('com_create_guid')){
	function com_create_guid(){
		return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
		mt_rand(0, 0xffff), mt_rand(0, 0xffff),
		mt_rand(0, 0xffff),
		mt_rand(0, 0x0fff) | 0x4000,
		mt_rand(0, 0x3fff) | 0x8000,
		mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
	}
}

function Translate ($host, $path, $key, $params, $content) {
    $headers = "Content-type: application/json\r\n" .
        "Content-length: " . strlen($content) . "\r\n" .
        "Ocp-Apim-Subscription-Key: $key\r\n" .
        "X-ClientTraceId: " . com_create_guid() . "\r\n";
    $options = array (
        'http' => array (
            'header' => $headers,
            'method' => 'POST',
            'content' => $content
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents ($host . $path . $params, false, $context);
    return $result;
}

$requestBody = array (
    array (
        'Text' => $text,
    ),
);
$content = json_encode($requestBody);
$result = Translate($host, $path, $key, $params, $content);

$json = json_decode($result);
$newtext =  $json[0]->translations[0]->text;
?>
<div id="text1">
    <?php echo $newtext; ?>
</div>
<br>
<button id="btn">speach</button>
<script>
    document.querySelector('#btn').onclick = function(){
        var msg = new SpeechSynthesisUtterance();
        msg.volume = 1;
        msg.rate = 1;
        msg.pitch = 2;
        msg.lang = "en-US";
        msg.text = document.getElementById("text1").innerHTML;

        speechSynthesis.speak(msg);
    }
</script>

こいつはすげー

$params = “&to=zh”; にすると、
————-
我们的目标是在中长期内提高公司的价值, 并 我们认识到, 积极参与服务、资本投资和商业联盟的前期投资是重要的。 相同 , 作为上市公司, 我们有责任通过利润回报回报股东。 在上述政策下, 本期年终股息为每股8.86 日元 (总股息为504亿日元) 我们。 我们将继续投资于未来的增长, 并将适当的利润返还给我们的股东。 我们的目标是提高企业价值。
————-
ざっとみたところ、良さそう。
これを日銀のStatements on Monetary Policyでやりたいと思います。

オークションで一眼レフ落札したら、フィルムカメラだった!

エンジニアたるもの、写真の意識が高くないと駄目だ、とあるカメラやってる方にインスパイアーされ、ヤフオクで一眼レフを落札

ワクワク^^

届きました。

いいね~この重厚感

あれ、ちょっと待て、これフィルム?

普通そこ間違えるかね。。

といいつつ、速攻でフィルムと電池を買ってしまった。

息抜きに写真でも撮りに行きますかね。

決算ir情報をphpで翻訳する

yahoo 譲渡制限付株式報酬としての新株式の発行に関するお知らせ(259文字)
当社は中長期的かつ持続的な企業価値の向上を目指しており、そのためには、将来の成長を見据えた
サービスへの先行投資や設備投資、資本業務提携を積極的に行うことが重要だと認識しています。同時
に、利益還元を通じて株主の皆さまに報いることが上場会社としての責務と捉えています。
上記方針のもと、当期の期末配当金につきましては、1 株当たり8.86 円(配当金総額は504 億円)と
いたしました。
当社はこれからも、将来の成長のための投資を継続しながら、株主の皆さまへの適切な利益還元を行
うことにより、企業価値の向上を目指していきます。

$key = 'hoge';

$host = "https://api.cognitive.microsofttranslator.com";
$path = "/translate?api-version=3.0";
$params = "&to=en";
$text = "当社は中長期的かつ持続的な企業価値の向上を目指しており、そのためには、将来の成長を見据えた
サービスへの先行投資や設備投資、資本業務提携を積極的に行うことが重要だと認識しています。同時
に、利益還元を通じて株主の皆さまに報いることが上場会社としての責務と捉えています。
上記方針のもと、当期の期末配当金につきましては、1 株当たり8.86 円(配当金総額は504 億円)と
いたしました。
当社はこれからも、将来の成長のための投資を継続しながら、株主の皆さまへの適切な利益還元を行
うことにより、企業価値の向上を目指していきます。";

if(!function_exists('com_create_guid')){
	function com_create_guid(){
		return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
		mt_rand(0, 0xffff), mt_rand(0, 0xffff),
		mt_rand(0, 0xffff),
		mt_rand(0, 0x0fff) | 0x4000,
		mt_rand(0, 0x3fff) | 0x8000,
		mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
	}
}

function Translate ($host, $path, $key, $params, $content) {
    $headers = "Content-type: application/json\r\n" .
        "Content-length: " . strlen($content) . "\r\n" .
        "Ocp-Apim-Subscription-Key: $key\r\n" .
        "X-ClientTraceId: " . com_create_guid() . "\r\n";
    $options = array (
        'http' => array (
            'header' => $headers,
            'method' => 'POST',
            'content' => $content
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents ($host . $path . $params, false, $context);
    return $result;
}

$requestBody = array (
    array (
        'Text' => $text,
    ),
);
$content = json_encode($requestBody);
$result = Translate($host, $path, $key, $params, $content);

$json = json_decode($result);
echo $json[0]->translations[0]->text;

echoの結果->565文字
—–
We aim to improve our corporate value in the medium to long term and We recognize that it is important to actively engage in upfront investment in services, capital investment, and business alliances. Same , it is our duty as a listed company to repay our shareholders through the return of profits. Under the above policy, the year-end dividend for the current period is 8.86 yen per share (total dividend of 50.4 billion yen) We. We will continue to invest in future growth and to return appropriate profits to our shareholders. We aim to improve corporate value.

悪くない!というか、金融系に強い帰国子女に頼むよりも質が高く、早くて安い(笑)
これは自動化したい。

月200万文字まで無料なので、1000文字の翻訳だとすると、上限2000回か。
全銘柄のEdinet IR自動翻訳だとちょっとキツイな。
うーん、どうする?

Azure Translator Text APIを使ってphpで翻訳する

file_get_contentsしたjsonをdecodeします。

$key = 'hogehoge';

$host = "https://api.cognitive.microsofttranslator.com";
$path = "/translate?api-version=3.0";
$params = "&to=en";
$text = "1文をバラバラにして単語レベルで翻訳をするのではなく、1文をひとまとめにして翻訳";

if(!function_exists('com_create_guid')){
	function com_create_guid(){
		return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
		mt_rand(0, 0xffff), mt_rand(0, 0xffff),
		mt_rand(0, 0xffff),
		mt_rand(0, 0x0fff) | 0x4000,
		mt_rand(0, 0x3fff) | 0x8000,
		mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
	}
}

function Translate ($host, $path, $key, $params, $content) {
    $headers = "Content-type: application/json\r\n" .
        "Content-length: " . strlen($content) . "\r\n" .
        "Ocp-Apim-Subscription-Key: $key\r\n" .
        "X-ClientTraceId: " . com_create_guid() . "\r\n";
    $options = array (
        'http' => array (
            'header' => $headers,
            'method' => 'POST',
            'content' => $content
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents ($host . $path . $params, false, $context);
    return $result;
}

$requestBody = array (
    array (
        'Text' => $text,
    ),
);
$content = json_encode($requestBody);
$result = Translate($host, $path, $key, $params, $content);


$json = json_decode($result);
echo $json[0]->translations[0]->text;

これは。。。

eminem lose yourself
——-
Look, if you had one shot, one opportunity
To seize everything you ever wanted
One moment
Would you capture it or just let it slip?
Yo
His palms are sweaty, knees weak, arms are heavy
There’s vomit on his sweater already, mom’s spaghetti
He’s nervous, but on the surface he looks calm and ready
To drop bombs, but he keeps on forgettin’
What he wrote down, the whole crowd goes so loud
He opens his mouth, but the words won’t come out
He’s chokin’, how, everybody’s jokin’ now
The clocks run out, times up, over, blaow!
Snap back to reality, oh there goes gravity
Oh, there goes Rabbit, he choked
He’s so mad, but he won’t give up that easy? No
He won’t have it, he knows his whole back city’s ropes
It don’t matter,
He’s dope,…

ラップの翻訳って難しいと思うが、
結果

ほお

翻訳のアルゴリズムは?

前:ルールベース翻訳や統計翻訳
->文法や単語などのルールを一つ一つ登録して翻訳

後:ニューラルネットワーク
->1文をバラバラにして単語レベルで翻訳をするのではなく、1文をひとまとめにして翻訳

そうなのか、VoiceTraとかも統計翻訳の機械学習かと思ってた。。
NICT(情報通信研究機構)
http://www.nict.go.jp/
ここは興味ある。金融庁以来。

しかし予算500億も使ってんのかよ。。コロプラの売上高と一緒じゃんか。。ちくしょー羨ましすぎる。。
https://www.nict.go.jp/pdf/business-report-2016.pdf

ibm translator

使ってみる。

[vagrant@localhost translator]$ curl -u "username":pass" \
> -H "Accept: application/json" \
> "https://gateway.watsonplatform.net/language-translator/api/v2/translate?model_id=en-ja&text=ibm+translator"
{
  "translations" : [ {
    "translation" : "IBM変換プログラム"
  } ],
  "word_count" : 2,
  "character_count" : 14
}

幾つか試したが、レスポンスがなかったり、tokyo -> “translation” : “統教” と精度がイマイチだったり。。。
やってることは凄いんだろうけど、これ以上深堀りする気ナシ。

IBM developerWorks

IBMって、どうなんでしょう?
勝屋さんが元IBMのVCですよね。

とりあえず、翻訳系のサービスが作りたい。
っま、動かしながら考えましょう。

watson APIs Language Translator

The IBM Watson Language Translator service converts text input in one language into a destination language for the end user using background from domain-specific models. Translation is available among Arabic, Chinese (Simplified and Traditional), English, French, Portuguese, German, Spanish, Dutch, Turkish, Russian, Korean, Italian and Polish (some languages may not be available for all domains).

日本語 原文

現在、我が国では、IT投資が活発化するとともに、グローバルな事業展開が一層の拡大傾向にあります。一方で、先端IT技術を活用した新しいビジネスモデルへの需要が高まっています。企業に対しても、持続可能な社会の実現を見据えた投資によってイノベーションを発揮し、事業を通じた社会課題の解決に積極的に取り組んでいくことが求められています。

watson 翻訳結果(英語)
想像以上に悪くない気がする。。

In Japan, IT investment is becoming more active, and global business expansion is becoming more and more expanding.On the other hand, there is a growing demand for new business models using cutting-edge IT technologies.It is also necessary for companies to exert innovation through investment that is a view to realizing a sustainable society, and to actively work on solving social issues through business.

あああああああああああああああああ
Japanese からは Englishしかないいいいいいいいいいいい
というか、英語以外は、ほとんど英語への翻訳しかないですね。