0

如果基数为 1:1,我需要从第一个表名创建 OWL 类,从第二个表名创建 OWL 类。如果基数为 1:* 并且其中一个表描述了对象属性,则从第一个表名创建 OWL 对象属性,而不是从第二个表名创建 OWL 类。如何从列名创建 OWL 类并完成其余工作?我在 Eclipse 中安装了 Protege OWL API。

package snippet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import edu.stanford.smi.protege.exception.OntologyLoadException;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.model.OWLNamedClass;

public class Snippet {

public static void main(String[] args) throws OntologyLoadException {
    //-Dprotege.dir=

    //  SQL Server DB with JDBC
     String url = "jdbc:sqlserver://xxx:1433";
     String userName = "xxx";
     String password = "xxx";

    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection con = DriverManager.getConnection (url, userName, password);
        Statement smt = con.createStatement();
        smt.executeQuery("SELECT * from table_references");
        ResultSet rs = smt.getResultSet();

        while (rs.next()) { 
            String column1 = rs.getString("referenced_object_id");
            String column2 = rs.getString("name");
            String column3 = rs.getString("parent_column_id");
            String column4 = rs.getString("referenced_column_id");

            System.out.println(column1 + " | " + column2 + " | " + column3 + " | " + column4);
        }   

    } 
    catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //Protege API   
}

}

4

3 回答 3

0

您需要创建一个 OWLEntity,然后将其添加到您的经理。就像是:

String axiom=ontoIRI+"#"+input;

        //convert String into OWLAxiom
        OWLEntity entity=factory.getOWLEntity(EntityType.CLASS,IRI.create(axiom));

        //executing addition
        OWLDeclarationAxiom tempAxiom= factory.getOWLDeclarationAxiom(entity) ;

        // Add the axiom to our ontology
        AddAxiom addAx = new AddAxiom(tempOnto, tempAxiom);
        tempManager.applyChange(addAx);

这只允许您向本体添加建模元素。每个建模元素都可以添加适当的限制。也遵循相同的 AddAxiom 语法来添加限制。

于 2013-05-23T11:49:30.347 回答
0

我不知道公理。我是这样做的:

     OWLModel owlModel = ProtegeOWL.createJenaOWLModel();
        while (rs.next()) { 
            String column1 = rs.getString("referenced_object_id");
            String column2 = rs.getString("name");
            String column3 = rs.getString("parent_column_id");
            String column4 = rs.getString("referenced_column_id");

            System.out.println(column1 + " | " + column2 + " | " +    column3 + " | " + column4);

            String sql = "SELECT name from sys.tables WHERE object_id='" + column1 + "'";

            if(column2.startsWith("op_")) {

                // create object property,class and point if its domain or range class
                //Now gettin error,that Object property already exist. Need to do something, I don't know what. 
               // if(owlModel.getJenaModel().contains(column2))  maybe

                OWLObjectProperty Property = owlModel.createOWLObjectProperty(column2);

            } else {
                // create class
                OWLNamedClass clas = owlModel.createOWLNamedClass(column2);
            }

[屏幕](http://postimg.org/image/m8vbeer7h/

于 2013-05-23T18:56:45.337 回答
0

您正在使用 Jena API,它不如 OWL API 来修改本体。在您最初的问题中,您提到了 OWL API 的使用。我建议你看看它,它更容易:OWLAPI

于 2013-05-23T20:24:37.947 回答