简体   繁体   中英

How to add object property with Jena? Special format

Hello I am trying to add an object property between this two individuals. I also have the object property in the code and the individuals are in the ontology. In only need to connect them using a property. The individuals look like this in the code, my problem is that I have never work with that ontologies using this "Description" tag.

<!-- http://vivo.iu.edu/individual/n6356 -->

<owl:Thing rdf:about="http://vivo.iu.edu/individual/n6356">
    <rdf:type rdf:resource="&bibo;Article"/>
    <rdf:type rdf:resource="&bibo;Document"/>
    <rdf:type rdf:resource="&vivo;ConferencePaper"/>
    <rdf:type rdf:resource="&vivo;InformationResource"/>
    <rdf:type rdf:resource="&owl;NamedIndividual"/>
    <rdfs:label xml:lang="en-us">Indiana University Digital Music Library Project</rdfs:label>
    <vitro:modTime rdf:datatype="&xsd;dateTime">2010-07-28T15:36:03</vitro:modTime>
    <vitro:moniker rdf:datatype="&xsd;string">conference paper</vitro:moniker>
    <bibo:doi rdf:datatype="&xsd;string">http://doi.acm.org/10.1145/379437.379774</bibo:doi>
    <title>Indiana University Digital Music Library Project</title>
    <dateTimeValue rdf:resource="http://vivo.iu.edu/individual/n4086167"/>
    <bibo:presentedAt rdf:resource="http://vivo.iu.edu/individual/n5092"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n6257"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n6300"/>
    <vitro:mostSpecificType rdf:resource="&vivo;ConferencePaper"/>
</owl:Thing>

<!-- http://vivo.iu.edu/individual/n6399 -->

<owl:Thing rdf:about="http://vivo.iu.edu/individual/n6399">
    <rdf:type rdf:resource="&bibo;Article"/>
    <rdf:type rdf:resource="&bibo;Document"/>
    <rdf:type rdf:resource="&vivo;ConferencePaper"/>
    <rdf:type rdf:resource="&vivo;InformationResource"/>
    <rdf:type rdf:resource="&owl;NamedIndividual"/>
    <rdfs:label xml:lang="en-us">Assessing Future Ecosystem Services: a Case Study of the Northern Highlands Lake District  Wisconsin</rdfs:label>
    <vitro:modTime rdf:datatype="&xsd;dateTime">2010-07-28T15:36:03</vitro:modTime>
    <vitro:moniker rdf:datatype="&xsd;string">conference paper</vitro:moniker>
    <bibo:doi rdf:datatype="&xsd;string">http://doi.acm.org/10.1145/379437.99999</bibo:doi>
    <title>Assessing Future Ecosystem Services: a Case Study of the Northern Highlands Lake District  Wisconsin</title>
    <dateTimeValue rdf:resource="http://vivo.iu.edu/individual/n111111"/>
    <bibo:presentedAt rdf:resource="http://vivo.iu.edu/individual/n2222"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n3333"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n4444"/>
    <vitro:mostSpecificType rdf:resource="&vivo;ConferencePaper"/>
</owl:Thing>

I have tried with this code but the getters give me null values. Getting the two individuals by its names, getting the object property and adding them to the model.

Individual doc = model.getIndividual("n6356");
Individual ref = model.getIndividual("n6399");
ObjectProperty cites = model.getObjectProperty("http://purl.org/ontology/bibo/cites");
model.add(doc,cites,ref);

Resources in RDF are either blank nodes or URI nodes. Your individuals happen to be IRI nodes, so you need to retrieve them as such with:

Individual doc = model.getIndividual("http://vivo.iu.edu/individual/n6356");
Individual ref = model.getIndividual("http://vivo.iu.edu/individual/n6399");

If you're going to do a lot of this, it probably makes sense to do:

final String NS = "http://vivo.iu.edu/individual/";
Individual doc = model.getIndividual(NS+"n6356");
Individual ref = model.getIndividual(NS+"n6399");

if you don't save your Model in Memory, don't forget to write it out.

final String NS = "http://vivo.iu.edu/individual/";
Individual doc = model.getIndividual(NS+"n6356");
Individual ref = model.getIndividual(NS+"n6399");
ObjectProperty cites = model.getObjectProperty("http://purl.org/ontology/bibo/cites");
model.add(doc,cites,ref).write(new FileOutputStream(new File("rdf/myRDFFile.owl"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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