简体   繁体   English

Virtuoso Jena提供程序查询别名语法

[英]Virtuoso Jena provider query alias syntax

I have in Java the following code, that uses the Virtuoso Jena provider API. 我在Java中使用了以下代码,它使用了Virtuoso Jena提供程序API。 I would like to do a query using an alias. 我想使用别名进行查询。 I tried putting parenthesis but nothing worked. 我试过括号,但没有任何效果。 If I put the same query in the endpoint directly it works. 如果我直接在端点中放置相同的查询,它就可以工作。

    query = "select ?a AS ?count where {?a <uri> ?b.} limit 10";        
    VirtGraph set = new VirtGraph (url, "user", "pass");
    Query sparql = QueryFactory.create(query);
    VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(sparql, set);
    vqe.execSelect();

I recieve this error: 我收到这个错误:

  com.hp.hpl.jena.query.QueryParseException:
    Lexical error at line 1, column 13.  Encountered: " " (32), after : "AS"
    at com.hp.hpl.jena.sparql.lang.ParserSPARQL.perform(ParserSPARQL.java:99)

The SPARQL syntax for an alias is: (?var AS ?alias) 别名的SPARQL语法是:(?var AS?alias)

What syntax should I use in the query to make it work with an alias? 我应该在查询中使用什么语法使其与别名一起使用?

Thanks. 谢谢。

SPARQL语法是(expr AS ?var)包括( )

query = "select (?a AS ?count) where {?a <a> ?b.} limit 10";      

I see you also asked this on the OpenLink Software Support Forums ... (ObDisclaimer: I work for OpenLink Software .) 我看到你也在OpenLink软件支持论坛上问过这个问题......(ObDisclaimer:我为OpenLink Software工作。)

I've also posted this answer there. 我也在那里发布了这个答案。

The error you're encountering is coming from the Jena parser, not from Virtuoso nor the Virtuoso Jena Provider. 您遇到的错误来自Jena解析器,而不是来自Virtuoso和Virtuoso Jena Provider。

First thing is to correct the query to use proper SPARQL syntax. 首先要纠正查询以使用正确的SPARQL语法。 Virtuoso is more forgiving than Jena, but it's best to conform to the spec -- Virtuoso比Jena更宽容,但最好符合规范 -

SELECT  ( ?a AS ?count ) 
 WHERE  { ?a  a  ?b } 
 LIMIT  10

Then you might want to change your query a bit, because I don't think the results you'll see from the above are what you're looking for -- 然后你可能想稍微改变你的查询,因为我不认为你从上面看到的结果是你正在寻找的 -

SELECT  ( COUNT(?a) AS ?count )
                       ?b 
 WHERE  { ?a  a  ?b } 
 LIMIT  10

If the error continues, I'd check the versions of all relevant components -- Jena, Virtuoso Jena Provider, Virtuoso JDBC Driver, Virtuoso. 如果错误仍然存​​在,我将检查所有相关组件的版本 - Jena,Virtuoso Jena Provider,Virtuoso JDBC Driver,Virtuoso。

Then, assuming all components are up to date, and given the query is working directly against Virtuoso, you may want to bypass the Jena parser as described in our documentation , and perhaps report a bug against Jena. 然后,假设所有组件都是最新的,并且鉴于查询正在直接针对Virtuoso,您可能希望绕过Jena解析器,如我们的文档中所述 ,并可能报告针对Jena的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM