简体   繁体   English

Virtuoso Jena提供程序构造查询错误

[英]Virtuoso Jena Provider Construct Query Error

My problem is similar to the one asked on this question: Is there a differense between a CONSTRUCT queries sent to a virtuoso endpoint and one sent to a Jena one? 我的问题类似于在此问题上提出的问题: 发送给虚拟端点的CONSTRUCT查询和发送给耶拿的一个CONSTRUCT查询之间有区别吗?

I am using Virtuoso opensource as my graphstore and using the jena provider in order to access the data in that graphstore. 我正在使用Virtuoso开源作为我的图形存储,并使用jena提供程序来访问该图形存储中的数据。 I am doing several querys and everything is working fine (except for the amazing amount of memory and time that takes every inference with virtuoso but that should go in another question...). 我正在执行几个查询,并且一切工作正常(除了惊人的内存和时间,需要使用virtuoso进行每个推断,但这应该在另一个问题中进行……)。

The problem came when I tried to generate a model using a construct query. 当我尝试使用构造查询生成模型时,问题就来了。 I have try using the VirtuosoQueryExecutionFactory and the query as string and the default QueryExecutionFactory with the query factory: 我尝试使用VirtuosoQueryExecutionFactory和查询作为字符串,并使用带有查询工厂的默认QueryExecutionFactory

qexec = VirtuosoQueryExecutionFactory.create(queryString,inputModel);

model = qexec.execConstruct();

And

Query query = QueryFactory.create(queryString);
qexec = QueryExecutionFactory.create(query,inputModel);

model = qexec.execConstruct();

The query gives the expected result in the sparql endpoint but an empty model when querying in the code. 该查询在sparql端点中给出了预期的结果,但在代码中查询时为空模型。

LOGGER.info("The model is: {}", model);
LOGGER.info("The size is: {}", model.size());

Gives the following output: 提供以下输出:

The model is: <ModelCom   {} | >
The size is: 0

The model where I execute the querys is not empty and I did the same query from the sparql endpoint, as I said, recieving the spected results. 我执行查询的模型不是空的,并且正如我所说,我从sparql端点进行了相同的查询,从而收到了指定的结果。

Anyone know where could be the mistake? 有人知道哪里可能是错误吗?

Thanks. 谢谢。

Daniel. 丹尼尔。

EDIT: Here is the query I am trying to execute. 编辑:这是我要执行的查询。

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> 
PREFIX owl:<http://www.w3.org/2002/07/owl#> 
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>  
PREFIX spatiaCore:<http://www.cedint.upm.es/residentialontology.owl#> 
PREFIX test:<http://test.url#> 
PREFIX spatiaCore: <http://www.cedint.upm.es/residentialontology.owl#> 
CONSTRUCT { 
    ?u ?p ?o1. 
    ?o1 ?p2 ?o2. 
    ?o2 ?p3 ?o3. 
    ?o3 ?p4 ?o4. 
    ?o4 ?p5 ?o5. 
    ?o6 ?p6 ?u. 
    ?o7 ?p7 ?o6
}  

WHERE { 
    ?u rdf:type spatiaCore:User. 
    ?u spatiaCore:id "0000000003B3B474"^^<http://www.w3.org/2001/XMLSchema#string>. 
    ?u ?p ?o1.
    OPTIONAL { 
        ?o1 ?p2 ?o2. 
        OPTIONAL {   
            ?o2 ?p3 ?o3.  
            OPTIONAL {
                ?o3 ?p4 ?o4.  
                OPTIONAL {
                    ?o4 ?p5 ?o5. 
                }
            }
        }
    }
    OPTIONAL { 
        ?o6 ?p6 ?u. 
        OPTIONAL {
            ?o7 ?p7 ?o6
        } 
    }
} 

As you can see, the query tries to construct a graph with all the nodes the user is linked to with a depth of max five relationships and the nodes that are linked to the user with a depth of max two relationships. 如您所见,该查询尝试构造一个图表,其中用户链接到的所有节点的深度最大为五个关系,而链接到用户的节点的深度最大为两个关系。

What kind of method did you use for create VirtModel object? 您使用哪种方法来创建VirtModel对象?

NOTE: 注意:

If you used: 如果您使用过:

public static VirtModel openDefaultModel(DataSource ds);
public static VirtModel openDefaultModel(String url, String user, String password);

so the Model will contains only data from "virt:DEFAULT" graph. 因此模型将仅包含来自“ virt:DEFAULT”图的数据。 And VirtuosoQueryExecutionFactory will add next pragma to query text: VirtuosoQueryExecutionFactory将添加下一个杂注以查询文本:

define input:default-graph-uri <virt:DEFAULT>

If you used something like: 如果您使用了类似的方法:

public static VirtModel openDatabaseModel(String graphName, DataSource ds);
public static VirtModel openDatabaseModel(String graphName, String url, String user, String password) 

so the Model will contains only data from graphName graph. 因此模型仅包含来自graphName图的数据。 And VirtuosoQueryExecutionFactory will add next pragma to query text: VirtuosoQueryExecutionFactory将添加下一个杂注以查询文本:

define input:default-graph-uri <graphName>

If you want to use data from all graphs, you must call: 如果要使用所有图形中的数据,则必须调用:

VirtModel vmodel = ....create model method...
vmodel.setReadFromAllGraphs(true);

If you set above to TRUE, the pragma for default-graph-uri will not added. 如果您在上方将其设置为TRUE,则不会添加default-graph-uri的杂注。

The worked example of using Construct with Virtuoso Jena provider: 通过Virtuoso Jena提供程序使用Construct的工作示例:

url = "jdbc:virtuoso://localhost:1111";
VirtGraph set = new VirtGraph ("test1", url, "dba", "dba");

set.clear();

String qry = "INSERT INTO GRAPH <test1> { <aa> <bb> 'cc' . <aa1> <bb> 'zz' }";
VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(qry, set);
vur.exec();                  

Model inputModel = new VirtModel(set);
System.out.println("InputModel :"+inputModel);
System.out.println("InputModel size :"+inputModel.size());
System.out.println();


qry = "CONSTRUCT { ?x <a> ?y } WHERE { ?x <bb> ?y }";
QueryExecution vqe = VirtuosoQueryExecutionFactory.create (qry, inputModel);

Model model = vqe.execConstruct();
System.out.println("Model :"+model);
System.out.println("Model size :"+model.size());

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

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