Re: [MarkLogic Dev General] Dynamically building a structured query
Charles – Adding the @method attribute doesn't seem to have any effect. Maybe defaulting to auto or digest when it's missing is an undocumented feature. The way I understood xdmp:url-encode, it's supposed to be functionally similar to encode-for-uri but with prettier, more human-readible output. The W3C function is fine for our purposes, but I thought it was odd that xdmp:http-get didn't like the output of xdmp:url-encode. It's not a show stopper, but if no one knows I can punt this to support and report back. -Will From: Charles GreerOrganization: MarkLogic Corporation Reply-To: MarkLogic Discussion Date: Thursday, February 21, 2013 1:31 PM To: MarkLogic Discussion Subject: Re: [MarkLogic Dev General] Dynamically building a structured query Hi Will, I'm surprised that url-encode and encode-for-uri are different; maybe somebody more knowledgeable can explain that one. All things equal, I'd prefer the w3c function that you found. I'm assuming that 401 is a bit closer to the solution, not a different error -- are you missing a method attribute on http:authentication? The default REST server requires method="digest" Charles On 02/21/2013 01:19 PM, Will Thompson wrote: After some testing, it appears that xdmp:http-get doesn't like xdmp:xdmp:url-encode output, but it's okay with fn:encode-for-uri. The call is to a self-signed SSL appserver. This works: let $rest-url := concat($url, 'v1/values/uris?options=uris&format=xml&structuredQuery=', fn:encode-for-uri(xdmp:quote($q))) return xdmp:http-get($url, { element http:authentication { element http:username { 'user' }, element http:password { 'pass' } } } falsehttp:verify-cert> ) But swapping fn:encode-for-uri for xdmp:url-encode results in a 401 error: 401 Unauthorized Digest realm="public", qop="auth", nonce="c975aeaf1b6774e1a51f5b30d9ca7c61", opaque="a08df0deda23d70d" application/xml MarkLogic 211 close "http://marklogic.com/rest-api"> 401 Failed Auth Unauthenticated I tested saving the output of both functions to a local file and using those strings to hit the endpoint from a browser, and they both worked. Is this a bug or something I likely don't understand about http-get and/or url-encode? -Will From: Charles Greer Organization: MarkLogic Corporation Reply-To: MarkLogic Discussion Date: Wednesday, February 20, 2013 4:24 PM To: MarkLogic Discussion Subject: Re: [MarkLogic Dev General] Dynamically building a structured query Hi Will, What's wrong with double quotes? Are you looking to encode the whole shebang? How about concat($url, $path, "?options=uris&structuredQuery=", xdmp:url-encode(xdmp:quote($structured-query-xml))) Charles On 02/20/2013 04:06 PM, Will Thompson wrote: > This is kind of a pedantic style-related question, but I am building a > structured query and want to submit it to the REST values endpoint. However, > that endpoint doesn't like double quotes, so I can't do something tidy like: > concat($url, $path, "?options=uris&structuredQuery=", > xdmp:quote($structured-query-xml)) because xdmp:quote outputs double quotes for > the namespace declaration. I tried POSTing the XML, but the values endpoint only > accepts GET requests (?). I couldn't find an option to force xdmp:quote to > serialize attributes using single quotes (maybe that’s not technically allowed?). > > Is there a better way to approach this, or is my best option to just replace the > double quotes from xdmp:quote output? > > -Will > > > > > ___ > General mailing list > General@developer.marklogic.comhttp://developer.marklogic.com/mailman/listinfo/general -- Charles Greer Senior Engineer MarkLogic Corporation charles.gr...@marklogic.com Phone: +1 707 408 3277 www.marklogic.com ___ General mailing list General@developer.marklogic.comhttp://developer.marklogic.com/mailman/listinfo/general -- Charles Greer Senior Engineer MarkLogic Corporation charles.gr...@marklogic.com Phone: +1 707 408 3277 www.marklogic.com ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] gettext for XML and MarkLogic?
I like a good challenge and love to break my teeth on this but first i have to create a map with d3 using a so-called dorling cartogram algorithm (the data comes of course from MarkLogic) see you very much later! ;-) cheers, Jakob. On Thu, Feb 21, 2013 at 8:39 PM, Ryan Dew wrote: > I like that approach. I opened an issue to look into it how I can > incorporate those ideas into my library. Who knows, though, Jakob might > just beat me to it. > > Thanks, > Ryan Dew > > > On Thu, Feb 21, 2013 at 7:18 AM, Florent Georges wrote: > >> Ryan Dew wrote: >> >> > Those are interesting enhancements. I don't think it would be >> > hard at all to extend it to support injection of numbers or >> > words. Simply have the map entry contain an additional element >> > that ties itself to a position in a sequence of items passed >> > and replace it appropriately. >> >> The problem is that the position itself could be dependent on >> the locale :-) >> >> > To be honest, I have no idea how I would address singular/ >> > plural forms. It seems like that would have to be handled >> > externally and the bundle would just need separate keys in a >> > bundle for singular and plural forms. If you have any >> > suggestions, I would love to here them. >> >> The approach I used a few years ago (God, that was in 2005 >> actually, time's flying :-P) is described succently there: >> >> http://xsl.markmail.org/thread/zg4irqyap5begxmc >> >> Basically it uses XML to express a kind of format string, >> instead of simple strings, and use elements as placeholders. It >> also had more sophisticated features for some domain-specific >> formatting, like formating a "person" using a format string, to >> have different address or name formatting. But the general idea >> is something like: >> >> >>The amount is . >> >> >>Le montant est . >> >> >> The place where the text must appear (the "caller") must >> provide a value for the place holder. This value can itself be >> locale-dependent (e.g. different numbers formating, in EN you use >> "." as the decimal point and in FR we use ","). This example is >> very simple and could be resolved by using simple strings and by >> having the caller assembling them, but in some cases if you have >> 2 variable parts A and B, in one language you will have part A >> appearing before B and in another language B appearing before A. >> With such a "template" format each localization can reorganize >> itself the variable parts. >> >> For variable parts that are themselves dependent on some >> dynamic values, the part can be a sort of a map: >> >> >>The book contains >> . >> >> >>Le livre contient >> . >> >> >> The caller has to define that he'll pass a value for "number" >> (most likely a number) and a value for "sections" (either "sg" or >> "pl" to select the singular or plural form). The result is a >> more-or-less readable sentence with elements for variable parts. >> >> This is just my recollection after several years, and the >> solution is probably not perfect, but it gives more flexibility >> to people localizing the keys, and developers internationalizing >> just have to define the different keys and the name of the >> variable parts if any. >> >> Regards, >> >> -- >> Florent Georges >> http://fgeorges.org/ >> http://h2oconsulting.be/ >> > > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Dynamically building a structured query
Hi Will, I'm surprised that url-encode and encode-for-uri are different; maybe somebody more knowledgeable can explain that one. All things equal, I'd prefer the w3c function that you found. I'm assuming that 401 is a bit closer to the solution, not a different error -- are you missing a method attribute on http:authentication? The default REST server requires method="digest" Charles On 02/21/2013 01:19 PM, Will Thompson wrote: After some testing, it appears that xdmp:http-get doesn't like xdmp:xdmp:url-encode output, but it's okay with fn:encode-for-uri. The call is to a self-signed SSL appserver. This works: let $rest-url := concat($url, 'v1/values/uris?options=uris&format=xml&structuredQuery=', fn:encode-for-uri(xdmp:quote($q))) return xdmp:http-get($url, { element http:authentication { element http:username { 'user' }, element http:password { 'pass' } } } false ) But swapping fn:encode-for-uri for xdmp:url-encode results in a 401 error: 401 Unauthorized Digest realm="public", qop="auth", nonce="c975aeaf1b6774e1a51f5b30d9ca7c61", opaque="a08df0deda23d70d" application/xml MarkLogic 211 close http://marklogic.com/rest-api";> 401 Failed Auth Unauthenticated I tested saving the output of both functions to a local file and using those strings to hit the endpoint from a browser, and they both worked. Is this a bug or something I likely don't understand about http-get and/or url-encode? -Will From: Charles Greer mailto:cgr...@marklogic.com>> Organization: MarkLogic Corporation Reply-To: MarkLogic Discussion mailto:general@developer.marklogic.com>> Date: Wednesday, February 20, 2013 4:24 PM To: MarkLogic Discussion mailto:general@developer.marklogic.com>> Subject: Re: [MarkLogic Dev General] Dynamically building a structured query Hi Will, What's wrong with double quotes? Are you looking to encode the whole shebang? How about concat($url, $path, "?options=uris&structuredQuery=", xdmp:url-encode(xdmp:quote($structured-query-xml))) Charles On 02/20/2013 04:06 PM, Will Thompson wrote: > This is kind of a pedantic style-related question, but I am building a > structured query and want to submit it to the REST values endpoint. However, > that endpoint doesn't like double quotes, so I can't do something tidy like: > concat($url, $path, "?options=uris&structuredQuery=", > xdmp:quote($structured-query-xml)) because xdmp:quote outputs double quotes for > the namespace declaration. I tried POSTing the XML, but the values endpoint only > accepts GET requests (?). I couldn't find an option to force xdmp:quote to > serialize attributes using single quotes (maybe that's not technically allowed?). > > Is there a better way to approach this, or is my best option to just replace the > double quotes from xdmp:quote output? > > -Will > > > > > ___ > General mailing list > General@developer.marklogic.comhttp://developer.marklogic.com/mailman/listinfo/general -- Charles Greer Senior Engineer MarkLogic Corporation charles.gr...@marklogic.com Phone: +1 707 408 3277 www.marklogic.com ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general -- Charles Greer Senior Engineer MarkLogic Corporation charles.gr...@marklogic.com Phone: +1 707 408 3277 www.marklogic.com ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Dynamically building a structured query
After some testing, it appears that xdmp:http-get doesn't like xdmp:xdmp:url-encode output, but it's okay with fn:encode-for-uri. The call is to a self-signed SSL appserver. This works: let $rest-url := concat($url, 'v1/values/uris?options=uris&format=xml&structuredQuery=', fn:encode-for-uri(xdmp:quote($q))) return xdmp:http-get($url, { element http:authentication { element http:username { 'user' }, element http:password { 'pass' } } } false ) But swapping fn:encode-for-uri for xdmp:url-encode results in a 401 error: 401 Unauthorized Digest realm="public", qop="auth", nonce="c975aeaf1b6774e1a51f5b30d9ca7c61", opaque="a08df0deda23d70d" application/xml MarkLogic 211 close 401 Failed Auth Unauthenticated I tested saving the output of both functions to a local file and using those strings to hit the endpoint from a browser, and they both worked. Is this a bug or something I likely don't understand about http-get and/or url-encode? -Will From: Charles GreerOrganization: MarkLogic Corporation Reply-To: MarkLogic Discussion Date: Wednesday, February 20, 2013 4:24 PM To: MarkLogic Discussion Subject: Re: [MarkLogic Dev General] Dynamically building a structured query Hi Will, What's wrong with double quotes? Are you looking to encode the whole shebang? How about concat($url, $path, "?options=uris&structuredQuery=", xdmp:url-encode(xdmp:quote($structured-query-xml))) Charles On 02/20/2013 04:06 PM, Will Thompson wrote: This is kind of a pedantic style-related question, but I am building a structured query and want to submit it to the REST values endpoint. However, that endpoint doesn't like double quotes, so I can't do something tidy like: concat($url, $path, "?options=uris&structuredQuery=", xdmp:quote($structured-query-xml)) because xdmp:quote outputs double quotes for the namespace declaration. I tried POSTing the XML, but the values endpoint only accepts GET requests (?). I couldn't find an option to force xdmp:quote to serialize attributes using single quotes (maybe that’s not technically allowed?). Is there a better way to approach this, or is my best option to just replace the double quotes from xdmp:quote output? -Will ___ General mailing list General@developer.marklogic.comhttp://developer.marklogic.com/mailman/listinfo/general -- Charles Greer Senior Engineer MarkLogic Corporation charles.gr...@marklogic.com Phone: +1 707 408 3277 www.marklogic.com ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] gettext for XML and MarkLogic?
Ryan Dew wrote: > I like that approach. I opened an issue to look into it how I > can incorporate those ideas into my library. Who knows, > though, Jakob might just beat me to it. Excellent, let us know about the progress! For those interested: https://github.com/ryanjdew/XQuery-i18n/issues/1 Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] gettext for XML and MarkLogic?
I like that approach. I opened an issue to look into it how I can incorporate those ideas into my library. Who knows, though, Jakob might just beat me to it. Thanks, Ryan Dew On Thu, Feb 21, 2013 at 7:18 AM, Florent Georges wrote: > Ryan Dew wrote: > > > Those are interesting enhancements. I don't think it would be > > hard at all to extend it to support injection of numbers or > > words. Simply have the map entry contain an additional element > > that ties itself to a position in a sequence of items passed > > and replace it appropriately. > > The problem is that the position itself could be dependent on > the locale :-) > > > To be honest, I have no idea how I would address singular/ > > plural forms. It seems like that would have to be handled > > externally and the bundle would just need separate keys in a > > bundle for singular and plural forms. If you have any > > suggestions, I would love to here them. > > The approach I used a few years ago (God, that was in 2005 > actually, time's flying :-P) is described succently there: > > http://xsl.markmail.org/thread/zg4irqyap5begxmc > > Basically it uses XML to express a kind of format string, > instead of simple strings, and use elements as placeholders. It > also had more sophisticated features for some domain-specific > formatting, like formating a "person" using a format string, to > have different address or name formatting. But the general idea > is something like: > > >The amount is . > > >Le montant est . > > > The place where the text must appear (the "caller") must > provide a value for the place holder. This value can itself be > locale-dependent (e.g. different numbers formating, in EN you use > "." as the decimal point and in FR we use ","). This example is > very simple and could be resolved by using simple strings and by > having the caller assembling them, but in some cases if you have > 2 variable parts A and B, in one language you will have part A > appearing before B and in another language B appearing before A. > With such a "template" format each localization can reorganize > itself the variable parts. > > For variable parts that are themselves dependent on some > dynamic values, the part can be a sort of a map: > > >The book contains > . > > >Le livre contient > . > > > The caller has to define that he'll pass a value for "number" > (most likely a number) and a value for "sections" (either "sg" or > "pl" to select the singular or plural form). The result is a > more-or-less readable sentence with elements for variable parts. > > This is just my recollection after several years, and the > solution is probably not perfect, but it gives more flexibility > to people localizing the keys, and developers internationalizing > just have to define the different keys and the name of the > variable parts if any. > > Regards, > > -- > Florent Georges > http://fgeorges.org/ > http://h2oconsulting.be/ > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] gettext for XML and MarkLogic?
Ryan Dew wrote: > Those are interesting enhancements. I don't think it would be > hard at all to extend it to support injection of numbers or > words. Simply have the map entry contain an additional element > that ties itself to a position in a sequence of items passed > and replace it appropriately. The problem is that the position itself could be dependent on the locale :-) > To be honest, I have no idea how I would address singular/ > plural forms. It seems like that would have to be handled > externally and the bundle would just need separate keys in a > bundle for singular and plural forms. If you have any > suggestions, I would love to here them. The approach I used a few years ago (God, that was in 2005 actually, time's flying :-P) is described succently there: http://xsl.markmail.org/thread/zg4irqyap5begxmc Basically it uses XML to express a kind of format string, instead of simple strings, and use elements as placeholders. It also had more sophisticated features for some domain-specific formatting, like formating a "person" using a format string, to have different address or name formatting. But the general idea is something like: The amount is . Le montant est . The place where the text must appear (the "caller") must provide a value for the place holder. This value can itself be locale-dependent (e.g. different numbers formating, in EN you use "." as the decimal point and in FR we use ","). This example is very simple and could be resolved by using simple strings and by having the caller assembling them, but in some cases if you have 2 variable parts A and B, in one language you will have part A appearing before B and in another language B appearing before A. With such a "template" format each localization can reorganize itself the variable parts. For variable parts that are themselves dependent on some dynamic values, the part can be a sort of a map: The book contains . Le livre contient . The caller has to define that he'll pass a value for "number" (most likely a number) and a value for "sections" (either "sg" or "pl" to select the singular or plural form). The result is a more-or-less readable sentence with elements for variable parts. This is just my recollection after several years, and the solution is probably not perfect, but it gives more flexibility to people localizing the keys, and developers internationalizing just have to define the different keys and the name of the variable parts if any. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] gettext for XML and MarkLogic?
Those are interesting enhancements. I don't think it would be hard at all to extend it to support injection of numbers or words. Simply have the map entry contain an additional element that ties itself to a position in a sequence of items passed and replace it appropriately. To be honest, I have no idea how I would address singular/plural forms. It seems like that would have to be handled externally and the bundle would just need separate keys in a bundle for singular and plural forms. If you have any suggestions, I would love to here them. Unless, you were just suggesting, like the above, that you could inject a plural or singular form of a word into a longer string, which is probably what you meant now that I think about it. Thanks, Ryan Dew On Thu, Feb 21, 2013 at 4:00 AM, Florent Georges wrote: > Ryan Dew wrote: > > Hi, > > > I'm sure it can be improved, but if you want to see an example > > of a library that makes use of map:map objects and server > > fields, like Mike mentioned, you can go here: > > https://github.com/ryanjdew/XQuery-i18n/blob/master/i18n.xqy > > Interesting. But if I am right, it only resolves strings given > two key: a name and a locale. But the tricky part is to inject > variable parts. For instance numbers (computed by the app), > adapting words with singular/plural forms, injecting additional > words (e.g. adjectives generally don't go to the same place in EN > and FR), etc. > > Did I miss anything? Or do you have any plan to support some > of those? > > Regards, > > -- > Florent Georges > http://fgeorges.org/ > http://h2oconsulting.be/ > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] gettext for XML and MarkLogic?
Ryan Dew wrote: Hi, > I'm sure it can be improved, but if you want to see an example > of a library that makes use of map:map objects and server > fields, like Mike mentioned, you can go here: > https://github.com/ryanjdew/XQuery-i18n/blob/master/i18n.xqy Interesting. But if I am right, it only resolves strings given two key: a name and a locale. But the tricky part is to inject variable parts. For instance numbers (computed by the app), adapting words with singular/plural forms, injecting additional words (e.g. adjectives generally don't go to the same place in EN and FR), etc. Did I miss anything? Or do you have any plan to support some of those? Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general