ttl和SPARQL-Generate嵌套GENERATE中的一对多关系定义

one to many relationship definition in ttl and SPARQL-Generate nested GENERATE

我不确定的事情太多了,我可能没有问对问题。

我想用 https://ci.mines-stetienne.fr/sparql-generate/playground.html 将一些 JSON 数据映射到 turtle 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)
    }

我定义的ontologyhttps://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

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)
}