mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 16:36:21 +02:00
* Update librarian to new API * Implementing new schema with document + processing objects
94 lines
2.2 KiB
Python
Executable file
94 lines
2.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
import json
|
|
import sys
|
|
import base64
|
|
import time
|
|
|
|
url = "http://localhost:8088/api/v1/"
|
|
|
|
############################################################################
|
|
|
|
id = "http://trustgraph.ai/doc/6d034da9-2759-45c2-af24-14db7f4c44c2"
|
|
|
|
source = "../sources/20160001634.pdf"
|
|
|
|
with open(source, "rb") as f:
|
|
doc = base64.b64encode(f.read()).decode("utf-8")
|
|
|
|
input = {
|
|
"operation": "add-document",
|
|
"document-metadata": {
|
|
"id": id,
|
|
"time": int(time.time()),
|
|
"kind": "application/pdf",
|
|
"title": "Application of SAE ARP4754A to Flight Critical Systems",
|
|
"comments": "Application of federal safety standards to NASA spacecraft",
|
|
"metadata": [
|
|
{
|
|
"s": {
|
|
"v": id,
|
|
"e": True,
|
|
},
|
|
"p": {
|
|
"v": "http://www.w3.org/2000/01/rdf-schema#label",
|
|
"e": True,
|
|
},
|
|
"o": {
|
|
"v": "Challenger report volume 1", "e": False,
|
|
},
|
|
},
|
|
{
|
|
"s": {
|
|
"v": id,
|
|
"e": True,
|
|
},
|
|
"p": {
|
|
"v": 'https://schema.org/keywords',
|
|
"e": True,
|
|
},
|
|
"o": {
|
|
"v": "space shuttle", "e": False,
|
|
},
|
|
},
|
|
{
|
|
"s": {
|
|
"v": id,
|
|
"e": True,
|
|
},
|
|
"p": {
|
|
"v": 'https://schema.org/keywords',
|
|
"e": True,
|
|
},
|
|
"o": {
|
|
"v": "nasa", "e": False,
|
|
},
|
|
},
|
|
],
|
|
"user": "trustgraph",
|
|
"tags": ["nasa", "safety-engineering"],
|
|
},
|
|
"content": doc,
|
|
}
|
|
|
|
resp = requests.post(
|
|
f"{url}librarian",
|
|
json=input,
|
|
)
|
|
|
|
print(resp.text)
|
|
resp = resp.json()
|
|
|
|
print(resp)
|
|
|
|
if "error" in resp:
|
|
print(f"Error: {resp['error']}")
|
|
sys.exit(1)
|
|
|
|
print(resp)
|
|
|
|
sys.exit(0)
|
|
|
|
############################################################################
|
|
|