[英]Controlling conversion of RDF to “prettier” JSON-LD
I'm aware that conversion of RDF to JSON-LD has some limitations, but I wonder if there is a good way of making the conversion avoid use of blank nodes? 我知道将RDF转换为JSON-LD有一些限制,但我想知道是否有一种很好的方法可以使转换避免使用空白节点?
For example, given an RDF graph: 例如,给定RDF图:
@prefix ex: <http://example.org/ontology#> .
<http://example.org/x123> ex:house [
a ex:House ;
ex:houseNumber "1a" ;
ex:doorColour "blue"
] ;
ex:house [
a ex:House ;
ex:houseNumber "1b" ;
ex:doorColour "green"
] .
Is it possible, using (Java) JSON-LD to enforce conversion to an array-based representation of the bnodes: 是否有可能使用(Java)JSON-LD强制转换为基于数组的bnodes表示:
{
"id": "http://example.org/x123",
"house": [{
"type": "House",
"houseNumber": "1a",
"doorColour": "blue"
}, {
"type": "House",
"houseNumber": "1b",
"doorColour": "green"
}],
"@context": {
"ex": "http://example.org/ontology#",
"house": "ex:house",
"houseNumber": "ex:houseNumber",
"doorColour": "ex:doorColour",
"House": "ex:House",
"id": "@id",
"type": "@type"
}
}
Rather than something like: 而不是像:
{
"@graph": [
{
"@id": "_:b0",
"@type": "http://example.org/ontology#House",
"http://example.org/ontology#doorColour": "blue",
"http://example.org/ontology#houseNumber": "1a"
},
{
"@id": "_:b1",
"@type": "http://example.org/ontology#House",
"http://example.org/ontology#doorColour": "green",
"http://example.org/ontology#houseNumber": "1b"
},
{
"@id": "http://example.org/x123",
"http://example.org/ontology#house": [
{
"@id": "_:b0"
},
{
"@id": "_:b1"
}
]
}
]
}
At the moment, I'm iterating over the statements in the graph and manually producing the JSON, but is it at all possible to do this using libraries like java-jsonld or some other JSON-LD technique? 目前,我正在迭代图中的语句并手动生成JSON,但是使用java-jsonld或其他JSON-LD技术等库可以做到这一点吗?
You can use framing to achieve that. 您可以使用框架来实现这一目标。 Have a look at the library example in the JSON-LD playground.
看看JSON-LD游乐场中的库示例。 Unfortunately it is not standardized yet so various implementations may not produce exactly the same output and/or super different features
不幸的是,它尚未标准化,因此各种实现可能不会产生完全相同的输出和/或超级不同的特征
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.