You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Bonus Lesson 12 : Triples, Counting, Analysing and Combining"
4
+
nav_order: 12
5
+
parent: Tutorial
6
+
---
7
+
8
+
9
+
## Lesson 12 : Using Triples for Counting, Analysing and Combining
10
+
11
+
In Metafacture every record is assinged a record id. Using this id Metafacture is able to disassemble metadata records into so called triples.
12
+
With triples Metafacture is able to count, analyse and even combine or reassable metadata. In this session we learn about triples and their use cases.
13
+
14
+

15
+
16
+
### What is a triple in metafacture?
17
+
18
+
A triple describes a combinantion of Subject, Predicate, Object. It is inspired by RDF triples but in context of Metafacture you do not need URI for subject and predicate. Instead the triples contain certain values that are derived from the metadata stream events metafacture processes.
19
+
20
+
The subject is usually the id of an record in metafacture. Most decoders and handlers assinge a specific or an upcounted record id to each record. But you can also use the flux command `change-id`to specify the record id that you want to set.
21
+
22
+
### Small excursion: Metadata stream evens in metafacture
23
+
24
+
If you decode e.g. MARC Data and set the value in 001 as the record id ( when using marc-xml you need to add `| change-id(idliteral="id", keepidliteral="true")`)
25
+
Metafacture internally translates this as the following:
26
+
27
+
Marc Record
28
+
```
29
+
001
30
+
948469390
31
+
245 Ind1=1 Ind2=2
32
+
$$a Title
33
+
$$b Remainder of title
34
+
$$c Resposibility Statement
35
+
```
36
+
37
+
`decode-marc21` translates this to a sequence of metadata events:
38
+
-> Start record 948469390
39
+
-> Literal 001: 948469390
40
+
-> Start entity 24510
41
+
-> Literal a: Title
42
+
-> Literal b: Remainder of title
43
+
-> Literal c: Respondibility Statement
44
+
-> End entity
45
+
-> End record
46
+
47
+
### Generating triples
48
+
49
+
When using the flux command `stream to triples` this is translated into triples:
50
+
Each entity and each top level literal is turned into a triple:
51
+
52
+
```TSV
53
+
948469390 001 948469390
54
+
948469390 24510 {a:Title,b:Remainder of title,c: Respondibility Statement}
In context of a full metafacture workflow this example would look something like this:
78
+
79
+
Input of an formeta record:
80
+
```
81
+
record-id{name: Klaus, died {when: 1401, where: HH} }
82
+
```
83
+
84
+
FLUX:
85
+
```
86
+
inputFile
87
+
|open-file
88
+
|as-lines
89
+
|decode-formeta
90
+
|stream-to-triples
91
+
|print
92
+
;
93
+
```
94
+
95
+
If you print it out directly it would look something like this:
96
+
```
97
+
record-id:name=Klaus (STRING)
98
+
record-id:died={when:1401,where:HH} (ENTITY)
99
+
```
100
+
101
+
You can see that the literal is typed by the statement in the braket. [See this example in the playground.](https://metafacture.org/playground/?flux=inputFile%0A%7Copen-file%0A%7Cas-lines%0A%7Cdecode-formeta%0A%7Cstream-to-triples%0A%7Cprint%0A%3B&data=record-id%7Bname%3A+Klaus%2C+died+%7Bwhen%3A+1401%2C+where%3A+HH%7D+%7D)
102
+
103
+
104
+
In order to improve the readability or change the output to your liking you can configure the output with the `template` function
105
+
106
+
e.g. if you add `|template("Subject:${s} Predicate:${p} Object:${o}")` before print the output would change to:
After you stream records into triples you can do a lot of things. The first use case would be listing all contributors of all records and the record id of the publication that they belong to.
You are able to count the value of each element of an triple. Usually the object is the most interesting, but also the predicate can be interesting to.
161
+
162
+
In the next example we copy the publication places into a new top level field:
0 commit comments