SPARQL distinct rowcount未返回正确的数字

SPARQL distinct rowcount未返回正确的数字,sparql,jena,apache-jena,Sparql,Jena,Apache Jena,我有以下SPARQL查询,请注意选择谓词中的行数和查询末尾的GROUPBY子句 我希望查询在每个记录中返回正确的行数,我注意到返回的行数不正确,这意味着如果有一条记录我得到1,有时是2,如果有2条以上的记录,我仍然得到2,基本上它似乎返回随机值 我知道这是因为我的问题,有人能告诉我我可能做错了什么吗?我正在使用ApacheJena PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX pf: <http:

我有以下SPARQL查询,请注意选择谓词中的行数和查询末尾的GROUPBY子句

我希望查询在每个记录中返回正确的行数,我注意到返回的行数不正确,这意味着如果有一条记录我得到1,有时是2,如果有2条以上的记录,我仍然得到2,基本上它似乎返回随机值

我知道这是因为我的问题,有人能告诉我我可能做错了什么吗?我正在使用ApacheJena

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  pf:   <http://jena.hpl.hp.com/ARQ/property#>
PREFIX  d:    <http://data-vocabulary.org/>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
PREFIX  s:    <http://schema.org/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  gr:   <http://purl.org/goodrelations/v1#>

SELECT DISTINCT  (count(*) AS ?rowCount) ?productName ?offerImage ?offerName ?productCategory ?salePrice ?suggestedRetailPrice ?productImage ?productThumbNail ?productUrl (GROUP_CONCAT(DISTINCT ?productdescription) AS ?productdescriptions) ?productBrand ?productId ?productSku ?productModel ?productMPN ?productManufacturer ?productGtin13 ?productGtin14 ?productGtin8 ?productAvailable ?productUnAvailable ?productUsedCondition ?productNewCondition ?productColor ?productAggregateRatingValue ?productReviewCount
WHERE
  {         

        ?p2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> d:Product .
        ?p2 <http://data-vocabulary.org/Product/offerDetails> ?schOffer .
        ?schOffer <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> d:Offer .
        ?schOffer <http://data-vocabulary.org/Offer/price> ?salePrice
        OPTIONAL
          { ?schOffer <http://data-vocabulary.org/Offer/name> ?offerName }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/name> ?productName }
        OPTIONAL
          { ?schOffer <http://data-vocabulary.org/Offer/image> ?offerImage }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/url> ?productUrl }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/image> ?productImage }
        OPTIONAL
          { ?schOffer <http://data-vocabulary.org/Offer/category> ?productCategory }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/description> ?productdescription }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/brand> ?pBrandNode
            OPTIONAL
              { ?pBrandNode <http://data-vocabulary.org/Brand/name> ?brandNodeName }
            OPTIONAL
              { ?pBrandNode <http://data-vocabulary.org/Organization/name> ?brandNodeName }
            BIND(str(coalesce(?brandNodeName, ?pBrandNode)) AS ?productBrand)
          }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/manufacturer> ?pManufacturerNode
            OPTIONAL
              { ?pManufacturerNode <http://data-vocabulary.org/manufacturer/name> ?manufacturerNodeName }
            BIND(str(coalesce(?manufacturerNodeName, ?pManufacturerNode)) AS ?productManufacturer)
          }
        OPTIONAL
          { ?p2 <http://schema.org/Product/aggregateRating> ?pAggregateRating
            OPTIONAL
              { ?pAggregateRating <http://schema.org/AggregateRating/ratingValue> ?productAggregateRatingValue }
            OPTIONAL
              { ?pAggregateRating <http://schema.org/AggregateRating/reviewCount> ?productReviewCount }
          }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/productID> ?productId }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/sku> ?productSku }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/itemCondition> ?productNewCondition .
            ?productNewCondition <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> s:NewCondition
          }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/itemCondition> ?productUsedCondition .
            ?productUsedCondition <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> s:UsedCondition
          }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/gtin13> ?productGtin13 }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/gtin14> ?productGtin14 }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/gtin8> ?productGtin8 }
        OPTIONAL
          { ?schOffer <http://data-vocabulary.org/Offer/availability> ?productAvailable
            FILTER ( ?productAvailable = s:InStock )
          }
        OPTIONAL
          { ?schOffer <http://data-vocabulary.org/Offer/availability> ?productUnAvailable
            FILTER ( ?productUnAvailable = s:OutOfStock )
          }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/model> ?productModel }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/mpn> ?productMPN }
        OPTIONAL
          { ?p2 <http://data-vocabulary.org/Product/color> ?productColor }

  }
GROUP BY ?productName ?offerImage ?offerName ?productCategory ?salePrice ?suggestedRetailPrice ?productImage ?productThumbNail ?productUrl ?productBrand ?productId ?productSku ?productModel ?productMPN ?productManufacturer ?productGtin13 ?productGtin14 ?productGtin8 ?productAvailable ?productUnAvailable ?productUsedCondition ?productNewCondition ?productColor ?productAggregateRatingValue ?productReviewCount
前缀rdfs:
前缀pf:
前缀d:
前缀foaf:
前缀s:
前缀xsd:
前缀gr:
选择DISTINCT(count(*)作为?rowCount)?productName?offerName?productCategory?salePrice?suggestedRetailPrice?productImage?Product缩略图?productUrl(GROUP_CONCAT(DISTINCT?productdescription)作为?productdescriptions)?产品品牌?产品ID?产品SKU?产品型号?产品MPN?产品制造商?产品GTIN13?产品GTIN14?产品GTIN8?产品可用?产品不可用?产品使用条件?产品新条件?产品颜色?产品聚合值?产品审核计数
哪里
{         
?p2 d:产品。
?p2?肖弗。
肖弗d:报价。
肖弗?塞尔普莱斯
可选的
{?肖弗?奥弗纳姆}
可选的
{?p2?产品名称}
可选的
{?schOffer?offerImage}
可选的
{?p2?产品URL}
可选的
{?p2?产品图像}
可选的
{?肖弗?产品类别}
可选的
{?p2?产品描述}
可选的
{?p2?pBrandNode
可选的
{?pBrandNode?brandNodeName}
可选的
{?pBrandNode?brandNodeName}
绑定(str(聚合(?brandNodeName,?pBrandNode))为产品品牌)
}
可选的
{?p2?pManufacturerNode
可选的
{?pManufacturerNode?manufacturerNodeName}
绑定(str(聚合(?制造商代号,?pManufacturerNode))为产品制造商)
}
可选的
{?p2?pAggregateRating
可选的
{?pAggregateRating?ProductAggregatingValue}
可选的
{?pAggregateRating?productReviewCount}
}
可选的
{?p2?productId}
可选的
{?p2?产品SKU}
可选的
{?p2?productNewCondition。
?产品新条件s:新条件
}
可选的
{?p2?productUsedCondition。
?产品使用条件s:使用条件
}
可选的
{?p2?产品GTIN13}
可选的
{?p2?productGtin14}
可选的
{?p2?productGtin8}
可选的
{?schOffer?产品可用
过滤器(?productAvailable=s:InStock)
}
可选的
{?schOffer?不可用
过滤器(?productUnAvailable=s:库存不足)
}
可选的
{?p2?产品模型}
可选的
{?p2?productMPN}
可选的
{?p2?productColor}
}
按?产品名称?报价?报价名称?产品类别?销售价格?建议的详细价格?产品图像?产品缩略图?产品URL?产品品牌?产品ID?产品SKU?产品型号?产品MPN?产品制造商?产品GTIN13?产品GTIN14?产品GTIN8?产品可用?产品不可用?产品使用条件?产品新情况分组?productColor?ProductAggregationValue?productReviewCount

这意味着模式在一个组中有多个项目。尝试在没有计数和分组的情况下跑步,然后查看结果,结果是2