简体   繁体   English

将Owl API DB转换为OWL

[英]Protege Owl API DB to OWL

I need to create OWL class from the first table name if cardinality 1:1 and OWL class from the second table name. 如果基数为1:1,则需要从第一个表名称创建OWL类,而从第二个表名称创建OWL类。 If cardinality 1:* and one of tables describes object properties, create OWL object property from the first table name, than create OWL class from the second table name. 如果基数为1:*并且其中一个表描述了对象属性,则从第一个表名称创建OWL对象属性,而不是从第二个表名称创建OWL类。 How can I create OWL class from column name and do the rest? 如何从列名创建OWL类,其余的做些什么? I have Protege OWL API installed in Eclipse. 我在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   
}

} }

You need to create an OWLEntity and then add that to your manager. 您需要创建一个OWLEntity,然后将其添加到您的经理中。 Something like: 就像是:

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);

This will only allow you to add a modelling element to your ontology. 这仅允许您将建模元素添加到本体中。 Each modelling element can have appropriate restrictions added. 每个建模元素都可以添加适当的限制。 Follow the same AddAxiom syntax to add restrictions as well. 遵循相同的AddAxiom语法来添加限制。

I dont know about axioms. 我不知道公理。 I done like that: 我是那样做的:

     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);
            }

[sreen] ( http://postimg.org/image/m8vbeer7h/ ) [sreen]( http://postimg.org/image/m8vbeer7h/

You are using Jena API which is not as good as OWL API for modifying an ontology. 您使用的Jena API不如OWL API修改本体。 In your original question, you mention the use of OWL API. 在最初的问题中,您提到了OWL API的使用。 I would suggest you taking a look at it, it is way more easy: OWLAPI 我建议您看一下,它更简单: OWLAPI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM