コード例 #1
0
def test_delete_database(mocked_requests, mocked_requests2):
    woql_client = WOQLClient("http://localhost:6363")
    woql_client.connect(user="******", key="root", team="admin")

    woql_client.create_database(
        "myFirstTerminusDB",
        "admin",
        label="my first db",
        description="my first db comment",
        include_schema=False,
    )

    with pytest.raises(UserWarning):
        woql_client.delete_database()
コード例 #2
0
def test_create_database_with_schema(mocked_requests, mocked_requests2):
    woql_client = WOQLClient("http://localhost:6363")
    woql_client.connect()
    woql_client.create_database(
        "myFirstTerminusDB",
        "admin",
        label="my first db",
        description="my first db comment",
        include_schema=True,
    )
    requests.post.assert_called_once_with(
        "http://localhost:6363/api/db/admin/myFirstTerminusDB",
        auth=("admin", "root"),
        json={"label": "my first db", "comment": "my first db comment", "schema": True},
        headers={"user-agent": f"terminusdb-client-python/{__version__}"},
    )
コード例 #3
0
def test_create_database_and_change_team(mocked_requests, mocked_requests2):
    woql_client = WOQLClient("http://localhost:6363")
    woql_client.connect(user="******", team="admin", key="root")
    woql_client.create_database(
        "myFirstTerminusDB",
        "my_new_team",
        label="my first db",
        description="my first db comment",
        include_schema=False,
    )

    requests.post.assert_called_once_with(
        "http://localhost:6363/api/db/my_new_team/myFirstTerminusDB",
        auth=("admin", "root"),
        json={"label": "my first db", "comment": "my first db comment"},
        headers={"user-agent": f"terminusdb-client-python/{__version__}"},
    )
コード例 #4
0
propteries["QueryAddOnObj"] = propteries.apply(
    construction_schema_addon_property, axis=1, type_list=list(types["id"]))

server_url = "https://127.0.0.1:6363"
user = "******"
account = "admin"
key = "root"
dbid = "schema_tutorial"
label = "Schema Tutorial"
description = "Create a graph with Schema.org data"

client = WOQLClient(server_url)
client.connect(user=user, account=account, key=key, db=dbid)

try:
    client.create_database(dbid, user, label=label, description=description)
except Exception as E:
    error_obj = E.errorObj
    if "api:DatabaseAlreadyExists" == error_obj.get("api:error",
                                                    {}).get("@type", None):
        print(f'Warning: Database "{dbid}" already exists!\n')
    else:
        raise (E)

print("create schema for types")
create_schema_objects(client, list(types["QueryObjects"]))
print("create schema relations for simple types")
#construct_simple_type_relations(type_list=list(types["id"]))
create_schema_objects(client, construct_simple_type_relations())
print("create schema add on for types")
create_schema_add_ons(client, list(types["QueryAddOnObj"]))
コード例 #5
0
        hus_obj = WOQLQuery().insert("hus"+str(hus["Id"]), "House").label(hus["Name"])
        if hus["Region"] is not None:
            hus_obj.property("region", "doc:Region_"+hus["Region"])
        for seat in hus["Seats"]:
            hus_obj.property("seats", "doc:Seats_"+seat)
        if hus["Founder"] is not None:
            hus_obj.property("founder", "doc:Person_"+str(hus["Founder"]))
        if hus["Words"] is not None:
            data_obj = {"@value" : hus["Words"], "@type" : "xsd:string"}
            hus_obj.property("words", data_obj)
        if hus["Heir"] is not None:
            hus_obj.property("heir", "doc:Person_"+str(hus["Heir"]))
        if hus["Overlord"] is not None:
            hus_obj.property("overlord", "doc:Person_"+str(hus["Overlord"]))
        results.append(hus_obj)


    return WOQLQuery().woql_and(*results).execute(client, "Adding data for Game of Thrones.")

db_id = "game_of_thrones"
client = WOQLClient(server_url = "http://localhost:6363")
client.connect(key="root", account="admin", user="******")
existing = client.get_metadata(db_id, client.uid())
if not existing:
    client.create_database(db_id, "admin", label="Game of Thrones Graph", description="Create a graph with Game of Thrones data")
else:
    client.db(db_id)
create_schema(client)
load_data(client, houses, characters)
コード例 #6
0
                                                     type,
                                                     label="v:Label_" +
                                                     str(i)))
    return insert


def generateMultiInsertQuery(codes, type):
    matches = []
    inserts = []
    index = 0
    for code in codes:
        matches.append(generateMatchClause(code, type, index))
        inserts.append(generateInsertClause(code, type, index))
        index = index + 1
    return WOQLQuery().when(WOQLQuery().woql_and(*matches),
                            WOQLQuery().woql_and(*inserts))


db_id = "pyplane"
client = WOQLClient(server_url="http://localhost:6363")
client.connect(key="root", account="admin", user="******")
existing = client.get_metadata(db_id, client.uid())
if not existing:
    client.create_database(db_id,
                           "admin",
                           label="Flights Graph",
                           description="Create a graph with Open Flights data")
else:
    client.db(db_id)
create_schema(client)
コード例 #7
0
types = pd.read_csv("all-layers-types.csv")
types["QueryObjects"] = types.apply(construction_schema_objects, axis=1)
types["QueryAddOnObj"] = types.apply(construction_schema_addon, axis=1, type_list=list(types["id"]))

propteries = pd.read_csv("all-layers-properties.csv")
propteries["QueryObjects"] = propteries.apply(construction_schema_objects, axis=1)
propteries["QueryObjects_DR"] = propteries.apply(construct_prop_dr, axis=1)
propteries["QueryAddOnObj"] = propteries.apply(construction_schema_addon_property, axis=1, type_list=list(types["id"]))


db_id = "schema_tutorial"
client = WOQLClient(server_url = "http://localhost:6363")
client.connect(key="root", account="admin", user="******")
existing = client.get_metadata(db_id, client.uid())
if not existing:
    client.create_database(db_id, "admin", label="Schema.org Graph", description="Create a graph with Schema.org")
else:
    client.db(db_id)

print("crete schema for types")
create_schema_objects(client, list(types["QueryObjects"]))
print("crete schema relations for simple types")
#construct_simple_type_relations(type_list=list(types["id"]))
create_schema_objects(client, construct_simple_type_relations())
print("crete schema add on for types")
create_schema_add_ons(client, list(types["QueryAddOnObj"]))
#print("crete schema for properties")
#create_schema_objects(client, list(propteries["QueryObjects"]))
print("create schema for DR objects")
create_schema_add_ons(client, list(propteries["QueryObjects_DR"]))
print("crete schema add on for properties")
コード例 #8
0
        data_type = data['type']
        WOQLObj = WOQLQuery().insert('doc:'+id, data_type)
        if data_type == 'http://schema.org/DateTime':
            date_value = {"@value" : data['value'], "@type" : "xsd:dateTime"}
            execution_queue.append(WOQLObj.property(data_type+'Value', date_value))
            return
        for prop in data['properties']:
            extract_data(data['properties'][prop], id+prop+'/')
            WOQLObj = WOQLObj.property('http://schema.org/'+prop, 'doc:'+id+prop+'/')
        execution_queue.append(WOQLObj)
    else:
        if '://' in data:
            data_type = 'http://schema.org/URL'
        else:
            data_type = 'http://schema.org/Text'
        WOQLObj = WOQLQuery().insert('doc:'+id, data_type)
        data_obj = {"@value" : data, "@type" : "xsd:string"}
        execution_queue.append(WOQLObj.property(data_type+'Value',data_obj))

extract_data(data['microdata'][0])

db_id = "schema_tutorial"
client = WOQLClient(server_url = "http://localhost:6363")
client.connect(key="root", account="admin", user="******")
existing = client.get_metadata(db_id, client.uid())
if not existing:
    client.create_database(db_id, "admin", { "label": "Schema.org Graph", "comment": "Create a graph with Schema.org data"})
else:
    client.db(db_id)
WOQLQuery().woql_and(*execution_queue).execute(client)