CLI 工具 ala csvsql for SPARQL and TTL, n3, ... files - Hello World example for teaching purposes

CLI tool ala csvsql for SPARQL and TTL, n3, ... files - Hello World example for teaching purposes

编辑:使这个问题更具体。请提供 "hello world" 使用您选择的工具在 Linux 上本地对 .ttl 文件执行 sparql 查询的示例。

csvsql 允许通过 SQL 直接查询 .csv 文件(即不导入);例如:

$ csvsql --query  "select m.usda_id, avg(i.sepal_length) as
mean_sepal_length from iris as i join irismeta as m on (i.species =
m.species) group by m.species" examples/iris.csv examples/irismeta.csv

我希望能够使用 SPARQL over Turtle .ttl 或其他典型的 RDF 文件进行查询。

如何为 SPARQL 和 Turtle 或类似文件实现类似 "one-off" "direct query" 的功能? (例如,将给定文件加载到内存中的小脚本,例如 运行 blazegraph instance, and runs query returns result and withdraws what's in memory; or maybe something using librdf, e.g., Rasqal/Redland or Neo4j or any other SPARQL implementation - preferably something without running background instance, one-off, KISS

恕我直言,这样的工具非常适合可能想要在三元组中存储数据并在不启动完整服务器的情况下查询数据的爱好者和发烧友。这对教育目的也非常有益。

您能否提供具体示例,以代码段为后盾,说明如何执行此操作? (本地 Linux)

具体的 Apache Jena 命令是 sparql

这些命令来自 http://apache.org/dist/jena/binaries/ 的二进制下载。解压后有 bin/bat/ 目录的脚本到 运行 来自命令行。

Rasqal 的 command-line 查询工具 roqet 执行此操作;参见 http://librdf.org/rasqal/roqet.html

或在线 http://triplr.org/query

使用示例编辑它是如何工作和打包的:

Rasqal 示例包:

让我们尝试从 https://wiki.blazegraph.com/wiki/index.php/Quick_Start 教程执行 "hello world" 查询。

这里是示例 data.ttl 文件:

PREFIX : <http://blazegraph.com/>
PREFIX schema: <http://schema.org/>

:systap a schema:Organization ;
        schema:owns :blazegraph .
:blazegraph a schema:Product ;
            schema:brand :systap;
            :productOf <http://systap.com/>;
            :implements <http://rdf4j.org>,<http://blueprints.tinkerpop.com> .

和示例 "hello world" Sparql 查询:

$ roqet -i sparql -e 'SELECT * WHERE { <http://blazegraph.com/blazegraph> ?p ?o }' -D data.ttl
roqet: Running query 'SELECT * WHERE { <http://blazegraph.com/blazegraph> ?p ?o }'
roqet: Query has a variable bindings result
row: [p=uri<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, o=uri<http://schema.org/Product>]
row: [p=uri<http://schema.org/brand>, o=uri<http://blazegraph.com/systap>]
row: [p=uri<http://blazegraph.com/productOf>, o=uri<http://systap.com/>]
row: [p=uri<http://blazegraph.com/implements>, o=uri<http://rdf4j.org>]
row: [p=uri<http://blazegraph.com/implements>, o=uri<http://blueprints.tinkerpop.com>]
roqet: Query returned 5 results

甚至更通用

$ roqet -i sparql -e 'SELECT * WHERE { ?s ?p ?o }' -D data.ttl  | xsel -b
roqet: Running query 'SELECT * WHERE { ?s ?p ?o }'
roqet: Query has a variable bindings result
row: [s=uri<http://blazegraph.com/systap>, p=uri<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, o=uri<http://schema.org/Organization>]
row: [s=uri<http://blazegraph.com/systap>, p=uri<http://schema.org/owns>, o=uri<http://blazegraph.com/blazegraph>]
row: [s=uri<http://blazegraph.com/blazegraph>, p=uri<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, o=uri<http://schema.org/Product>]
row: [s=uri<http://blazegraph.com/blazegraph>, p=uri<http://schema.org/brand>, o=uri<http://blazegraph.com/systap>]
row: [s=uri<http://blazegraph.com/blazegraph>, p=uri<http://blazegraph.com/productOf>, o=uri<http://systap.com/>]
row: [s=uri<http://blazegraph.com/blazegraph>, p=uri<http://blazegraph.com/implements>, o=uri<http://rdf4j.org>]
row: [s=uri<http://blazegraph.com/blazegraph>, p=uri<http://blazegraph.com/implements>, o=uri<http://blueprints.tinkerpop.com>]
roqet: Query returned 7 results