0

私はApache Jenaプロジェクトに取り組んでいます。ローカルホストで Fuseki サーバーを実行しています。トリプルストアのすべてのデータを JTable に表示する Fuseki サーバー用の Java プログラムを作成したいと考えています。クエリの結果を JTable に解析する方法がわかりません。

私のコードソファ:(ウィンドウ、テーブル、フレームなどが作成される部分を省略)

private void Go() {
    String query = "SELECT ?subject ?predicate ?object \n" +
                   "WHERE { \n" +
                   "?subject ?predicate ?object }";
    Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ) ;
    QueryEngineHTTP httpQuery = new QueryEngineHTTP("http://localhost:3030/AnimalDataSet/", sparqlQuery);

    ResultSet results = httpQuery.execSelect();
    System.out.println(ResultSetFormatter.asText(results));
    while (results.hasNext()) {
        QuerySolution solution = results.next();
    }
    httpQuery.close();
}

sysout はこれを出力します。これは正しいデータです。

-------------------------------------------------------------------------------------------------------------------------------------
| subject                    | predicate                                         | object                                           |
=====================================================================================================================================
| <urn:animals:data>         | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | <http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq> |
| <urn:animals:data>         | <http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>   | <urn:animals:lion>                               |
| <urn:animals:data>         | <http://www.w3.org/1999/02/22-rdf-syntax-ns#_2>   | <urn:animals:tarantula>                          |
| <urn:animals:data>         | <http://www.w3.org/1999/02/22-rdf-syntax-ns#_3>   | <urn:animals:hippopotamus>                       |
| <urn:animals:lion>         | <http://www.some-ficticious-zoo.com/rdf#name>     | "Lion"                                           |
| <urn:animals:lion>         | <http://www.some-ficticious-zoo.com/rdf#species>  | "Panthera leo"                                   |
| <urn:animals:lion>         | <http://www.some-ficticious-zoo.com/rdf#class>    | "Mammal"                                         |
| <urn:animals:tarantula>    | <http://www.some-ficticious-zoo.com/rdf#name>     | "Tarantula"                                      |
| <urn:animals:tarantula>    | <http://www.some-ficticious-zoo.com/rdf#species>  | "Avicularia avicularia"                          |
| <urn:animals:tarantula>    | <http://www.some-ficticious-zoo.com/rdf#class>    | "Arachnid"                                       |
| <urn:animals:hippopotamus> | <http://www.some-ficticious-zoo.com/rdf#name>     | "Hippopotamus"                                   |
| <urn:animals:hippopotamus> | <http://www.some-ficticious-zoo.com/rdf#species>  | "Hippopotamus amphibius"                         |
| <urn:animals:hippopotamus> | <http://www.some-ficticious-zoo.com/rdf#class>    | "Mammal"                                         |
-------------------------------------------------------------------------------------------------------------------------------------

ここの誰かが、クエリからのデータを JTbale に解析する方法を知っていることを本当に願っています:D

前もって感謝します!

4

1 に答える 1

1

私はさらにいくつかの調査を行い、最終的に解決策を見つけました!実際には非常に簡単です。

while ループを次のように変更するだけです。

while(rs.hasNext())
    {
        QuerySolution sol = rs.nextSolution();
        RDFNode object = sol.get("object"); 
        RDFNode predicate = sol.get("predicate"); 
        RDFNode subject = sol.get("subject");

        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.addRow(new Object[]{subject, predicate, object});
    }

そして、それは私にとってはうまくいきます!

興味のあるすべての人のために、コメントのあるペーストビンに現在のバージョンを公開しました: 私のプロジェクトの完全な(現在の)バージョンへのリンク

于 2015-11-25T14:20:08.007 に答える