Majed Sadi
Majed Sadi

Reputation: 87

how to create resources with different names using programming (dynamically) Resource s1, Resource s2,,,

Q1. using Jena framework and Java, can I create an array of resources , the reason am reading an CSV file and creating resources for each line, assume that two lines re related so I need away tto do this:

Resource single_process1 = createResource()

then for second line:

Resource single_process2 = createRessource()

you notice the numbers 1, 2 , I need to create it (add it to be part of the resource name) so later on because the two resources are related so I need to combine them as referencing that this combined process consists of the two single processes (resources). is array of resources is possible , any other option?

Q2. how to reference rdf:type or sio: in Jena

Upvotes: 2

Views: 120

Answers (1)

Ian Dickinson
Ian Dickinson

Reputation: 13305

First off, please only post one question at a time to StackOverflow. The purpose of this site is to try to collect accurate, quality answers to individual questions so that future users can benefit from them. Therefore, each question needs to be in a separate post.

I'm having a little difficulty understanding your question. If I can paraphrase:

  • you are processing a CSV file
  • during processing, each row of the file corresponds to one resource and its properties, and you add the corresponding triples to your Jena Model. A single Resource is created to be the subject of every triple for a given row
  • subsequently, you discover that two of the subject resources should refer to the same thing (i.e. the data from two rows of your CSV file refer to the same real-world entity)
  • you want to merge the triples from the two resources to use only one subject resource

If that's an accurate summary, it's certainly a little unusual ... but it's your data! Anyway, you can merge the statements from two resources into one reasonably easily:

Resource r0 = .... ; // the first subject resource
Resource r1 = .... ; // the second subject resource

// we discover that r0 and r1 refer to the same thing, so we 
// want to merge their properties ...

List<Statement> r1Props = r1.listProperties().toList();

for (Statement s: r1Props) {
    // add the property to r0, so <r1 P O> becomes <r0 P O>
    r0.addProperty( s.getPredicate(), s.getObject() );

    // remove the statement about r1
    // once all of r1's triples are removed, r1 is no longer in the Model
    s.remove();
}

What I'm not sure about is what this has to do with arrays of resources. You'll have to explain that a bit more.

Regarding Q2, you can use the class com.hp.hpl.jena.vocabulary.RDFS to refer to the URI's in the RDFS namespace, and similarly for RDF, OWL and a few others. To create your own vocabulary class, see Jena schemagen.

Upvotes: 1

Related Questions