narrative-graph 0.3.0

Turn prose into candidate relational facts — entity detection, relation labeling, confidence scoring, entirely local.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
//! The phrase-rule table: verbs and verb-plus-preposition phrases that name a
//! relation between two mentions, read as the *whole* text between them.
//!
//! IMPORTANT: a phrase rule is exact, not a substring search. After a closed
//! set of leading fillers (auxiliaries, adverbs) and trailing determiners are
//! peeled off, what remains between the mentions must equal one listed phrase.
//! "Nora met Marco" matches `meets`; "Nora met her friend Marco" does not,
//! because "her friend" is content the table does not account for. That is what
//! keeps a verb from being read across a clause that happens to contain it.

use super::super::cooccurrence::base;
use super::{PhraseRule, Slot};

/// Words that may stand in front of the verb phrase without changing what it
/// states. Negators are here so that "never married" reaches the rule and
/// `assertion_stance` can read it as a denial.
pub(super) const PHRASE_FILLERS: &[&str] = &[
    "had",
    "has",
    "have",
    "was",
    "were",
    "is",
    "are",
    "did",
    "does",
    "do",
    "didn't",
    "doesn't",
    "don't",
    "hadn't",
    "hasn't",
    "wasn't",
    "weren't",
    "isn't",
    "not",
    "never",
    "also",
    "still",
    "now",
    "soon",
    "later",
    "finally",
    "always",
    "just",
    "once",
    "already",
    "eventually",
    "then",
    "first",
    "even",
    "really",
    "quickly",
    "quietly",
    "slowly",
    "briefly",
    "secretly",
    "later",
    "recently",
    "formerly",
    "previously",
    "originally",
    "later",
    "briefly",
    "long",
    "ago",
];

/// Words that may follow the verb phrase before the object: articles and
/// possessive determiners. "to" and "with" belong to the phrases themselves.
pub(super) const PHRASE_TRAILERS: &[&str] =
    &["the", "a", "an", "his", "her", "their", "its", "our"];

const fn rule(
    phrases: &'static [&'static str],
    relation: &'static str,
    rule: &'static str,
    base: f32,
    subject: Slot,
    object: Slot,
) -> PhraseRule {
    PhraseRule {
        phrases,
        relation,
        rule,
        base,
        subject,
        object,
        passive: false,
    }
}

const fn passive(
    phrases: &'static [&'static str],
    relation: &'static str,
    rule: &'static str,
    base: f32,
    subject: Slot,
    object: Slot,
) -> PhraseRule {
    PhraseRule {
        phrases,
        relation,
        rule,
        base,
        subject,
        object,
        passive: true,
    }
}

use Slot::{Any, Person, Place, Venue};

pub(super) static PHRASE_RULES: &[PhraseRule] = &[
    // Marriage and romance.
    rule(
        &[
            "married",
            "marries",
            "marry",
            "is married to",
            "was married to",
            "got married to",
            "gets married to",
            "wed",
            "weds",
            "wedded",
        ],
        "spouse_of",
        "phrase-marry",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &["divorced", "divorces", "divorce"],
        "divorced",
        "phrase-divorce",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &[
            "engaged to",
            "got engaged to",
            "gets engaged to",
            "is engaged to",
            "was engaged to",
        ],
        "engaged_to",
        "phrase-engaged",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &[
            "dated",
            "dates",
            "date",
            "dating",
            "started dating",
            "began dating",
            "stopped dating",
        ],
        "dating",
        "phrase-dating",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &["proposed to", "proposes to", "propose to"],
        "proposed_to",
        "phrase-propose",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &[
            "broke up with",
            "breaks up with",
            "split up with",
            "splits up with",
        ],
        "broke_up_with",
        "phrase-breakup",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &[
            "loves",
            "loved",
            "love",
            "fell in love with",
            "falls in love with",
            "in love with",
            "adores",
            "adored",
        ],
        "loves",
        "phrase-love",
        base::PHRASE_STANCE,
        Person,
        Person,
    ),
    rule(
        &[
            "hates", "hated", "hate", "despises", "despised", "loathes", "loathed", "resents",
            "resented",
        ],
        "hates",
        "phrase-hate",
        base::PHRASE_STANCE,
        Person,
        Person,
    ),
    rule(
        &["kissed", "kisses", "kiss"],
        "kissed",
        "phrase-kiss",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    // Friendship, acquaintance, conflict.
    rule(
        &[
            "befriended",
            "befriends",
            "befriend",
            "friends with",
            "became friends with",
            "becomes friends with",
            "made friends with",
            "makes friends with",
        ],
        "friend_of",
        "phrase-friend",
        base::PHRASE_STANCE,
        Person,
        Person,
    ),
    rule(
        &["knows", "knew", "know", "known"],
        "knows",
        "phrase-know",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["met", "meets", "meet", "met with", "meets with"],
        "meets",
        "phrase-meet",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &[
            "argued with",
            "argues with",
            "fought with",
            "fights with",
            "quarreled with",
            "quarrelled with",
            "feuded with",
            "feuds with",
        ],
        "argues_with",
        "phrase-argue",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["betrayed", "betrays", "betray"],
        "betrayed",
        "phrase-betray",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["killed", "kills", "murdered", "murders"],
        "killed",
        "phrase-kill",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["rescued", "rescues", "protects", "protected"],
        "protects",
        "phrase-protect",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["trusts", "trusted", "trust"],
        "trusts",
        "phrase-trust",
        base::PHRASE_STANCE,
        Person,
        Person,
    ),
    // Contact: an event between two people, narrated, and nothing lasting.
    // "calls" is absent: "Fenn calls Pryor" in a courtroom summons a witness.
    rule(
        &[
            "telephones",
            "telephoned",
            "phones",
            "phoned",
            "texts",
            "texted",
            "emails",
            "emailed",
        ],
        "contacts",
        "phrase-contact",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &[
            "hugged",
            "hugs",
            "embraced",
            "embraces",
            "comforted",
            "comforts",
        ],
        "comforts",
        "phrase-comfort",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["thanked", "thanks", "greeted", "greets"],
        "greets",
        "phrase-greet",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["helped", "helps", "help"],
        "helps",
        "phrase-help",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["killed by"],
        "killed",
        "phrase-kill-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["betrayed by"],
        "betrayed",
        "phrase-betray-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["raised by"],
        "raised",
        "phrase-raise-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["adopted by"],
        "adopted",
        "phrase-adopt-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["taught by"],
        "teacher_of",
        "phrase-teach-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["protected by", "rescued by"],
        "protects",
        "phrase-protect-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["trained by", "coached by"],
        "mentors",
        "phrase-coach-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["loved by"],
        "loves",
        "phrase-love-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    passive(
        &["hated by"],
        "hates",
        "phrase-hate-by",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    // Family and teaching.
    rule(
        &["raised", "raises", "raise"],
        "raised",
        "phrase-raise",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["adopted", "adopts", "adopt"],
        "adopted",
        "phrase-adopt",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &["gave birth to", "gives birth to"],
        "mother_of",
        "phrase-birth",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &["fathered", "fathers"],
        "father_of",
        "phrase-father",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &["taught", "teaches", "teach", "tutored", "tutors"],
        "teacher_of",
        "phrase-teach",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &["coached", "coaches", "trained", "trains"],
        "mentors",
        "phrase-coach",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    // Work.
    rule(
        &[
            "works for",
            "worked for",
            "work for",
            "reports to",
            "reported to",
        ],
        "works_for",
        "phrase-works-for",
        base::PHRASE_FACTUAL,
        Person,
        Any,
    ),
    rule(
        &["works with", "worked with", "work with"],
        "works_with",
        "phrase-works-with",
        base::PHRASE_EVENT,
        Person,
        Person,
    ),
    rule(
        &[
            "works in",
            "worked in",
            "teaches at",
            "taught at",
            "interned at",
            "volunteers at",
            "volunteered at",
        ],
        "works_at",
        "phrase-works-at",
        base::PHRASE_FACTUAL,
        Person,
        Place,
    ),
    rule(
        &["hired", "hires", "hire", "employs", "employed"],
        "employs",
        "phrase-employ",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    passive(
        &["employed by", "hired by"],
        "employs",
        "phrase-employed-by",
        base::PHRASE_FACTUAL,
        Person,
        Any,
    ),
    // Study.
    rule(
        &[
            "studied at",
            "studies at",
            "graduated from",
            "graduates from",
            "enrolled at",
            "enrolled in",
        ],
        "attends",
        "phrase-studies-at",
        base::PHRASE_FACTUAL,
        Person,
        Place,
    ),
    rule(
        &["attended", "attends", "attend"],
        "attends",
        "phrase-attend",
        base::PHRASE_EVENT,
        Person,
        Venue,
    ),
    // Residence and place.
    rule(
        &[
            "lives in",
            "lived in",
            "live in",
            "living in",
            "lives at",
            "lived at",
            "lives on",
            "lived on",
            "resides in",
            "resided in",
            "moved to",
            "moves to",
            "moved into",
            "moves into",
            "relocated to",
            "settled in",
            "settles in",
            "grew up in",
            "grows up in",
        ],
        "lives_in",
        "phrase-lives-in",
        base::PHRASE_FACTUAL,
        Person,
        Place,
    ),
    rule(
        &["born in", "was born in", "is born in"],
        "born_in",
        "phrase-born-in",
        base::PHRASE_FACTUAL,
        Person,
        Place,
    ),
    rule(
        &["died in", "dies in"],
        "died_in",
        "phrase-died-in",
        base::PHRASE_FACTUAL,
        Person,
        Place,
    ),
    rule(
        &[
            "lives with",
            "lived with",
            "live with",
            "living with",
            "moved in with",
            "moves in with",
        ],
        "lives_with",
        "phrase-lives-with",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &[
            "lives next to",
            "lived next to",
            "lives next door to",
            "lived next door to",
        ],
        "neighbor_of",
        "phrase-next-door",
        base::PHRASE_FACTUAL,
        Person,
        Person,
    ),
    rule(
        &[
            "is in",
            "was in",
            "is located in",
            "was located in",
            "is situated in",
            "stands in",
            "sits in",
            "lies in",
        ],
        "located_in",
        "phrase-located-in",
        base::PHRASE_FACTUAL,
        Venue,
        Place,
    ),
    // Membership and ownership: the object must be a venue by its own name.
    rule(
        &[
            "joined",
            "joins",
            "join",
            "is a member of",
            "was a member of",
            "belongs to",
            "belonged to",
        ],
        "member_of",
        "phrase-member",
        base::PHRASE_FACTUAL,
        Person,
        Venue,
    ),
    rule(
        &[
            "leads",
            "led",
            "heads",
            "headed",
            "chairs",
            "chaired",
            "captained",
        ],
        "leads",
        "phrase-lead",
        base::PHRASE_EVENT,
        Person,
        Venue,
    ),
    rule(
        &[
            "owns",
            "owned",
            "own",
            "bought",
            "buys",
            "purchased",
            "inherited",
            "inherits",
        ],
        "owns",
        "phrase-own",
        base::PHRASE_FACTUAL,
        Person,
        Venue,
    ),
    rule(
        &["founded", "founds", "cofounded"],
        "founded",
        "phrase-found",
        base::PHRASE_FACTUAL,
        Person,
        Venue,
    ),
    rule(
        &["runs", "ran", "run", "manages", "managed"],
        "runs",
        "phrase-run",
        base::PHRASE_FACTUAL,
        Person,
        Venue,
    ),
];