Extract directed triples without treating co-occurrence as evidence
systems
relation extraction
workforce research
Learn how a small dependency-pattern extractor turns linked Riverton mentions into relation triples with status and evidence spans.
Tomas has a stack of short notices and one question: which organisation offers which credential, and which credential does a job require? A word search gives him fragments. It finds required, but it cannot tell whether the sentence says a licence is required, preferred, or not required.
Relation extraction finds a statement that two entities stand in a named, directed relationship. The output is a triple such as ORG-0002 offers CRD-0002, plus a status and a pointer back to the sentence that said it.
This lesson keeps the example small. It links mentions with the Riverton alias table, inspects the parser links, and compares the extractor with a co-occurrence baseline that only knows two mentions shared a sentence.
Note
The Riverton Workforce Lab, its job board, and its training flyer are fictional and were created for teaching.
TipWhat you will learn
By the end of this lesson, you will be able to:
define a relation schema before extracting triples;
keep entity IDs, direction, status, and offsets with each triple;
explain why two linked mentions in one sentence are not automatically related;
mark negated and hedged statements separately from asserted ones;
compare pair detection with triple extraction without mixing their units; and
say why a same-author reference is only a demonstration.
Define the relation schema
A schema says which relation types the extractor is allowed to produce. It also says which entity type can appear on each side. This matters because direction is part of the claim: an organisation offers a credential; the credential does not offer the organisation.
library(readr)library(dplyr)library(tibble)library(tidyr)library(purrr)library(stringr)library(digest)library(spacyr)library(knitr)source("R/use-spacy.R")relation_schema <-tribble(~relation, ~subject_type, ~object_type, ~direction, ~status_values, ~what_counts,"offers", "organisation", "credential","organisation -> credential", "asserted, negated, hedged","The sentence says the organisation offers, may offer, or does not offer the credential.","requires", "organisation", "credential","organisation -> credential", "asserted, negated, hedged","The sentence says the organisation requires, may require, or does not require the credential.")knitr::kable( relation_schema,col.names =c("Relation", "Subject type", "Object type", "Direction","Status values", "What counts" ),caption ="Relation schema used before any extraction output",row.names =FALSE)
Relation schema used before any extraction output
Relation
Subject type
Object type
Direction
Status values
What counts
offers
organisation
credential
organisation -> credential
asserted, negated, hedged
The sentence says the organisation offers, may offer, or does not offer the credential.
requires
organisation
credential
organisation -> credential
asserted, negated, hedged
The sentence says the organisation requires, may require, or does not require the credential.
The schema is small on purpose. It does not try to extract every fact in a job notice. It only checks two relations that later lessons can put into a knowledge base.
Read the source records and aliases
The 28 Riverton sentences are the verbatim source records used in earlier lessons. The alias table supplies IDs for organisations, places, and credentials. The extractor uses those IDs for arguments; named entity recognition is not used to choose the arguments.
Riverton alias table used to find relation arguments
Entity ID
Canonical name
Type
Alias
CRD-0001
Forklift Operator Licence
credential
Forklift Operator Licence
CRD-0001
Forklift Operator Licence
credential
forklift certification
CRD-0002
Data Support Certificate
credential
DATA SUPPORT CERTIFICATE
CRD-0002
Data Support Certificate
credential
Data Support Certificate
LOC-0001
Riverton
place
Riverton
LOC-0001
Riverton
place
Riverton, Calder
LOC-0002
Riverton
place
Riverton
LOC-0002
Riverton
place
Riverton, Tidewater
LOC-0003
Bellhaven
place
Bellhaven
ORG-0001
Riverton Workforce Lab
organisation
Riverton Workforce Lab
ORG-0001
Riverton Workforce Lab
organisation
Workforce Lab
ORG-0001
Riverton Workforce Lab
organisation
the Lab
ORG-0002
Riverton Skills Centre
organisation
RSC
ORG-0002
Riverton Skills Centre
organisation
Riverton Skills Centre
ORG-0002
Riverton Skills Centre
organisation
Skills Centre
ORG-0003
Marrow County Transit
organisation
MCT
ORG-0003
Marrow County Transit
organisation
Marrow County Transit
The table includes two rows for the alias Riverton, which is an ambiguity the lesson leaves unresolved. For relation arguments, the examples below use organisation and credential aliases that link to one ID.
Inspect the 28 verbatim sentences once
The job-board and flyer lines are useful for inspection, but they do not contain two distinct linked entity mentions in one sentence. The table below is the only place this lesson prints all 28 source sentences. It shows why none of these lines can produce complete relation triples.
Inspection table for all 28 verbatim Riverton sentences
Sentence ID
Document ID
Text
Linked mentions
Schema cue
Polarity read by hand
Modality read by hand
s001
J001
Paid 12-week training is provided.
none
offer-like wording
asserted or not applicable
plain
s002
J001
No prior data experience is required.
none
require-like wording
negated
plain
s003
J001
Evening schedules are available.
none
none
asserted or not applicable
plain
s004
J001
Applicants need basic spreadsheet skills.
none
require-like wording
asserted or not applicable
plain
s005
J002
A high school diploma is required.
none
require-like wording
asserted or not applicable
plain
s006
J002
The employer pays for certification training.
none
offer-like wording
asserted or not applicable
plain
s007
J002
Rotating night shifts are part of the job.
none
none
asserted or not applicable
plain
s008
J002
Workers must be able to lift 50 pounds.
none
require-like wording
asserted or not applicable
plain
s009
J003
A portfolio is required.
none
require-like wording
asserted or not applicable
plain
s010
J003
Six months of experience is preferred.
none
none
asserted or not applicable
preferred, not asserted as required
s011
J003
Remote work is available two days each week.
none
none
asserted or not applicable
plain
s012
J003
Each new hire receives a mentor.
none
none
asserted or not applicable
plain
s013
J004
A medical records certificate is preferred.
none
none
asserted or not applicable
preferred, not asserted as required
s014
J004
The position uses a daytime schedule.
none
none
asserted or not applicable
plain
s015
J004
On-the-job training is provided.
none
offer-like wording
asserted or not applicable
plain
s016
J005
This is a paid apprenticeship.
none
none
asserted or not applicable
plain
s017
J005
A valid driver's license is required.
none
require-like wording
asserted or not applicable
plain
s018
J005
The work is outdoors and includes local travel.
none
none
asserted or not applicable
plain
s019
J006
Two years of customer service experience are required.
none
require-like wording
asserted or not applicable
plain
s020
J006
Weekend shifts are required.
none
require-like wording
asserted or not applicable
needs review
s021
J006
Product training is included.
none
offer-like wording
asserted or not applicable
plain
s022
J006
Clear written communication is an essential skill.
none
none
asserted or not applicable
plain
s023
F001
RIVERTON SKILLS OPEN HOUSE
RIVERTON (LOC-0001; LOC-0002, ambiguous)
none
asserted or not applicable
plain
s024
F001
DATA SUPPORT CERTIFICATE
DATA SUPPORT CERTIFICATE (CRD-0002)
none
asserted or not applicable
needs review
s025
F001
Paid training stipend
none
none
asserted or not applicable
plain
s026
F001
Evening classes
none
none
asserted or not applicable
plain
s027
F001
No prior experience required
none
require-like wording
negated
plain
s028
F001
Apply by October 15
none
none
asserted or not applicable
plain
The important negative result is concrete: these 28 lines do not give the extractor complete entity pairs. A page or posting could supply a missing employer, but that would be a page-structure assumption, not sentence evidence; this lesson does not use that assumption. The polarity and modality columns are read by hand so the table can flag lines worth inspecting.
Write a same-author reference before extraction
The next examples are extractor test sentences. They are constructed to test the parser patterns and are not claims about the Riverton handbook or knowledge base. The reference below is written before the extractor runs. The same author wrote the sentences, the reference, and the rules, so the score is only a demonstration.
constructed_sentences <-tribble(~sentence_id, ~document_id, ~source, ~text, ~teaching_case,"c01", "T001", "extractor test sentence", "Riverton Skills Centre offers the Data Support Certificate.", "active offer","c02", "T002", "extractor test sentence", "The Data Support Certificate is offered by Riverton Skills Centre.", "passive offer","c03", "T003", "extractor test sentence", "Riverton Skills Centre does not offer the Forklift Operator Licence.", "verb negation","c05", "T005", "extractor test sentence", "Riverton Skills Centre offers the Data Support Certificate and the Forklift Operator Licence.", "coordinated objects","c06", "T006", "extractor test sentence", "Riverton Skills Centre may offer the Forklift Operator Licence next year.", "hedged offer","c07", "T007", "extractor test sentence", "Marrow County Transit runs a bus to Riverton Skills Centre.", "same-sentence distractor","c08", "T008", "extractor test sentence", "The Workforce Lab counted job ads that require the Forklift Operator Licence.", "relative-clause distractor","c09", "T009", "extractor test sentence", "Marrow County Transit no longer requires the Forklift Operator Licence.", "negation under an adverb","c11", "T011", "extractor test sentence", "No Forklift Operator Licence is required by Marrow County Transit.", "determiner no on argument","c13", "T013", "extractor test sentence", "Marrow County Transit is reported to require the Forklift Operator Licence.", "reported requirement")reference_triples <-tribble(~sentence_id, ~relation, ~subject_id, ~object_id, ~status,"c01", "offers", "ORG-0002", "CRD-0002", "asserted","c02", "offers", "ORG-0002", "CRD-0002", "asserted","c03", "offers", "ORG-0002", "CRD-0001", "negated","c05", "offers", "ORG-0002", "CRD-0002", "asserted","c05", "offers", "ORG-0002", "CRD-0001", "asserted","c06", "offers", "ORG-0002", "CRD-0001", "hedged","c09", "requires", "ORG-0003", "CRD-0001", "negated","c11", "requires", "ORG-0003", "CRD-0001", "negated","c13", "requires", "ORG-0003", "CRD-0001", "hedged")knitr::kable( constructed_sentences,col.names =c("Sentence ID", "Document ID", "Source", "Extractor test sentence", "Teaching case"),caption ="Constructed extractor test sentences, not Riverton facts",row.names =FALSE)
Constructed extractor test sentences, not Riverton facts
Sentence ID
Document ID
Source
Extractor test sentence
Teaching case
c01
T001
extractor test sentence
Riverton Skills Centre offers the Data Support Certificate.
active offer
c02
T002
extractor test sentence
The Data Support Certificate is offered by Riverton Skills Centre.
passive offer
c03
T003
extractor test sentence
Riverton Skills Centre does not offer the Forklift Operator Licence.
verb negation
c05
T005
extractor test sentence
Riverton Skills Centre offers the Data Support Certificate and the Forklift Operator Licence.
coordinated objects
c06
T006
extractor test sentence
Riverton Skills Centre may offer the Forklift Operator Licence next year.
hedged offer
c07
T007
extractor test sentence
Marrow County Transit runs a bus to Riverton Skills Centre.
same-sentence distractor
c08
T008
extractor test sentence
The Workforce Lab counted job ads that require the Forklift Operator Licence.
relative-clause distractor
c09
T009
extractor test sentence
Marrow County Transit no longer requires the Forklift Operator Licence.
negation under an adverb
c11
T011
extractor test sentence
No Forklift Operator Licence is required by Marrow County Transit.
determiner no on argument
c13
T013
extractor test sentence
Marrow County Transit is reported to require the Forklift Operator Licence.
reported requirement
knitr::kable( reference_triples,col.names =c("Sentence ID", "Relation", "Subject ID", "Object ID", "Status"),caption ="Same-author reference triples written before the extractor runs",row.names =FALSE)
Same-author reference triples written before the extractor runs
Sentence ID
Relation
Subject ID
Object ID
Status
c01
offers
ORG-0002
CRD-0002
asserted
c02
offers
ORG-0002
CRD-0002
asserted
c03
offers
ORG-0002
CRD-0001
negated
c05
offers
ORG-0002
CRD-0002
asserted
c05
offers
ORG-0002
CRD-0001
asserted
c06
offers
ORG-0002
CRD-0001
hedged
c09
requires
ORG-0003
CRD-0001
negated
c11
requires
ORG-0003
CRD-0001
negated
c13
requires
ORG-0003
CRD-0001
hedged
The reference has no row for the bus sentence or the job-ad counting sentence. Both contain more than one linked mention, but neither states one of the schema relations between those mentions. The test-sentence IDs skip some numbers; no test sentence was removed after the extractor ran.
Parse and align mentions to tokens
spaCy supplies dependency links. The code aligns each alias-table mention to the tokens covered by its character offsets, then chooses the token whose head points outside the mention as the mention head.
Alias-table mentions aligned to spaCy dependency heads
Sentence ID
Entity ID
Mention
Start
End
Mention head
Head relation
c01
ORG-0002
Riverton Skills Centre
1
22
Centre
nsubj
c01
CRD-0002
Data Support Certificate
35
58
Certificate
dobj
c02
CRD-0002
Data Support Certificate
5
28
Certificate
nsubjpass
c02
ORG-0002
Riverton Skills Centre
44
65
Centre
pobj
c03
ORG-0002
Riverton Skills Centre
1
22
Centre
nsubj
c03
CRD-0001
Forklift Operator Licence
43
67
Licence
dobj
c05
ORG-0002
Riverton Skills Centre
1
22
Centre
nsubj
c05
CRD-0002
Data Support Certificate
35
58
Certificate
dobj
c05
CRD-0001
Forklift Operator Licence
68
92
Licence
conj
c06
ORG-0002
Riverton Skills Centre
1
22
Centre
nsubj
c06
CRD-0001
Forklift Operator Licence
38
62
Licence
dobj
c07
ORG-0003
Marrow County Transit
1
21
Transit
nsubj
c07
ORG-0002
Riverton Skills Centre
37
58
Centre
pobj
c08
ORG-0001
Workforce Lab
5
17
Lab
nsubj
c08
CRD-0001
Forklift Operator Licence
52
76
Licence
dobj
c09
ORG-0003
Marrow County Transit
1
21
Transit
nsubj
c09
CRD-0001
Forklift Operator Licence
46
70
Licence
dobj
c11
CRD-0001
Forklift Operator Licence
4
28
Licence
nsubjpass
c11
ORG-0003
Marrow County Transit
45
65
Transit
pobj
c13
ORG-0003
Marrow County Transit
1
21
Transit
nsubjpass
c13
CRD-0001
Forklift Operator Licence
50
74
Licence
dobj
The offsets are one-based character positions in the unmodified sentence text. That lets the triple point back to the exact evidence instead of to a rebuilt token string.
In the head-relation column, nsubj marks an active subject, dobj a direct object, nsubjpass a passive subject, pobj an object of a preposition, and conj a coordinated item. Lesson 18 introduces dependency parses.
Extract directed triples
The extractor looks for offer and require triggers. It handles active subjects, passive agents, coordinated objects, not on a verb, No on an argument, no longer under an adverb, and hedging from may. The reported requirement is a visible miss for this small pattern set.
Extracted triples with status and evidence offsets
Sentence ID
Document ID
Relation
Subject ID
Object ID
Status
Subject start
Subject end
Object start
Object end
Evidence start
Evidence end
Evidence text
c01
T001
offers
ORG-0002
CRD-0002
asserted
1
22
35
58
1
59
Riverton Skills Centre offers the Data Support Certificate.
c02
T002
offers
ORG-0002
CRD-0002
asserted
44
65
5
28
1
66
The Data Support Certificate is offered by Riverton Skills Centre.
c03
T003
offers
ORG-0002
CRD-0001
negated
1
22
43
67
1
68
Riverton Skills Centre does not offer the Forklift Operator Licence.
c05
T005
offers
ORG-0002
CRD-0001
asserted
1
22
68
92
1
93
Riverton Skills Centre offers the Data Support Certificate and the Forklift Operator Licence.
c05
T005
offers
ORG-0002
CRD-0002
asserted
1
22
35
58
1
93
Riverton Skills Centre offers the Data Support Certificate and the Forklift Operator Licence.
c06
T006
offers
ORG-0002
CRD-0001
hedged
1
22
38
62
1
73
Riverton Skills Centre may offer the Forklift Operator Licence next year.
c09
T009
requires
ORG-0003
CRD-0001
negated
1
21
46
70
1
71
Marrow County Transit no longer requires the Forklift Operator Licence.
c11
T011
requires
ORG-0003
CRD-0001
negated
45
65
4
28
1
66
No Forklift Operator Licence is required by Marrow County Transit.
The negation check is deliberately broader than “look for not under the verb.” It catches no longer through the adverb and No Forklift Operator Licence through the determiner on the credential argument.
Compare pairs separately from triples
The co-occurrence baseline pairs every two distinct linked mentions in a constructed sentence. It does not assign a relation type or direction, so those fields are not applicable. The extractor is scored twice: once for entity-pair detection and once for labelled triples.
Labelled triple results for the dependency extractor
Sentence ID
Relation
Subject ID
Object ID
Status
Extractor
Reference
Co-occurrence relation
Co-occurrence direction
Result
c01
offers
ORG-0002
CRD-0002
asserted
TRUE
TRUE
not applicable
not applicable
true positive
c02
offers
ORG-0002
CRD-0002
asserted
TRUE
TRUE
not applicable
not applicable
true positive
c03
offers
ORG-0002
CRD-0001
negated
TRUE
TRUE
not applicable
not applicable
true positive
c05
offers
ORG-0002
CRD-0001
asserted
TRUE
TRUE
not applicable
not applicable
true positive
c05
offers
ORG-0002
CRD-0002
asserted
TRUE
TRUE
not applicable
not applicable
true positive
c06
offers
ORG-0002
CRD-0001
hedged
TRUE
TRUE
not applicable
not applicable
true positive
c09
requires
ORG-0003
CRD-0001
negated
TRUE
TRUE
not applicable
not applicable
true positive
c11
requires
ORG-0003
CRD-0001
negated
TRUE
TRUE
not applicable
not applicable
true positive
c13
requires
ORG-0003
CRD-0001
hedged
FALSE
TRUE
not applicable
not applicable
false negative
The pair table and triple table answer different questions. Co-occurrence can ask whether the right two IDs appeared together. It cannot answer which relation holds, which way the arrow points, or whether the sentence denied the claim. The reported-verb test sentence is also visible as a false negative for this small dependency-pattern extractor.
Where modern systems fit
Current relation-extraction papers often use large language models, prompts, or trained classifiers. Those systems still need the same schema, argument spans, status policy, and evidence checks. Published comparisons disagree by domain and scoring method, so this page does not make a performance claim about them.
What to remember
Relation extraction produces typed, directed triples, not loose word matches.
The argument IDs in this lesson come from the alias table, not from NER.
No on an argument and no longer under an adverb can change triple status.
Co-occurrence pairs have no relation type or direction.
This same-author score is a demonstration, not a benchmark.
Every triple needs sentence, document, and offset evidence.
The safe habit is to treat candidate pairs as leads for review and schema triples as claims that need sentence evidence.