Created
September 24, 2021 13:40
-
-
Save simongray/c0d756104ba581d4438c69acdaa20395 to your computer and use it in GitHub Desktop.
Query the DanNet pre-release dataset using SPARQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from rdflib import Graph | |
# Fetch data | |
url = 'https://github.com/kuhumcst/DanNet/releases/download/v2021.9.24/dannet-expanded.ttl' | |
r = requests.get(url) | |
open('dannet-expanded.ttl', 'wb').write(r.content) | |
# Build a graph | |
g = Graph() | |
g.parse('dannet-expanded.ttl') | |
# Query the graph | |
usage_query = """ | |
SELECT ?sense ?usage_str | |
WHERE { | |
?sense ontolex:usage ?usage . | |
?usage rdf:value ?usage_str . | |
} | |
""" | |
result = g.query(usage_query) | |
# Print results | |
for row in result: | |
print(f"{row.sense} -> {row.usage_str}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
requests
andrdflib
packages to be installed, e.g runpip install requests rdflib
beforehand.