2016-04-19 8 views
-1

ARQを使用してOntModelインスタンスをトリプルストア(TDBなど)に挿入するにはどうすればよいですか? 。単に本を作成し、そして今、私はトリプルストアにこれを挿入したいOntModelにこれらを追加するコード:ARQ(Jena用SPARQLプロセッサ)を使用してOntModelインスタンスをTDBなどのように挿入する

public static void createDummyBooks(){ 
     // Create an empty ontology model 
     OntModel ontModel = ModelFactory.createOntologyModel(); 
     String ns = new String("http://www.iexample.com/book#"); 
     String baseURI = new String("http://www.iexample.com/book"); 
     Ontology onto = ontModel.createOntology(baseURI); 

     //creating a book 
     OntClass book = ontModel.createClass(ns + "Book"); 
     OntClass nonFinctionBook = ontModel.createClass(ns + "NonFictionBook"); 
     OntClass fictionBook = ontModel.createClass(ns + "FictionBook"); 

     // Create datatype property 'hasAge' 
     DatatypeProperty hasTtitle = ontModel.createDatatypeProperty(ns + "hasTitle"); 
     // 'hasAge' takes integer values, so its range is 'integer' 
     // Basic datatypes are defined in the ‘vocabulary’ package 
     hasTtitle.setDomain(book); 
     hasTtitle.setRange(XSD.xstring); // com.hp.hpl.jena.vocabulary.XSD 

     // Create individuals 
     Individual theProgrammingBook = nonFinctionBook.createIndividual(ns + "ProgrammingBook"); 
     Individual theFantasyBook = fictionBook.createIndividual(ns + "FantasyBook"); 


     Literal bookTitle = ontModel.createTypedLiteral("Programming with Ishmael", XSDDatatype.XSDstring); 
     Literal fantasyBookTitle = ontModel.createTypedLiteral("The adventures of Ishmael", XSDDatatype.XSDstring); 
     // Create statement 'ProgrammingBook hasTitle "Programming with Ishmael" ' 
     Statement theProgrammingBookHasTitle = ontModel.createStatement(nonFinctionBook, hasTtitle, bookTitle); 
     // Create statement 'FantasyBook hasTitle "The adventures of Ishmael" ' 
     Statement theFantasyBookHasTitle = ontModel.createStatement(theFantasyBook, hasTtitle, fantasyBookTitle); 
     List<Statement> statements = new ArrayList<Statement>();  
     statements.add(theProgrammingBookHasTitle); 
     statements.add(theFantasyBookHasTitle); 

     ontModel.add(statements); 
     //just displaying here - but how do I now write/insert this into my Triple Store/TDB using AQR API? 
     ontModel.write(System.out, "RDF/XML-ABBREV"); 

    } 

任意のアイデアに感謝

+1

オントロジーの開発の場でも働いているのですが、何が役に立たないのかを気にせずに、この質問に投票するのはなぜですか?質問に答えることができない場合は、スキップして助けてくれる他の質問を見てください。 – ishmaelMakitla

答えて

1

いくつか検索した後とAPIで遊んで?。私はこれを見つけたvery useful tutorial - それは特定の焦点を持っていたが、それは私に何をする必要があるかについての良いアイデアを与えました。どのようにしてHTTPデータセットアクセッサーDatasetAccessorを使用して私の最終的にOntModelを私の既存のdatasetに挿入/追加することができましたか?

//The Graph Store protocol for sem_tutorials (my dummy dataset) is http://localhost:3030/sem_tutorials/data 
private static final String FUSEKI_SERVICE_DATASETS_URI = "http://localhost:3030/sem_tutorials/data"; 
private void testSavingModel(OntModel model){ 
    DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(FUSEKI_SERVICE_DATASETS_URI); 
if(accessor != null){ 
    //because I already had a number of Triples there already - I am only adding this model 
    accessor.add(model); 
    } 
} 

これは簡単でした。 SPARQLクエリselect * {?s ?p ?o}を実行してチェックしたところ、データはそこにありました! これは、Jenaを使用してセマンティックWebアプリケーションを開発している人にも役立つことを願っています。

+1

最後に、Jena APIとFusekiサーバーの間のギャップを埋め尽くす方法を紹介している最後に有益なチュートリアルをお寄せいただきありがとうございます。私はこの質問が純粋なドキュメンテーションとこのトピックに関するチュートリアルベースを考慮して、なぜ落とされたのか理解できません。 – Macilias

0

こちらのチュートリアルは素晴らしく、最後にOntModelをhttpでFusekiに転送する方法を示しています。ここでは完全を期すために埋め込まれた布石3.4.0に同じことを行う方法の例次のとおりです。http DatasetAccessorと同様に

// this will represent content of the db 
    Dataset ds = DatasetFactory.createTxnMem(); 
    DatasetGraph dsg = ds.asDatasetGraph(); 

    // here some Jena Objects to be inserted 
    String NS = "http://myexample.com/#" 
    OntModel m = ModelFactory.createOntologyModel(); 
    OntClass r = m.createClass(NS + Request.class.getName()); 
    Individual i = r.createIndividual(NS + request.hashCode()); 

    FusekiServer server = FusekiServer.create() 
       .setPort(4321) 
       .add("/ds", ds) 
       .build(); 
    server.start(); 

    DatasetAccessor accessor = DatasetAccessorFactory.create(ds); 

    //upload Jena Model into Fuseki 
    Txn.executeWrite(dsg,() -> { 
     accessor.add(m); 
     TDB.sync(dsg); 
     dsg.commit(); 
    }); 

    //query content of Fuseki 
    Txn.executeWrite(dsg,() -> { 
     Quad q = SSE.parseQuad("(_ :s :p _:b)"); 
     dsg.add(q); 
    }); 

はここで重要です。私が思いついたこの例を最適化する方法を知っているなら、コメントしてください!

Jena API < - >埋め込みFusekiに関する例があることが分かっていれば、こちらも追加してください!