Skip to content
Snippets Groups Projects
Commit 4434b71b authored by Jonathan Hartman's avatar Jonathan Hartman
Browse files

started a section on Data Cleaning by porting over the code from the notebook

parent ad7d6fc8
Branches
Tags v1.10.2
No related merge requests found
...@@ -178,6 +178,99 @@ the letter "Q" followed by a series of numbers... ...@@ -178,6 +178,99 @@ the letter "Q" followed by a series of numbers...
| Q1205424 | NFDI4Objects | | Q1205424 | NFDI4Objects |
| Q17575706 | NFDI4Objects | | Q17575706 | NFDI4Objects |
## Switching Languages
One of the neat things about org-babel is that we can pass seemlessly pass data between languages.
You may recall from the cell that contained our SPARQ query this bit: `:exports both`. This ensures
that both the code and the results of that cell are present when the file is exported. For our
specific purpose here, that means that other cells can use the output of this cell as input.
We can specifically ask for the results of a previous cell by referencing the name of that cell.
Our SPARQL cell had the line `#+NAME: raw-dataset`, which means we can ask for the result of this
cell by referencing this name as a variable. Let's look at how to do that in the next section.
## Passing Data Between Cells
We'll look at the orb-babel cell first, then at a closer look at the shell command.
```
#+CAPTION: Cleaning the raw data.
#+NAME: clean-dataset
#+BEGIN_SRC sh -n :var input=raw-dataset :colnames yes :exports both
echo "$input" | sed -E '/Q[0-9]+/d'
#+END_SRC
```
## sed and Regex
As a brief explination of the code, we are taking the result of the `raw-dataset` cell, and
assigning that value to the variable "$input". We are then echoing that input, but filtering it
using `sed`, A Unix utility that can be used for parsing and transforming text.
The `-E` switch is telling sed that we are going to use an extended regex expression.
The pattern `'/Q[0-9]+/d'` has a few different components:
- `/` marks the start of the pattern
- `Q[0-9]+` is a regex pattern that says "match lines that contain a ! followed by one or more
digits
- `/d` is a sed command that deletes the current pattern space, which in the context of $input
will be the entire line
## Viewing our Results
```
| wLabel | pLabel |
|--------------------------------------------------------------+-------------------|
| Academy of Sciences and Humanities in Hamburg | Text+ |
| Academy of Sciences and Literature Mainz | NFDI4Culture |
| Academy of Sciences and Literature Mainz | NFDI4Memory |
| Academy of Sciences and Literature Mainz | NFDI4Objects |
| Academy of Sciences and Literature Mainz | Text+ |
| Alfred Wegener Institute for Polar and Marine Research | NFDI4Biodiversity |
| Alfred Wegener Institute for Polar and Marine Research | NFDI4DataScience |
| Alfred Wegener Institute for Polar and Marine Research | NFDI4Earth |
| Anthropological Society (Munich) | NFDI4Objects |
| Arachnologische Gesellschaft | NFDI4Biodiversity |
| Arbeitskreis Provenienzforschung e.V. | NFDI4Memory |
| Archivschule Marburg | NFDI4Memory |
| Archäologische Kommission für Niedersachsen | NFDI4Objects |
| Archäologisches Museum Hamburg und Stadtmuseum Harburg | NFDI4Objects |
| Arthistoricum | NFDI4Culture |
| Association for Data-Intensive Radio Astronomy | PUNCH4NFDI |
| Association for Technology and Construction in Agriculture | FAIRAgro |
| Association of German Architects | NFDI4Culture |
| Association of Population Based Cancer Registries in Germany | NFDI4Health |
| Association of states archaeologists | NFDI4Objects |
| BERD@NFDI | Base4NFDI |
| Bach-Archiv Leipzig | NFDI4Culture |
| Bauhaus-Universität Weimar | NFDI4Ing |
| Bavarian Academy of Sciences and Humanities | BERD@NFDI |
| Bavarian Academy of Sciences and Humanities | NFDI4Earth |
| Bavarian Academy of Sciences and Humanities | NFDI4Memory |
| Bavarian Academy of Sciences and Humanities | NFDI4Objects |
| Bavarian Academy of Sciences and Humanities | NFDIxCS |
| Bavarian Academy of Sciences and Humanities | PUNCH4NFDI |
| Bavarian Academy of Sciences and Humanities | Text+ |
| Bavarian Forest National Park | NFDI4Biodiversity |
| Bavarian Natural History Collections | NFDI4Biodiversity |
| Bavarian Natural History Collections | NFDI4Objects |
| Bavarian State Archaeological Collection | NFDI4Objects |
| Bavarian State Archives | FAIRAgro |
| Bavarian State Archives | NFDI4Biodiversity |
| Bavarian State Archives | NFDI4Earth |
| Bavarian State Archives | NFDI4Objects |
| Bavarian State Library | NFDI4Culture |
| Bavarian State Library | NFDI4Memory |
| Bavarian State Research Center for Agriculture | FAIRAgro |
| Beethoven House | NFDI4Culture |
| Beilstein Institute for the Advancement of Chemical Sciences | NFDI4Chem |
| Berlin State Library | Base4NFDI |
| Berlin State Library | NFDI4Memory |
```
# Processing Data # Processing Data
# Preserving Data # Preserving Data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment