|
|
@@ -53,6 +53,39 @@ def cycle_plants(cycle_uri: Optional[str] = None, limit: Optional[int] = 50) ->
|
|
|
return run_sparql(query)
|
|
|
|
|
|
|
|
|
+def describe_subject(subject_uri: str, limit: Optional[int] = 10) -> Dict[str, Any]:
|
|
|
+ """Direct SPARQL implementation (no HTTP self-calls)."""
|
|
|
+ bounded_limit = _safe_limit(limit, default=10)
|
|
|
+ query = f"""
|
|
|
+ SELECT ?predicate ?object ?objectLabel WHERE {{
|
|
|
+ <{subject_uri}> ?predicate ?object .
|
|
|
+ OPTIONAL {{ ?object rdfs:label ?objectLabel }}
|
|
|
+ }}
|
|
|
+ LIMIT {bounded_limit}
|
|
|
+ """
|
|
|
+ return run_sparql(query)
|
|
|
+
|
|
|
+
|
|
|
+def property_usage_statistics(property_uri: str, examples_limit: Optional[int] = 5) -> Dict[str, Any]:
|
|
|
+ """Direct SPARQL implementation (no HTTP self-calls)."""
|
|
|
+ bounded = _safe_limit(examples_limit, default=5)
|
|
|
+ count_query = f"""
|
|
|
+ SELECT (COUNT(DISTINCT ?subject) AS ?usageCount) WHERE {{
|
|
|
+ ?subject <{property_uri}> ?object .
|
|
|
+ }}
|
|
|
+ LIMIT {SPARQL_MAX_LIMIT}
|
|
|
+ """
|
|
|
+ usage_query = f"""
|
|
|
+ SELECT ?subject ?subjectLabel ?object ?objectLabel WHERE {{
|
|
|
+ ?subject <{property_uri}> ?object .
|
|
|
+ OPTIONAL {{ ?subject rdfs:label ?subjectLabel }}
|
|
|
+ OPTIONAL {{ ?object rdfs:label ?objectLabel }}
|
|
|
+ }}
|
|
|
+ LIMIT {bounded}
|
|
|
+ """
|
|
|
+ return {"count": run_sparql(count_query), "examples": run_sparql(usage_query)}
|
|
|
+
|
|
|
+
|
|
|
def latest_cycle_by_dates(limit: Optional[int] = 1) -> Dict[str, Any]:
|
|
|
"""Pick the latest cycle using available start/end dates.
|
|
|
|