RDF4J Workbench Add RDF: How do I add multiple files?

陌路散爱 提交于 2019-12-11 04:59:31

问题


I'm using RDF4J Workbench 2.1.2.

System Information
Application Information
Application Name    RDF4J Workbench
Version 2.1.2
Runtime Information
Operating System    Windows 10 10.0 (amd64)
Java Runtime    Oracle Corporation Java HotSpot(TM) 64-Bit Server VM (1.8.0_111)
Process User    gwcox
Memory
Used    315 MB
Maximum 889 MB

I have a set of RDF files containing ontologies I'm working on. Some RDF files import others. For example, my instantiations ontology/RDF file imports the several ontologies defining my classes and relationships.

The RDF files are stored locally, not at the URIs used to identify them. I often need to clear my repository and re-load my ontologies in the process of development and debugging. At present, a half-dozen ontologies need to be loaded for full functionality.

How can I load multiple ontologies stored as local files into my active repository in RDF4J workbench? I can use RDF4J workbench itself or a command line script to do the loading. I know I can manually use the Modify/Add command from the workbench multiple times, but I'd like to reduce it to one command to save time and avoid errors.

Thanks.


回答1:


RDF4J Workbench itself has no functionality to add multiple files in one go.

However, if this is something that you need to repeatedly execute, a simple approach is to use the Console, and write a short batch script for it. The script is simply a text file with successive Console commands (one per line). For example:

open myRepository
clear
load /path/to/file1.rdf into urn:context1
load /path/to/file2.rdf into urn:context2

Then you can simply execute this by doing (from the command line):

cat script.txt | ./console.sh 

Another way to achieve what you want is to use curl, and to access the RDF4J Server directly via its REST API. For example, to upload a Turtle file to your repository using curl, you'd do something like this:

curl -X POST -H "Content-type: text/turtle" --data-binary @file.ttl http://localhost:8080/rdf4j-server/repositories/myRepo/statements

Finally, you could of course also write a short Java program, using the RDF4J Repository API to communicate with the server.




回答2:


To elaborate on Jeen Broekstra's answer, I'm going with the Console script. Here's my particular script (loadMyOntologies.txt):

connect "http://localhost:8088/rdf4j-server"
open TakeRDF4J4SPIN
clear
load "C:\Users\Greg\TBCFreeWorkspace\NSC_2025_Sharing\soo.rdf"
load "C:\Users\Greg\TBCFreeWorkspace\NSC_2025_Sharing\Instantiations.rdf"
exit

Note that I've changed the port that my Apache Tomcat server runs on to 8088.

Of course, others' versions will vary in the name of the repository (open command argument) and the paths to the ontologies.

I will add more load commands as I increase the number of my ontologies I'm working with. Also, I'm working in the default context/graph, so I've omitted the optional urn:context that Jeen included.

I access the above through a simple batch (loadMyOntologies.bat) file since I'm working with Windows 8:

.\console.bat < loadMyOntologies.txt

My batch and text files are in my RDF4J bin directory (path abbreviated below), where console.bat is located (the Windows version of console.sh that Jeen mentioned):

c:\Users\Greg\...\eclipse-rdf4j-2.0.1\bin

I've confirmed in RDF4J workbench that I can combine this script with working in the workbench, and the script will save me a considerable amount of time, especially as I combine more ontologies to solve larger problems.

If you're paying really close attention, you may notice that the version of RDF4J in this example (2.0.1) is older than the version I initially posted (2.1.2). I'm finishing up on a different machine that I haven't updated yet, but it works! I'm sure this solution applies to the newer version on my other machine as well.



来源:https://stackoverflow.com/questions/40852494/rdf4j-workbench-add-rdf-how-do-i-add-multiple-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!