API Jena - 获取数据属性的值

发布于 2024-11-29 17:04:30 字数 10926 浏览 3 评论 0原文

我用java创建了一个界面,有4个标签、4个文本字段和一些按钮,如“添加”、“修改”、“下一步”等。用户将输入姓名、名字、出生日期等。单击“添加”按钮后,他输入的信息将添加到 rdf 文件中。我使用的是 API Jena,“下一步”(法语为“Suivant”)按钮不起作用。不明白为什么。你能解释一下出了什么问题吗?

完整代码:

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;


public class FamilyModel extends Frame
{   
TextField[]tabTF=new TextField[4];
Button bAjout, bModifier, bSupprimer, bPrecedent, bSuivant;
OntModel model;
Onto onto;

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,100,25);
    add(la);
}


public FamilyModel ()
{
        setLayout (null);
        setBackground (Color.pink);
        setBounds (100,200,600,450);

        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,45,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); 
        setVisible(true);

        bModifier=creerBouton("Modifier",138,250); 
        setVisible(true);

        bSupprimer=creerBouton("Supprimer",250,250); 
        setVisible(true);

        bPrecedent=creerBouton("Precedent",360,250); 

        bSuivant=creerBouton("Suivant",450,250); 
        setVisible(true);   

        onto = new Onto();

        readFileRDF();

        traitement(this); 


}



void traitement(Frame fenetre)
{

    bAjout.addActionListener(new ActionAjoutPersonne());
    bSuivant.addActionListener(new ActionSuivant());
}


//Button Add
public class ActionAjoutPersonne implements ActionListener
{

    public void actionPerformed(ActionEvent evt)
    {

        Resource p1 = onto.model.createResource(onto.uriBase+tabTF[0].getText());


        p1.addProperty(onto.aPourPrenom, tabTF[0].getText());         
        p1.addProperty(onto.aPourNom, tabTF[1].getText());         
        p1.addProperty(onto.aDateNaiss, tabTF[2].getText()); 

        if (tabTF[3].getText().equals("F"))
        {
            p1.addProperty(onto.aGenre, tabTF[3].getText()); 
            p1.addProperty(RDF.type, onto.femme);
        }
        else if (tabTF[3].getText().equals("H"))
        {
            p1.addProperty(onto.aGenre, tabTF[3].getText());    
            p1.addProperty(RDF.type, onto.homme);
        }

        StringWriter sw = new StringWriter();
        onto.model.write(sw, "RDF/XML-ABBREV");
        String owlCode = sw.toString();
        File file = new File("d:/Onto1.rdf");
        try{
            FileWriter fw = new FileWriter(file);
            fw.write(owlCode);
            fw.close();
        } catch(FileNotFoundException fnfe){
            fnfe.printStackTrace();} 
        catch(IOException ioe){
                ioe.printStackTrace();
        }                
    }
}



public void readFileRDF(){
     String inputFile="D:/Onto1.rdf";
     try{
     InputStream in =new  FileInputStream(inputFile);
      if (in == null) {  
      System.out.println("File not found");
     }  
      onto.model.read(in," ");

     }catch(Exception e) {
           System.out.println("model.read catched error: " + e);
     }
}

//Button Next
class ActionSuivant implements ActionListener
{
    public void actionPerformed(ActionEvent evt)
    {

        readFileRDF();

        //Instances Classe Personne    
        ExtendedIterator instances=onto.personne.listInstances();


        while (instances.hasNext())
            {

                 Individual thisInstance = (Individual) instances.next();
                 thisInstance.getLocalName();

                 {

                   tabTF[0].setText((thisInstance.getPropertyValue(onto.aPourPrenom)).toString());
                   tabTF[1].setText((thisInstance.getPropertyValue(onto.aPourNom)).toString());
                   tabTF[2].setText((thisInstance.getPropertyValue(onto.aDateNaiss)).toString());
                   tabTF[3].setText((thisInstance.getPropertyValue(onto.aGenre)).toString());
                 }
                 System.out.println("Hello-Apres If");                 
             }
         }
    }


//ontologie
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");


    //Sous-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();      
}
}

Onto.rdf 文件:

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:j.0="http://www.something.com/FAM#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://www.something.com/FAM"/>
  <owl:Class rdf:about="http://www.something.com/FAM#divorce">
<rdfs:subClassOf>
  <owl:Class rdf:about="http://www.something.com/FAM#evenement"/>
</rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#masculin">
    <rdfs:subClassOf>
      <owl:Class rdf:about="http://www.something.com/FAM#genre"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#deces">
    <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#evenement"/>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#feminin">
    <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#genre"/>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#mariage">
     <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#evenement"/>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#femme">
    <rdfs:subClassOf>
      <owl:Class rdf:about="http://www.something.com/FAM#personne"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#homme">
    <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#personne"/>
   </owl:Class>
  <owl:ObjectProperty rdf:about="http://www.something.com/FAM#aGenre">
    <rdfs:range rdf:resource="http://www.something.com/FAM#genre"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="http://www.something.com/FAM#aPourFille">
    <rdfs:range rdf:resource="http://www.something.com/FAM#femme"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="http://www.something.com/FAM#aPourFils">
    <rdfs:range rdf:resource="http://www.something.com/FAM#homme"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:ObjectProperty>
  <owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aPourNom">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aDateNaiss">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aPourPrenom">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
   </owl:DatatypeProperty>
  <j.0:femme rdf:about="http://www.something.com/FAMRita">
    <j.0:aGenre>F</j.0:aGenre>
    <j.0:aDateNaiss>Mars</j.0:aDateNaiss>
    <j.0:aPourNom>Henriques</j.0:aPourNom>
    <j.0:aPourPrenom>Rita</j.0:aPourPrenom>
  </j.0:femme>
  <rdf:Description rdf:about="http://www.something.com/FAMRicardo">
    <j.0:aGenre>H</j.0:aGenre>
    <j.0:aDateNaiss>maio</j.0:aDateNaiss>
    <j.0:aPourNom>Silva</j.0:aPourNom>
    <j.0:aPourPrenom>Ricardo</j.0:aPourPrenom>
  </rdf:Description>

I created an interface in java with 4 labels, 4 textfields and some buttons like "Add", "modify, "next", etc. The user will enter name, first name, birth date, etc. After clicking the button "add", the information that he has entered will be added on rdf file. I'm using API Jena. The "next" (in french "Suivant") button does not work. When i click "Next", nothing appears on textfields. I don't understand why. Can you explain me what's wrong?

Complete Code:

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;


public class FamilyModel extends Frame
{   
TextField[]tabTF=new TextField[4];
Button bAjout, bModifier, bSupprimer, bPrecedent, bSuivant;
OntModel model;
Onto onto;

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,100,25);
    add(la);
}


public FamilyModel ()
{
        setLayout (null);
        setBackground (Color.pink);
        setBounds (100,200,600,450);

        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,45,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); 
        setVisible(true);

        bModifier=creerBouton("Modifier",138,250); 
        setVisible(true);

        bSupprimer=creerBouton("Supprimer",250,250); 
        setVisible(true);

        bPrecedent=creerBouton("Precedent",360,250); 

        bSuivant=creerBouton("Suivant",450,250); 
        setVisible(true);   

        onto = new Onto();

        readFileRDF();

        traitement(this); 


}



void traitement(Frame fenetre)
{

    bAjout.addActionListener(new ActionAjoutPersonne());
    bSuivant.addActionListener(new ActionSuivant());
}


//Button Add
public class ActionAjoutPersonne implements ActionListener
{

    public void actionPerformed(ActionEvent evt)
    {

        Resource p1 = onto.model.createResource(onto.uriBase+tabTF[0].getText());


        p1.addProperty(onto.aPourPrenom, tabTF[0].getText());         
        p1.addProperty(onto.aPourNom, tabTF[1].getText());         
        p1.addProperty(onto.aDateNaiss, tabTF[2].getText()); 

        if (tabTF[3].getText().equals("F"))
        {
            p1.addProperty(onto.aGenre, tabTF[3].getText()); 
            p1.addProperty(RDF.type, onto.femme);
        }
        else if (tabTF[3].getText().equals("H"))
        {
            p1.addProperty(onto.aGenre, tabTF[3].getText());    
            p1.addProperty(RDF.type, onto.homme);
        }

        StringWriter sw = new StringWriter();
        onto.model.write(sw, "RDF/XML-ABBREV");
        String owlCode = sw.toString();
        File file = new File("d:/Onto1.rdf");
        try{
            FileWriter fw = new FileWriter(file);
            fw.write(owlCode);
            fw.close();
        } catch(FileNotFoundException fnfe){
            fnfe.printStackTrace();} 
        catch(IOException ioe){
                ioe.printStackTrace();
        }                
    }
}



public void readFileRDF(){
     String inputFile="D:/Onto1.rdf";
     try{
     InputStream in =new  FileInputStream(inputFile);
      if (in == null) {  
      System.out.println("File not found");
     }  
      onto.model.read(in," ");

     }catch(Exception e) {
           System.out.println("model.read catched error: " + e);
     }
}

//Button Next
class ActionSuivant implements ActionListener
{
    public void actionPerformed(ActionEvent evt)
    {

        readFileRDF();

        //Instances Classe Personne    
        ExtendedIterator instances=onto.personne.listInstances();


        while (instances.hasNext())
            {

                 Individual thisInstance = (Individual) instances.next();
                 thisInstance.getLocalName();

                 {

                   tabTF[0].setText((thisInstance.getPropertyValue(onto.aPourPrenom)).toString());
                   tabTF[1].setText((thisInstance.getPropertyValue(onto.aPourNom)).toString());
                   tabTF[2].setText((thisInstance.getPropertyValue(onto.aDateNaiss)).toString());
                   tabTF[3].setText((thisInstance.getPropertyValue(onto.aGenre)).toString());
                 }
                 System.out.println("Hello-Apres If");                 
             }
         }
    }


//ontologie
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");


    //Sous-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();      
}
}

Onto.rdf file:

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:j.0="http://www.something.com/FAM#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://www.something.com/FAM"/>
  <owl:Class rdf:about="http://www.something.com/FAM#divorce">
<rdfs:subClassOf>
  <owl:Class rdf:about="http://www.something.com/FAM#evenement"/>
</rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#masculin">
    <rdfs:subClassOf>
      <owl:Class rdf:about="http://www.something.com/FAM#genre"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#deces">
    <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#evenement"/>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#feminin">
    <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#genre"/>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#mariage">
     <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#evenement"/>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#femme">
    <rdfs:subClassOf>
      <owl:Class rdf:about="http://www.something.com/FAM#personne"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.something.com/FAM#homme">
    <rdfs:subClassOf rdf:resource="http://www.something.com/FAM#personne"/>
   </owl:Class>
  <owl:ObjectProperty rdf:about="http://www.something.com/FAM#aGenre">
    <rdfs:range rdf:resource="http://www.something.com/FAM#genre"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="http://www.something.com/FAM#aPourFille">
    <rdfs:range rdf:resource="http://www.something.com/FAM#femme"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="http://www.something.com/FAM#aPourFils">
    <rdfs:range rdf:resource="http://www.something.com/FAM#homme"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:ObjectProperty>
  <owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aPourNom">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aDateNaiss">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aPourPrenom">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/>
   </owl:DatatypeProperty>
  <j.0:femme rdf:about="http://www.something.com/FAMRita">
    <j.0:aGenre>F</j.0:aGenre>
    <j.0:aDateNaiss>Mars</j.0:aDateNaiss>
    <j.0:aPourNom>Henriques</j.0:aPourNom>
    <j.0:aPourPrenom>Rita</j.0:aPourPrenom>
  </j.0:femme>
  <rdf:Description rdf:about="http://www.something.com/FAMRicardo">
    <j.0:aGenre>H</j.0:aGenre>
    <j.0:aDateNaiss>maio</j.0:aDateNaiss>
    <j.0:aPourNom>Silva</j.0:aPourNom>
    <j.0:aPourPrenom>Ricardo</j.0:aPourPrenom>
  </rdf:Description>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-12-06 17:04:30

好的,这就是发生的事情。当用户点击 Suivant 按钮时,操作侦听器会读取 Onto1.rdf 文件的内容,并尝试使用 资源的 RDF 值填充表单rdf:type http://www.something.com/FAM#personne。在该 RDF 文件中,有两个资源,包括 ...#FAMRitardf:type http://www.something.com/FAM#femme< /代码>。由于 #femme 是一个子类型(即 rdfs:subClassOf#personne,因此您可以合理地期望列出 personne 的实例OntClass 将返回 FAMRita 实例。

然而,这种情况并没有发生,这就是为什么您没有填写表单字段的原因。原因是这样的:

public Onto() {
    model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );

在耶拿,OntModel 是用 xxx_MEM 制作的> 配置文件特别没有打开推理。这意味着该模型不会推断出#FAMRita也具有类型#personne,因此它不会由listInstances迭代器。

简单的解决方法是:

public Onto() {
    model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );

这意味着你会得到推论,丽塔就会出现。

OK, here's what is happening. When a user hits the Suivant button, the action listener reads the contents of the Onto1.rdf file, and attempts to populate the form with RDF values for resources of rdf:type http://www.something.com/FAM#personne. In that RDF file, there are two resources including ...#FAMRita of rdf:type http://www.something.com/FAM#femme. Since #femme is a sub-type (ie rdfs:subClassOf) #personne, it's reasonable for you to expect that listing instance of the personne OntClass will return the FAMRita instance.

However, that doesn't happen, which is why you don't get your form fields filled in. The reason is this:

public Onto() {
    model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );

In Jena, the OntModels made with a xxx_MEM profile specifically have no reasoning turned on. This means that the model does not infer that #FAMRita also has type #personne, hence it not returned by the listInstances iterator.

The easy fix is this:

public Onto() {
    model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );

which means that you will get inference, and Rita will show up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文