Goo labs API client for python. And provide some command line tools.
- nits
- Provide API Client for Goo labs API.
- Provide some command line tools.
- You need to get app id at Goo labs website in order to use this library.
Make environment with pip:
$ pip install goolabs
For Max OS X user. If you want to use command line tool only, you can install from homebrew:
$ brew install goolabs
Morphological analysis for Japanese.
See also https://labs.goo.ne.jp/api/2015/1302/
from goolabs import GoolabsAPI
app_id = "xxxxxxxxxxxxxxxxxxxx"
api = GoolabsAPI(app_id)
# See sample response below.
sample_response = api.morph(sentence=u"日本語を分析します。")
# All the arguments of this func.
api.morph(
request_id="morph-req001",
sentence=u"日本語を分析します。",
info_filter="form|pos|read",
pos_filter=u"名詞|格助詞|動詞活用語尾|動詞接尾辞|句点",
)
# Possible parts of speech, please refer to the following URL.
# https://labs.goo.ne.jp/api/2015/1158/
Sample response.
Scoring the similarity of two words.
See also https://labs.goo.ne.jp/api/2015/1295/
Sample response.
Convert the Japanese to Hiragana or Katakana.
See also https://labs.goo.ne.jp/api/2015/1293/
from goolabs import GoolabsAPI
app_id = "xxxxxxxxxxxxxxxxxxxx"
api = GoolabsAPI(app_id)
# See sample response below.
ret = api.hiragana(sentence=u"漢字が混ざっている文章", output_type="hiragana")
# All the arguments of this func.
api.hiragana(
request_id="hiragana-req001",
sentence=u"漢字が混ざっている文章",
output_type="hiragana" # hiragana or katakana
)
Sample response.
Extract the unique representation from sentence.
see also https://labs.goo.ne.jp/api/2015/1299/.
from goolabs import GoolabsAPI
app_id = "xxxxxxxxxxxxxxxxxxxx"
api = GoolabsAPI(app_id)
# See sample response below.
ret = api.entity(sentence=u"鈴木さんがきょうの9時30分に横浜に行きます。")
# All the arguments of this func.
api.entity(
request_id="entity-req001",
sentence=u"鈴木さんがきょうの9時30分に横浜に行きます。"
class_filter=u"ART|ORG|PSN|LOC|DAT|TIM"
)
Sample response.
Summarizes the sent-in Japanese reviews into a short summary.
see also https://labs.goo.ne.jp/api/2015/1305/
from goolabs import GoolabsAPI
app_id = "xxxxxxxxxxxxxxxxxxxx"
api = GoolabsAPI(app_id)
# See sample response below.
ret = api.shortsum(
review_list=[
"機能は限られていますが、必要十分でしょう。",
"価格も安いと思います。お店の対応もよかったです。",
"このシリーズを買うの3台目になりました。黒の発色が綺麗です。"
"値段を考えれば十分すぎる性能で",
]
)
# All the arguments of this func.
api.shortsum(
request_id="shortsum-req001",
review_list=[
"機能は限られていますが、必要十分でしょう。",
"価格も安いと思います。お店の対応もよかったです。",
"このシリーズを買うの3台目になりました。黒の発色が綺麗です。"
"値段を考えれば十分すぎる性能で",
],
length=60 # 60 or 120 or 180
)
Sample response.
Extracts "Japanese keywords", such as person names, location names, and so on, from an input document consisting of a title and a body.
see also https://labs.goo.ne.jp/api/2015/1325/
from goolabs import GoolabsAPI
app_id = "xxxxxxxxxxxxxxxxxxxx"
api = GoolabsAPI(app_id)
# See sample response below.
ret = api.keyword(
title="「和」をコンセプトとする 匿名性コミュニケーションサービス「MURA」",
body="NTTレゾナント株式会社(本社:東京都港区、代表取締役社長:若井 昌宏",
)
# All the arguments of this func.
api.keyword(
request_id="keyword-req001",
title="「和」をコンセプトとする 匿名性コミュニケーションサービス「MURA」",
body="NTTレゾナント株式会社(本社:東京都港区、代表取締役社長:若井 昌宏",
max_num=10,
forcus="ORG",
)
Sample response.
Extract expression expressing date and time and normalize its value
see also https://labs.goo.ne.jp/api/jp/time-normalization
Sample response.
You can see the HTTP response you called right before.
$ goolabs
Usage: goolabs [OPTIONS] COMMAND [ARGS]...
Command line tools for Goo labs API(https://labs.goo.ne.jp/api/).
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
chrono Extract expression expressing date and time...
entity Extract unique representation from sentence.
hiragana Convert the Japanese to Hiragana or Katakana.
keyword Extract "keywords" from an input document.
morph Morphological analysis for Japanese.
shortsum Summarize reviews into a short summary.
similarity Scoring the similarity of two words.
To use this cli, it is recommended to set the environment variable GOOLABS_APP_ID.
You may pass the App id every time you use it, but it's not recommended.
$ goolabs morph --help
Usage: goolabs morph [OPTIONS] [SENTENCE]
Morphological analysis for Japanese.
Options:
-a, --app-id TEXT
-r, --request-id TEXT
-i, --info-filter TEXT form,pos,read
-p, --pos-filter TEXT 名詞,句点,格助詞..etc
-f, --file FILENAME
-j, --json / --no-json
--help Show this message and exit.
Sample usage.
$ goolabs morph 日本語を分析します。
日本語,名詞,ニホンゴ
を,格助詞,ヲ
分析,名詞,ブンセキ
し,動詞活用語尾,シ
ます,動詞接尾辞,マス
。,句点,$
# more option
$ goolabs morph --info-filter form,pos,read --pos-filter 名詞,句点 日本語を分析します。
# specify a file as an alternative to the sentence
$ goolabs morph --file sentence.txt
# get raw json
$ goolabs morph --json --request-id req001 日本語
{
"word_list": [
[
[
"日本語",
"名詞",
"ニホンゴ"
]
]
],
"request_id": "req001"
}
Sample usage.
Sample usage.
$ goolabs hiragana 日本語
にほんご
# convert to Katakana
$ goolabs hiragana --output-type katakana 日本語
ニホンゴ
# specify a file as an alternative to the sentence
$ goolabs hiragana --file sentence.txt
# get raw json
$ goolabs hiragana --json --request-id req003 日本語
{
"output_type": "hiragana",
"converted": "にほんご",
"request_id": "req003"
}
Sample usage.
$ goolabs entity 佐藤氏、2014年12月に足の小指骨折し豊洲の病院へ
佐藤,PSN
2014年12月,DAT
豊洲,LOC
# more option
$ goolabs entity --class-filter PSN,LOC 佐藤氏、2014年12月に足の小指骨折し豊洲の病院へ
# specify a file as an alternative to the sentence
$ goolabs entity --file sentence.txt
# get raw json
$ goolabs entity --json --request-id req004 佐藤氏
{
"ne_list": [
[
"佐藤",
"PSN"
]
],
"request_id": "req004"
}
Sample usage.
$ goolabs shortsum このシリーズを買うの3台目になりました。黒の発色が綺麗です
黒の発色が綺麗です。
# more option
$ goolabs shortsum --length 180 黒の発色が綺麗です...
# specify a file as an alternative to the review
$ goolabs shortsum --file review.txt
# get raw json
$ goolabs shortsum --json --request-id req005 このシリーズを買うの3台目になりました。黒の発色が綺麗です
{
"length": 120,
"summary": "黒の発色が綺麗です。",
"request_id": "req005"
}
Sample usage.
$ goolabs keyword "匿名性コミュニケーションサービス「MURA」" "NTTレゾナント株式会社"
匿名性,0.6
コミュニケーションサービス,0.6
MURA,0.6
NTTレゾナント株式会社,0.4
# more option
$ goolabs keyword --max_num 2 --forcus ORG "匿名性コミュニケーションサービス「MURA」" "NTTレゾナント株式会社"
# specify a file as an alternative to the body
$ goolabs keyword --file body.txt "匿名性コミュニケーションサービス「MURA」"
# get raw json
$ goolabs keyword --json --request-id req006 "匿名性コミュニケーションサービス「MURA」" "NTTレゾナント株式会社"
{
"keywords": [
{ "匿名性": 0.6 },
{ "コミュニケーションサービス": 0.6 },
{ "MURA": 0.6 },
{ "NTTレゾナント株式会社": 0.4 }
],
"request_id": "req006"
}
Sample usage.
$ goolabs chrono "今日の10時半に出かけます。"
今日: 2017-05-29
10時半: 2017-05-29T10:30
# more option
$ goolabs chrono -d "2016-04-01T09:00:00" "今日の10時半に出かけます。"
今日: 2016-04-01
10時半: 2016-04-01T10:30
# specify a file as an alternative to the body
$ goolabs chrono --file sentence.txt
# get raw json
$ goolabs chrono --json --request-id req007 "今日の10時半に出かけます"
{
"datetime_list": [
[
"今日",
"2017-05-29"
],
[
"10時半",
"2017-05-29T10:30"
]
],
"doc_time": "2017-05-29T12:36:33",
"request_id": "req007"
}
- Python 2.6, 2.7, 3,3, 3.4 or later.
- Source code of this library Licensed under the MIT License.
- You have to use of Goo labs API under the Term
See the LICENSE.rst file for specific terms.
- tell-k <ffk2005 at gmail.com>
- Add new api "chrono".
- Add support for Python3.6.
- Add type annotation.
- Add new api "keyword".
- Add "-l" option for "goolabs shortsum" command.
- Add new api "shortsum".
- improved unit test code
- Exclude test code from installed packages
- Add unit test for commandline tools.
- First release