Windows环境下使用Tarql转换CSV至RDF无输出结果的技术求助
Windows下Tarql转换CSV到RDF无输出无文件的排查与解决
问题情况
在Windows系统中执行Tarql命令将CSV转换为RDF,命令运行无报错,但命令行无任何输出,也未生成目标RDF文件。
使用的命令
C:\tarql-master\target\appassembler\bin\tarql.bat --ntriples xx.rq xx.csv
对应的SPARQL查询代码
PREFIX dc: <http://dcontology/a#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> CONSTRUCT { ?URI owl:class dc:dataset; dc:identifier ?identifier; dc:title ?title; dc:description ?description; dc:category ?category; dc:keywords ?keywords; dc:PublicationDate ?PublicationDate; dc:UpdateDate ?UpdateDate; dc:frequencyofupdate ?frequencyofupdate; dc:Format ?Format; dc:License ?license } FROM <file:Metabase.csv> WHERE { BIND (URI(CONCAT('http://dcontology/dataset/', ?identifier)) AS ?URI) BIND (xsd:integer(?identifier) AS ?identifier) BIND (xsd:string(?title) AS ?title) BIND (xsd:string(?description) AS ?description) BIND (xsd:string(?category) AS ?category) BIND (xsd:string(?keywords) AS ?keywords) BIND (xsd:string(?PublicationDate) AS ?PublicationDate) BIND (xsd:string(?UpdateDate) AS ?UpdateDate) BIND (xsd:string(?FrequencyOfUpdate) AS ?FrequencyOfUpdate) BIND (xsd:string(?format) AS ?format) BIND (xsd:string(?license) AS ?license) }
CSV表头字段
identifier、title、description、category、keywords、PublicationDate、UpdateDate、FrequencyOfUpdate、format、license
解决步骤
移除多余的
FROM子句
Tarql通过命令行参数接收CSV文件,SPARQL中的FROM <file:Metabase.csv>会让Tarql把CSV当作RDF文件读取,自然读不到数据。直接删掉这一行。统一字段名大小写
Tarql对CSV字段名大小写敏感,SPARQL中存在多处不匹配:
- 将
dc:frequencyofupdate ?frequencyofupdate改为dc:frequencyofupdate ?FrequencyOfUpdate(匹配CSV表头的FrequencyOfUpdate) - 将
dc:Format ?Format改为dc:Format ?format(匹配CSV表头的format)
- 补充缺失的
owl前缀
SPARQL中使用了owl:class但未声明前缀,需在开头添加:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
- 调整BIND语句顺序并修正URI拼接
先把?identifier转为整数,再用字符串形式拼接URI,否则会因类型不兼容导致失败:
BIND (xsd:integer(?identifier) AS ?identifier) BIND (URI(CONCAT('http://dcontology/dataset/', STR(?identifier))) AS ?URI)
- 指定输出文件
Tarql默认将结果输出到控制台,若要生成文件,需在命令末尾添加重定向:
C:\tarql-master\target\appassembler\bin\tarql.bat --ntriples xx.rq xx.csv > output.nt
内容的提问来源于stack exchange,提问作者KYD
相关产品推荐
相关产品推荐

