A collection of practical, ready-to-use SPARQL queries for your Obsidian vault. Copy, paste, and adapt these examples to your needs!
- Basic Queries
- Task Management
- Project Organization
- Relationships
- Time-Based Queries
- Aggregation Examples
- Graph Construction
- Advanced Patterns
- Advanced Features (v2)
Get all notes in your vault:
SELECT ?asset ?label
WHERE {
?asset <https://exocortex.my/ontology/exo#Asset_label> ?label .
}
LIMIT 100Use Case: Quick overview of vault contents.
Find all unique entity classes in your vault:
SELECT DISTINCT ?class
WHERE {
?asset <https://exocortex.my/ontology/exo#Instance_class> ?class .
}Result Example:
ems__Taskems__Projectems__Area
Count how many assets of each type you have:
SELECT ?class (COUNT(?asset) AS ?count)
WHERE {
?asset <https://exocortex.my/ontology/exo#Instance_class> ?class .
}
GROUP BY ?class
ORDER BY DESC(?count)Use Case: Vault statistics dashboard.
List all non-archived tasks:
SELECT ?task ?label ?status
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
OPTIONAL { ?task <https://exocortex.my/ontology/ems#Task_status> ?status . }
FILTER NOT EXISTS {
?task <https://exocortex.my/ontology/exo#Asset_archived> ?archived .
FILTER(?archived = true || ?archived = "true" || ?archived = "archived")
}
}
ORDER BY ?labelUse Case: Daily task review.
Get tasks grouped by their status:
SELECT ?status (COUNT(?task) AS ?count)
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/ems#Task_status> ?status .
}
GROUP BY ?status
ORDER BY DESC(?count)Use Case: Sprint progress tracking.
Show all tasks currently being worked on:
SELECT ?task ?label ?project
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
?task <https://exocortex.my/ontology/ems#Task_status> "in-progress" .
OPTIONAL {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
}
ORDER BY ?project ?labelUse Case: Focus list for active work.
Find tasks with significant effort votes:
SELECT ?task ?label ?votes
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
FILTER(?votes > 5)
}
ORDER BY DESC(?votes)Use Case: Identify tasks requiring more time/resources.
Find orphaned tasks not assigned to any project:
SELECT ?task ?label ?status
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
OPTIONAL { ?task <https://exocortex.my/ontology/ems#Task_status> ?status . }
FILTER NOT EXISTS {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
}
ORDER BY ?labelUse Case: Cleanup and organization.
List tasks sorted by priority:
SELECT ?task ?label ?priority
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
OPTIONAL { ?task <https://exocortex.my/ontology/ems#Task_priority> ?priority . }
}
ORDER BY ?priority ?labelUse Case: Priority-based task planning.
Find tasks created recently (assuming you have a creation date property):
SELECT ?task ?label ?created
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
?task <https://exocortex.my/ontology/exo#created_at> ?created .
FILTER(?created > "2025-01-01")
}
ORDER BY DESC(?created)
LIMIT 20Use Case: Review recent additions.
List projects and count their tasks:
SELECT ?project ?projectLabel (COUNT(?task) AS ?taskCount)
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
OPTIONAL {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
}
GROUP BY ?project ?projectLabel
ORDER BY DESC(?taskCount)Use Case: Project workload overview.
Group projects by their parent area:
SELECT ?area ?areaLabel ?project ?projectLabel
WHERE {
?area <https://exocortex.my/ontology/exo#Instance_class> "ems__Area" .
?area <https://exocortex.my/ontology/exo#Asset_label> ?areaLabel .
?project <https://exocortex.my/ontology/ems#belongs_to_area> ?area .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
}
ORDER BY ?areaLabel ?projectLabelUse Case: Hierarchical organization view.
Find projects with at least one in-progress task:
SELECT DISTINCT ?project ?projectLabel
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?task <https://exocortex.my/ontology/ems#Task_status> "in-progress" .
}
ORDER BY ?projectLabelUse Case: Focus on active projects.
Find empty projects that might need cleanup:
SELECT ?project ?projectLabel
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
FILTER NOT EXISTS {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
}
ORDER BY ?projectLabelUse Case: Cleanup stale projects.
Calculate task completion percentage per project:
SELECT ?project ?projectLabel
(COUNT(?task) AS ?totalTasks)
(SUM(IF(?status = "done", 1, 0)) AS ?doneTasks)
(SUM(IF(?status = "done", 1, 0)) * 100 / COUNT(?task) AS ?completionRate)
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?task <https://exocortex.my/ontology/ems#Task_status> ?status .
}
GROUP BY ?project ?projectLabel
HAVING (COUNT(?task) > 0)
ORDER BY DESC(?completionRate)Use Case: Progress tracking dashboard.
Show full hierarchy for each task:
SELECT ?task ?taskLabel ?project ?projectLabel ?area ?areaLabel
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
OPTIONAL {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
OPTIONAL {
?project <https://exocortex.my/ontology/ems#belongs_to_area> ?area .
?area <https://exocortex.my/ontology/exo#Asset_label> ?areaLabel .
}
}
}
ORDER BY ?areaLabel ?projectLabel ?taskLabelUse Case: Full context view for tasks.
Find assets linked to a specific note (replace path):
SELECT ?related ?relatedLabel ?relationType
WHERE {
<vault://path/to/your/note.md> ?relationType ?related .
?related <https://exocortex.my/ontology/exo#Asset_label> ?relatedLabel .
}Use Case: Explore connections from a specific note.
Find notes that link to each other:
SELECT ?note1 ?note1Label ?note2 ?note2Label
WHERE {
?note1 <https://exocortex.my/ontology/exo#Asset_label> ?note1Label .
?note2 <https://exocortex.my/ontology/exo#Asset_label> ?note2Label .
?note1 <https://exocortex.my/ontology/exo#links_to> ?note2 .
?note2 <https://exocortex.my/ontology/exo#links_to> ?note1 .
FILTER(?note1 != ?note2)
}Use Case: Find tightly coupled concepts.
Find tasks scheduled for today (assuming time properties):
SELECT ?task ?taskLabel ?startTime
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#Effort_startTime> ?startTime .
FILTER(regex(?startTime, "2025-01-09"))
}
ORDER BY ?startTimeUse Case: Daily schedule planning.
Find long-running tasks (high effort time):
SELECT ?task ?taskLabel ?duration
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#Effort_duration_minutes> ?duration .
FILTER(?duration > 120)
}
ORDER BY DESC(?duration)Use Case: Identify time-intensive tasks.
Calculate duration between start and end timestamps using dateDiffMinutes:
PREFIX exo: <https://exocortex.my/ontology/exo#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
SELECT ?task ?label (exo:dateDiffMinutes(?start, ?end) AS ?durationMin) (exo:dateDiffHours(?start, ?end) AS ?durationHrs)
WHERE {
?task exo:Instance_class "ems__Task" .
?task exo:Asset_label ?label .
?task ems:Effort_startTimestamp ?start .
?task ems:Effort_endTimestamp ?end .
}
ORDER BY DESC(?durationMin)
LIMIT 10Use Case: Calculate task durations from timestamps when Effort_duration_minutes is not stored.
Calculate average sleep time using custom date functions:
PREFIX exo: <https://exocortex.my/ontology/exo#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
SELECT (SUM(?durationMin) AS ?totalMin) (COUNT(?durationMin) AS ?count)
WHERE {
SELECT (exo:dateDiffMinutes(?start, ?end) AS ?durationMin)
WHERE {
?task exo:Asset_prototype ?proto .
?task ems:Effort_startTimestamp ?start .
?task ems:Effort_endTimestamp ?end .
FILTER(CONTAINS(STR(?proto), "sleep-prototype-uuid"))
FILTER(CONTAINS(?start, "Nov 25 2025")) # Filter by date
}
}Use Case: Calculate average duration for repeated activities (sleep, exercise, etc.). Divide totalMin by count for the average.
Sum effort votes per project:
SELECT ?project ?projectLabel (SUM(?votes) AS ?totalVotes)
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
}
GROUP BY ?project ?projectLabel
ORDER BY DESC(?totalVotes)Use Case: Resource allocation planning.
Calculate average effort per status:
SELECT ?status (AVG(?votes) AS ?avgVotes) (COUNT(?task) AS ?taskCount)
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/ems#Task_status> ?status .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
}
GROUP BY ?status
ORDER BY DESC(?avgVotes)Use Case: Effort estimation insights.
Count tasks across all areas (including nested projects):
SELECT ?area ?areaLabel (COUNT(?task) AS ?taskCount)
WHERE {
?area <https://exocortex.my/ontology/exo#Instance_class> "ems__Area" .
?area <https://exocortex.my/ontology/exo#Asset_label> ?areaLabel .
?project <https://exocortex.my/ontology/ems#belongs_to_area> ?area .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
GROUP BY ?area ?areaLabel
ORDER BY DESC(?taskCount)Use Case: Workload distribution across areas.
Build a graph of task→project relationships:
CONSTRUCT {
?task <http://example.org/in_project> ?project .
?task <http://example.org/has_label> ?taskLabel .
?project <http://example.org/has_label> ?projectLabel .
}
WHERE {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
}Use Case: Export relationships for visualization tools.
Create direct task→area relationships (bypassing projects):
CONSTRUCT {
?task <http://example.org/belongs_to_area> ?area .
}
WHERE {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?project <https://exocortex.my/ontology/ems#belongs_to_area> ?area .
}Use Case: Simplify hierarchical queries.
Add inferred priority classes based on votes:
CONSTRUCT {
?task <http://example.org/priority_class> ?priorityClass .
}
WHERE {
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
BIND(
IF(?votes > 10, "critical",
IF(?votes > 5, "high",
IF(?votes > 2, "medium", "low")
)
) AS ?priorityClass
)
}Use Case: Automatic prioritization.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?task ?label
WHERE {
?task rdf:type ems:Task .
?task exo:Asset_label ?label .
}Use Case: Find all tasks using standard RDF vocabulary instead of ExoRDF-specific predicates.
Performance: O(n) - Same as exo__Instance_class queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?asset ?type ?label
WHERE {
?asset rdf:type ?type .
?type rdfs:subClassOf* exo:Asset .
?asset exo:Asset_label ?label .
}
LIMIT 100Use Case: Find ALL assets (tasks, projects, areas) regardless of specific type, using transitive subclass inference.
Performance: O(n×m) where m is class hierarchy depth. Use LIMIT to avoid large result sets.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?class ?superClass
WHERE {
?class rdfs:subClassOf ?superClass .
}Use Case: Explore the Exocortex class hierarchy to understand asset type relationships.
Result Example:
ems:Task rdfs:subClassOf exo:Asset
ems:Project rdfs:subClassOf exo:Asset
ems:Area rdfs:subClassOf exo:Asset
exo:Asset rdfs:subClassOf rdfs:Resource
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?asset ?label
WHERE {
?asset rdfs:isDefinedBy <https://exocortex.my/ontology/ems/> .
?asset exo:Asset_label ?label .
}Use Case: Find all assets defined by a specific ontology (EMS, IMS, etc.).
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?type (COUNT(?asset) AS ?count)
WHERE {
?asset rdf:type ?type .
?type rdfs:subClassOf* exo:Asset .
}
GROUP BY ?type
ORDER BY DESC(?count)Use Case: Statistics on asset distribution across types.
Performance: O(n) with grouping overhead.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
SELECT ?superClass
WHERE {
ems:Task rdfs:subClassOf+ ?superClass .
}Use Case: Discover class hierarchy for a specific type.
Result Example:
exo:Asset
rdfs:Resource
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?task ?label ?ontology
WHERE {
?task rdf:type ems:Task .
?task rdfs:label ?label .
?task rdfs:isDefinedBy ?ontology .
}
LIMIT 50Use Case: Combine multiple standard RDF/RDFS properties in one query.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?property ?superProperty
WHERE {
?property rdfs:subPropertyOf+ rdfs:label .
}Use Case: Find all properties that are subproperties of rdfs:label (transitively).
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?task ?label ?status
WHERE {
# Use RDF/RDFS for type
?task rdf:type ems:Task .
# Use ExoRDF for specific properties
?task exo:Asset_label ?label .
?task ems:Task_status ?status .
FILTER(?status = "in-progress")
}Use Case: Mix standard RDF/RDFS predicates with domain-specific ExoRDF predicates.
Best Practice: Use RDF/RDFS for interoperability, ExoRDF for performance-critical queries.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
PREFIX exo: <https://exocortex.my/ontology/exo#>
ASK {
?task rdf:type ems:Task .
ems:Task rdfs:subClassOf exo:Asset .
}Use Case: Validate that tasks are properly classified as assets via class hierarchy.
Result: true or false
Find tasks incorrectly assigned to multiple projects:
SELECT ?task ?taskLabel (COUNT(?project) AS ?projectCount)
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
GROUP BY ?task ?taskLabel
HAVING (COUNT(?project) > 1)Use Case: Data validation and cleanup.
Find all descendants of an area (projects + tasks):
SELECT ?descendant ?descendantLabel ?type
WHERE {
{
<vault://Areas/My-Area.md> ^<https://exocortex.my/ontology/ems#belongs_to_area> ?descendant .
?descendant <https://exocortex.my/ontology/exo#Asset_label> ?descendantLabel .
BIND("project" AS ?type)
} UNION {
<vault://Areas/My-Area.md> ^<https://exocortex.my/ontology/ems#belongs_to_area> / ^<https://exocortex.my/ontology/ems#belongs_to_project> ?descendant .
?descendant <https://exocortex.my/ontology/exo#Asset_label> ?descendantLabel .
BIND("task" AS ?type)
}
}Use Case: Complete area breakdown.
Search for assets by label content:
SELECT ?asset ?label
WHERE {
?asset <https://exocortex.my/ontology/exo#Asset_label> ?label .
FILTER(regex(?label, "machine learning", "i"))
}
LIMIT 50Use Case: Quick search across vault.
Complex multi-condition query:
SELECT ?task ?taskLabel ?status ?votes ?project
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#Task_status> ?status .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
FILTER(?status = "in-progress" || ?status = "backlog")
FILTER(?votes > 3)
FILTER(regex(?taskLabel, "urgent|important", "i"))
FILTER NOT EXISTS {
?task <https://exocortex.my/ontology/exo#Asset_archived> ?archived .
}
}
ORDER BY DESC(?votes) ?taskLabel
LIMIT 20Use Case: Highly specific task filtering.
The following features were added in SPARQL Engine v2 for more powerful queries.
BIND creates computed values in your query.
Create a formatted label:
SELECT ?task ?label ?displayLabel
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
BIND(CONCAT("Task: ", ?label) AS ?displayLabel)
}Use Case: Format labels for display.
Classify tasks by effort votes:
SELECT ?task ?label ?votes ?priority
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
BIND(
IF(?votes > 10, "critical",
IF(?votes > 5, "high",
IF(?votes > 2, "medium", "low")
)
) AS ?priority
)
}
ORDER BY DESC(?votes)Use Case: Auto-classify tasks by urgency.
Extract parts of URIs:
SELECT ?task ?label ?folder
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
BIND(REPLACE(STR(?task), "^.*/([^/]+)/[^/]+$", "$1") AS ?folder)
}Use Case: Group assets by folder.
Test for the presence or absence of patterns.
Tasks that have blockers:
SELECT ?task ?label
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
FILTER EXISTS {
?task <https://exocortex.my/ontology/ems#Task_blockedBy> ?blocker .
}
}Use Case: Identify tasks waiting on dependencies.
Tasks with no blockers:
SELECT ?task ?label
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?label .
FILTER NOT EXISTS {
?task <https://exocortex.my/ontology/ems#Task_blockedBy> ?blocker .
}
}
ORDER BY ?labelUse Case: Find tasks ready to start.
Find projects that have at least one high-priority task:
SELECT ?project ?projectLabel
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
FILTER EXISTS {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
FILTER(?votes > 5)
}
}Use Case: Prioritize projects with urgent tasks.
Navigate relationships with path expressions.
Find all ancestors of a task (one or more levels):
SELECT ?task ?taskLabel ?ancestor ?ancestorLabel
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#belongs_to_project>+ ?ancestor .
?ancestor <https://exocortex.my/ontology/exo#Asset_label> ?ancestorLabel .
}Use Case: Full hierarchy traversal.
Find all ancestors including zero levels (self):
SELECT ?project ?related
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/ems#belongs_to_area>* ?related .
}Use Case: Include node itself in results.
Find direct or no parent:
SELECT ?task ?parent
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/ems#belongs_to_project>? ?parent .
}Use Case: Optional single-step relationships.
Match tasks or projects:
SELECT ?asset ?label
WHERE {
?asset (<https://exocortex.my/ontology/ems#belongs_to_project>|<https://exocortex.my/ontology/ems#belongs_to_area>) ?parent .
?asset <https://exocortex.my/ontology/exo#Asset_label> ?label .
}Use Case: Match multiple relationship types.
Find task's area via project (two-hop traversal):
SELECT ?task ?taskLabel ?area ?areaLabel
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#belongs_to_project>/<https://exocortex.my/ontology/ems#belongs_to_area> ?area .
?area <https://exocortex.my/ontology/exo#Asset_label> ?areaLabel .
}Use Case: Multi-hop relationship navigation.
Find all tasks belonging to a project (reverse direction):
SELECT ?project ?projectLabel ?task ?taskLabel
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
?project ^<https://exocortex.my/ontology/ems#belongs_to_project> ?task .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
}Use Case: Reverse relationship traversal.
Find all descendants of an area (projects and tasks):
SELECT ?area ?areaLabel ?descendant ?descendantLabel
WHERE {
?area <https://exocortex.my/ontology/exo#Instance_class> "ems__Area" .
?area <https://exocortex.my/ontology/exo#Asset_label> ?areaLabel .
?area (^<https://exocortex.my/ontology/ems#belongs_to_area>/^<https://exocortex.my/ontology/ems#belongs_to_project>?)+ ?descendant .
?descendant <https://exocortex.my/ontology/exo#Asset_label> ?descendantLabel .
}Use Case: Complete area breakdown.
Use queries within queries for complex analysis.
Find projects with task counts above average:
SELECT ?project ?projectLabel ?taskCount
WHERE {
{
SELECT ?project (COUNT(?task) AS ?taskCount)
WHERE {
?project <https://exocortex.my/ontology/exo#Instance_class> "ems__Project" .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
}
GROUP BY ?project
}
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
FILTER(?taskCount > 5)
}
ORDER BY DESC(?taskCount)Use Case: Filter by aggregated values.
Find the 3 highest-voted tasks per project:
SELECT ?project ?projectLabel ?task ?taskLabel ?votes ?rank
WHERE {
{
SELECT ?project ?task ?votes (COUNT(?t2) + 1 AS ?rank)
WHERE {
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
OPTIONAL {
?t2 <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?t2 <https://exocortex.my/ontology/ems#Effort_votes> ?v2 .
FILTER(?v2 > ?votes)
}
}
GROUP BY ?project ?task ?votes
HAVING (COUNT(?t2) + 1 <= 3)
}
?project <https://exocortex.my/ontology/exo#Asset_label> ?projectLabel .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
}
ORDER BY ?projectLabel ?rankUse Case: Dashboard showing top priorities per project.
Find tasks with above-average votes for their project:
SELECT ?task ?taskLabel ?votes ?projectAvg
WHERE {
?task <https://exocortex.my/ontology/exo#Instance_class> "ems__Task" .
?task <https://exocortex.my/ontology/exo#Asset_label> ?taskLabel .
?task <https://exocortex.my/ontology/ems#Effort_votes> ?votes .
?task <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
{
SELECT ?project (AVG(?v) AS ?projectAvg)
WHERE {
?t <https://exocortex.my/ontology/ems#belongs_to_project> ?project .
?t <https://exocortex.my/ontology/ems#Effort_votes> ?v .
}
GROUP BY ?project
}
FILTER(?votes > ?projectAvg)
}
ORDER BY DESC(?votes)Use Case: Find outliers within their context.
Exocortex provides custom SPARQL functions beyond the standard specification.
Look up an entity directly by its UUID without scanning:
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?asset ?label
WHERE {
BIND(exo:byUUID("550e8400-e29b-41d4-a716-446655440000") AS ?asset)
?asset exo:Asset_label ?label .
}Use Case: O(1) lookup when you know the UUID. ~100x faster than FILTER(CONTAINS(...)).
Get all properties of a specific note:
PREFIX exo: <https://exocortex.my/ontology/exo#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
SELECT ?label ?status ?votes ?createdAt
WHERE {
BIND(exo:byUUID("550e8400-e29b-41d4-a716-446655440000") AS ?task)
?task exo:Asset_label ?label .
OPTIONAL { ?task ems:Effort_status ?status }
OPTIONAL { ?task ems:Effort_votes ?votes }
OPTIONAL { ?task exo:Asset_createdAt ?createdAt }
}Use Case: Fetch complete entity details when UUID is known.
Use a variable containing a UUID string:
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?asset ?label
WHERE {
BIND("550e8400-e29b-41d4-a716-446655440000" AS ?uuid)
BIND(exo:byUUID(?uuid) AS ?asset)
?asset exo:Asset_label ?label .
}Use Case: Pass UUID from external source (e.g., API integration).
Look up a task and find its parent project:
PREFIX exo: <https://exocortex.my/ontology/exo#>
PREFIX ems: <https://exocortex.my/ontology/ems#>
SELECT ?task ?taskLabel ?project ?projectLabel
WHERE {
BIND(exo:byUUID("550e8400-e29b-41d4-a716-446655440000") AS ?task)
?task exo:Asset_label ?taskLabel .
?task ems:belongs_to_project ?project .
?project exo:Asset_label ?projectLabel .
}Use Case: Navigate relationships starting from known UUID.
Look up multiple entities by UUID in a single query:
PREFIX exo: <https://exocortex.my/ontology/exo#>
SELECT ?entity ?label
WHERE {
VALUES ?uuid {
"uuid-1"
"uuid-2"
"uuid-3"
}
BIND(exo:byUUID(?uuid) AS ?entity)
FILTER(BOUND(?entity))
?entity exo:Asset_label ?label .
}Use Case: Resolve multiple UUIDs efficiently in one query.
Replace URIs with your actual property names:
<https://exocortex.my/ontology/exo#Asset_label> → Your property URI
"ems__Task" → Your class nameAdd LIMIT to large queries:
SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
LIMIT 100- Start with specific patterns (e.g., filter by class first)
- Use
OPTIONALsparingly - Avoid
FILTER NOT EXISTSon large datasets
Test queries in stages:
- Get basic pattern working
- Add filters one by one
- Add aggregations last
- Learn SPARQL: Read the User-Guide.md
- Optimize Queries: Check Performance-Tips.md
- Extend Functionality: See Developer-Guide.md
Share Your Queries! Submit your useful queries via GitHub Discussions to help the community!