如何将变量从java传递到turtle文件?
我有一个具有以下结构的项目:
-config
-repositories
-test-repo.ttl
test-repo.ttl 文件如下所示:
@prefix lookup: <http://www.metaphacts.com/ontologies/platform/repository/lookup#> .
@prefix pathfinder: <http://www.metaphacts.com/ontologies/platform/service/pathfinder/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rep: <http://www.openrdf.org/config/repository#> .
@prefix sail: <http://www.openrdf.org/config/sail#> .
@prefix sr: <http://www.openrdf.org/config/repository/sail#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mph: <http://www.metaphacts.com/ontologies/platform/repository#> .
@prefix ephedra: <http://www.metaphacts.com/ontologies/platform/ephedra#> .
@prefix fedsail: <http://www.openrdf.org/config/sail/federation#> .
@prefix sparqlr: <http://www.openrdf.org/config/repository/sparql#> .
[] a rep:Repository;
rep:repositoryID "test-repo";
rdfs:label "Repository to access data.";
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository";
sr:sailImpl [
sail:sailType "metaphacts:RESTService";
ephedra:serviceURL "https://request-to-access-data.com";
ephedra:implementsService ephedra:test-ephedra;
ephedra:httpMethod "GET";
ephedra:httpHeader [
ephedra:name "Authorization";
ephedra:value "my_secret_token"
]
]
] .
每次运行项目时,字符串 my_secret_token 都会发生变化,因此我需要从 java 文件输入其值。我是java的绝对初学者。是否可以有一个 java 文件,在其中创建 my_secret_token 变量并为其分配值“123”,然后将该值传递给海龟文件中的 ephedra:value 字段?
如果是这样,你能帮助我实现这一目标吗?
I have a project with the structure:
-config
-repositories
-test-repo.ttl
The test-repo.ttl file looks like this:
@prefix lookup: <http://www.metaphacts.com/ontologies/platform/repository/lookup#> .
@prefix pathfinder: <http://www.metaphacts.com/ontologies/platform/service/pathfinder/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rep: <http://www.openrdf.org/config/repository#> .
@prefix sail: <http://www.openrdf.org/config/sail#> .
@prefix sr: <http://www.openrdf.org/config/repository/sail#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mph: <http://www.metaphacts.com/ontologies/platform/repository#> .
@prefix ephedra: <http://www.metaphacts.com/ontologies/platform/ephedra#> .
@prefix fedsail: <http://www.openrdf.org/config/sail/federation#> .
@prefix sparqlr: <http://www.openrdf.org/config/repository/sparql#> .
[] a rep:Repository;
rep:repositoryID "test-repo";
rdfs:label "Repository to access data.";
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository";
sr:sailImpl [
sail:sailType "metaphacts:RESTService";
ephedra:serviceURL "https://request-to-access-data.com";
ephedra:implementsService ephedra:test-ephedra;
ephedra:httpMethod "GET";
ephedra:httpHeader [
ephedra:name "Authorization";
ephedra:value "my_secret_token"
]
]
] .
The string my_secret_token changes every time the project is run, so I would need to imput its value from a java file. I am an absolute beginner in java. Is it possible to have a java file in which I create the my_secret_token variable and assign it the value of "123" for example, and then to pass this value to the ephedra:value
field in the turtle file?
If so, can you help me to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我完全理解你想要做什么,但如果纯粹是为了更改 Turtle 文件中的文字字符串,我想一种简单的方法是将文件读入内存中的 RDf 模型,更改值,然后再次将模型写回文件。像这样的东西(未经测试,但希望它给出了总体思路):
I am not sure I fully understand what you're trying to do, but if it's purely about changing that literal string in your Turtle file, I guess one simple way to do is to read the file into an in-memory RDf model, change the value, then write the model back to file again. Something like this (untested, but it gives the general idea hopefully):