Execute a SPARQL SELECT query against the DanNet triplestore.
This tool provides direct access to DanNet's RDF data through SPARQL queries.
The query is automatically prepended with common namespace prefix declarations,
so you can use short prefixes instead of full URIs in your queries.
============================================================
CRITICAL PERFORMANCE RULES (read before writing any query):
============================================================
1. ALWAYS start from a known entity URI or a word lookup — never scan the whole graph.
FAST: dn:synset-3047 wn:hypernym ?x .
SLOW: ?x wn:hypernym ?y . (scans every synset)
2. ALWAYS use DISTINCT for SELECT queries to avoid duplicate rows.
3. NEVER use FILTER(CONTAINS(...)) on labels across the whole graph.
SLOW: ?s rdfs:label ?l . FILTER(CONTAINS(?l, "hund"))
FAST: Use get_word_synsets("hund") first, then query specific synset URIs.
4. NEVER create cartesian products — every triple pattern must share a variable
with at least one other pattern.
SLOW: ?x a ontolex:LexicalConcept . ?y a ontolex:LexicalEntry . (cross join!)
5. ALWAYS add LIMIT (even if max_results caps it server-side, explicit LIMIT
lets the query engine optimize).
6. Use property paths for multi-hop traversals:
FAST: dn:synset-3047 wn:hypernym+ ?ancestor . (transitive closure)
FAST: ?entry ontolex:canonicalForm/ontolex:writtenRep "hund"@da . (path)
7. Prefer VALUES over FILTER for matching multiple known entities:
FAST: VALUES ?synset { dn:synset-3047 dn:synset-3048 } ?synset rdfs:label ?l .
SLOW: ?synset rdfs:label ?l . FILTER(?synset = dn:synset-3047 || ?synset = dn:synset-3048)
8. The triplestore contains BOTH DanNet (Danish, dn: namespace) AND the Open
English WordNet (en: namespace). Unanchored queries will scan both.
To restrict to Danish data, anchor on dn: URIs or use @da language tags.
============================================
FAST QUERY TEMPLATES (copy and adapt these):
============================================
# TEMPLATE 1: Find synsets for a Danish word (via word lookup)
SELECT DISTINCT ?synset ?label ?def WHERE {
?entry ontolex:canonicalForm/ontolex:writtenRep "WORD"@da .
?entry ontolex:sense/ontolex:isLexicalizedSenseOf ?synset .
?synset rdfs:label ?label .
OPTIONAL { ?synset skos:definition ?def }
}
# TEMPLATE 2: Get all properties of a known synset
SELECT ?p ?o WHERE {
dn:synset-NNNN ?p ?o .
} LIMIT 50
# TEMPLATE 3: Find hypernyms (broader concepts) of a known synset
SELECT DISTINCT ?hypernym ?label WHERE {
dn:synset-NNNN wn:hypernym ?hypernym .
?hypernym rdfs:label ?label .
}
# TEMPLATE 4: Find hyponyms (narrower concepts) of a known synset
SELECT DISTINCT ?hyponym ?label WHERE {
?hyponym wn:hypernym dn:synset-NNNN .
?hyponym rdfs:label ?label .
}
# TEMPLATE 5: Trace full hypernym chain (taxonomic ancestors)
SELECT DISTINCT ?ancestor ?label WHERE {
dn:synset-NNNN wn:hypernym+ ?ancestor .
?ancestor rdfs:label ?label .
}
# TEMPLATE 6: Find all relationships OF a known synset
SELECT DISTINCT ?rel ?target ?targetLabel WHERE {
dn:synset-NNNN ?rel ?target .
?target rdfs:label ?targetLabel .
FILTER(isURI(?target))
} LIMIT 50
# TEMPLATE 7: Find all relationships TO a known synset
SELECT DISTINCT ?source ?rel ?sourceLabel WHERE {
?source ?rel dn:synset-NNNN .
?source rdfs:label ?sourceLabel .
FILTER(isURI(?source))
} LIMIT 50
# TEMPLATE 8: Query multiple known synsets at once
SELECT DISTINCT ?synset ?label ?def WHERE {
VALUES ?synset { dn:synset-3047 dn:synset-3048 dn:synset-6524 }
?synset rdfs:label ?label .
OPTIONAL { ?synset skos:definition ?def }
}
# TEMPLATE 9: Find functional relations for a specific synset
SELECT DISTINCT ?rel ?target ?targetLabel WHERE {
dn:synset-NNNN ?rel ?target .
?target rdfs:label ?targetLabel .
VALUES ?rel { dns:usedFor dns:usedForObject wn:agent wn:instrument wn:causes }
}
# TEMPLATE 10: Find ontological type of a synset (stored as RDF Bag)
SELECT ?type WHERE {
dn:synset-NNNN dns:ontologicalType ?bag .
?bag ?pos ?type .
FILTER(STRSTARTS(STR(?pos), STR(rdf:_)))
}
============================================
KNOWN PREFIXES (automatically declared):
============================================
dn: (DanNet data), dns: (DanNet schema), dnc: (DanNet concepts),
wn: (WordNet relations), ontolex: (lexical model), skos: (definitions),
rdfs: (labels), rdf: (types), owl: (ontology), lexinfo: (morphology),
marl: (sentiment), dc: (metadata), ili: (interlingual index),
en: (English WordNet), enl: (English lemmas), cor: (Danish register)
Args:
query: SPARQL SELECT query string (prefixes will be automatically added)
timeout: Query timeout in milliseconds (default: 8000, max: 15000)
max_results: Maximum number of results to return (default: 100, max: 100)
distinct: Auto-apply DISTINCT to SELECT queries (default: True).
Set to False when you need duplicate rows, e.g. for frequency counts.
inference: Control model selection for query execution (default: None).
None = auto-detect: tries base model first, retries with inference
if SELECT results are empty (best for most queries).
True = force inference model: needed for inverse relations like
wn:hyponym, wn:holonym, etc. that are derived by OWL reasoning.
False = force base model only, no retry.
Returns:
Dict containing SPARQL results in standard JSON format:
- head: Query metadata with variable names
- results: Bindings array with variable-value mappings
Each value includes type (uri/literal) and language information when applicable
Note: Only SELECT queries are supported. The query is validated before execution.