与Protégé/ TopBraid Composer的结果相反,Jena的子查询交叉点返回空白

时间:2014-05-27 22:13:46

标签: rdf sparql jena protege topbraid-composer

我在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 source

您可以从here下载数据集。

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 64bits运行eclipse。

1 个答案:

答案 0 :(得分: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>  |
---------------------------------------------------------------------------------------------------------------------------------------