def create_schema(client): # creating objects doctype movie_obj = WOQLQuery().doctype("Movie", label="Movie Title", description="Movie short description") person_obj = WOQLQuery().doctype("Person", label="Name of the person") genre_obj = WOQLQuery().doctype("Genre", label="Genre of a movie") # adding property movie_obj = (movie_obj.property( "Director", "Person", label="Dirctor of the movie").property( "Cast", "Person", label="Cast of the movie").property( "MovieGenre", "Genre", label="Genre of the movie").property( "Year", "xsd:integer", label="Year of release").property( "Runtime", "xsd:integer", label="Runtime", description="Runtime of the movie in mins").property( "Rating", "xsd:decimal", label="Rating of the movie", description="User rating for the movie 0-10"). property("Votes", "xsd:integer", label="Votes", description="Number of votes")) WOQLQuery().woql_and(movie_obj, genre_obj, person_obj).execute( client, "Building Schema for the movie graph")
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.property("registered_in", "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().when(True).woql_and(base, country, airline, airport, flight) return schema.execute(client)