如何将一个组织模式单元格的结果作为表格在另一个组织模式单元格中进行处理?

问题描述 投票:0回答:1

在我的文档中,我创建了第一个单元格块用于检索数据:

#+name: raw-dataset
#+BEGIN_SRC sparql :url https://query.wikidata.org/sparql :format text/csv :cache yes :exports both
SELECT ?wLabel ?pLabel
WHERE
{
  ?p wdt:P31 wd:Q98270496 .
  ?p wdt:P1416 ?w .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ASC(?wLabel) ASC(?pLabel)
LIMIT 10
#+END_SRC

#+RESULTS[7981b64721a5ffc448aa7da773ce07ea8dbaf8ac]: raw-dataset
| wLabel                                        | pLabel       |
|-----------------------------------------------+--------------|
| Q105775472                                    | NFDI4Health  |
| Q1117007                                      | NFDI4Health  |
| Q115254989                                    | NFDI4Objects |
| Q1205424                                      | NFDI4Objects |
| Q17575706                                     | NFDI4Objects |
| 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+        |

这按预期工作,但我想摆脱那些以

Q1....
开头的行。 出于教学原因,我不想想在 SPARQL 查询中执行此操作,而是在第二个单元格中执行此操作。

现在麻烦开始了。 当我读到

raw-dataset
的结果时,所有内容都写在一行中。没有使用行尾字符等。

#+begin_src sh :var data=raw-dataset :exports both :results output raw
echo ${data}
#+end_src

#+RESULTS:
Q105775472 NFDI4Health Q1117007 NFDI4Health Q115254989 NFDI4Objects Q1205424 NFDI4Objects Q17575706 NFDI4Objects 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+

所以,这显然就是我尝试用例如清理数据集的原因

grep
无法工作

#+begin_src sh :var data=raw-dataset :exports both
echo ${data} | grep -L -E "Q[1-9]"
#+end_src

我不想更改

raw-dataset
的结果输出,因为将其导出到例如一个网站将其描述为一张漂亮的桌子:

问题:如何保留

raw-dataset
的表格格式化结果,但仍然能够通过简单的第二步清理数据;或者我如何将
raw-dataset
的结果作为结构化表读取?

sparql org-mode
1个回答
0
投票

我偶然发现,当我说出

shebang
时,例如
zsh
,然后我得到了想要的结果:

#+begin_src sh :var data=raw-dataset :shebang "#!/opt/homebrew/bin/zsh" :exports both
echo ${data}
#+end_src

#+RESULTS:
| Q105775472                                    | NFDI4Health  |
| Q1117007                                      | NFDI4Health  |
| Q115254989                                    | NFDI4Objects |
| Q1205424                                      | NFDI4Objects |
| Q17575706                                     | NFDI4Objects |
| 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+        |
© www.soinside.com 2019 - 2024. All rights reserved.