我不确定的事情太多,可能没有问正确的问题。
我想使用 https://ci.mines-stetienne.fr/sparql-generate/playground.html 将一些JSON数据映射为乌龟RDF格式。
这是一个工作版本,其中有问题的部分已被注释掉:
BASE <http://example.com/>
PREFIX iter: <http://w3id.org/sparql-generate/iter/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX gr: <http://purl.org/goodrelations/v1#>
PREFIX cocoon: <https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.ttl>
GENERATE {
[] a cocoon:VM;
rdfs:label ?name;
cocoon:numberOfCores ?cores;
cocoon:hasCPUcapacity[
a cocoon:PhysicalQuantity;
cocoon:numericValue ?gceu;
cocoon:hasUnitOfMeasurement cocoon:gceu;
];
cocoon:hasMemory [
a cocoon:PhysicalQuantity;
cocoon:numericValue ?memory;
cocoon:hasUnitOfMeasurement cocoon:GB;
];
# GENERATE {
# gr:hasPriceSpecification [
# gr:UnitPriceSpecification;
# gr:hasCurrency "USD"^^xsd:string;
# gr:hasCurrencyValue ?regionalPrice^^xsd:float;
# gr:hasRegion cocoon:?region;
# ];
# }
# ITERATOR iter:JSONPath(?gcloudVM,".price") AS ?price .
# .
}
SOURCE <https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/example/jq/gcloud/vm.json> AS ?source
ITERATOR iter:JSONPath(?source,"$[*]") AS ?gcloudVM
WHERE {
BIND (fun:JSONPath(?gcloudVM,".name") AS ?name)
BIND (fun:JSONPath(?gcloudVM,".cores") AS ?cores)
BIND (fun:JSONPath(?gcloudVM,".memory") AS ?memory)
BIND (fun:JSONPath(?gcloudVM,".gceu") AS ?gceu)
BIND (fun:JSONPath(?price,".price") AS ?regionalPrice)
BIND (fun:JSONPath(?price,".region") AS ?region)
}
我定义的本体https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.ttl
假设它是正确的,我的问题是嵌套的GENERATE
。
我要注释
"price": [
{
"region": "us",
"price": 0.0076
},
{
"region": "us-central1",
"price": 0.0076
}
]
也许像这样:
gr:hasPriceSpecification [
gr:UnitPriceSpecification;
gr:hasCurrency "USD"^^xsd:string;
gr:hasCurrencyValue 0.0076^^xsd:float;
gr:hasRegion cocoon:us;
];
gr:hasPriceSpecification [
gr:UnitPriceSpecification;
gr:hasCurrency "USD"^^xsd:string;
gr:hasCurrencyValue 0.0076^^xsd:float;
gr:hasRegion cocoon:us-central1;
];
完整数据位于 https://github.com/miranda-zhang/cloud-computing-schema/blob/master/example/jq/gcloud/vm.json
答案 0 :(得分:2)
AKSW是正确的,我摆脱了语法错误。
BASE <https://w3id.org/cocoon/>
PREFIX iter: <http://w3id.org/sparql-generate/iter/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX gr: <http://purl.org/goodrelations/v1#>
PREFIX cocoon: <https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/ontology/1.0/cocoon.ttl>
GENERATE {
<data#{?name}> a cocoon:VM;
rdfs:label ?name;
cocoon:numberOfCores ?cores;
cocoon:hasCPUcapacity[
a cocoon:PhysicalQuantity;
cocoon:numericValue ?gceu;
cocoon:hasUnitOfMeasurement cocoon:gceu;
];
cocoon:hasMemory [
a cocoon:PhysicalQuantity;
cocoon:numericValue ?memory;
cocoon:hasUnitOfMeasurement cocoon:GB;
];
GENERATE {
<data#{?name}> gr:hasPriceSpecification [
a gr:UnitPriceSpecification ;
gr:hasCurrency "USD"^^xsd:string;
gr:hasCurrencyValue "{?regionalPrice}"^^xsd:float;
gr:hasRegion "{?region}"^^xsd:string;
]
}
ITERATOR iter:JSONPath(?gcloudVM,".price[*]") AS ?price
WHERE {
BIND (fun:JSONPath(?price,".price") AS ?regionalPrice)
BIND (fun:JSONPath(?price,".region") AS ?region)
}
.
}
SOURCE <https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/example/jq/gcloud_vm.json> AS ?source
ITERATOR iter:JSONPath(?source,"$[*]") AS ?gcloudVM
WHERE {
BIND (fun:JSONPath(?gcloudVM,".name") AS ?name)
BIND (fun:JSONPath(?gcloudVM,".cores") AS ?cores)
BIND (fun:JSONPath(?gcloudVM,".memory") AS ?memory)
BIND (fun:JSONPath(?gcloudVM,".gceu") AS ?gceu)
BIND (fun:JSONPath(?price,".price") AS ?regionalPrice)
BIND (fun:JSONPath(?price,".region") AS ?region)
}