marklogic / marklogic-jena

Adapter for using MarkLogic with the Jena RDF Framework
Other
5 stars 11 forks source link

Adding and deleting triples with BCP 47 language codes fails #39

Closed MichalWozniakSmartlogic closed 7 years ago

MichalWozniakSmartlogic commented 8 years ago

Issue: failing adding and deleting triples to/from Marklogic database with languages in the BCP 47 format. Tested on Marklogic database server 8.0.4.

Background: In order to send triples to the database we use a dedicated method "mergeGraph(String uri, Graph graph)" of class JenaDatabaseClient in the marklogic-jena client. However, adding of such a triple fails:

http://smartlogic.com/label#PLA http://www.w3.org/2008/05/skos-xl#literalForm "CDM12501"@en-123

with the following response from the server (for an analogous triple):

RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: XDMP-DOCUNEXPECTED1.0-mlxdmp:nquad($body, $options) -- syntax error, unexpected - at :1:146falsexdmp:nquad($body, $options)syntax error, unexpected -1146/MarkLogic/rest-api/models/semantics-model.xqy1146semmod:extract-triples-from-body(map:map(ap.../map:map), (), document{text{"<http://smartlogic.com/label#225170089852404799936514360679_P..."}})headersmap:map(ap.../map:map)repair()bodydocument{text{"<http://smartlogic.com/label#225170089852404799936514360679_P..."}}content-type"application/n-triples"options()1.0-ml/MarkLogic/rest-api/models/semantics-model.xqy76149semmod:graph-insert(map:map(ap.../map:map), map:map(1866948629.../map:map), document{text{"<http://smartlogic.com/label#225170089852404799936514360679_P..."}}, eput:config-callback#2, fn:true())headersmap:map(ap.../map:map)paramsmap:map(1866948629.../map:map)bodydocument{text{"<http://smartlogic.com/label#225170089852404799936514360679_P..."}}callbackeput:config-callback#2append-permissionsfn:true()graphsem:iri("urn:x-evn-master:m4")_()content-type"application/n-triples"_()category()param-permissions()_()role-names()role-ids()request-permissions()repair()putative-result"CONTENT_UPDATED"old-permissions(sec:capabilityupdate/sec:capabilitysec:role-id166759843341.../sec:permission, sec:capabilityread/sec:capabilitysec:role-id16675984334178.../sec:permission, sec:capabilityupdate/sec:capabilitysec:role-id155206546613.../sec:permission, ...)update-perms()1.0-ml/MarkLogic/rest-api/models/semantics-model.xqy6524semmod:graph-insert(map:map(ap.../map:map), map:map(1866948629.../map:map), document{text{"<http://smartlogic.com/label#225170089852404799936514360679_P..."}}, eput:config-callback#2)1.0-ml/MarkLogic/rest-api/endpoints/graphstore-update.xqy4491.0-ml

Qconsole: Also, it turns out there is no easy way to add that triple via qconsole. In particular, the following query fails:

INSERT {
  GRAPH <x-evn-master:myExample> {
    <http://smartlogic.com/label#PLA> <http://www.w3.org/2008/05/skos-xl#literalForm> "CDM12501"@en-123
  }
} WHERE {}

with the following message:

[1.0-ml] XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected -, expecting } Stack Trace

At line 3 column 99: In sem:sparql-update("INSERT { GRAPH x-evn-master:myExample { <http://...", (), (), (), ())

  1. INSERT {
  2. GRAPH {
  3. http://smartlogic.com/label#PLA http://www.w3.org/2008/05/skos-xl#literalForm "CDM12501"@en-123
  4. }
  5. } WHERE {}

Temporary workaround: lead by clues on BCP 47 from documentation about the SPARQLQueryDefinition class we have implemented a workaround to this problem by writing the following function (that makes use of MarkLogicDatasetGraph.bindObject to pass the language code as a binding rather than a triple statement):

  private void mergeWithSparql(Node graphUri, List<Triple> ts) {
    PrefixMapping pm = marklogicGraph.getPrefixMapping();
    StringBuilder sb = new StringBuilder();
    sb.append(QueryHelpers.prefixMappingAsString(pm));
    sb.append("\n");
    sb.append("INSERT { GRAPH " + FmtUtils.stringForURI(graphUri.getURI()) + " { \n");
    for (int i = 0; i < ts.size(); i++) {
      Triple t = ts.get(i);
      String template = "%s %s ?o" + String.valueOf(i) + " .\n";
      String sStr = FmtUtils.stringForNode(t.getSubject(), pm);
      String pStr = FmtUtils.stringForNode(t.getPredicate(), pm);
      String tripleStr = String.format(template, sStr, pStr);
      sb.append(tripleStr);
    }
    sb.append("}} WHERE {}");

    SPARQLQueryDefinition qdef = new SPARQLQueryDefinitionImpl(sb.toString());
    for (int i = 0; i < ts.size(); i++) {
      Triple t = ts.get(i);
      qdef = MarkLogicDatasetGraph.bindObject(qdef, "o" + String.valueOf(i), t.getObject());
    }
    client.executeUpdate(qdef);
  }
grechaw commented 8 years ago

Thanks for making this issue. I made an internal issue (number 38358) that has been fixed. Release 8.0-5 will not require this workaround -- I'll leave this issue in place until that server release is out.

grechaw commented 8 years ago

Marklogic Server 8.0-5 was released some time ago. @MichalWozniakSmartlogic maybe you'd like to confirm whether this is now fixed.

grechaw commented 7 years ago

Closing this issue as it has been fixed in the 8.0-5 release of MarkLogic. @MichalWozniakSmartlogic if you happen have problems still with language codes do feel free to reopen.