我正在为ML8 Java API写一些POC。我已经在ML8中为我的数据库启用了三重索引,但是我在Java API文档中找不到任何文档。因此,不确定如何从Java API中使用这个三元索引,或者这是否纯粹是一个数据库设置问题。如果任何人有..请分享一些信息。
发布于 2015-03-03 01:22:52
MarkLogic REST API附带了两个端点,/v1/graphs
和/v1/graphs/sparql
,它们实现了SPARQL协议。
使用后者对REST服务器执行SPARQL和SPARQL update查询。当Jena和Sesame出现时,我已经成功地编写了Java应用程序,它们可以开箱即用地使用这些端点。
这些示例基本上是从Jena和Sesame文档中抄袭过来的。这两个项目都有很好的文档。
对于Sesame,请使用SPARQLRepository。
Repository rep = new SPARQLRepository(ENDPOINT);
rep.initialize();
RepositoryConnection conn = rep.getConnection();
String queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } ";
TupleQuery tupleQuery = conn.prepareTupleQuery(
QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
try {
while (result.hasNext()) { // iterate over the result
BindingSet bindingSet = result.next();
Value valueOfX = bindingSet.getValue("x");
Value valueOfY = bindingSet.getValue("y");
System.out.println(valueOfX);
System.out.println(valueOfY);
}
} finally {
result.close();
}
在Jena中,使用如下代码:
String ENDPOINT = "http://localhost:8007/v1/graphs";
HttpAuthenticator authenticator = new SimpleAuthenticator("admin",
"admin".toCharArray());
// make a model by parsing a file
Model model = ModelFactory.createDefaultModel();
String turtle = "src/main/resources/data/one.ttl";
model.read(turtle, null);
// configure access to graph protocol
DatasetGraphAccessor markLogicClient = new DatasetGraphAccessorHTTP(
ENDPOINT, authenticator);
DatasetAdapter datasetAdapter = new DatasetAdapter(markLogicClient);
// add a graph to MarkLogic
datasetAdapter.add(model);
String query = "select ?s ?p ?o where { ?s ?p ?o } limit 1";
QueryExecution queryExec = QueryExecutionFactory
.sparqlService(URI, query, authenticator);
ResultSet results = queryExec.execSelect();
logger.debug("Success. Result: " + results.toString());
for (; results.hasNext();) {
QuerySolution soln = results.nextSolution();
Iterator<String> i = soln.varNames();
for (; i.hasNext();) {
String n = i.next();
logger.debug("Name: " + n + " Val: "
+ soln.get(n).toString());
}
发布于 2015-03-02 19:14:11
据我所知,Java API对XQuery的'sem:‘函数组没有提供太多支持,您必须使用/编写扩展(如果有)来添加所需的功能。一年前,我曾问过关于加载RDF数据的类似问题,我认为这与您的问题有点相关:
MarkLogic sem: function group in MarkLogic Java API
正如你可以在上面的链接中看到的,你可以使用许多‘变通方法’,比如REST API调用和用于加载的mlcp。
发布于 2015-03-02 22:23:19
使用Java来调用XQuery or JavaScript program which calls the sem:
API。您可以通过使用模块调用或use XCC module invocation directly的extending the high-level Java API来完成此操作。如果您扩展了Java API,您可能会考虑将您的工作开源,以供他人使用。
https://stackoverflow.com/questions/28806138
复制相似问题