用于python的goo实验室api客户端。并提供一些命令行工具。

goolabs的Python项目详细描述


用于python的goo实验室api客户端。并提供一些命令行工具。

traviscoveralls.iolatest versionlicenserequirements status

Features

  • Goo labs API提供api客户端。
  • 提供一些命令行工具。

Required

Set up

使用pip创建环境:

$ pip install goolabs

对于Max OS X用户。如果只想使用命令行工具,可以从自制程序安装:

$ brew install goolabs

Usage

变形

日语的形态分析。

另请参见https://labs.goo.ne.jp/api/2015/1302/

fromgoolabsimportGoolabsAPIapp_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/

样本响应。

{"word_list":[[["日本語","名詞","ニホンゴ"],["を","格助詞","ヲ"],["分析","名詞","ブンセキ"],["し","動詞活用語尾","シ"],["ます","動詞接尾辞","マス"],["。","句点","$"]]],"request_id":"labs.goo.ne.jp\t1419262824\t0"}

相似性

给两个词的相似性打分。

另请参见https://labs.goo.ne.jp/api/2015/1295/

fromgoolabsimportGoolabsAPIapp_id="xxxxxxxxxxxxxxxxxxxx"api=GoolabsAPI(app_id)# See sample response below.ret=api.similarity(query_pair=["windows",u"ウィンドウズ"])# All the arguments of this func.api.similarity(request_id="similarity-req001",query_pair=["windows",u"ウィンドウズ"])

样本响应。

{"score":0.7679829666474438,"request_id":"labs.goo.ne.jp\t1419263621\t0"}

平假名

把日语转换成平假名或片假名

另请参见https://labs.goo.ne.jp/api/2015/1293/

fromgoolabsimportGoolabsAPIapp_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)

样本响应。

{"output_type":"hiragana","converted":"かんじが まざっている ぶんしょう","request_id":"labs.goo.ne.jp\t1419263773\t0"}

全部

从句子中提取唯一的表示。

另请参见https://labs.goo.ne.jp/api/2015/1299/

fromgoolabsimportGoolabsAPIapp_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")

样本响应。

{"ne_list":[["鈴木","PSN"],["きょう","DAT"],["9時30分","TIM"],["横浜","LOC"]],"request_id":"labs.goo.ne.jp\t1419264063\t0"}

小计

把日本的评论总结成一个简短的摘要。

另请参见https://labs.goo.ne.jp/api/2015/1305/

fromgoolabsimportGoolabsAPIapp_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)

样本响应。

{"length":60,"summary":"黒の発色が綺麗です。機能は限られていますが、必要十分でしょう。価格も安いと思います。","request_id":"shortsum-req001"}

关键字

提取“日语关键字”,如人名、地名等, 来自由标题和正文组成的输入文档。

另请参见https://labs.goo.ne.jp/api/2015/1325/

fromgoolabsimportGoolabsAPIapp_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",)

样本响应。

{"keywords":[{"和":0.5893},{"コンセプト":0.5893},{"匿名性":0.5893},{"コミュニケーションサービス":0.5893},{"MURA":0.5893},{"NTTレ ゾナント株式会社":0.35},{"本社":0.35},{"東京都港区":0.35},{"代表取締役社長":0.35},{"若井":0.35}],"request_id":"labs.goo.ne.jp\t1457928295\t0"}

时间

提取表示日期和时间的表达式并规范化其值

另请参见https://labs.goo.ne.jp/api/jp/time-normalization

fromgoolabsimportGoolabsAPIapp_id="xxxxxxxxxxxxxxxxxxxx"api=GoolabsAPI(app_id)# See sample response below.ret=api.chrono(sentence="今日の10時半に出かけます。",)# All the arguments of this func.api.chrono(request_id="chrono-req001",sentence="今日の10時半に出かけます。",doc_time="2016-04-01T09:00:00",)

样本响应。

{"request_id":"record007",,"datetime_list":}{"datetime_list":[["今日","2016-04-01"],["10時半","2016-04-01T10:30"]],"doc_time":"2016-04-01T09:00:00","request_id":"labs.goo.ne.jp\t1457928295\t0"}

其他提示

您可以看到刚才调用的http响应。

api=GoolabsAPI(app_id)api.morph(sentence=u"日本語を分析します。")# api.response is a instance of "requests.Response".print(api.response.status_code)# => 200print(api.response.json())# => raw json data.

Command line tool

$ 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.

设置环境变量goolabs_app_id

要使用此cli,建议设置环境变量goolabs_app_id。

# write your shell setting files(ex ~/.bashrc).
exportGOOLABS_APP_ID=xxxxxxxxxxxxxxx

每次使用时都可以传递应用程序ID,但不建议这样做。

$ goolabs morph --app-id xxxxx 日本語を分析します。

变形

$ 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.

示例用法。

$ 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"}

相似性

$ goolabs similarity --help
Usage: goolabs similarity [OPTIONS] QUERY_PAIR...

  Scoring the similarity of two words.

Options:
  -a, --app-id TEXT
  -r, --request-id TEXT
  -j, --json / --no-json
  --help                  Show this message and exit.

示例用法。

$ goolabs similarity ウィンドウズ windows
0.767982966647

# get raw json.
$ goolabs similarity --json --request-id req002 ウィンドウズ windows
{"score": 0.7679829666474438,
  "request_id": "req002"}

平假名

$ goolabs hiragana --help
Usage: goolabs hiragana [OPTIONS][SENTENCE]

  Convert the Japanese to Hiragana or Katakana.

Options:
  -o, --output-type [hiragana|katakana]
  -a, --app-id TEXT
  -r, --request-id TEXT
  -f, --file FILENAME
  -j, --json / --no-json
  --help                          Show this message and exit.

示例用法。

$ 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"}

实体

$ goolabs entity --help
Usage: goolabs entity [OPTIONS][SENTENCE]

  Extract unique representation from sentence.

Options:
  -c, --class-filter TEXT  ART,ORG,PSN,LOC,DAT
  -a, --app-id TEXT
  -r, --request-id TEXT
  -f, --file FILENAME
  -j, --json / --no-json
  --help                   Show this message and exit.

示例用法。

$ 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"}

小计

$ goolabs shortsum --help
Usage: goolabs shortsum [OPTIONS][REVIEW]

  Summarize reviews into a short summary.

Options:
  -a, --app-id TEXT
  -l, --length [60|120|180]
  -r, --request-id TEXT
  -f, --file FILENAME
  -j, --json / --no-json
  --help                  Show this message and exit.

示例用法。

$ 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"}

关键字

$ goolabs keyword --help
Usage: goolabs keyword [OPTIONS] TITLE [BODY]

  Extract "keywords" from an input document.

Options:
  -a, --app-id TEXT
  -m, --max_num INTEGER
  -fo, --forcus [ORG|PSN|LOC]
  -r, --request-id TEXT
  -f, --file FILENAME
  -j, --json / --no-json
  --help                       Show this message and exit.

示例用法。

$ 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"}

时间

$ goolabs chrono --help
Usage: goolabs chrono [OPTIONS][SENTENCE]

 Extract expression expressing date and time and normalize its value

ptions:
 -a, --app-id TEXT
 -r, --request-id TEXT
 -d, --doc-time TEXT
 -f, --file FILENAME
 -j, --json / --no-json
 --help                  Show this message and exit.

示例用法。

$ 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 Support

  • Python 2.6、2.7、3、3、3.4或更高版本。

License

  • 根据麻省理工学院许可证授权的此库的源代码。
  • 你必须在the Term下使用goo labs api

有关特定术语,请参见LICENSE.rst文件

Authors

  • 在gmail.com上告诉k<;ffk2005>

History

0.4.0(2017年5月30日)

  • 添加新的api“chrono”
  • 添加对python3.6的支持。
  • 添加类型批注。

0.3.0(2016年3月14日)

  • 添加新的api“keyword”。

0.2.2(2015年7月12日)

  • 为“goolabs shortsum”命令添加“-l”选项

0.2.0(2015年7月12日)

  • 添加新的api“shortsum“。
  • 改进的单元测试代码

0.1.2(2015年1月1日)

  • 从已安装的包中排除测试代码

0.1.1(2014年12月31日)

  • 为命令行工具添加单元测试

0.1.0(2014年12月25日)

  • 首次发布

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Google应用程序引擎FreeMarker模板java。安全AccessControlException   在Java中,空字符串(“”)如何存储在内存中?   java如何使用PUT进行创建   java无法构造com的实例。谷歌。云数据存储。钥匙   Java递归中的堆栈溢出错误   java通过结构化设计模式重构冗余代码   javascript使用Selenium IDE 2.9.1上传文件   JAVAutil。扫描仪在Java中将文本文件加载到对象中   这个JAVA程序的时间复杂度是多少   java Springboot+tomcat+ssh=连接链路故障   矢量Java不安全操作   用于Java不同生成代码的协议缓冲区gRPC protobuf生成器   java OSGi为什么我的包命名为“unknown0.0.0”和MANIFEST。MF文件被覆盖了吗?   java日期保持为空(Android)   使用stax解析器java解析xml   java有一种方法可以在运行时确定对象是否是使用Lambdaj创建的。关于()方法?