映射Jena数据库的麻烦

时间:2014-07-01 13:08:55

标签: java eclipse mapping jena ontology

我在 Jena 中的映射存在问题。我已经创建了与我的数据库 MySql 的连接,但是当我尝试读取存在映射的文件时,Eclipse给了我这个错误:

Exception in thread "main" com.hp.hpl.jena.sdb.SDBException: Can't find store description
    at com.hp.hpl.jena.sdb.StoreDesc.read(StoreDesc.java:85)
    at com.hp.hpl.jena.sdb.StoreDesc.read(StoreDesc.java:46)
    at OntModel3.main(OntModel3.java:89)

这里有我的java代码:

public class OntModel3 {

    public static void main(String[] args) throws OWLOntologyStorageException,
    OWLOntologyCreationException, IOException, SQLException  {
        String className = "com.mysql.jdbc.Driver";  
        String DB_URL = "jdbc:mysql://localhost:3306/prova_rules"; 
        String DB_USER = "root";                         
        String DB_PASSWD = "";    

        //create store description

        StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.MySQL) ;

        JDBC.loadDriverMySQL();

        SDBConnection conn = SDBFactory.createConnection(DB_URL, DB_USER, DB_PASSWD) ;
        System.out.println("mi sono connesso, forse");


        Store store = SDBFactory.connectStore(conn, storeDesc) ;
        StoreUtils.isFormatted(store);

        storeDesc = StoreDesc.read("prova-mappings.ttl");

        /*
        //  storeDesc = StoreDesc.read("prova0-mappings.ttl") ;
        Model model = SDBFactory.connectDefaultModel(store) ;

        StmtIterator sIter = model.listStatements() ;
        for ( ; sIter.hasNext() ; )
    {
        Statement stmt = sIter.nextStatement() ;
        System.out.println(stmt) ;
    }
    sIter.close() ;
    store.close() ;

    /*
    // create SDBConnection
    SDBConnection sdbConnection = new SDBConnection(DB_URL,DB_USER,DB_PASSWD);
    // connect to store
    Store store = SDBFactory.connectStore(sdbConnection,storeDesc);

    // connect store to dataset
    Dataset dataset = SDBFactory.connectDataset(store);

    System.out.println("yuppi, mi sono connesso");

    // prepare the model
    Model tmpModel = ModelFactory.createDefaultModel();
    FileManager.get().readModel(tmpModel,ontologyFile);
    System.out.println(tmpModel.size());

    System.out.println("yuppi, mi sono preparato");

    // add the model into the dataset
    dataset.getDefaultModel().add(tmpModel);

    System.out.println("yuppi, mi sono adattato");
    // all done ... hopefully
    store.close();

    /* 
     * JDBC.loadDriverMySQL();

    String jdbcURL = "jdbc:mysql://localhost:3306/provadbprogconont";

    storeDesc = StoreDesc.read("C:/Users/Michela/Desktop/Prova2/prova0-mapping.ttl") ;

    String queryString ="";

    //SDBConnectionDesc jdbcConnection;

        SDBConnection conn = SDBFactory.createConnection(jdbcURL, "root", "01234") ;
        Query query = QueryFactory.create(queryString ) ;


    Store store = SDBFactory.connectStore(conn, storeDesc) ;

    Dataset ds = SDBFactory.connectDataset(store) ;
    QueryExecution qe = QueryExecutionFactory.create(query, ds) ;
    try {
        ResultSet rs = qe.execSelect() ;
        ResultSetFormatter.out(rs) ;
    } finally { qe.close() ; }
    store.close() ;
     */
}
}

在这里你可以找到我的映射文件:

@prefix: <http://example/> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://www.semanticweb.org/prova_rules_M#> .
@base <http://example.com/base/> .

# D2RQ Namespace  
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .

# Namespace of the mapping file; does not appear in mapped data
@prefix map: <C:/Users/Tiziano/workspace/Prova2/prova-mappings.ttl> .

map:Database1 a d2rq:Database;
    d2rq:jdbcDSN "jdbc:mysql://localhost:3306/prova_rules";
    d2rq:jdbcDriver "com.mysql.jdbc.Driver";
    d2rq:username "root";
    d2rq:password "";

<MAPPING-ID1>
    rr:TriplesMap;
    rr:logicalTable [ rr:tableName "\"esame\"" ];
    rr:subjectMap [ rr:template "http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura/campowrite1={\"campowrite1\"}";
                     rr:class <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura>
 ];
    rr:predicateObjectMap [
         rr:predicate   <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura#campowrite1> ;
         rr:objectMap   [ rr:column "\"campowrite1\""; rr:datatype <http://www.w3.org/2001/XMLSchema#integer> ]
    ];
    rr:predicateObjectMap [
         rr:predicate   <http://www.semanticweb.org/aalisabeth/ontologies/2014/0/untitled-ontology-352/scrittura#campowrite2> ;
         rr:objectMap [ rr:column "\"campowrite2\"" ]
    ].

Can anyone help me with this error: 

Exception in thread "main" com.hp.hpl.jena.sdb.SDBException: Can't find store description
    at com.hp.hpl.jena.sdb.StoreDesc.read(StoreDesc.java:85)
    at com.hp.hpl.jena.sdb.StoreDesc.read(StoreDesc.java:46)
    at OntModel3.main(OntModel3.java:89)

1 个答案:

答案 0 :(得分:0)

Apache Jena SDB使用自己的数据库架构;它不提供现有SQL模式到RDF的映射。

尝试像D2RQ这样的系统。