Skip to content

Instantly share code, notes, and snippets.

View davidsbatista's full-sized avatar
🏗️
building stuff :)

David S. Batista davidsbatista

🏗️
building stuff :)
View GitHub Profile
@davidsbatista
davidsbatista / gist:e0b19d8e1a93ca6f460e57735051cd6f
Last active March 19, 2023 14:00
Get the "known as" for legal entity types in different countries, e.g.: "LLC", "Inc.", "GmbH", "Ldt."
## Full query gives timeout
SELECT ?entity ?entityLabel
WHERE
{
?item_type wdt:P279 wd:Q1269299 . # Item's type is a subclass of type of business entity
?business_entity wdt:P31 ?item_type .
?entity rdfs:label ?entityLabel .
?entity skos:altLabel ?alternativeNames .
FILTER (lang(?alternativeNames) = "de")
@davidsbatista
davidsbatista / gist:365d09fb6578c6b0a73dae0a0d2a3f81
Created January 19, 2023 20:27
plot on map headquarters of companies in the german stock market (query.wikidata.org)
#defaultView:Map
SELECT DISTINCT ?companyLabel ?company ?headquarters ?headquartersLabel ?coordinates WHERE {
VALUES ?stock_markets {wd:Q155718 wd:Q378967 wd:Q595622 wd:Q874430} .
?company wdt:P361 ?stock_markets .
?company rdfs:label ?companyLabel . FILTER(LANG(?companyLabel) = "en")
?company wdt:P159 ?headquarters.
?headquarters rdfs:label ?headquartersLabel . FILTER(LANG(?headquartersLabel) = "en")
?headquarters wdt:P625 ?coordinates
}
ORDER BY ASC(?companyLabel)
@davidsbatista
davidsbatista / gist:30fdead90869539114bb892c2f22ab6c
Created July 26, 2022 07:59
Electric power dams in Portugal
#defaultView:Map
SELECT DISTINCT ?dam ?name ?elevation ?coords WHERE {
# ?dam wdt:P31/wdt:P279* wd:Q12323 .
?dam wdt:P31/wdt:P279* wd:Q15911738 . # only hidroelectric cpower
?dam wdt:P17 wd:Q45 . # only located in Portugal
?dam rdfs:label ?name FILTER(LANG(?name) = "pt") .
?dam p:P2044 ?elevation_sea_level .
?elevation_sea_level ps:P2044 ?elevation .
?dam p:P625 ?coordinataes .
?coordinataes ps:P625 ?coords;
@davidsbatista
davidsbatista / gist:3eca48c03865413f724fb703dea49244
Last active January 19, 2023 23:00
Get all dams in Portugal with the latitude and longitude
#defaultView:Map
SELECT DISTINCT ?dam ?coords ?lat ?long WHERE {
?dam wdt:P31/wdt:P279* wd:Q12323 .
?dam wdt:P17 wd:Q45 .
?dam p:P625 ?coordinataes .
?coordinataes ps:P625 ?coords;
psv:P625 [
wikibase:geoLatitude ?lat;
wikibase:geoLongitude ?long
] .
@davidsbatista
davidsbatista / gist:ea5bf3a984cfa6e5ec0f27440a008f04
Created March 17, 2022 19:50
Number of connections served for a given airport
SELECT ?iata_code ?airport_name (COUNT(?connectsairport) AS ?nr_connections)
WHERE
{
VALUES ?airport { wd:Q17480 wd:Q9694 wd:Q160556 wd:Q403671}
?airport wdt:P238 ?iata_code.
?airport rdfs:label ?airport_name.
OPTIONAL {
?airport wdt:P81 ?connectsairport.
}
FILTER(LANG(?airport_name) = "en")
@davidsbatista
davidsbatista / gist:3f9310a25274b3e2063bee3e1f5f877d
Created March 8, 2022 13:14
capitals of counties in the USA, with state and state code, filtered by population
SELECT DISTINCT ?capital ?capital_label ?pop ?code WHERE {
?county wdt:P31/wdt:P279* wd:Q47168 .
?county wdt:P36 ?capital .
?capital rdfs:label ?capital_label .
?capital wdt:P1082 ?pop .
?county wdt:P131 ?state .
?state wdt:P31 wd:Q35657 .
?state wdt:P300 ?code .
FILTER(LANG(?capital_label) = "en")
FILTER(?pop >= 50000).
@davidsbatista
davidsbatista / gist:b9dc19b762b0f16f1ea754124f5a6024
Created February 25, 2022 12:52
Get train station, ibnr, and train station type associated to each IBNR
SELECT DISTINCT ?station_label ?ibnr_stmt ?x ?ibnr_type_stmnt ?label WHERE
{
wd:Q376589 rdfs:label ?station_label.
wd:Q376589 p:P954 ?ibnr_stmt.
?ibnr_stmt ps:P954 ?x.
?ibnr_stmt pq:P518 ?ibnr_type_stmnt.
?ibnr_type_stmnt rdfs:label ?label.
FILTER(lang(?station_label) = 'de')
FILTER(lang(?label) = 'de')
}
@davidsbatista
davidsbatista / gist:bf103dfcb0cbc64741bc821809f70525
Last active January 19, 2023 22:38
Get airports and cities/locations that they serve
SELECT ?iata_code ?places_served_label(LANG(?places_served_label) AS ?places_served_label_lang) ?country_code
WHERE {
?item wdt:P238 ?iata_code.
?item wdt:P931 ?places_served.
?places_served rdfs:label ?places_served_label.
?places_served wdt:P17 ?country.
?country wdt:P297 ?country_code.
FILTER( LANG(?places_served_label) = "de" || LANG(?places_served_label) = "en").
}
@davidsbatista
davidsbatista / sklearn confusion matrix
Created April 16, 2019 14:59
sklearn confusion matrix
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.utils.multiclass import unique_labels
def plot_confusion_matrix(y_true, y_pred, classes, normalize=False, title=None, cmap=plt.cm.Blues):
"""
@davidsbatista
davidsbatista / SyntaxNet-PT.MD
Last active March 25, 2017 01:03
Setting up Google SyntaxNet for Portuguese