Reputation: 1854
I have too many things that I'm not sure of, I may not have asked the right question.
I want to use https://ci.mines-stetienne.fr/sparql-generate/playground.html to map some JSON data to turtle RDF format.
Here is a working a version, with the problematic part commented out:
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)
}
The ontology I defined https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.ttl
Assuming it is correct, my problem is the nested GENERATE
.
I want to annotate
"price": [
{
"region": "us",
"price": 0.0076
},
{
"region": "us-central1",
"price": 0.0076
}
]
Maybe into something like:
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;
];
Full data is at https://github.com/miranda-zhang/cloud-computing-schema/blob/master/example/jq/gcloud/vm.json
Upvotes: 1
Views: 241
Reputation: 1854
AKSW is right, I got rid of the syntax error.
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)
}
Upvotes: 2