How to add dynamically rdf resource to rdf file in java using Jena?

Viewed 127

I have this JFrame :

initial jframe

Whenever I clik on add button, JComboBoxes and JLabels will be added to my JFrame.

The final JFrame looks like this :

final jframe

The items of JComboBoxes are URIs that I have extracted from an ontology.

For example I want my rdf file contains 4 different resources ,so I add 4 ComboBoxes and I select 4 different URIs but the problem is : it only works for the first URI,but the three others will be identical.

This is the result of my rdf file :

the rdf file

This is my code for generating the rdf file

btnGenerateRdf.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
String u = c2.getSelectedItem().toString();
String uu = c4.getSelectedItem().toString();
                
Model model = ModelFactory.createDefaultModel();
String u1 = u.substring(u.lastIndexOf("#") + 1);
String str=u1.replace('_',' ');
String uu1 = uu.substring(uu.lastIndexOf("#") + 1);
String str1=uu1.replace('_',' ');
    
    
                Resource node = model.createResource(u)
                         .addProperty(VCARD.N,
                                      model.createResource()
                                           .addProperty(FOAF.name, str));
                
                
        Resource node1 = model.createResource(uu)
                         .addProperty(VCARD.N,
                                      model.createResource()
                                           .addProperty(FOAF.name, str1));
        String s = c4.getSelectedItem().toString();         
    if(add.getActionListeners()!=null)
        {   
            Resource[] nodes = new Resource[panel_2.getComponentCount()-2];
            for(int i = 0 ; i<panel_2.getComponentCount()-2;i++)

            {
        String s1 = s.substring(s.lastIndexOf("#") + 1);// to get the final substring
        String s2=s1.replace('_',' ');
      nodes[i] = model.createResource(s)
                 .addProperty(VCARD.N,
                              model.createResource()
                                   .addProperty(FOAF.name,s2));
        
            
}   
0 Answers
Related