@frogcat/ttl2jsonld (英语)
Turtle to JSON-LD 用于节点.js和浏览器的转换器,没有库依赖性.
演示
可在线演示 这里。 。 。 .
使用此转换器,您可以获取 Output JSON-LD 从 Input Turtle,如 JSON-LD 1.0 规格 。 。 。 .
输入龟
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://manu.sporny.org/about#manu> a foaf:Person;
foaf:name "Manu Sporny";
foaf:homepage <http://manu.sporny.org/> .
产出JSON-LD
{
"@context": {
"foaf": "http://xmlns.com/foaf/0.1/"
},
"@id": "http://manu.sporny.org/about#manu",
"@type": "foaf:Person",
"foaf:name": "Manu Sporny",
"foaf:homepage": { "@id": "http://manu.sporny.org/" }
}
安装
节点.js
$ npm install @frogcat/ttl2jsonld
浏览器
<script src="https://frogcat.github.io/ttl2jsonld/ttl2jsonld.js"></script>
使用量
节点.js
你可以自己写代码.
const ttl2jsonld = require('@frogcat/ttl2jsonld').parse;
const ttl = `@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://manu.sporny.org/about#manu> a foaf:Person;
foaf:name "Manu Sporny";
foaf:homepage <http://manu.sporny.org/> .
`;
const jsonld = ttl2jsonld(ttl);
console.log(JSON.stringify(jsonld,null,2));
命令行接口也可用.
$ npm install @frogcat/ttl2jsonld
$ ttl2jsonld {input_turtle} > {output_jsonld}
or
$ cat {input_turtle} | ttl2jsonld > {output_jsonld}
浏览器
此转换器被导出到 ttl2jsonld 全球对象。 打电话 ttl2jsonld.parse(ttl) 用于进行转换.
<!-- include ttl2jsonld.js -->
<script src="https://frogcat.github.io/ttl2jsonld/ttl2jsonld.js"></script>
<!-- run script -->
<script>
const ttl = `@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://manu.sporny.org/about#manu> a foaf:Person;
foaf:name "Manu Sporny";
foaf:homepage <http://manu.sporny.org/> .
`;
const jsonld = ttl2jsonld.parse(ttl);
console.log(JSON.stringify(jsonld,null,2));
</script>
API 密码
鉴于 turtle_string, (中文(简体) ), ttl2jsonld.parse 返回 JSON 对象.
var json_object = ttl2jsonld.parse(turtle_string);
想要通过BaseIRI时,请像这样给出第二个论证.
var json_object = ttl2jsonld.parse(turtle_string, {
baseIRI : "http://example.org/"
});
对于开发者
大楼
- 以 国家。 。 。 .
- 主代码为
spec/ttl2jsonld.pegjs。 。 。 . - 编辑代码时,运行
npm run build生成ttl2jsonld.js。 。 。 .
测试
- 测试过 测试套装 财务报告和审定财务报表 https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl 互联网档案馆的存檔,存档日期2014-12-21 。 。 。 .
- 目前298/301次测试成功.
- 运行
npm run spec-turtle开始测试套房. - 其他杂项测试设在
test/test.js, (中文(简体) ),npm run test运行.