简体   繁体   English

如何使用 Java 代码启动 Fuseki 服务器并使用 java 代码将 OWL 文件上传到它?

[英]How to start Fuseki server using Java code and upload OWL file to it using java code?

I want to start Fuseki server using Java code.Then I want to upload OWL file into it.我想使用 Java 代码启动 Fuseki 服务器。然后我想将 OWL 文件上传到其中。 Now I started using following CMD code and manually upload the file.Is there any possible way to do it using Java code?现在我开始使用下面的 CMD 代码并手动上传文件。有没有办法使用 Java 代码来做到这一点? Server starting code using CMD.服务器起始代码使用 CMD。

    D:
    cd Fuseki
    cd jena-fuseki-1.0.1
    fuseki-server --update --mem /ds

Is there any possible way to run above code in JAVA code and upload a OWL file into Fuseki server?有没有办法在 JAVA 代码中运行上述代码并将 OWL 文件上传到 Fuseki 服务器?

The core idea of the solution is to use Jena ARQ API.该解决方案的核心思想是使用Jena ARQ API。 You need to use class com.hp.hpl.jena.query.DatasetAccessor and .putModel() method.您需要使用 class com.hp.hpl.jena.query.DatasetAccessor.putModel()方法。

This blog https://pinesong.ghost.io/how-to-upload-rdf-file-to-jena-fuseki-server-using-java-code gives the details.这篇博客https://pinesong.ghost.io/how-to-upload-rdf-file-to-jena-fuseki-server-using-java-code提供了详细信息。

This can be done using the fuseki as an embedded server.这可以使用 fuseki 作为嵌入式服务器来完成。 You can either opt for persistance using a triplestore TDB that Jena comes with or you can create an in-memory model.您可以选择使用 Jena 附带的三重存储 TDB 的持久性,也可以创建内存中的 model。 I'll show the case for the former but the idea remains the same for the latter.我将展示前者的情况,但后者的想法仍然相同。

//Creating a persistent triple store (Jena TDB)
String dir = "C:\\..."; // triplestore directory
Dataset dataset = TDBFactory.createDataset(dir);

//Loading an ontology stored on the disk
String ontDir = "C:\\...ontology.owl"; //Directory of your OWL file
Model graph = RDFDataMgr.loadModel(ontDir);

dataset.addNamedModel("..GraphURI..", graph);

// Starting the fuseki server
FusekiServer fusekiServer = FusekiServer.create()
            .port(3001)
            .add("/ds", dataset, true)
            .build();

fusekiServer.start();

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

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