import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.impl.*;
import com.hp.hpl.jena.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.XSD;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import org.apache.log4j.Logger;
public class FamilyModel extends Frame{
TextField[]tabTF=new TextField[4];
Button bAjout, bModifier, bSupprimer, bPrecedent, bSuivant;
Button creerBouton(String S, int x, int y)
{
Button b=new Button(S);
add(b);
b.setBounds(x,y,120,30);
return b;
}
void creerLabel(String etiquette, int x, int y)
{
Label la=new Label(etiquette);
la.setBounds(x,y,120,25);
add(la);
}
public FamilyModel ()
{
setLayout (null);
setBackground (Color.pink);
setBounds (100,200,600,450);
addWindowListener(new FermerFenetre()); //close windows when click on X
creerLabel("Prenom : ",10,50);
creerLabel("Nom : ",10,100);
creerLabel("Date de Naissance: ",10,145);
creerLabel("Genre (H ou F): ",10,190);
//TextFields
for(int i=0;i<4;i++)
{
tabTF[i]=new TextField("");
tabTF[i].setBackground(Color.white);
add(tabTF[i]);
}
tabTF[0].setBounds(120,50,150,25);
tabTF[1].setBounds(120,100,150,25);
tabTF[2].setBounds(120,145, 100,25);
tabTF[3].setBounds(120,190, 45,25);
bAjout=creerBouton("Ajouter",20,250); //Add
setVisible(true);
bModifier=creerBouton("Modifier",138,250); //Modify
setVisible(true);
bSupprimer=creerBouton("Supprimer",250,250); //Remove
setVisible(true);
bPrecedent=creerBouton("Precedent",360,250); //back
bSuivant=creerBouton("Suivant",450,250); //next
setVisible(true);
traitement(this);
}
void traitement(Frame fenetre)
{
bAjout.addActionListener(new ActionAjoutPersonne()); //Add
bSuivant.addActionListener(new ActionSuivant()); //Next
}
//ActionAdd
public class ActionAjoutPersonne extends Onto implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Onto f;
f = new Onto();
for(int i=0;i<4;i++)
{
tabTF[i].getText();
Resource p1 = model.createResource(uriBase+tabTF[0].getText());
p1.addProperty(RDF.type, f.personne);
if (i==0)
{
p1.addProperty(f.aPourPrenom, tabTF[i].getText());
}
if (i==1)
{
p1.addProperty(f.aPourNom, tabTF[i].getText());
}
if (i==2)
{
p1.addProperty(f.aDateNaiss, tabTF[i].getText());
}
if (i==3)
{
if (tabTF[i].getText().equals("F"))
{
p1.addProperty(f.aGenre, tabTF[i].getText());
p1.addProperty(RDF.type, f.femme);
}
else
if (tabTF[i].getText().equals("H"))
{
p1.addProperty(f.aGenre, tabTF[i].getText());
p1.addProperty(RDF.type, f.homme);
}
}
StringWriter sw = new StringWriter();
model.write(sw, "RDF/XML-ABBREV");
String owlCode = sw.toString();
File file = new File("d:/teste20.rdf");
try{
FileWriter fw = new FileWriter(file);
fw.write(owlCode);
fw.close();
} catch(FileNotFoundException fnfe){
fnfe.printStackTrace();}
catch(IOException ioe){
ioe.printStackTrace();
}
}
}
}
//ActionNext
class ActionSuivant extends Onto implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Onto s = new Onto();
int indice=1;
String []M= new String [10];
//Read RDF File
InputStream in = FileManager.get().open("d:\teste20.rdf");
if (in == null)
{
throw new IllegalArgumentException("File: " + "d:\teste20.rdf" + " not found");
}
s.model.read(in, null);
//Search instances of Personne Class
ExtendedIterator instances=s.personne.listInstances();
indice++;
for(int p=0;p<10;p++) //10 instances
{
while (instances.hasNext())
{
Individual thisInstance = (Individual) instances.next();
M[p]= thisInstance.getLocalName();
if(p==indice)
{
tabTF[0].setText((thisInstance.getPropertyResourceValue(s.aPourPrenom)).toString());
tabTF[1].setText((thisInstance.getPropertyResourceValue(s.aPourNom)).toString());
tabTF[2].setText((thisInstance.getPropertyResourceValue(s.aDateNaiss)).toString());
}
}
}
}
}
//Clode window when clicked on X
public class FermerFenetre extends WindowAdapter {
public void windowClosing(WindowEvent evt)
{
if(evt.getWindow().getName().equals("frame0"))
{
System.exit(0);
}
else
{
evt.getWindow().dispose();
}
}
}
//ontology
public class Onto
{
OntClass personne, genre, homme, femme, feminin, masculin, evenement, deces, mariage, divorce;
OntModel model;
String uriBase;
ObjectProperty aPourFils, aPourFille, aGenre;
DatatypeProperty aPourNom, aPourPrenom, aDateNaiss;
public Onto (){
model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
uriBase = "http://www.something.com/FAM";
model.createOntology(uriBase);
//Classes
personne = model.createClass(uriBase+"#personne");
femme = model.createClass(uriBase+"#femme");
homme = model.createClass(uriBase+"#homme");
genre = model.createClass(uriBase+"#genre");
feminin = model.createClass(uriBase+"#feminin");
masculin = model.createClass(uriBase+"#masculin");
evenement = model.createClass(uriBase+"#evenement");
deces = model.createClass(uriBase+"#deces");
mariage = model.createClass(uriBase+"#mariage");
divorce = model.createClass(uriBase+"#divorce");
//Sub-classes
genre.addSubClass(feminin);
genre.addSubClass(masculin);
personne.addSubClass(homme);
personne.addSubClass(femme);
evenement.addSubClass(deces);
evenement.addSubClass(mariage);
evenement.addSubClass(divorce);
aPourFils = model.createObjectProperty(uriBase+"#aPourFils");
aPourFils.setDomain(personne);
aPourFils.setRange(homme);
aPourFille = model.createObjectProperty(uriBase+"#aPourFille");
aPourFille.setDomain(personne);
aPourFille.setRange(femme);
aGenre = model.createObjectProperty(uriBase+"#aGenre");
aGenre.setDomain(personne);
aGenre.setRange(genre);
aPourNom = model.createDatatypeProperty(uriBase+"#aPourNom");
aPourNom.setDomain(personne);
aPourNom.setRange(XSD.xstring);
aPourPrenom = model.createDatatypeProperty(uriBase+"#aPourPrenom");
aPourPrenom.setDomain(personne);
aPourPrenom.setRange(XSD.xstring);
aDateNaiss = model.createDatatypeProperty(uriBase+"#aDateNaiss");
aDateNaiss.setDomain(personne);
aDateNaiss.setRange(XSD.xstring);
}
}
public static void main(String args[])
{
new FamilyModel();
}
}