我有一个简单的RDF文件,并希望将其转换为漂亮的嵌套JSON.
:b0 a <http://schema.org/Book> ;
<http://schema.org/name> "Semantic Web Primer (First Edition)" ;
<http://schema.org/offers> _:b1 ;
<http://schema.org/publisher> "Linked Data Tools" .
_:b1 a <http://schema.org/Offer> ;
<http://schema.org/price> "2.95" ;
<http://schema.org/priceCurrency> "USD" .
Run Code Online (Sandbox Code Playgroud)
应该成为
{
"type" : "Book",
"name" : "Semantic Web Primer (First Edition)",
"offers" : {
"type" : "Offer",
"price" : "2.95",
"priceCurrency" : "USD"
},
"publisher" : "Linked Data Tools"
}
Run Code Online (Sandbox Code Playgroud) 我已经HTTPRepository初始化了一个仓库的URL。我使用RepositoryConnection来检索(天气)数据并将其添加到存储库。从Web服务检索数据,然后将其转换为RDF语句,并将其添加到存储库中。这是由独立应用程序定期完成的。
当我在IntelliJ中运行此应用程序时,一切正常。
为了在服务器上运行此应用程序,我创建了一个jar文件(包含所有依赖项)。该应用程序将按预期启动,并且能够从存储库中检索数据。
但是,当应用程序尝试将数据写入存储库时,我得到了UnsupportedRDFormatException:
org.eclipse.rdf4j.rio.UnsupportedRDFormatException: Did not recognise RDF format object BinaryRDF (mimeTypes=application/x-binary-rdf; ext=brf)
at org.eclipse.rdf4j.rio.Rio.lambda$unsupportedFormat$0(Rio.java:568) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_111]
at org.eclipse.rdf4j.rio.Rio.createWriter(Rio.java:134) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.rio.Rio.write(Rio.java:371) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.rio.Rio.write(Rio.java:324) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.addModel(HTTPRepositoryConnection.java:588) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.flushTransactionState(HTTPRepositoryConnection.java:662) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.commit(HTTPRepositoryConnection.java:326) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection.conditionalCommit(AbstractRepositoryConnection.java:366) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection.add(AbstractRepositoryConnection.java:431) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at nl.wur.fbr.data.weather.WeatherApp.retrieveData(WeatherApp.java:122) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at nl.wur.fbr.data.weather.WeatherData$WeatherTask.run(WeatherData.java:105) [weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_111]
at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_111]
Run Code Online (Sandbox Code Playgroud)
发生错误的源代码是:
org.eclipse.rdf4j.rio.UnsupportedRDFormatException: Did not recognise RDF format object BinaryRDF (mimeTypes=application/x-binary-rdf; ext=brf)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用Ontotext GraphDB的一个实例,并且经常想要清除具有大量三元组的命名图.
目前,我的技术涉及向图形服务器发出SPARQL命令,该命令搜索并匹配命名图形中每个三元组的三重模式:
DELETE { GRAPH example:exampleGraph { ?s ?p ?o }} WHERE {?s ?p ?o .}
Run Code Online (Sandbox Code Playgroud)
当存在大量三元组时,这种方法通常需要相当长的时间来清除命名图.
我想知道是否有更有效的方法来做到这一点.即使是特定于三层商店的解决方案也是我可以接受的.
我还应该注意到我正在使用RDF4J库与图表进行通信.我知道某些解决方案可能适用于Ontotext Web界面,但我只对我可以以编程方式实现的解决方案感兴趣.
我的 rdf4j 有问题:我想从我的 GraphDB 存储库中删除“Feed”所有带有feed:hashCode谓词的三元组。
第一个查询验证是否存在一个三元组,其中url参数作为主语,feed:hashCode作为谓语,并且hash参数具有宾语,并且它有效。如果我的存储库中不存在此语句,则第二个查询开始,它应该删除所有带有feed:hashCode谓词和url主语的三元组,但它不起作用,问题是什么?
这是代码:
public static boolean updateFeedQuery(String url, String hash) throws RDFParseException, RepositoryException, IOException{
Boolean result=false;
Repository repository = new SPARQLRepository("http://localhost:7200/repositories/Feed");
repository.initialize();
try {
try (RepositoryConnection conn = repository.getConnection()) {
BooleanQuery feedUrlQuery = conn.prepareBooleanQuery(
// @formatter:off
"PREFIX : <http://purl.org/rss/1.0/>\n" +
"PREFIX feed: <http://feed.org/>\n" +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
"ASK{\n" +
"<"+url+"> feed:hashCode \""+hash+"\";\n"+
"rdf:type :channel.\n" +
"}"
// @formatter:on
); …Run Code Online (Sandbox Code Playgroud)