向NYT实体服务API发出POST请求的包装器。
nyt-entity-uploader的Python项目详细描述
向NYT Entity Service API发出请求的包装器。
用法
第一:您应该运行NYT Entity Service API的实例。
第二:在运行 uploader指向您自己的运行实体服务api端点。
示例1:作为python模块
您可以将上传程序作为python模块运行,并将名称作为 关键字参数。
$ export ENTITYSVC_BASE_URL='http://localhost.newsdev.net:8000' $ python Python 3.6.1 (default, Apr 4 2017, 09:40:21) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from entity_uploader import UploadEntity >>> e = UploadEntity(name="Bank of America") >>> e.to_dict() {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 0, 'created': True}
例2:运行example.py
example.py是读取实体列表的示例实现 来自example_entities.txt的名称。
$ export ENTITYSVC_BASE_URL='http://localhost.newsdev.net:8000' $ python example.py {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 0, 'created': True} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 95, 'created': False} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 100, 'created': False} {'name': "banque d'amerique", 'uuid': 'cb626971-1989-4d78-870d-e6835017c936', 'score': 62, 'created': True} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 95, 'created': False} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 90, 'created': False} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 86, 'created': False} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 86, 'created': False} {'name': 'Bank of America', 'uuid': 'f514b0e1-eea5-4676-aed2-2f9ee501cd5e', 'score': 86, 'created': False}
在本例中,默认的create_if_belowscore是80。第一次 实体,Bank of America已创建。下一个实体, Bank of America, N.A.没有创建,因为它具有相似性 得分95分。匹配实体Bank of America的uuid是 返回。下一个实体BANK OF AMERICA也是如此, 更高的分数是100分。下一个实体, banque d'amerique,是作为新实体创建的,因为它具有 匹配得分62,低于默认值 create_if_below80分。中的最后几个实体 example_entities.txt用不同程度的 亲密。