Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with semmod:results-payload #50

Open
tpiros opened this issue Mar 4, 2017 · 16 comments
Open

Error with semmod:results-payload #50

tpiros opened this issue Mar 4, 2017 · 16 comments

Comments

@tpiros
Copy link

tpiros commented Mar 4, 2017

I can't get this to work as I am getting an error with the semmod:results-payload function:

XDMP-TOOFEWARGS: (err:XPST0017) semmod:results-payload($headers, $params, $result) -- Too few args, expected 4 but got 3 . See the MarkLogic server error log for further detail.

After checking the results-payload function signature, I can verify that it is expecting 4 arguments, the 4th argument being a 'callback'. I am using ML8 and EA4 ML9.

Any suggestions how I could fix this issue?

@grtjn
Copy link

grtjn commented Mar 4, 2017 via email

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

@grtjn I thought ml-lodelive-ng uses dbpedia and not an internal ML endpoint.

@grtjn
Copy link

grtjn commented Mar 4, 2017

It packages two pre-defined configs, one for dbpedia, one for marklogic..

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

but I guess it presumes that you're running on the same port? I have an app running on port 3000 trying to access ML on a different host.

@grtjn
Copy link

grtjn commented Mar 4, 2017

The profile factory in ml-lodlive-ng gives you a plain json config. You can patch it with straight js. You could also just compare the ml profile with what you are currently using. Just to see where it differs from the one in this project or what you were using yourself..

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

Yes, this is the relevant bit:

MarkLogicProfile.connection = {
          // http matches all http requests, so this will be the only connection settings used
          'http:': {
            endpoint: '/v1/graphs/sparql',
            accepts: 'application/sparql-results+json',
            description: {
              en: 'MarkLogic LodLive'
            }
          }
        };

This is what I have:

var MyProfileObject = {};
      MyProfileObject.endpoints = {};

      MyProfileObject.connection = {
        'http:': {  
          endpoint: 'http://192.168.56.200:8060/lodlive.xqy',
          accepts: 'application/sparql-results+json'
        }
      };

Since I'm not running my app from the same machine where ML is, according to the documentation I need this lodlive.xqy file:

"This can be loaded into MarkLogic as RDF triples and can the be exposed via a standard REST application in MarkLogic. If accessing this REST endpoint from a different host or port it will be necessary to install the lodlive.xqy module at the root of the /modules directory for that REST server. Additionally, update your lodlive profile so that the lodlive.xqy url is used as the base."

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

I of course also have this added to the config:

MyProfileObject.endpoints = {
        all: '',
        jsonp: true
      };

@grtjn
Copy link

grtjn commented Mar 4, 2017

I think the statement you need lodlive.xqy is wrong. Just prefix /v1/etc with host and port you need for you app..

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

I have done that. In that case the error changes to:

REST-UNSUPPORTEDPARAM: (err:FOER0000) Endpoint does not support query parameter: invalid parameters: _, callback for request

This is due to the fact that I am executing a JSONP request (because I am on different hosts)

@grtjn
Copy link

grtjn commented Mar 4, 2017

Yeah, dont think v1 sparql supports jsonp. Can you live without that? 😁

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

Nope 😢 I need JSONP support. The problem is in the lodlive.xqy file somewhere ... but since XQY is not my strong suite I can't really figure it out. I have managed to update the code so that it no longer throws the error mentioned in the subject to be the following:

xquery version "1.0-ml";

import module namespace semmod = "http://marklogic.com/rest-api/models/semantics"
    at "/MarkLogic/rest-api/models/semantics-model.xqy";
import module namespace eput = "http://marklogic.com/rest-api/lib/endpoint-util"
    at "/MarkLogic/rest-api/lib/endpoint-util.xqy";

declare option xdmp:mapping "false";

let $params  := map:map()
let $_ := for $i in xdmp:get-request-field-names() return map:put($params, $i, xdmp:get-request-field($i))
let $headers := eput:get-request-headers()

let $result := semmod:sparql-query($headers,$params,map:get($params, "query"))
let $response := semmod:results-payload($headers,$params,$result, ())
let $_ := xdmp:set-response-content-type($response[1])

return (
  if (map:get($params, "callback")) then fn:concat(map:get($params, "callback"), "(") else (),
  $response[2],
  if (map:get($params, "callback")) then ")" else ()

  )

But this now throws the error of:

XDMP-NONMIXEDCOMPLEXCONT: fn:data(<html xmlns="http://www.w3.org/1999/xhtml"><head><title>SPARQL results</title></head>...</html>) -- Node has complex type with non-mixed complex content

Which has lead me to the actual implementation of semantics-model.xqy and I managed to track this back to 2 things: 1) the accepts header is not being sent propertly, 2) the data that gets returned is just not correct. But this is where my XQY knowledge has depleted and I'm totally stuck

@grtjn
Copy link

grtjn commented Mar 4, 2017

I'm on mobile unfortunately. Send me a mail on my work address as a reminder, i might have a spare moment tomorrow.

Why are you stuck with jsonp? Never needed it myself.. 😉

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

I am running a Node.js app from where I would like to display a LodLive graph 😄

@tpiros
Copy link
Author

tpiros commented Mar 4, 2017

I just had an idea, I'll try to proxy my request ... 😄

@grtjn
Copy link

grtjn commented Mar 5, 2017

Did proxying help?

@tpiros
Copy link
Author

tpiros commented Mar 7, 2017

@grtjn - yes it did help. Thanks. But I'd still like to see a working version of this lodlive.xqy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants