Cheuk Ting Ho
Developer advocate / Data Scientist - support open-source and building the community.
Β
Cheuk Ting Ho
Grab the slides: bit.ly/PythonicPizza
Β
Pythonic means code that doesn't just get the syntax right but that follows the conventions of the Python community and uses the language in the way it is intended to be used.
- Stackoverflow
Why can't I just do it in a for-loop?
for i in (i; i < items.length ; i++)
{
n = items[i];
... now do something
}
for i in items:
i.perform_action()
(i.some_attribute for i in items)
Β
Co-organizer ofΒ
Open Source contribution
Creator of
Volenteer of
Developer Advocate of
SELECT Name from TABLE where Person_ID = (SELECT mother from TABLE where Name="John")
SELECT Name from TABLE where Person_ID = (SELECT mother from TABLE WHERE Person_ID = (SELECT mother from TABLE where Name="John"))
WOQL.and(
WOQL.triple("v:Person", "mother", "v:MotherID"),
WOQL.triple("v:MotherID", "name", "v:MotherName"),
WOQL.triple("v:MotherID", "mother", "v:GrandmotherID"),
WOQL.triple("v:GrandmotherID", "name", "v:GrandmotherName"),
)
a Query Language Client for Pythonistas and Data Scientists
It comes with the Python Client, which you can pip install:
pip install terminus-client-python
**Newly added** Output to DataFrames
pip install terminus-client-python[dataframe]
woql.query_to_df(result)
Change the result returned form your query into pandas DataFrame
It let's you to "talk" to TerminusDB like this:
import woqlclient.woqlClient as woql
from woqlclient import WOQLQuery
server_url = "http://localhost:6363"
key = "root"
dbId = "pybike"
client = woql.WOQLClient()
client.connect(server_url, key)
client.createDatabase(dbId, "Bicycle Graph")
station = WOQLQuery().doctype("Station").label("Bike Station")
journey = WOQLQuery().doctype("Journey")
journey = journey.label("Journey")
journey = journey.property("start_station", "Station").label("Start Station")
journey = journey.property("end_station", "Station").label("End Station")
schema = WOQLQuery().when(True).woql_and(station, journey)
schema.execute(client)
Instead of this:
{
"when": [
{
"true": []
},
{
"and": [
{
"add_quad": [
"scm:Station",
"rdf:type",
"owl:Class",
"db:schema"
]
},
{
"add_quad": [
"scm:Station",
"rdfs:subClassOf",
"tcs:Document",
"db:schema"
]
},
{
"add_quad": [
"scm:Station",
"rdfs:label",
{
"@value": "Bike Station",
"@language": "en"
},
"db:schema"
]
},
{
"add_quad": [
"scm:end_station",
"rdf:type",
"owl:ObjectProperty",
"db:schema"
]
},
{
"add_quad": [
"scm:end_station",
"rdfs:range",
"scm:Station",
"db:schema"
]
},
{
"add_quad": [
"scm:end_station",
"rdfs:domain",
"scm:Journey",
"db:schema"
]
},
{
"and": [
{
"add_quad": [
"scm:start_station",
"rdf:type",
"owl:ObjectProperty",
"db:schema"
]
},
{
"add_quad": [
"scm:start_station",
"rdfs:range",
"scm:Station",
"db:schema"
]
},
{
"add_quad": [
"scm:start_station",
"rdfs:domain",
"scm:Journey",
"db:schema"
]
},
{
"and": [
{
"add_quad": [
"scm:Journey",
"rdf:type",
"owl:Class",
"db:schema"
]
},
{
"add_quad": [
"scm:Journey",
"rdfs:subClassOf",
"tcs:Document",
"db:schema"
]
},
{
"add_quad": [
"scm:Journey",
"rdfs:label",
{
"@value": "Journey",
"@language": "en"
},
"db:schema"
]
}
]
},
{
"add_quad": [
"scm:start_station",
"rdfs:label",
{
"@value": "Start Station",
"@language": "en"
},
"db:schema"
]
}
]
},
{
"add_quad": [
"scm:end_station",
"rdfs:label",
{
"@value": "End Station",
"@language": "en"
},
"db:schema"
]
}
]
}
]
}
Chaining:
WOQLQuery().doctype("journey").label("Journey)
or
Multi-parameters:
WOQLQuery().doctype(id="journey, label="Journey")
JavaScript: WOQL.and()
Python: WOQLQuery().and() ?
"and" is a key word, you dummy!
OK, woql_and then....π
WOQLQuery().woql_and()
also happened to: or, not, as, from...
Can we have this is Jupyter Notebook?Β
Load data from DataFrame
Many more fail-proof checks
e.g. check user inputs,
check database version etc...
Webinar:
Every Thursday 4pm UK time / 5pm CET
(sign up via meetup: https://www.meetup.com/TerminusDB-Community-London/)
Β
World of WoqlCraft:
Every Fridayday 4pm UK time / 5pm CET
Β
To get the newest updateπ:
Follow us on Twitter: @TerminusDB
Website: https://terminusdb.com/
Join the community at Discord:
https://discord.gg/Gvdqw97
We want to hear from you π
By Cheuk Ting Ho
Developer advocate / Data Scientist - support open-source and building the community.