gpt4 book ai didi

java - Model.listSubjectsWithProperty(Property p, String o) 不列出具有相同字符串值的类型文字的资源

转载 作者:行者123 更新时间:2023-12-01 18:33:19 25 4
gpt4 key购买 nike

我有一个模型,打印如下 -

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="http://www.graphsearch.org/property/"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:j.1="http://www.graphsearch.org/class/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="http://www.graphsearch.org/property/hasPassword">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/class/Nothing">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/property/hasEmail">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/class/User">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
<rdfs:subClassOf rdf:resource="http://www.graphsearch.org/class/Thing"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/class/Thing">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
<owl:disjointWith rdf:resource="http://www.graphsearch.org/class/Nothing"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/property/bornOn">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/property/hasName">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/property/livesInCity">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/resource/User/2">
<rdf:type rdf:resource="http://www.graphsearch.org/class/User"/>
<j.0:hasPassword>password</j.0:hasPassword>
<vcard:Given rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Ravi</vcard:Given>
<vcard:N rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Kumar</vcard:N>
<vcard:Family rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Singh</vcard:Family>
<vcard:EMAIL rdf:datatype="http://www.w3.org/2001/XMLSchema#string">visittoravi@gmail.com</vcard:EMAIL>
<vcard:BDAY rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">1989-06-14T18:30:00Z</vcard:BDAY>
<vcard:GROUP rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Male</vcard:GROUP>
<vcard:UID rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">2</vcard:UID>
</rdf:Description>
<rdf:Description rdf:about="http://www.graphsearch.org/property/hasGender">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
</rdf:RDF>

现在如果我说 -

model.listSubjectsWithProperty(VCARD.EMAIL,"visittoravi@gmail.com");

它没有给我任何资源,我理解的问题可能是因为 VCARD.EMAIL 属性有一个类型文字,我像这样添加 -

resource.addLiteral(VCARD.EMAIL, model.createTypedLiteral("visittoravi@gmail.com"));

这个问题真的是因为它是类型文字还是其他原因。我如何列出具有类型文字属性的资源。

最佳答案

如果属性的值是类型文字,例如,因为您添加了它:

resource.addLiteral(
VCARD.EMAIL,
model.createTypedLiteral("visittoravi@gmail.com"));

然后您需要使用类型文字来检索它:

model.listSubjectsWithProperty(
VCARD.EMAIL,
model.createTypedLiteral("visittoravi@gmail.com"));

这是一个完整的工作示例,其中包含一些最少的数据:

import java.io.ByteArrayInputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.vocabulary.VCARD;

public class PropertySubjectsExample {
static String CONTENT = "\n" +
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" +
"@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .\n" +
"@prefix : <http://stackoverflow.com/q/23161586/1281433/>\n" +
"\n" +
":x vcard:EMAIL \"visittoravi@gmail.com\"^^xsd:string .\n" +
"";

public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
model.read( new ByteArrayInputStream( CONTENT.getBytes()), null, "TTL" );
ResIterator subjects = model.listSubjectsWithProperty(
VCARD.EMAIL,
model.createTypedLiteral( "visittoravi@gmail.com" ));
while ( subjects.hasNext() ) {
System.out.println( subjects.next() );
}
}
}

输出:

http://stackoverflow.com/q/23161586/1281433/x

关于java - Model.listSubjectsWithProperty(Property p, String o) 不列出具有相同字符串值的类型文字的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23161586/

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