|
@@ 456-471 (lines=16) @@
|
| 453 |
|
else: |
| 454 |
|
return JSONSerializer.mentions_from_JSON(mns_json) |
| 455 |
|
|
| 456 |
|
def extract_entities(self, ds): |
| 457 |
|
""" |
| 458 |
|
Extracts and expands Entities from a Sentence or Document |
| 459 |
|
""" |
| 460 |
|
return self._extract(endpoint="extract", json_data=json.dumps(ds.to_JSON_dict(), sort_keys=True, indent=None)) |
| 461 |
|
|
| 462 |
|
def extract_and_filter_entities(self, ds): |
| 463 |
|
""" |
| 464 |
|
Extracts, expands, and filters Entities from a Sentence or Document |
| 465 |
|
""" |
| 466 |
|
return self._extract(endpoint="extract-filter", json_data=json.dumps(ds.to_JSON_dict(), sort_keys=True, indent=None)) |
| 467 |
|
|
| 468 |
|
def extract_base_entities(self, ds): |
| 469 |
|
""" |
| 470 |
|
Extracts non-expanded Entities from a Sentence or Document |
| 471 |
|
""" |
| 472 |
|
return self._extract(endpoint="base-extract", json_data=json.dumps(ds.to_JSON_dict(), sort_keys=True, indent=None)) |
| 473 |
|
|
| 474 |
|
############################################# |
|
@@ 440-454 (lines=15) @@
|
| 437 |
|
|
| 438 |
|
class OpenIEAPI(object): |
| 439 |
|
|
| 440 |
|
def __init__(self, address): |
| 441 |
|
self._service = "{}/api/openie/entities/".format(address) |
| 442 |
|
|
| 443 |
|
def _extract(self, endpoint, json_data): |
| 444 |
|
""" |
| 445 |
|
""" |
| 446 |
|
# /api/openie/entities/??? |
| 447 |
|
api_endpoint = self._service + endpoint |
| 448 |
|
mns_json = post_json(api_endpoint, json_data) |
| 449 |
|
if "error" in mns_json: |
| 450 |
|
error_msg = mns_json["error"] |
| 451 |
|
print(error_msg) |
| 452 |
|
return None |
| 453 |
|
else: |
| 454 |
|
return JSONSerializer.mentions_from_JSON(mns_json) |
| 455 |
|
|
| 456 |
|
def extract_entities(self, ds): |
| 457 |
|
""" |