我有一个像这样打印的模型 -
<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"));
这个问题真的是因为它是一个打字的文字或其他东西。 如何使用具有类型文字的属性列出资源。
答案 0 :(得分:4)
如果属性的值是类型文字,例如,因为您添加了:
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