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)
#!/usr/bin/python3 import os import time import datetime from terminusdb_client import WOQLClient from terminusdb_client import WOQLQuery as WOQL # Connect to the server server_url = "https://127.0.0.1:6363" db = "dbpedia_1" user = "******" account = "admin" key = "root" client = WOQLClient(server_url) client.connect(user=user, account=account, key=key, db=db) # Example of a single hop query = WOQL().limit( 1, WOQL.woql_and( WOQL().path("doc:Whitesnake", "scm:bandMember", "v:Member", "v:Path"), )) result = client.query(query) print(f"Band member: {result['bindings'][0]['Member']}") query = WOQL().limit( 1, WOQL.woql_and( WOQL().path("doc:Whitesnake", "scm:bandMember,scm:birthPlace", "v:Place", "v:Path"), ))
token_dt = (WOQLQuery().doctype( "SpaCyToken", 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")
from terminusdb_client import WOQLClient from terminusdb_client.woqlschema import WOQLSchema # For Terminus X, use the following # client = WOQLClient("https://cloud.terminusdb.com/<Your Team>/") # client.connect(db="demo_workshop", team="<Your Team>", use_token=True) client = WOQLClient("http://127.0.0.1:6363/") client.connect(db="getting_started", branch="contractors") data_schema = WOQLSchema() data_schema.from_db(client) Employee = data_schema.object.get("Employee") Address = data_schema.object.get("Address") Team = data_schema.object.get("Team") # Contractor 1 rhys_address = Address(postcode="DG4 2ZQ", street="Helland Bridge", street_num=1, town="Ulzieside") rhys = Employee( _id="Employee/006", name="Rhys Arnold", title="UX Designer", team=Team.it, contact_number="078 3951 7569", address=rhys_address,
from terminusdb_client import WOQLClient from terminusdb_client.woqlschema import WOQLSchema # For Terminus X, use the following # client = WOQLClient("https://cloud.terminusdb.com/<Your Team>/") # client.connect(db="demo_workshop", team="<Your Team>", use_token=True) client = WOQLClient("http://127.0.0.1:6363/") client.connect(db="getting_started") data_schema = WOQLSchema() data_schema.from_db(client) # Update a document destiny_raw = client.get_document("Employee/001") destiny = data_schema.import_objects(destiny_raw) destiny.address.postcode = "PH12 3RP" destiny.address.street = "Lairg Road" destiny.address.street_num = 73 destiny.address.town = "Newbigging" client.update_document(destiny, commit_msg="Update Destiny") # Linking a new document to an old document Employee = data_schema.object.get("Employee") Address = data_schema.object.get("Address") Team = data_schema.object.get("Team")
#!/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'})
from terminusdb_client import WOQLClient from terminusdb_client import WOQLQuery as Q DB = WOQLClient("https://127.0.0.1:6363", insecure=True) DB.connect(user="******", account="admin", key="root", db="TodoMVC", insecure=True) from fastapi import FastAPI, HTTPException, Response, status from fastapi.responses import JSONResponse from typing import List, Dict from pydantic import BaseModel app = FastAPI() class Todo(BaseModel): id: str title: str completed: bool links: Dict class State(BaseModel): todos: List[Todo] links: Dict
# Rebase the current branch onto the specified remote branch # more info: https://terminusdb.github.io/terminusdb-client-python/woqlClient.html#terminusdb_client.WOQLClient.rebase client.rebase("main") if __name__ == "__main__": db_id = "Netflix" url = "netflix.csv" # TODO: change the team name team = "<TEAM_NAME>" client = WOQLClient("https://cloud.terminusdb.com/"+team) try: client.connect(team=team, use_token=True) client.create_database(db_id, label = "Netflix Graph", description = "Create a graph with Netflix data") except Exception: client.connect(db=db_id, team=team, use_token=True) schema.commit(client, commit_msg = "Adding Netflix Schema") insert_content_data(client, url) contents = client.query_document({"@type" : "Content"}, count=50) insert_user_data(list(contents)) print("\nQUERING DOCUMENTS\n") query_documents(client)
# Assumes database already exists. # openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt server_url = "https://127.0.0.1:6363" #server_url = "https://195.201.12.87:6366" db = "dbpedia" db_label = "DBpedia" db_comment = "Mapped object, property and types from DBpedia's core dataset" user = "******" account = "admin" key = "root" branches = ["literals", "types", "objects", "geo"] client = WOQLClient(server_url, insecure=True) client.connect(user=user, account=account, key=key, db=db, insecure=True) 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)
#!/usr/bin/python3 from terminusdb_client import WOQLClient from terminusdb_client import WOQLQuery as WQ import csv # Place the snippet from TerminusX here: # TerminusX db = "stock_index" client = WOQLClient(endpoint) client.connect(account=team,user=user,key=key) exists = client.get_database(db) if not exists: client.create_database(db, team, "Stock Exchange Index Data", "Data From Indexes", { '@base' : "terminusdb:///stock_index/", '@schema' : "terminusdb:///stock_index/schema#" }, True) schema = [ { '@type' : 'Class', '@id' : 'IndexRecord', '@key' : { '@type' : 'ValueHash' }, 'index' : 'xsd:string', 'date' : 'xsd:date', 'open' : 'xsd:decimal', 'high' : 'xsd:decimal', 'low' : 'xsd:decimal',
#!/usr/bin/python3 from terminusdb_client import WOQLQuery as WQ from terminusdb_client import WOQLClient server_url = "https://*****:*****@value': Word, '@language': 'en' }), WQ().triple("v:X", "ontolex:canonicalForm", "v:_Blank"), WQ().triple("v:X", "ontolex:sense", "v:Lemma"), WQ().triple("v:Lemma", "ontolex:isLexicalizedSenseOf", "v:PWN"), WQ().triple("v:PWN", "wn:definition", "v:_Blank2"), WQ().triple("v:PWN", "wn:partOfSpeech", "v:Part_Of_Speech"), WQ().triple("v:_Blank2", "rdf:value", "v:Definition"), ).execute(client) bindings = result['bindings'] definitions = [] for binding in bindings: definitions.append({ 'word': Word,
brewery = Brewery() brewery.name = row['name'] brewery.type_of = Brewery_Type[row['brewery_type']] brewery.address_of = address brewery.phone = str(row['phone']) brewery.website_url = row['website_url'] breweries.append(brewery) return breweries if __name__ == "__main__": db_id = "Brewery" url = "https://raw.githubusercontent.com/openbrewerydb/openbrewerydb/master/breweries.csv" client = WOQLClient("http://127.0.0.1:6363") client.connect() try: client.create_database(db_id, team="admin", label="Open Brewery Graph", description="Create a graph with brewery data") except Exception: client.set_db(db_id) client.insert_document(my_schema.to_dict(), graph_type="schema", commit_msg="I am checking in the schema") csv_info(url) insert_data(client, url) results = client.get_all_documents(graph_type="instance", count=10) print("\nRESULTS\n", list(results))
#!/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))