def test_chained_property_method(self): woqlObject = WOQLQuery().doctype("Journey") woqlObject = woqlObject.property("start_station", "Station").label("Start Station") woqlObject2 = WOQLQuery().doctype("Journey") woqlObject2.property("start_station", "Station").label("Start Station") assert woqlObject.json() == woqlObject2.json()
def create_schema(client): ''' Build the schema. For this demo, there is a base document to capture ephemeral events. There is then a derived document for Voyage events, and Berth events. Note especially that ANY property common to all the derived documents MUST be put in the base: Here, the 'ship' property is common to both 'Voyage' and 'Berth' and so must be in the 'Ship_Event' document. If instead it is placed in 'Voyage' and also in 'Base', then TerminusDB will complain with a "class subsumption" error... :param client: TerminusDB server handle ''' base = WOQLQuery().doctype("Ship_Event").label("Ship Event").description("An ephemeral") base.property("ship", "string").label("Ship Name") base.property("start", "dateTime").label("Existed From") # try "dateTime rather than string? base.property("end", "dateTime").label("Existed To") voyage = WOQLQuery().add_class("Voyage").label("Voyage").description("Ship movement").parent("Ship_Event") voyage.property("route", "string").label("Route") docking = WOQLQuery().add_class("Docking").label("Docking").description("A ship docked at a berth").parent("Ship_Event") docking.property("berth", "string").label("Berth") schema = WOQLQuery().when(True).woql_and( base, docking, voyage ) try: print("[Building schema..]") with wary.suppress_Terminus_diagnostics(): schema.execute(client) except Exception as e: wary.diagnose(e)
def extract_data(data, id='event/'): if type(data) == dict: data_type = data['type'] WOQLObj = WOQLQuery().insert('doc:' + id, data_type) if data_type == 'https://schema.org/DateTime': date_value = {"@value": data['value'], "@type": "xsd:sting"} #type_casting = [WOQLQuery().eq('v:date_value', date_value), WOQLQuery().typecast('v:date_value', 'xsd:dateTime', 'v:eventDate')] #execution_queue.append(WOQLQuery().woql_and(*type_casting)) execution_queue.append( WOQLObj.property('dateTimeValue', date_value)) return for prop in data['properties']: extract_data(data['properties'][prop], id + prop + '/') WOQLObj = WOQLObj.property('http://schema.org/' + prop, 'doc:' + id + prop + '/') execution_queue.append(WOQLObj) else: if '://' in data: WOQLObj = WOQLQuery().insert('doc:' + id, 'http://schema.org/URL') else: WOQLObj = WOQLQuery().insert('doc:' + id, 'http://schema.org/Text') data_obj = {"@value": data, "@type": "xsd:string"} execution_queue.append(WOQLObj.property('stringValue', data_obj))
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)