
Part 3 of 5. The ontology from part 2 becomes 222 triples in three Turtle files. This post reads both demo journeys as Turtle, shows where the filter value ends up, and runs the queries that make the model worth having: walking a journey, a trap with shared dimensions, and an impact query that goes from a data layer variable all the way up to the business requirement it serves. It closes with why I stopped writing Turtle by hand.
Your web team wants to clean up the data layer and rename digitalData.page.pageInfo.name. Harmless?
That variable feeds Page name. Page name identifies two steps of the login journey. The last of those steps rolls up to the monthly login rate. And the monthly login rate exists because someone once asked how many customers log in each month. Four hops from a JavaScript variable to a business question.
In part 2 that chain was a diagram. In this post it becomes text files on disk, and the question becomes one SPARQL query you can run on your laptop. Everything here comes from the GitHub repo, and every query result shown is real output from the bundled demo data.
1. Three files, one graph
The whole graph lives in three plain-text files. No database, no server, nothing to install beyond a Python library.
| File | What it holds | Triples |
|---|---|---|
ontology/martech-ontology.ttl | The schema from part 2: classes, predicates, their comments | 97 |
examples/ecommerce-funnel-instances.ttl | The ecommerce purchase journey | 82 |
examples/login-journey-instances.ttl | The customer login journey | 43 |
The split follows how often things change. The ontology changes rarely and I own it. Instance files change every time someone documents a journey or a component, and they are owned by whoever knows that journey best. Keeping them apart means a new journey never touches the schema, and a schema change shows up as its own diff.
Once loaded, though, the files disappear. RDF has no concept of a table or a file boundary. Every triple goes into one pool, and two triples connect whenever they share a URI. There are no join keys to define and no import order to get right:
from pathlib import Path
from rdflib import Graph
g = Graph()
g.parse("ontology/martech-ontology.ttl")
for f in sorted(Path("examples").glob("*-instances.ttl")):
g.parse(f)
print(len(g)) # 222
rdflib (the standard Python library for RDF) does the parsing and runs the SPARQL later. That is the entire setup.
The flip side of “connected by URI” is that the URI is the identity. Ontology terms live under https://example.org/martech/ontology/, and each journey gets its own data namespace: .../data/ecommerce/ and .../data/login/. The base is a placeholder; swap it for a domain you control. The consequence matters later: if two journeys share a component, they have to use the same URI for it. Two files that each define their own Page name produce two nodes that never meet, and the graph won’t complain.
2. Reading Turtle in five minutes
Turtle (the plain-text format RDF is written in) looks odd at first and is simple underneath. Here is the KPI of the ecommerce journey, exactly as it sits in the file:
@prefix martech: <https://example.org/martech/ontology/> .
@prefix data: <https://example.org/martech/data/ecommerce/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
data:kpi_order_conversion_rate a martech:KPI ;
rdfs:label "Order conversion rate" ;
martech:formula "Orders / Product Views" ;
martech:owner "Ecommerce / Digital Marketing" ;
martech:target 0.0020 .
Five rules cover almost everything you’ll read in this series:
@prefixis a shorthand.martech:KPIexpands tohttps://example.org/martech/ontology/KPI. Nothing more.ameans “is of type”. The first line says this node is a KPI.;keeps the subject and starts a new predicate. The block above is five triples about one node, not one long statement.,keeps subject and predicate and adds another object. You’ll see it in a moment when one variable maps to four components..ends the statement. Forget it, and the parser stops with an error. That’s one of the friendly mistakes.
The second thing to read is what sits on the right-hand side. A prefixed name like data:stage_order is a link to another node. Something in quotes is a text literal. A bare number is a typed literal: 0.0020 is an xsd:decimal, and a SPARQL filter can compare it as a number.
This is where part 2’s rule type what you filter on turns into actual syntax. Write martech:target "0.0020" and the file still parses, but the target is now a string. rdflib happens to be forgiving when you compare that string to a number. The SPARQL spec isn’t, and other triple stores follow the spec. The quotes are a data type decision, so I never add them to numbers.
3. The ecommerce journey as triples
The ecommerce file follows one chain per stage: stage, Measurement, component. Here it is for the last stage, Order:
data:stage_order a martech:Stage ;
rdfs:label "Order" ;
martech:order 4 ;
martech:rolls_up_to data:kpi_order_conversion_rate .
data:measurement_order a martech:Measurement ;
martech:measured_entity data:stage_order ;
martech:measured_component data:component_orders .
data:component_orders a martech:Component ;
rdfs:label "Orders" ;
martech:component_type "metric" ;
martech:definition "Number of completed purchase orders." ;
martech:caveats "Includes orders later cancelled or refunded — not net of returns." ;
martech:context "The funnel's terminal event and the numerator of the order conversion rate KPI." ;
martech:owner "Digital Analytics" ;
martech:refs <https://sandbox/SANDBOX_NAME/xdm/orders> .
Three things are worth pointing out.
Only Order carries rolls_up_to. Product view, Cart add and Checkout have a label and an order value and nothing else. That’s part 2’s decision to attach the KPI to the stage where it is actually decided, not to the whole journey. In section 5 you’ll see the query that gets the journey-level answer back anyway.
The Measurement has no filter_value. It doesn’t need one. The ecommerce data layer resolves each funnel step upstream into its own metric, so Orders alone identifies the Order stage. I still route the link through a Measurement node, so both journeys share one query shape.
refs is in angle brackets, not quotes. It’s a full URI, not text: a pointer into AEP, following the URI convention from Julien Piccini’s aepp library. The XDM field’s definition stays in AEP. The graph only stores where to find it. Part 4 is about exactly that boundary.
The data layer variable is the one place the comma rule earns its keep:
data:dlv_conversion_funnel_step a martech:DataLayerVariable ;
rdfs:label "digitalData.conversion.conversionFunnel.step" ;
martech:source_system "Web data layer (digitalData)" ;
martech:maps_to data:component_checkouts,
data:component_orders,
data:component_product_list_adds,
data:component_product_views .
One variable, four maps_to triples. If you open the actual file, you’ll notice the subjects come out in alphabetical order: Cart add before Product view. The file was serialised by rdflib, and RDF has no row order. Triples are a set. That’s why martech:order is an explicit integer and not the position in the file.
4. The login journey: where the filter value lands
The login journey is where part 2’s Measurement node stops being a diagram. Both stages point at the same component, and the only thing telling them apart is a string:
data:measurement_login a martech:Measurement ;
martech:measured_entity data:stage_login ;
martech:measured_component data:component_page_name ;
martech:filter_value "/customer/login" .
data:measurement_login_success a martech:Measurement ;
martech:measured_entity data:stage_login_success ;
martech:measured_component data:component_page_name ;
martech:filter_value "/customer/login/success" .
Read the middle line of each block: data:component_page_name appears twice, and it’s the same URI both times. Page name is defined once in the file, with one definition, one set of caveats and one refs pointer to web.webPageDetails.name. The two stages don’t each get a copy. They each get a Measurement that says “Page name, but only this value”.
That’s eight triples for the whole idea. The value is a plain literal on the node that represents the relationship, which is where part 2 argued it belongs: not on Page name, because Page name is shared by every page on the site, and not on the stage, because the value means nothing without the component it filters.
The component’s own caveat already says as much in words: filtering by value is required to isolate a journey step. Section 5 shows what happens when a query ignores that.
5. Asking the graph
A SPARQL query (the query language for RDF graphs) is a pattern of triples with variables in it. The engine finds every way the pattern fits the graph. All queries below use the same two prefixes, left out after the first one for space. To run them, either call g.query(...) on the graph from section 1, or install the repo (pip install -e .), start martech-knowledge-graph serve and paste them into the Query page.
Walk both journeys with one query
PREFIX martech: <https://example.org/martech/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?journey ?order ?stage ?component ?filter WHERE {
?j a martech:Journey ; rdfs:label ?journey ; martech:has_stage ?s .
?s martech:order ?order ; rdfs:label ?stage .
?m martech:measured_entity ?s ; martech:measured_component ?c .
?c rdfs:label ?component .
OPTIONAL { ?m martech:filter_value ?filter }
} ORDER BY ?journey ?order
| journey | order | stage | component | filter |
|---|---|---|---|---|
| Customer login journey | 1 | Login | Page name | /customer/login |
| Customer login journey | 2 | Login success | Page name | /customer/login/success |
| Ecommerce purchase journey | 1 | Product view | Product views | |
| Ecommerce purchase journey | 2 | Cart add | Product list adds | |
| Ecommerce purchase journey | 3 | Checkout | Checkouts | |
| Ecommerce purchase journey | 4 | Order | Orders |
OPTIONAL is the query-side twin of the modelling decision in section 3. Because every stage goes through a Measurement, one pattern covers both journeys. The ecommerce rows simply come back with an empty filter.
The shared-dimension trap
Now ask the narrower question “which stage does Page name measure?” and leave the filter out:
SELECT ?stage WHERE {
?c rdfs:label "Page name" .
?m martech:measured_component ?c ; martech:measured_entity ?s .
?s rdfs:label ?stage .
}
Two rows: Login, and Login success. That isn’t a bug. It’s the correct answer to the question that was asked. But a colleague reading that result, or an LLM summarising it, will happily conclude that Page name measures “the login journey” and build a report on unfiltered page names. My rule: whenever measured_component is a dimension, carry filter_value all the way through the query and into the answer.
From a data layer variable to the business question
This is the query from the opening. Which KPI, with which target, and which requirement depend on digitalData.page.pageInfo.name?
SELECT DISTINCT ?journey ?kpi ?target ?requirement WHERE {
?dlv rdfs:label "digitalData.page.pageInfo.name" ;
martech:maps_to ?component .
?m martech:measured_component ?component ;
martech:measured_entity ?stage .
?j martech:has_stage ?stage ;
rdfs:label ?journey ;
martech:has_stage ?kpiStage .
?kpiStage martech:rolls_up_to ?k .
?k rdfs:label ?kpi ;
martech:target ?target .
?r martech:addressed_by ?k ;
rdfs:label ?requirement .
}
| journey | kpi | target | requirement |
|---|---|---|---|
| Customer login journey | Monthly login rate | 0.35 | Understand monthly login frequency |
Swap the label for digitalData.conversion.conversionFunnel.step and you get the ecommerce journey, Order conversion rate, 0.0020, and Understand shop performance and drop-off. Same query, different starting point.
The interesting line is the detour through the journey. The variable hits Login as well as Login success, but only Login success rolls up to the KPI. So the query goes up from whichever stage it hit to the journey, then back down to the stage that carries rolls_up_to. That’s part 2’s “store the precise edge, derive the coarse one” in practice: three lines of SPARQL instead of a redundant KPI edge on every stage.

The top row is the technical side, the bottom row the business side, and the journey in between is what joins them.
In a relational model, this is half a dozen joins across tables someone would have had to design for exactly this question. Here, nobody designed for it. The edges were already there.
6. Why I stopped hand-writing Turtle
Writing both journeys by hand once is the best way to learn Turtle. Writing the third one by hand is how errors get in. Not the loud ones, the quiet ones.
A missing full stop is loud: the parser refuses the file. A misspelled predicate is quiet:
data:measurement_order a martech:Measurement ;
martech:measured_componnent data:component_orders .
That parses without a warning. Turtle checks syntax, not vocabulary, and an RDFS ontology describes the schema without enforcing it. The graph now holds a perfectly valid triple with a predicate nobody queries for, and the Order stage silently drops out of every result in section 5. Same story for a component defined under two slightly different URIs in two files, the identity problem from section 1.
So the repo has journey_builder.py. You describe a journey in a CSV, one row per stage, and it generates the Turtle. The login journey, cut down to the columns that matter here:
| stage_key | stage_label | stage_order | rolls_up_to_kpi | component_key | filter_value |
|---|---|---|---|---|---|
| login | Login | 1 | no | page_name | /customer/login |
| login_success | Login success | 2 | yes | page_name | /customer/login/success |
The full template adds columns for the journey, requirement, KPI, component context and data layer variable. Those repeat on every row, which is ugly in a spreadsheet and fine in practice. From that, the builder handles exactly the parts that go wrong by hand:
- every predicate name comes from code, so a typo can’t reach the file
- every stage gets its Measurement node, with
filter_valueonly where the row has one - a component used by several stages is defined once, and a component that already exists elsewhere in the workspace is referenced by its URI instead of redefined, so its curated context isn’t overwritten
- strings are escaped, numbers stay numbers
Run it on the two example journeys and you get the same structure as the hand-written files: 82 triples for ecommerce and 43 for login. The subject names are shorter (data:journey instead of data:journey_login), because the namespace already says which journey it is.
What the builder doesn’t do is decide content. The requirement wording, the KPI formula and the caveats still need a person who knows the journey. The tool only guarantees that what they write lands in the graph in a shape the queries can find. The platform’s Journeys page is a form over this same function, but that’s a story for part 5.
Key takeaways
- Files are packaging, URIs are identity. Split the schema from the instance data however suits your team. Once loaded it is one graph, and anything sharing a URI is connected.
- Quotes are a type decision. A bare number is a number, a quoted one is text. Type what you filter on, starting in the Turtle itself.
- One query shape beats one special case. Routing every stage through a Measurement means one
OPTIONALcovers journeys with and without filter values. - Carry the filter value to the answer. A shared dimension without its value answers a different question than the one you meant.
- Generate the Turtle. The parser catches syntax. Nothing catches a misspelled predicate except not typing it.
One exercise before part 4. Pick the data layer variable your developers touch most often and write the impact query for it. If the graph can’t answer, you’ve found the gap: a missing maps_to, a stage without a Measurement, or a KPI nobody connected to a requirement. If it can, send that result to the next person who asks whether a rename is safe.
Part 4 looks at the other end of the refs arrow: why I’m not just using AEP’s own knowledge graph, and what “reference, don’t merge” looks like when more than one team owns the data.