1

我在 apache-jena-2.11.1 (eclipse 64jvm)、Protégé 和 TopBraid Composer(免费版)上运行相同的 SPARQL 查询。

Jena 返回一个空集,而 Protégé 和 TopBraid Composer 都返回/找到正确的结果。

SPARQL 查询:

PREFIX  core: <http://www.linked-usdl.org/ns/usdl-core#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  price: <http://www.linked-usdl.org/ns/usdl-price#>
PREFIX  pf:   <http://jena.hpl.hp.com/ARQ/property#>
PREFIX  spin: <http://spinrdf.org/spin#>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  gr:   <http://purl.org/goodrelations/v1#>
PREFIX  cloudtaxonomy: <http://rdfs.genssiz.org/CloudTaxonomy#>

SELECT REDUCED  ?offering
WHERE
  { { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Location .
              ?f rdfs:label ?value
              FILTER REGEX(?value, "tokyo", "i")
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Location .
              ?f rdfs:label ?value
              FILTER REGEX(?value, "tokyo", "i")
            }
        }
    }
    { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:MemorySize .
              ?f gr:hasMinValue ?value
              FILTER ( ?value >= 3.7 )
            }
        }
    }
    { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:DiskSize .
              ?f gr:hasMinValue ?value
              FILTER ( ?value >= 150.0 )
            }
        }
    }
    { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Feature .
              ?f rdfs:label ?value
              FILTER REGEX(?value, "Virtual Machine", "i")
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Feature .
              ?f rdfs:label ?value
              FILTER REGEX(?value, "Virtual Machine", "i")
            }
        }
    }
  }

Jena 正确地从模型中加载信息,并且每个平台都有相同的数据。他们中的任何一个都没有使用推理器。

JAVA源码

您可以从这里下载数据集。

Protégé 和 TopBraid 找到 19 个结果,Jena 找到 0 个。

Jena:       VERSION: 2.11.1
Jena:       BUILD_DATE: 2014-01-18T19:01:20+0000
ARQ:        VERSION: 2.11.1
ARQ:        BUILD_DATE: 2014-01-18T19:01:20+0000
RIOT:       VERSION: 2.11.1
RIOT:       BUILD_DATE: 2014-01-18T19:01:20+0000

$ sparql --query query.qv --data amazonOnDemand_fullset0.ttl
------------
| offering |
============
------------

关于这里可能是什么问题的任何想法?使用 jdk 1.8.0 64 位运行 eclipse。

4

1 回答 1

1

当我使用 Jena 的命令行工具运行它时(在下载您的数据并将您的查询存储在 中query.rq),我得到了一些结果。我不知道它们是否是你所期望的,或者你从 Protégé 那里得到的,因为你没有发布它们,但它不是空的,所以我认为这是你所期望的。

$ sparql --version
Jena:       VERSION: 2.11.0
Jena:       BUILD_DATE: 2013-09-12T10:49:49+0100
ARQ:        VERSION: 2.11.0
ARQ:        BUILD_DATE: 2013-09-12T10:49:49+0100
RIOT:       VERSION: 2.11.0
RIOT:       BUILD_DATE: 2013-09-12T10:49:49+0100

$ sparql --query query.rq --data amazonOnDemand_fullset0.ttl 
---------------------------------------------------------------------------------------------------------------------------------------
| offering                                                                                                                            |
=======================================================================================================================================
| <http://PricingAPIAmazonOnDemandOfferings.com#m3.2xlarge_2956_TIME247806256606408linux-AmazonOnDemandInstance_TIME247806256614533>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#c3.4xlarge_3132_TIME247806265310896linux-AmazonOnDemandInstance_TIME247806265318593>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.xlarge_3352_TIME247806280140383linux-AmazonOnDemandInstance_TIME247806280147225>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#m1.xlarge_3044_TIME247806261045248linux-AmazonOnDemandInstance_TIME247806261052518>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#hi1.4xlarge_3462_TIME247806285100936linux-AmazonOnDemandInstance_TIME247806285106495> |
| <http://PricingAPIAmazonOnDemandOfferings.com#m2.4xlarge_3308_TIME247806277291059linux-AmazonOnDemandInstance_TIME247806277311157>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#cr1.8xlarge_3330_TIME247806279000311linux-AmazonOnDemandInstance_TIME247806279016134> |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.4xlarge_3396_TIME247806282156677linux-AmazonOnDemandInstance_TIME247806282162664>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#cc2.8xlarge_3220_TIME247806271984550linux-AmazonOnDemandInstance_TIME247806271997379> |
| <http://PricingAPIAmazonOnDemandOfferings.com#m2.xlarge_3264_TIME247806274243312linux-AmazonOnDemandInstance_TIME247806274255286>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#m2.2xlarge_3286_TIME247806275687432linux-AmazonOnDemandInstance_TIME247806275695557>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#m1.medium_3000_TIME247806258807012linux-AmazonOnDemandInstance_TIME247806258833953>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#hs1.8xlarge_3440_TIME247806284122937linux-AmazonOnDemandInstance_TIME247806284128497> |
| <http://PricingAPIAmazonOnDemandOfferings.com#m1.large_3022_TIME247806259925275linux-AmazonOnDemandInstance_TIME247806259933827>    |
| <http://PricingAPIAmazonOnDemandOfferings.com#c3.2xlarge_3110_TIME247806264234541linux-AmazonOnDemandInstance_TIME247806264242239>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.8xlarge_3418_TIME247806283147932linux-AmazonOnDemandInstance_TIME247806283153491>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#c1.xlarge_3198_TIME247806269972105linux-AmazonOnDemandInstance_TIME247806269986217>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.2xlarge_3374_TIME247806281161573linux-AmazonOnDemandInstance_TIME247806281167987>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#c3.8xlarge_3154_TIME247806266383402linux-AmazonOnDemandInstance_TIME247806266391099>  |
---------------------------------------------------------------------------------------------------------------------------------------

编辑后,您提供了完整的代码,但它仍然有效。我已经下载了它以及数据的副本,除了更改路径名之外,我得到了您期望的结果。

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.util.FileManager;

public class JenaVsProtegeAndTopBraidExample {

    public static void main(String[] args) {

        Model data = FileManager.get().loadModel( "/home/taylorj/Downloads/amazonOnDemand_fullset0.ttl", "TTL");
        test(data);
    }

    private static void test(Model model) {
        String q = "PREFIX core: <http://www.linked-usdl.org/ns/usdl-core#>  PREFIX price: <http://www.linked-usdl.org/ns/usdl-price#>  PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  PREFIX gr: <http://purl.org/goodrelations/v1#>  PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>  PREFIX cloudtaxonomy: <http://rdfs.genssiz.org/CloudTaxonomy#> PREFIX spin: <http://spinrdf.org/spin#> SELECT REDUCED ?offering   WHERE {  {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering.  ?offering core:includes ?serv .  {  ?serv gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Location .  ?f rdfs:label ?value  FILTER regex(?value, 'tokyo', 'i')  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Location .  ?f rdfs:label ?value  FILTER regex(?value, 'tokyo', 'i')  }  }  } . {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering . ?offering core:includes ?serv .  {  ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  }UNION{  ?serv gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  } UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:MemorySize .  ?f gr:hasMinValue ?value  FILTER(?value >= 3.7)  }  }  } . {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering . ?offering core:includes ?serv .  {  ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  }UNION{  ?serv gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  } UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:DiskSize .  ?f gr:hasMinValue ?value  FILTER(?value >= 150.0)  }  }  } . {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering.  ?offering core:includes ?serv .  {  ?serv gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Feature .  ?f rdfs:label ?value  FILTER regex(?value, 'Virtual Machine', 'i')  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Feature .  ?f rdfs:label ?value  FILTER regex(?value, 'Virtual Machine', 'i')  }  }  }  }";

        Query query = QueryFactory.create(q);
        System.out.println(query.toString());

        QueryExecution exec = QueryExecutionFactory.create(query, model);

        ResultSet results = exec.execSelect();
        ResultSetFormatter.out(System.out, results, query);

        exec.close();
    }
}

输出:

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  pf:   <http://jena.hpl.hp.com/ARQ/property#>
PREFIX  price: <http://www.linked-usdl.org/ns/usdl-price#>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  spin: <http://spinrdf.org/spin#>
PREFIX  core: <http://www.linked-usdl.org/ns/usdl-core#>
PREFIX  cloudtaxonomy: <http://rdfs.genssiz.org/CloudTaxonomy#>
PREFIX  gr:   <http://purl.org/goodrelations/v1#>

SELECT REDUCED  ?offering
WHERE
  { { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Location .
              ?f rdfs:label ?value
              FILTER regex(?value, "tokyo", "i")
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Location .
              ?f rdfs:label ?value
              FILTER regex(?value, "tokyo", "i")
            }
        }
    }
    { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:MemorySize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 3.7 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:MemorySize .
              ?f gr:hasMinValue ?value
              FILTER ( ?value >= 3.7 )
            }
        }
    }
    { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:DiskSize .
              ?f gr:hasValue ?value
              FILTER ( ?value >= 150.0 )
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:quantitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:DiskSize .
              ?f gr:hasMinValue ?value
              FILTER ( ?value >= 150.0 )
            }
        }
    }
    { SELECT REDUCED  ?offering
      WHERE
        { ?offering rdf:type core:ServiceOffering .
          ?offering core:includes ?serv
            { ?serv gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Feature .
              ?f rdfs:label ?value
              FILTER regex(?value, "Virtual Machine", "i")
            }
          UNION
            { ?serv core:hasServiceModel ?model .
              ?model gr:qualitativeProductOrServiceProperty ?f .
              ?f rdf:type cloudtaxonomy:Feature .
              ?f rdfs:label ?value
              FILTER regex(?value, "Virtual Machine", "i")
            }
        }
    }
  }

---------------------------------------------------------------------------------------------------------------------------------------
| offering                                                                                                                            |
=======================================================================================================================================
| <http://PricingAPIAmazonOnDemandOfferings.com#m3.2xlarge_2956_TIME247806256606408linux-AmazonOnDemandInstance_TIME247806256614533>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#c3.4xlarge_3132_TIME247806265310896linux-AmazonOnDemandInstance_TIME247806265318593>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.xlarge_3352_TIME247806280140383linux-AmazonOnDemandInstance_TIME247806280147225>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#m1.xlarge_3044_TIME247806261045248linux-AmazonOnDemandInstance_TIME247806261052518>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#hi1.4xlarge_3462_TIME247806285100936linux-AmazonOnDemandInstance_TIME247806285106495> |
| <http://PricingAPIAmazonOnDemandOfferings.com#m2.4xlarge_3308_TIME247806277291059linux-AmazonOnDemandInstance_TIME247806277311157>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#cr1.8xlarge_3330_TIME247806279000311linux-AmazonOnDemandInstance_TIME247806279016134> |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.4xlarge_3396_TIME247806282156677linux-AmazonOnDemandInstance_TIME247806282162664>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#cc2.8xlarge_3220_TIME247806271984550linux-AmazonOnDemandInstance_TIME247806271997379> |
| <http://PricingAPIAmazonOnDemandOfferings.com#m2.xlarge_3264_TIME247806274243312linux-AmazonOnDemandInstance_TIME247806274255286>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#m2.2xlarge_3286_TIME247806275687432linux-AmazonOnDemandInstance_TIME247806275695557>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#m1.medium_3000_TIME247806258807012linux-AmazonOnDemandInstance_TIME247806258833953>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#hs1.8xlarge_3440_TIME247806284122937linux-AmazonOnDemandInstance_TIME247806284128497> |
| <http://PricingAPIAmazonOnDemandOfferings.com#m1.large_3022_TIME247806259925275linux-AmazonOnDemandInstance_TIME247806259933827>    |
| <http://PricingAPIAmazonOnDemandOfferings.com#c3.2xlarge_3110_TIME247806264234541linux-AmazonOnDemandInstance_TIME247806264242239>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.8xlarge_3418_TIME247806283147932linux-AmazonOnDemandInstance_TIME247806283153491>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#c1.xlarge_3198_TIME247806269972105linux-AmazonOnDemandInstance_TIME247806269986217>   |
| <http://PricingAPIAmazonOnDemandOfferings.com#i2.2xlarge_3374_TIME247806281161573linux-AmazonOnDemandInstance_TIME247806281167987>  |
| <http://PricingAPIAmazonOnDemandOfferings.com#c3.8xlarge_3154_TIME247806266383402linux-AmazonOnDemandInstance_TIME247806266391099>  |
---------------------------------------------------------------------------------------------------------------------------------------
于 2014-05-27T22:49:03.140 回答