我有两个SPARQL查询,一个获取总数没有缺陷,第二个获取总数没有。测试用例。我想将一个计数结果除以另一个计数,即(缺陷总数/测试用例总数)。 如何使用除法运算符划分两个查询结果。
任何人都可以建议我同意吗?
PREFIX process: <http://jazz.net/ns/process#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX merge: <http://jazz.net/ns/lqe/merge/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oslc: <http://open-services.net/ns/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rtc_merged: <http://jazz.net/ns/lqe/merge/gensym/cm/>
PREFIX oslc_config: <http://open-services.net/ns/config#>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT
?rtc_merged_Defect1_projectArea
?rtc_merged_Defect1_shortId_COUNT
WHERE{
{
SELECT DISTINCT
?rtc_merged_Defect1_projectArea
(COUNT(DISTINCT ?rtc_merged_Defect1_shortId) AS ?rtc_merged_Defect1_shortId_COUNT)
WHERE{
VALUES( ?rtc_merged_Defect1_paUri )
{
( <https://localhost:9443/ccm/process/project-areas/__ANzQBasEeegkPxZTDywOA> )
}
?rtc_merged_Defect1_uri process:projectArea ?rtc_merged_Defect1_paUri.
?rtc_merged_Defect1_uri oslc:instanceShape ?rtc_merged_Defect1_uri_instanceShape.
?rtc_merged_Defect1_uri_instanceShape merge:mergeShape rtc_merged:Defect.
OPTIONAL {
?rtc_merged_Defect1_uri process:projectArea ?rtc_merged_Defect1_projectArea_enumValue.
OPTIONAL {?rtc_merged_Defect1_projectArea_enumValue rdfs:label|dcterms:title ?rtc_merged_Defect1_projectArea_enumName.}
}
OPTIONAL {?rtc_merged_Defect1_ver dcterms:isVersionOf ?rtc_merged_Defect1_uri; rdf:type oslc_config:VersionResource.}
?rtc_merged_Defect1_uri oslc:shortId ?rtc_merged_Defect1_shortId.
BIND( IF (bound(?rtc_merged_Defect1_ver), concat(str(?rtc_merged_Defect1_uri), "?oslc_config.context="), ?rtc_merged_Defect1_uri) as ?rtc_merged_Defect1)
BIND( IF(bound(?rtc_merged_Defect1_projectArea_enumName), ?rtc_merged_Defect1_projectArea_enumName, IF(bound(?rtc_merged_Defect1_projectArea_enumValue), ?rtc_merged_Defect1_projectArea_enumValue, "")) as ?rtc_merged_Defect1_projectArea)
}
GROUP BY ?rtc_merged_Defect1_projectArea
}
} //This is my first query.
===============================================================
PREFIX process: <http://jazz.net/ns/process#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX merge: <http://jazz.net/ns/lqe/merge/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oslc: <http://open-services.net/ns/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rqm_merged: <http://jazz.net/ns/lqe/merge/gensym/qm/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX oslc_config: <http://open-services.net/ns/config#>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT
?rqm_merged_QMTestCase1_projectArea
?rqm_merged_QMTestCase1_shortId_COUNT
WHERE{
{
SELECT DISTINCT
?rqm_merged_QMTestCase1_projectArea
(COUNT(DISTINCT ?rqm_merged_QMTestCase1_shortId) AS ?rqm_merged_QMTestCase1_shortId_COUNT)
WHERE{
VALUES( ?rqm_merged_QMTestCase1_paUri )
{
( <https://localhost:9443/qm/process/project-areas/_EazMoBatEeeR-7d5-ZtSzw> )
}
?rqm_merged_QMTestCase1_uri process:projectArea ?rqm_merged_QMTestCase1_paUri.
?rqm_merged_QMTestCase1_uri oslc:instanceShape ?rqm_merged_QMTestCase1_uri_instanceShape.
?rqm_merged_QMTestCase1_uri_instanceShape merge:mergeShape rqm_merged:QM%20Test%20Case.
OPTIONAL {
?rqm_merged_QMTestCase1_uri process:projectArea ?rqm_merged_QMTestCase1_projectArea_enumValue.
OPTIONAL {?rqm_merged_QMTestCase1_projectArea_enumValue rdfs:label|dcterms:title ?rqm_merged_QMTestCase1_projectArea_enumName.}
}
OPTIONAL {?rqm_merged_QMTestCase1_ver dcterms:isVersionOf ?rqm_merged_QMTestCase1_uri; rdf:type oslc_config:VersionResource.}
?rqm_merged_QMTestCase1_uri oslc:shortId ?rqm_merged_QMTestCase1_shortId.
BIND( IF (bound(?rqm_merged_QMTestCase1_ver), concat(str(?rqm_merged_QMTestCase1_uri), "?oslc_config.context="), ?rqm_merged_QMTestCase1_uri) as ?rqm_merged_QMTestCase1)
BIND( IF(bound(?rqm_merged_QMTestCase1_projectArea_enumName), ?rqm_merged_QMTestCase1_projectArea_enumName, IF(bound(?rqm_merged_QMTestCase1_projectArea_enumValue), ?rqm_merged_QMTestCase1_projectArea_enumValue, "")) as ?rqm_merged_QMTestCase1_projectArea)
}
GROUP BY ?rqm_merged_QMTestCase1_projectArea
}
}
答案 0 :(得分:0)
解决方案是使用两个子SELECT查询(我在这里使用存根,因为您当前的SPARQL查询令人困惑(重复并使用不必要的子SELECT)):
SELECT (?cnt1/?cnt2 AS ?result) WHERE {
// first query
{
SELECT (COUNT(?s) AS ?cnt1) WHERE {
...
}
}
// second query
{
SELECT (COUNT(?s) AS ?cnt2) WHERE {
...
}
}
}