def load_csvs(client, csvs): """Load the CSVs as input Parameters ========== client : a WOQLClient() connection csvs : a dict of all csvs to be input """ for key, url in csvs.items(): csv = get_csv_variables(url) wrangles = get_wrangles() inputs = WOQLQuery().woql_and(csv, *wrangles) inserts = get_inserts() answer = WOQLQuery().when(inputs, inserts) answer.execute(client, f"Adding {url} into database")
def create_schema(client): """The query which creates the schema Parameters - it uses variables rather than the fluent style as an example ========== client : a WOQLClient() connection """ base = WOQLQuery().doctype("EphemeralEntity", label="Ephemeral Entity", description="An entity that has a lifespan") base.property("lifespan_start", "dateTime", label="Existed From") base.property("lifespan_end", "dateTime", label="Existed To") country = WOQLQuery().add_class("Country").label("Country").description("A nation state").parent("EphemeralEntity") country.property("iso_code", "string", label="ISO Code") country.property("fip_code", "string", label="FIP Code") airline = WOQLQuery().add_class("Airline").label("Airline").description("An operator of airplane flights").parent("EphemeralEntity") airline = airline.property("registered_in", "scm:Country", label="Registered In"), airport = WOQLQuery().add_class("Airport").label("Airport").description("An airport where flights terminate").parent("EphemeralEntity") airport.property("situated_in", "Country", label="Situated In"), flight = WOQLQuery().add_class("Flight").label("Flight").description("A flight between airports").parent("EphemeralEntity") flight.property("departs", "Airport", label="Departs") flight.property("arrives", "Airport", label="Arrives") flight.property("operated_by", "Airline", label="Operated By") schema = WOQLQuery().woql_and(base, country, airline, airport, flight) return schema.execute(client, "Creating schema for flight data")
def create_schema_add_ons(client, queries): new_queries = [] for query_list in queries: if len(query_list) > 1: new_queries.append(WOQLQuery().woql_and(*query_list)) elif len(query_list) == 1: new_queries.append(query_list[0]) result_query = WOQLQuery().woql_and(*new_queries) return result_query.execute(client)
def create_schema(client): """The query which creates the schema Parameters ========== client : a WOQLClient() connection """ schema = WOQLQuery().woql_and( WOQLQuery().doctype("Party", label="Party", description="Political Party"), WOQLQuery().doctype("Representative", label="Representative", description="An elected member Dublin city council"). property("member_of", "Party", label="Member of").cardinality(1), WOQLQuery().doctype("Similarity", label="Similarity"). property("similarity", "decimal", label="Similarity"). property("similar_to", "Representative", label="Similar To").cardinality(2) ) return schema.execute(client, "Creating schema for Dublin voting data")
def create_schema_objects(client, queries): result_query = WOQLQuery().woql_and(*queries) return result_query.execute(client)