예제 #1
0
def run():
    csvpath = "equinox.csv"
    key = os.environ['TERMINUSDB_ACCESS_TOKEN']
    endpoint = os.environ['TERMINUSDB_ENDPOINT']
    team = os.environ['TERMINUSDB_TEAM']
    team_quoted = urllib.parse.quote(team)
    #client = WOQLClient(f"https://cloud.terminusdb.com/{team_quoted}/")
    if endpoint == 'http://127.0.0.1:6363':
        client = WOQLClient(f"{endpoint}")
    else:
        client = WOQLClient(f"{endpoint}/{team_quoted}/")

    # make sure you have put the token in environment variable
    # https://docs.terminusdb.com/v10.0/#/terminusx/get-your-api-key
    # print(f"key: {key}")
    use_token = True
    if key == 'false':
        use_token = False
        client.connect(user='******', team=team, use_token=use_token)
    else:
        client.connect(team=team, use_token=use_token)

    # use when not recreating
    # client.connect(db=dbid,team=team,use_token=use_token)

    exists = client.get_database(dbid)
    if exists:
        client.delete_database(dbid, team=team)

    client.create_database(dbid,
                           team,
                           label=label,
                           description=description,
                           prefixes=prefixes)

    schema = infer_schema(csvpath)
    schema_objects = basic_schema + schema.dump_schema()
    #print(json.dumps(schema_objects, indent=4))
    import_schema(client,schema_objects)
    objects = load_data(csvpath,schema)
    # print(json.dumps(objects, indent=4))
    import_data(client,objects)
    # If you need to start over with connections...
    # delete_relationships(client)

    connect_polities(client,csvpath)
예제 #2
0
        label="SpaCy Tokens").property("lemma", "string").property(
            "pos", "string").property("tag", "string").property(
                "dep", "string").property("shape", "string").property(
                    "is_alpha",
                    "boolean").property("is_stop", "boolean").property(
                        "head", "SpaCyToken").property("doc", "SpaCyDoc"))
    schema = spacy_doc + token_dt
    return schema.execute(client, "Create a schema for SpaCy Tokens")


if __name__ == "__main__":
    db_id = "nlp_spacy"
    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,
            accountid="admin",
            label="Spacy Tokens",
            description="Storing tokenization result form SpaCy")
    else:
        client.delete_database(
            db_id)  # delete the original database if the sechema is updated
        client.create_database(
            db_id,
            accountid="admin",
            label="Spacy Tokens",
            description="Storing tokenization result form SpaCy")
        #client.db(db_id)
    build_schema(client)
#!/usr/bin/python3

from terminusdb_client import WOQLClient
from terminusdb_client import WOQLQuery as WQ

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

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)

# 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")

# Create the schema graph
예제 #4
0
#!/usr/bin/python3

from terminusdb_client import WOQLClient
from terminusdb_client import WOQLQuery

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

client.delete_database("bike")
client.create_database("bike","admin",label="Bikes", description="description")

query = WOQLQuery().get(
    WOQLQuery().woql_as("Start station","v:Start_Station")
        .woql_as("End station", "v:End_Station")
        .woql_as("Start date", "v:Start_Time")
        .woql_as("End date", "v:End_Time")
        .woql_as("Duration", "v:Duration")
        .woql_as("Start station number", "v:Start_ID")
        .woql_as("End station number", "v:End_ID")
        .woql_as("Bike number", "v:Bike")
        .woql_as("Member type", "v:Member_Type")
).post("bike_csv")
result = client.query(query,
                      "This is a commit string",
                      {'bike_csv' : '/home/gavin/tmp/bike_tutorial.csv'})
예제 #5
0
#!/usr/bin/env python3b

from terminusdb_client import WOQLClient, WOQLQuery
import pytest


import time
import sys
import random

db = 'testdb_python_insert_test'
client = WOQLClient("https://127.0.0.1:6363")
client.connect(user="******", account="admin", key="root")
try:
    client.delete_database(db, "admin")
except:
    pass
client.create_database(db, "admin", include_schema=False)

schema_db = 'testdb_python_insert_schema_test'
schema_client = WOQLClient("https://127.0.0.1:6363")
schema_client.connect(user="******", account="admin", key="root")
try:
    schema_client.delete_database(schema_db, "admin")
except:
    pass
schema_client.create_database(schema_db, "admin")

def random_string_number():
    return str(random.randint(1, 1000000))