# Deep Query

Sometimes data can be spread across multiple pages, so clicking around to find the data you need can be tedious. Deep Query lets you create queries to find the information you need in a single click.

<figure><img src="/files/Ld70xgOsTZaoOMs3MbW3" alt=""><figcaption><p>Example of a Deep Query.</p></figcaption></figure>

## Query Language

Deep Query uses SPARQL for its query language. You'll need to familiarise yourself with its syntax. If you get the syntax wrong, the editor will provide hints to help resolve them.

* [SPARQL 1.1 Query Language Documentation](https://www.w3.org/TR/sparql11-query/)

## Example Query

The below query for Xenoblade Chronicles X lists all collectibles in Sylvalum along with their time and weather conditions. It uses a range of resources and SPARQL features such as:

* &#x20;"Blank nodes" using `[` and `]`for streamlined relationship traversal.
* `FILTER` to show only a specific region.
* `OPTIONAL`for showing the description when it's available. Without it, it will only show rows with descriptions.

{% tabs %}
{% tab title="Query" %}

```sparql
PREFIX s: <https://frontiernav.net/schema/>
PREFIX se: <https://frontiernav.net/schema/entity/>
PREFIX sr: <https://frontiernav.net/schema/relationship/>
PREFIX et: <https://frontiernav.net/wiki/xenoblade-chronicles-x/types/>
PREFIX e: <https://frontiernav.net/wiki/xenoblade-chronicles-x/entities/>
PREFIX p: <https://frontiernav.net/wiki/xenoblade-chronicles-x/properties/>

SELECT DISTINCT ?collectible ?rarity_name ?time ?weather ?description
WHERE {
  ?collectible se:type et:Collectible .
  ?collectible p:CollectibleArea-CONTAINS-Collectible [sr:start [p:Region-CONTAINS-CollectibleArea [sr:start ?region]]] .
  FILTER (?region=e:sylvalum)
  ?collectible p:Collectible-RARITY [sr:end ?rarity_name] .
  ?collectible p:Collectible-TIME [sr:end ?time] .
  ?collectible p:Collectible-WEATHER [sr:end ?weather] .
  OPTIONAL{?collectible p:description ?description .}
}
LIMIT 10
```

{% endtab %}

{% tab title="Result" %}

<table data-full-width="true"><thead><tr><th width="200">?name</th><th width="145">?rarity_name</th><th width="148">?time</th><th width="117">?weather</th><th>?description</th></tr></thead><tbody><tr><td>Taoman Acid</td><td>Rare</td><td>Early Morning</td><td>Rain</td><td>A chemical produced when rainwater reacts with an unknown airborne substance. It's harmless for living organisms, but can dissolve most inorganic matter.</td></tr><tr><td>Mizaria Celery</td><td>Prime</td><td>Early Morning</td><td>Rain</td><td>A rare type of celery that arises only from the crevices of deceased fauna soaked by incessant rain. Its taste depends entirely on the type of carcass from which it grew.</td></tr><tr><td>Camocloak</td><td>Unique</td><td>Early Morning</td><td>Rain</td><td>The cloth used to make this cloak imitates its surroundings. It looks to have been invented by an advanced civilization that has since gone extinct.</td></tr><tr><td>L-002 Dagoo Heat Ray</td><td>Prime</td><td>Early Morning</td><td>Rain</td><td>A high-energy laser mounted on the White Whale. It has since been decommissioned, but the scars of battle still stain its scorched barrel.</td></tr><tr><td>Rainy Cricket</td><td>Unique</td><td>Early Morning</td><td>Rain</td><td>A giant cricket that sleeps in the sand and rarely ventures above the surface. Aggressive in its short waking hours, it will attack on sight.</td></tr><tr><td>Antorus Rose</td><td>Rare</td><td>Early Morning</td><td>Rain</td><td>A rose with petals that can be used as dyes—which can then be combined to form any color on the spectrum. It is said that these vivid colors will never fade.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Resource Identifiers

All resources inside the database are referenced in SPARQL as "IRIs"; essentially URLs.

IRIs are long, so use `PREFIX` to shorten them. For convenience, the default query includes all prefixes.

Below is a list of resource types, how to reference them with prefixes, along with some examples.

## Wiki

```sparql
PREFIX w: <https://frontiernav.net/wiki/>
```

You can find the wiki identifier by the URL while at a wiki.

For example `w:xenoblade-chronicles-x` is the Xenoblade Chronicles X wiki.

### Query Multiple Wikis

By default `WHERE` uses the current wiki's resources. The below query adds a second wiki to its query using the `SERVICE` syntax. It lists collectibles in Xenoblade Chronicles which are also available in its Future Connected expansion.

```sparql
SELECT ?collectible
FROM w:xenoblade-chronicles
WHERE {
  ?collectible a et:Collectible .
  ?collectible p:name ?name .
  SERVICE w:xenoblade-chronicles-future-connected {
    [] xcfc_p:name ?name
  }
}
```

You can also use the `FROM NAMED` syntax.

```sparql
SELECT ?collectible
FROM w:xenoblade-chronicles
FROM NAMED w:xenoblade-chronicles-future-connected
WHERE {
  ?collectible a et:Collectible .
  ?collectible p:name ?name .
  GRAPH w:xenoblade-chronicles-future-connected {
    [] xcfc_p:name ?name
  }
}
```

When using multiple wikis, you will need to specify additional prefixes to access that wiki's resources.

```sparql
PREFIX xc1_p: <https://frontiernav.net/wiki/xenoblade-chronicles/properties/>
PREFIX xc2_p: <https://frontiernav.net/wiki/xenoblade-chronicles-2/properties/>
```

## Wiki Resources

The IRI for wiki resources are prefixed by the wiki identifier. For the examples below, replace `wiki-id` with the appropriate wiki identifier.

For example, Xenoblade Chronicles X's wiki identifier is `xenoblade-chronicles-x` so its resources looks like `<https://frontiernav.net/wiki/xenoblade-chronicles-x/properties/description>`.

## Entity Type, Category, Table

```sparql
PREFIX et: <https://frontiernav.net/wiki/wiki-id/types/>
```

You can find the entity type identifier by the URL while at a category page.

For example `t:Collectible` is the "Collectible" category. The below matcher will only match entities under the Collectible category.

```sparql
?collectible se:type t:Collectible .
```

## Property, Column

```sparql
PREFIX p: <https://frontiernav.net/wiki/wiki-id/properties/>
```

You can find the identifier for each property predicate by hovering over their columns in the database view.

For example, all tables have a `Name` column which has a `name` identifier, so its IRI is `<https://frontiernav.net/wiki/wiki-id/properties/name>`  or `p:name`.

## Entity, Row, Page

```sparql
PREFIX e: <https://frontiernav.net/wiki/wiki-id/entities/>
```

You can find the entity identifier by the URL while at an entity page.

Generally, accessing entities directly isn't too useful. If you don't know the entity identifier, you can match a property to find it.

```sparql
?collectible p:name ?name .
```

## Relationship

```sparql
PREFIX r: <https://frontiernav.net/wiki/wiki-id/relationships/>
```

You can access relationship data similar to entities using properties as predicates.

To traverse relationships, use "blank nodes" syntax to avoid creating intermediate variables for relationships. For example, we can go from a collectible, through its weather relationship property and get the weather's name in a single line.

```sparql
?collectible p:Collectible-WEATHER [sr:end [p:name ?weather]] .
```

## Relationship Type

```sparql
PREFIX rt: <https://frontiernav.net/wiki/wiki-id/relationshipTypes/>
```

Generally, you won't need to directly reference relationship types in your query.

## Schema Resources

The above resources are used to access wiki-specific resources. To access metadata such as identifiers, timestamps and pointers, you'll need to use schema resources.

## Database Schema

<pre class="language-sparql"><code class="lang-sparql"><strong>PREFIX s: &#x3C;https://frontiernav.net/schema/>
</strong></code></pre>

<table><thead><tr><th width="115">IRI</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>s:type</code></td><td>The schema type of the subject.</td><td><pre><code>s:entityType
s:relationshipType
s:entity
s:relationship
</code></pre></td></tr></tbody></table>

## Entity Schema

```sparql
PREFIX se: <https://frontiernav.net/schema/entity/>
```

<table><thead><tr><th width="145">IRI</th><th width="290">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>se:id</code></td><td>The entity indentifier</td><td><code>e:gem</code></td></tr><tr><td><code>se:type</code></td><td>The entity type of this entity.</td><td><code>et:Collectible</code></td></tr><tr><td><code>se:updatedAt</code></td><td>When this entity was last changed.</td><td><code>2025-01-01T00:00:00.000Z</code></td></tr></tbody></table>

## Relationship Schema

```sparql
PREFIX sr: <https://frontiernav.net/schema/relationship/>
```

<table><thead><tr><th width="145">Predicate</th><th width="290">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>sr:id</code></td><td>The relationship indentifier</td><td><code>r:gem__Collectible-RARITY__rare</code></td></tr><tr><td><code>sr:type</code></td><td>The relationship type of this relationship.</td><td><code>rt:Collectible-RARITY</code></td></tr><tr><td><code>sr:updatedAt</code></td><td>When this relationship was last changed.</td><td><code>2025-01-01T00:00:00.000Z</code></td></tr><tr><td><code>sr:start</code></td><td>The start entity of this relationship.</td><td><code>e:gem</code></td></tr><tr><td><code>sr:end</code></td><td>The end entity of this relationship.</td><td><code>e:rare</code></td></tr></tbody></table>

## Entity Type Schema

Not yet supported.

## Relationship Type Schema

Not yet supported.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.frontiernav.net/navigation/query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
