Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions docs/12-Bonus_Fix_Data_Lookup
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
layout: default
title: "Bonus Lesson 12 : Data lookup in Fix"
nav_order: 12
parent: Tutorial
---

## Bonus Lesson 12 : Data lookup in Fix

THIS IS AN EARLY DRAFT.

When transforming data you often need to map certain values to concepts based on a vocabulary mapping.

In Fix you can use the function `lookup` to map one term to another. But in oder to map these you need to
define the mapping list that you want to use.

### Internal lookup

The simplest form to define a list is to state the map within the lookup function, like this: `lookup("path.to.field", key_1: "value_1", ...)`

Look at this simple example ([Playground-Link](https://metafacture.org/playground/?flux=inputFile%0A%7Copen-file%0A%7Cas-lines%0A%7Cdecode-json%0A%7Cfix%28transformationFile%29%0A%7Cencode-json%0A%7Cprint%0A%3B%0A&transformation=lookup%28%22colour%22%2C%22r%22%3A%22red%22%2C%22b%22%3A%22blue%22%2C%22y%22%3A%22yellow%22%29%0A&data=%7B+%22colour%22+%3A+%22r%22+%7D%0A%7B+%22colour%22+%3A+%22b%22+%7D%0A%7B+%22colour%22+%3A+%22y%22+%7D)):

inputFile

```JSON
{ "colour" : "r" }
{ "colour" : "b" }
{ "colour" : "y" }
```

Flux
```
inputFile
|open-file
|as-lines
|decode-json
|fix(transformationFile)
|encode-json
|print
;
```

Fix
```
lookup("colour","r":"red","b":"blue","y":"yellow")
```

Result
```JSON
{"colour":"red"}
{"colour":"blue"}
{"colour":"yellow"}
```

It is not always helpful to configure the map within the `lookup` function, because e.g. the list is too long and makes overcrowds the function or you want to use the map multiple times within the Fix transformation.

Then it is better to cofigure the map by using `put_map`, like in the following scenario ([Playground-Link](https://metafacture.org/playground/?flux=inputFile%0A%7Copen-file%0A%7Cas-records%0A%7Cdecode-json%0A%7Cfix%28transformationFile%29%0A%7Cencode-json%0A%7Cprint%0A%3B%0A&transformation=%23+Define+a+map+within+the+fix+file%0Aput_map%28%22map%22%2C%0A++%22dog%22%3A%22mammal%22%2C%0A++%22cat%22%3A%22mammal%22%2C%0A++%22parrot%22%3A%22bird%22%2C%0A++%22shark%22%3A%22fish%22%2C%0A++%22dragon%22%3A%22fictional+animal%22%2C%0A++%22unicorn%22%3A%22fictional+animal%22%29%0A%0Alookup%28%22animal.type%22%2C+%22map%22%29%0A&data=%7B++%22animal%22%3A+%7B+%22name%22%3A+%22Jake%22%2C+%22type%22%3A+%22dog%22++%7D+%7D%0A%7B++%22animal%22%3A+%7B+%22name%22%3A+%22Blacky%22%2C+%22type%22%3A+%22parrot%22+%7D+%7D%0A)):

inputFile

```JSON
{ "animal": { "name": "Jake", "type": "dog" } }
{ "animal": { "name": "Blacky", "type": "parrot" } }
```

FLUX

```
inputFile
|open-file
|as-records
|decode-json
|fix(transformationFile)
|encode-json
|print
;
```

```
# Define a map within the fix file
put_map("map",
"dog":"mammal",
"cat":"mammal",
"parrot":"bird",
"shark":"fish",
"dragon":"fictional animal",
"unicorn":"fictional animal")

lookup("animal.type", "map")
```

This results in:
```
{"animal":{"name":"Jake","type":"mammal"}}
{"animal":{"name":"Blacky","type":"bird"}}
```

Instead of defining the map within the `lookup` function, here the map is defined with `put_map` and named `map`.
By this name `map` you can then refer to the map in the lookup function.



Look at this more elaborate usecase in the playground that maps codes 002@ from PICA records to literal format information: [Version with unnamed map](https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+as-lines%0A%7C+decode-pica%0A%7C+fix%28transformationFile%29%0A%7C+encode-json%28prettyPrinting%3D%22true%22%29%0A%7C+print%3B&transformation=copy_field%28%[email protected]%22%2C+%22dcterms%3Aformat%22%29%0Asubstring%28%22dcterms%3Aformat%22%2C+%220%22%2C+%221%22%29%0Alookup%28%22dcterms%3Aformat%22%2C+%22A%22%3A+%22print%22%2C+%22B%22%3A+%22audiovisual%22%2C+%22O%22%3A+%22online%22%29%0Aretain%28%22002@%22%2C+%22dcterms%3Aformat%22%29&data=001@+%1Fa5%1F01-2%1E001A+%1F01100%3A15-10-94%1E001B+%1F09999%3A12-06-06%1Ft16%3A10%3A17.000%1E001D+%1F09999%3A99-99-99%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Aag%1E003@+%1F0482147350%1E006U+%1F094%2CP05%1E007E+%1F0U+70.16407%1E007I+%1FSo%1F074057548%1E011@+%1Fa1970%1E017A+%1Farh%1E021A+%1FaDie+@Berufsfreiheit+der+Arbeitnehmer+und+ihre+Ausgestaltung+in+vo%CC%88lkerrechtlichen+Vertra%CC%88gen%1FdEine+Grundrechtsbetrachtg%1E028A+%1F9106884905%1F7Tn3%1FAgnd%1F0106884905%1FaProjahn%1FdHorst+D.%1E033A+%1FpWu%CC%88rzburg%1E034D+%1FaXXXVIII%2C+165+S.%1E034I+%1Fa8%1E037C+%1FaWu%CC%88rzburg%2C+Jur.+F.%2C+Diss.+v.+7.+Aug.+1970%1E%0A001@+%1F01%1Fa5%1E001A+%1F01140%3A08-12-99%1E001B+%1F09999%3A05-01-08%1Ft22%3A57%3A29.000%1E001D+%1F09999%3A99-99-99%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Aa%1E003@+%1F0958090564%1E004A+%1Ffkart.+%3A+DM+9.70%2C+EUR+4.94%2C+sfr+8.00%2C+S+68.00%1E006U+%1F000%2CB05%2C0285%1E007I+%1FSo%1F076088278%1E011@+%1Fa1999%1E017A+%1Farb%1Fasi%1E019@+%1FaXA-AT%1E021A+%1FaZukunft+Bildung%1FhPolitische+Akademie.+%5BHrsg.+von+Gu%CC%88nther+R.+Burkert-Dottolo+und+Bernhard+Moser%5D%1E028C+%1F9130681849%1F7Tp1%1FVpiz%1FAgnd%1F0130681849%1FE1952%1FaBurkert%1FdGu%CC%88nther+R.%1FBHrsg.%1E033A+%1FpWien%1FnPolit.+Akad.%1E034D+%1Fa79+S.%1E034I+%1Fa24+cm%1E036F+%1Fx299+12%1F9551720077%1FgAdn%1F7Tb1%1FAgnd%1F01040469-7%1FaPolitische+Akademie%1FgWien%1FYPA-Information%1FhPolitische+Akademie%2C+WB%1FpWien%1FJPolitische+Akad.%2C+WB%1Fl99%2C2%1E036F/01+%1Fx12%1F9025841467%1FgAdvz%1Fi2142105-5%1FYAktuelle+Fragen+der+Politik%1FhPolitische+Akademie%1FpWien%1FJPolitische+Akad.+der+O%CC%88VP%1FlBd.+2%1E045E+%1Fa22%1Fd18%1Fm370%1E047A+%1FSFE%1Fata%1E%0A001@+%1Fa5%1F01%1E001A+%1F01140%3A19-02-03%1E001B+%1F09999%3A19-06-11%1Ft01%3A20%3A13.000%1E001D+%1F09999%3A26-04-03%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Aal%1E003@+%1F0361809549%1E004A+%1FfHlw.%1E006U+%1F000%2CL01%1E006U+%1F004%2CP01-s-41%1E006U+%1F004%2CP01-f-21%1E007G+%1FaDNB%1F0361809549%1E007I+%1FSo%1F072658383%1E007M+%1F04413/0275%1E011@+%1Fa1925%1E019@+%1FaXA-DXDE%1FaXA-DE%1E021A+%1FaHundert+Jahre+Buchdrucker-Innung+Hamburg%1FdWesen+u.+Werden+d.+Vereinigungen+Hamburger+Buchdruckereibesitzer+1825-1925+%3B+Gedenkschrift+zur+100.+Wiederkehr+d.+Gru%CC%88ndungstages%2C+verf.+im+Auftr.+d.+Vorstandes+d.+Buchdrucker-Innung+%28Freie+Innung%29+zu+Hamburg%1FhFriedrich+Voeltzer%1E028A+%1F9101386281%1F7Tp1%1FVpiz%1FAgnd%1F0101386281%1FE1895%1FaVo%CC%88ltzer%1FdFriedrich%1E033A+%1FpHamburg%1FnBuchdrucker-Innung+%28Freie+Innung%29%1E033A+%1FpHamburg%1Fn%5BVerlagsbuchh.+Broschek+%26+Co.%5D%1E034D+%1Fa44+S.%1E034I+%1Fa4%1E%0A001@+%1Fa5%1F01-3%1E001A+%1F01240%3A01-08-95%1E001B+%1F09999%3A24-09-10%1Ft17%3A42%3A20.000%1E001D+%1F09999%3A99-99-99%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Af%1E003@+%1F0945184085%1E004A+%1F03-89007-044-2%1FfGewebe+%3A+DM+198.00%2C+sfr+198.00%2C+S+1386.00%1E006T+%1F095%2CN35%2C0856%1E006U+%1F095%2CA48%2C1186%1E006U+%1F010%2CP01%1E007I+%1FSo%1F061975997%1E011@+%1Fa1995%1E017A+%1Fara%1E021A+%1Fx213%1F9550711899%1FYNeues+Handbuch+der+Musikwissenschaft%1Fhhrsg.+von+Carl+Dahlhaus.+Fortgef.+von+Hermann+Danuser%1FpLaaber%1FJLaaber-Verl.%1FS48%1F03-89007-030-2%1FgAc%1E021B+%1FlBd.+13.%1FaRegister%1Fhzsgest.+von+Hans-Joachim+Hinrichsen%1E028C+%1F9121445453%1F7Tp3%1FVpiz%1FAgnd%1F0121445453%1FE1952%1FaHinrichsen%1FdHans-Joachim%1E034D+%1FaVIII%2C+408+S.%1E045V+%1F9090001001%1E047A+%1FSFE%1Fagb/fm%1E%0A001@+%1F01-2%1Fa5%1E001A+%1F01239%3A18-08-11%1E001B+%1F09999%3A05-09-11%1Ft23%3A31%3A44.000%1E001D+%1F01240%3A30-08-11%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Af%1E003@+%1F01014417392%1E004A+%1Ffkart.%1E006U+%1F011%2CA37%1E007G+%1FaDNB%1F01014417392%1E007I+%1FSo%1F0752937239%1E010@+%1Fager%1E011@+%1Fa2011%1E017A+%1Fara%1Fasf%1E021A+%1Fxtr%1F91014809657%1F7Tp3%1FVpiz%1FAgnd%1F01034622773%1FE1958%1FaLu%CC%88beck%1FdMonika%1FYPersonalwirtschaft+mit+DATEV%1FhMonika+Lu%CC%88beck+%3B+Helmut+Lu%CC%88beck%1FpBodenheim%1FpWien%1FJHerdt%1FRXA-DE%1FS650%1FgAc%1E021B+%1FlTrainerbd.%1E032@+%1Fg11%1Fa1.+Ausg.%1E034D+%1Fa129+S.%1E034M+%1FaIll.%1E047A+%1FSFE%1Famar%1E047A+%1FSERW%1Fasal%1E047I+%1Fu%24%1Fc04%1FdDNB%1Fe1%1E)

[Version with `put_map`](https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+as-lines%0A%7C+decode-pica%0A%7C+fix%28transformationFile%29%0A%7Cencode-json%28prettyPrinting%3D%22true%22%29%0A%7Cprint%0A%3B&transformation=put_map%28%22formats%22%2C+%0A++++%22A%22%3A+%22print%22%2C+%0A++++%22B%22%3A+%22audiovisual%22%2C+%0A++++%22O%22%3A+%22online%22%29%0A%0Acopy_field%28%[email protected]%22%2C+%22dcterms%3Aformat%22%29%0Asubstring%28%22dcterms%3Aformat%22%2C+%220%22%2C+%221%22%29%0Alookup%28%22dcterms%3Aformat%22%2C+%22formats%22%29%0Aretain%28%22002@%22%2C+%22dcterms%3Aformat%22%29&data=001@+%1Fa5%1F01-2%1E001A+%1F01100%3A15-10-94%1E001B+%1F09999%3A12-06-06%1Ft16%3A10%3A17.000%1E001D+%1F09999%3A99-99-99%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Aag%1E003@+%1F0482147350%1E006U+%1F094%2CP05%1E007E+%1F0U+70.16407%1E007I+%1FSo%1F074057548%1E011@+%1Fa1970%1E017A+%1Farh%1E021A+%1FaDie+@Berufsfreiheit+der+Arbeitnehmer+und+ihre+Ausgestaltung+in+vo%CC%88lkerrechtlichen+Vertra%CC%88gen%1FdEine+Grundrechtsbetrachtg%1E028A+%1F9106884905%1F7Tn3%1FAgnd%1F0106884905%1FaProjahn%1FdHorst+D.%1E033A+%1FpWu%CC%88rzburg%1E034D+%1FaXXXVIII%2C+165+S.%1E034I+%1Fa8%1E037C+%1FaWu%CC%88rzburg%2C+Jur.+F.%2C+Diss.+v.+7.+Aug.+1970%1E%0A001@+%1F01%1Fa5%1E001A+%1F01140%3A08-12-99%1E001B+%1F09999%3A05-01-08%1Ft22%3A57%3A29.000%1E001D+%1F09999%3A99-99-99%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Aa%1E003@+%1F0958090564%1E004A+%1Ffkart.+%3A+DM+9.70%2C+EUR+4.94%2C+sfr+8.00%2C+S+68.00%1E006U+%1F000%2CB05%2C0285%1E007I+%1FSo%1F076088278%1E011@+%1Fa1999%1E017A+%1Farb%1Fasi%1E019@+%1FaXA-AT%1E021A+%1FaZukunft+Bildung%1FhPolitische+Akademie.+%5BHrsg.+von+Gu%CC%88nther+R.+Burkert-Dottolo+und+Bernhard+Moser%5D%1E028C+%1F9130681849%1F7Tp1%1FVpiz%1FAgnd%1F0130681849%1FE1952%1FaBurkert%1FdGu%CC%88nther+R.%1FBHrsg.%1E033A+%1FpWien%1FnPolit.+Akad.%1E034D+%1Fa79+S.%1E034I+%1Fa24+cm%1E036F+%1Fx299+12%1F9551720077%1FgAdn%1F7Tb1%1FAgnd%1F01040469-7%1FaPolitische+Akademie%1FgWien%1FYPA-Information%1FhPolitische+Akademie%2C+WB%1FpWien%1FJPolitische+Akad.%2C+WB%1Fl99%2C2%1E036F/01+%1Fx12%1F9025841467%1FgAdvz%1Fi2142105-5%1FYAktuelle+Fragen+der+Politik%1FhPolitische+Akademie%1FpWien%1FJPolitische+Akad.+der+O%CC%88VP%1FlBd.+2%1E045E+%1Fa22%1Fd18%1Fm370%1E047A+%1FSFE%1Fata%1E%0A001@+%1Fa5%1F01%1E001A+%1F01140%3A19-02-03%1E001B+%1F09999%3A19-06-11%1Ft01%3A20%3A13.000%1E001D+%1F09999%3A26-04-03%1E001U+%1F0utf8%1E001X+%1F00%1E002@+%1F0Aal%1E003@+%1F0361809549%1E004A+%1FfHlw.%1E006U+%1F000%2CL01%1E006U+%1F004%2CP01-s-41%1E006U+%1F004%2CP01-f-21%1E007G+%1FaDNB%1F0361809549%1E007I+%1FSo%1F072658383%1E007M+%1F04413/0275%1E011@+%1Fa1925%1E019@+%1FaXA-DXDE%1FaXA-DE%1E021A+%1FaHundert+Jahre+Buchdrucker-Innung+Hamburg%1FdWesen+u.+Werden+d.+Vereinigungen+Hamburger+Buchdruckereibesitzer+1825-1925+%3B+Gedenkschrift+zur+100.+Wiederkehr+d.+Gru%CC%88ndungstages%2C+verf.+im+Auftr.+d.+Vorstandes+d.+Buchdrucker-Innung+%28Freie+Innung%29+zu+Hamburg%1FhFriedrich+Voeltzer%1E028A+%1F9101386281%1F7Tp1%1FVpiz%1FAgnd%1F0101386281%1FE1895%1FaVo%CC%88ltzer%1FdFriedrich%1E033A+%1FpHamburg%1FnBuchdrucker-Innung+%28Freie+Innung%29%1E033A+%1FpHamburg%1Fn%5BVerlagsbuchh.+Broschek+)

### External lookup

Besides the use of internal maps, Metafacture is able to load external map files to be used. There are currently two types of external lookups that utilize the `put_filemap` function for CSV and TSV files as well as the `put_rdfmap` that can be used for SKOS files.

### CSV/TSV lookup

The scenario above with the animals could be recreated like this. You have a tsv file like the following with the name `animals.tsv`:

```TSV
dog mammal
cat mammal
parrot bird
shark fish
dragon fictional animal
unicorn fictional animal
```

You would adjust the fix as follow:

```
put_filemap("map","animals.tsv", sep_char: "\t")

lookup("animal.type", "map")
```

[See here a usecase where the bibliographic level is mapped from MARC leader to human readable representation by doing a lookup an a tabulator separated value file (tsv) residing at the web.](https://metafacture.org/playground/?flux=%22http%3A//lobid.org/download/marcXml-8-records.xml%22%0A%7C+open-http%0A%7C+decode-xml%0A%7C+handle-marcxml%0A%7C+fix%28transformationFile%29%0A%7C+encode-json%0A%7C+print%0A%3B&transformation=put_filemap%28%22https%3A//gist.githubusercontent.com/TobiasNx/005d8d7b65324c88b1aa28fa5bea540b/raw/da995f9f3837f51709cae965426271f76aae2bb6/bibliographicLevel.tsv%22%2C+%22bibliographicLevelMap%22%2Csep_char%3A%22\t%22%29%0A%0A%0Acopy_field%28%22leader%22%2C%22bibliographicLevel%22%29%0Asubstring%28%22bibliographicLevel%22%2C%227%22%2C%221%22%29%0Alookup%28%22bibliographicLevel%22%2C%22bibliographicLevelMap%22%29%0Aretain%28%22bibliographicLevel%22%29)


TODO: Explain relation of the file to the fix function. Is the path relative to the fix file or the place where you start the command?


Hint: `put_filemap` does not interpret the files as true CSV or as TSV but by seperating textstrings via the sep_char, therefore escape sign and quotations are not translated or deleted.

`put_filemap` is also able to create a map out of multi colum files for that you need configure the `key_column` and the `value column` like this: `put_filemap("map","animals.tsv", sep_char: "\t", key_column:"2",value_column:"0")`. The colums are counted by a zero index therefore in our example you set the third column ("2") for the keys and the first ("0") for the values.


### External SKOS lookup

TODO.
214 changes: 214 additions & 0 deletions docs/13_Bonus_Triples_Counting_Analysing_Combining
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
layout: default
title: "Bonus Lesson 12 : Triples, Counting, Analysing and Combining"
nav_order: 12
parent: Tutorial
---


## Lesson 12 : Using Triples for Counting, Analysing and Combining

In Metafacture every record is assinged a record id. Using this id Metafacture is able to disassemble metadata records into so called triples.
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.

![Triple](https://metafacture.org/img/triple.png)

### What is a triple in metafacture?

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.

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.

### Small excursion: Metadata stream evens in metafacture

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")`)
Metafacture internally translates this as the following:

Marc Record
```
001
948469390
245 Ind1=1 Ind2=2
$$a Title
$$b Remainder of title
$$c Resposibility Statement
```

`decode-marc21` translates this to a sequence of metadata events:
-> Start record 948469390
-> Literal 001: 948469390
-> Start entity 24510
-> Literal a: Title
-> Literal b: Remainder of title
-> Literal c: Respondibility Statement
-> End entity
-> End record

### Generating triples

When using the flux command `stream to triples` this is translated into triples:
Each entity and each top level literal is turned into a triple:

```TSV
948469390 001 948469390
948469390 24510 {a:Title,b:Remainder of title,c: Respondibility Statement}

```

If you have metadata stream events like these:

![Generating Triples](https://metafacture.org/img/generatingTriples.png)

-> Start record record-id
-> Literal name: Klaus
-> Start entity died
-> Literal when: 1401
-> Literal where: HH
-> End entity
-> End record

With `stream-to-triples` this is translated into:

```TSV
record-id name Klaus
record-id died {when:1401,where:HH}
```

In context of a full metafacture workflow this example would look something like this:

Input of an formeta record:
```
record-id{name: Klaus, died {when: 1401, where: HH} }
```

FLUX:
```
inputFile
|open-file
|as-lines
|decode-formeta
|stream-to-triples
|print
;
```

If you print it out directly it would look something like this:
```
record-id:name=Klaus (STRING)
record-id:died={when:1401,where:HH} (ENTITY)
```

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)


In order to improve the readability or change the output to your liking you can configure the output with the `template` function

e.g. if you add `|template("Subject:${s} Predicate:${p} Object:${o}")` before print the output would change to:

```TSV
Subject:record-id Predicate:name Object:Klaus
Subject:record-id Predicate:died Object:{when:1401,where:HH}
```

### Listing values to records

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.

FLUX:
```
"https://raw.githubusercontent.com/metafacture/metafacture-core/master/metafacture-runner/src/main/dist/examples/read/marc21/10.marc21"
| open-http
| as-lines
| decode-marc21 // sets the value of 001 as record-id
| fix(transformationFile)
| stream-to-triples
| template("${s}\t${o}")
| print
;
```

FIX:
```
do list(path:"100??|700??","var":"$i")
copy_field("$i.a","name.$append")
end
retain("name")
```

It outputs the record id and the name of each contributor:

```TSV
946638705 Kim, Soonsik
94685887X Grunsky, Konrad
947459928 Henze, Hartwig
948469390 Burning, Michael
950561274 Ru§�ppell, Georg
950592463 Pru§�tting, Hanns
950974439 Bigalke, Rainer
953176436 Hanau, Peter
954369300 Hommelhoff, Peter
954377915 Horn, Norbert
```

### Counting triples

After you stream records into triples you can do quiet a lot of things e.g. counting values.


![Counting Triples](https://metafacture.org/img/countingTriples.png)

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.

In the next example we copy the publication places into a new top level field:

FLUX
```
"https://raw.githubusercontent.com/metafacture/metafacture-core/master/metafacture-runner/src/main/dist/examples/read/marc21/10.marc21"
| open-http
| as-lines
| decode-marc21 // sets the value of 001 as record-id
| fix(transformationFile)
| stream-to-triples
| count-triples(countBy="object")
| template("${o}\ttimes\t${s}")
| print
;
```

FIX:
```
do list(path:"260??","var":"$i")
copy_field("$i.a","publicationPlace.$append")
end

retain("publicationPlace")
```

This results inot:
```
1 times Berlin
1 times Bern
1 times Brussels
1 times Frankfurt am Main
1 times Hohenwarsleben
1 times Husum
5 times Ko§�ln
1 times Mu§�nchen
1 times Mu§�nster/Westf.
1 times New York
1 times Newcastle
1 times Oxford
1 times Vienna
1 times Washington, D.C./Baltimore
```

You can add the following flux command after count triples in order to sort the results by the number of appeareance:
`| sort-triples(by="object",order="decreasing",numeric="true")`

## Counting patterns

TODO

## Merging records

TODO: Add this section or add this as additional lesson.
Empty file.
Empty file added docs/15_Bonus_Logging
Empty file.
Binary file added docs/images/countingTriples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/generatingTriples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/triple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.