예제 #1
0
try:
    client.delete_database(db)
except Exception as E:
    pass

client.create_database(db,
                       account,
                       label="Schemaless to Schema",
                       description="Two branch database one with schema",
                       include_schema=False)

# Create a schemaless branch
client.branch('schemaless')

# Switch back to main
client.checkout('main')

# Create the schema graph
client.create_graph("schema", "main", "Adding schema")

# Add the schema
WQ().woql_and(WQ().doctype("scm:BankAccount").label(
    "Bank Account").description("A bank account").property(
        "scm:owner", "xsd:string").label("owner").cardinality(1).property(
            "scm:balance", "xsd:nonNegativeInteger").label("balance")).execute(
                client, "Adding bank account object to schema")

# Add some data which meets the schema
WQ().woql_and(WQ().insert("doc:mike", "scm:BankAccount").property(
    "scm:owner", "mike").property("scm:balance",
                                  123)).execute(client, "Add mike")
예제 #2
0
except:
    pass

times = []
directory = 'wordnet_chunks'
for f in os.listdir(directory):
    filename = f'{directory}/{f}'
    ttl_file = open(filename)
    contents = ttl_file.read()
    ttl_file.close()
    before = time.time()
    print(f"Loading WordNet in chunks ({f})")
    client.insert_triples("instance", "main", contents,
                          f"Adding WordNet in chunks ({f})")
    after = time.time()
    total = (after - before)
    times.append(total)
    print(f"Update took {total} seconds")

print(f"Squashing main")
before = time.time()
client.checkout("main")
result = client.squash('Squash commit of properties and types')
after = time.time()
total = (after - before)
print(f"Squash took {total} seconds")

commit = result['api:commit']
print(f"Branch reset to {commit}")
client.reset(commit)
예제 #3
0
try:
    client.delete_database(db)
except Exception as E:
    print(E)

client.create_database(db,
                       account,
                       label=db_label,
                       description=db_comment,
                       include_schema=False)

for branch in branches:
    # Load the perties branch
    client.branch(branch, empty=True)
    client.checkout(branch)

    print(f"Importing from {branch}")
    for f in os.listdir(branch):
        filename = f'{branch}/{f}'
        ttl_file = open(filename)
        contents = ttl_file.read()
        ttl_file.close()

        # start the chunk work
        before = time.time()
        client.insert_triples("instance", "main", contents,
                              f"Adding {branch} in 200k chunk ({f})")
        after = time.time()

        total = (after - before)
    client.optimize(f'{account}/{db}/local/_commits')


try:
    client.delete_database(db)
except Exception as E:
    print(E)

client.create_database(db,
                       account,
                       label=db_label,
                       description=db_comment,
                       include_schema=False)

client.branch('properties')
client.checkout('properties')
times = []
directory = 'properties_100k'
for f in os.listdir(directory):
    optimizer(client)
    filename = f'{directory}/{f}'
    ttl_file = open(filename)
    contents = ttl_file.read()
    ttl_file.close()
    before = time.time()
    client.insert_triples("instance", "main", contents,
                          f"Adding properties in 100k chunk ({f})")
    after = time.time()
    total = (after - before)
    times.append(total)
    print(f"Update took {total} seconds")
예제 #5
0
#!/usr/bin/python3

import os
import time
from terminusdb_client import WOQLClient
from terminusdb_client import WOQLQuery as WQ

server_url = "https://127.0.0.1:6363"
db = "DBPedia_squash"
user = "******"
account = "admin"
key = "root"
client = WOQLClient(server_url)
client.connect(user=user, account=account, key=key, db=db)

# client.branch("squash", empty=True)
client.checkout("squash")
query = WQ().select().woql_and(
    WQ().using(f"{account}/{db}").triple("v:X","v:Y","v:Z"),
    WQ().add_triple("v:X","v:Y","v:Z"))
client.query(query, "Squash commit")
예제 #6
0
                       account,
                       label=db_label,
                       description=db_comment,
                       include_schema=False)

print("##########################################################")
print("#                                                        #")
print(
    f"# Starting run with optimization == {optimize}{space}                 #")
print("#                                                        #")
print("##########################################################")
print("")

# Load the perties branch
client.branch('literal_properties')
client.checkout('literal_properties')
times = []
print(f"Importing literal properties from {literal_properties_directory}")
for f in os.listdir(literal_properties_directory):
    filename = f'{literal_properties_directory}/{f}'
    ttl_file = open(filename)
    contents = ttl_file.read()
    ttl_file.close()

    # start the chunk work
    before = time.time()
    if optimize == True:
        optimizer(client)
    client.insert_triples("instance", "main", contents,
                          f"Adding literal properties in 100k chunk ({f})")
    after = time.time()
new_db = "DBPedia_squash"
client.remote_auth({"type": "basic", "user": user, "key": key})
client.clonedb(
    {
        "remote_url": f"{server_url}/{user}/{db}",
        "comment": "Squash test",
        "label": "Squash test"
    }, new_db)

new_db = "DBPedia_squash"
client = WOQLClient(server_url)
client.remote_auth({"type": "basic", "user": user, "key": key})
client.connect(user=user, account=account, key=key, db=new_db)
client.branch("types")
client.checkout("types")
client.pull({"remote": "origin", "remote_branch": "types"})

client.branch("properties")
client.checkout("properties")
client.pull({"remote": "origin", "remote_branch": "properties"})

client.checkout('main')
# Rebase valid data to schema branch
client.rebase({
    "rebase_from": f'{user}/{new_db}/local/branch/types',
    "author": user,
    "message": "Merging types into main"
})

client.checkout('main')