gpt4 book ai didi

rdf - 从 Jena ResultSet 获取 RDFNode

转载 作者:行者123 更新时间:2023-12-02 22:00:34 24 4
gpt4 key购买 nike

如何从 QueryExecution 生成的结果集中检索 Jena RDFNode?运行查询后我能够看到正确的结果集,但结果仅提供节点的 URI,谁能告诉我需要做什么才能获取 RDF 节点详细信息。这将让我提取每个属性,我以后可以操作这些属性。我看到的解决方法是使用显示实例属性而不是实例本身的查询。

当前结果:

http://assignment3.stdi.msmsuhail.ead/bpl.owl#Arsenal

预期结果:

<rdf:Description rdf:about="http://assignment3.stdi.msmsuhail.ead/bpl.owl#Arsenal">
<bpl:hasStadiumLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Holloway</bpl:hasStadiumLocation>
<rdf:type rdf:resource="http://assignment3.stdi.msmsuhail.ead/bpl.owl#Clubs"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
<bpl:hasStadiumName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Emirates Stadium</bpl:hasStadiumName>
<bpl:hasPlayer rdf:resource="http://assignment3.stdi.msmsuhail.ead/bpl.owl#TheoWalcott"/>
<bpl:hasPlayer rdf:resource="http://assignment3.stdi.msmsuhail.ead/bpl.owl#MikelArteta"/>
<bpl:hasName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Arsenal</bpl:hasName>
<bpl:hasNumberSeats rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">60355</bpl:hasNumberSeats>
<bpl:hasManager rdf:resource="http://assignment3.stdi.msmsuhail.ead/bpl.owl#ArseneWenger"/>
<bpl:hasPlayer rdf:resource="http://assignment3.stdi.msmsuhail.ead/bpl.owl#AaronRamsey"/>
</rdf:Description>

SPARQL 查询:

SELECT DISTINCT  ?clubs ?clubName 
WHERE {
?Club bpl:hasPlayer ?players.
?Club bpl:hasManager ?managers.
?players bpl:hasClub ?clubs .
?players bpl:hasAge ?playerAge.
?players bpl:hasName ?playerName.
?players bpl:hasNationality ?playerNationality.
?players bpl:hasPlayingPosition ?playerPosition.
?players bpl:isRetired ?playerIsRetired.
?clubs bpl:hasName ?clubName.
?clubs bpl:hasNumberSeats ?clubSeats.
?clubs bpl:hasStadiumName ?clubStadiumName .
?clubs bpl:hasStadiumLocation ?clubStadiumLocation.
?managers bpl:hasAge ?managerAge.
?managers bpl:hasName ?managerName.
?managers bpl:hasNationality ?managerNationality.
?managers bpl:isManager ?isManager.
}
ORDER BY ASC (?clubName)

Java 代码:

    while(resultSet!=null && resultSet.hasNext()){
QuerySolution querySolution = resultSet.nextSolution();
System.out.println(querySolution.get("clubs").toString());
}

最佳答案

QuerySolution#get(String) 的 Javadoc说返回值一个 RDFNode,所以你得到的值已经是一个 RDFNode。如果您正在运行本地查询(即,如果您有查询运行所针对的模型),那么您可以使用它获取属性值,例如,

RDFNode clubNode = querySolution.get( "club" );
Resource club = clubNode.asResource().inModel( model );
Statement stmt = club.getProperty( BPL.hasStadiumLocation );
System.out.println( stmt.getObject() ); // prints "Holloway"

关于rdf - 从 Jena ResultSet 获取 RDFNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17009154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com