Re: [basex-talk] Add line-number function
Thanks, I will experiment with this Universität Leipzig Institute of Computer Science, NLP Augustusplatz 10 04109 Leipzig Deutschland E-mail: cel...@informatik.uni-leipzig.de E-mail: giuseppegacel...@gmail.com Web site 1: http://www.dh.uni-leipzig.de/wo/team/ Web site 2: https://sites.google.com/site/giuseppegacelano/ > On Jul 6, 2018, at 2:32 PM, Christian Grün wrote: > > This is definitely something you can do in XQuery itself. Just a > little example, to get you started (shorter suggestions are welcome): > > let $text := text { 'this is an example' } > let $snippets := analyze-string($text, ' ')/* > let $starts := (0, fold-left($snippets, (), function($list, $result) { >let $length := string-length($result) >return if(empty($list)) then ( > $length >) else ( > ($list, $list[last()] + $length) >) > })) > for $snippet at $pos in $snippets > where local-name($snippet) = 'non-match' > return { > $snippet/text() } > > Cheers, > Christian > > > On Fri, Jul 6, 2018 at 1:59 PM Giuseppe Celano > wrote: >> >> Yes, fn:path (not fn:node)! >> >> the following works >> >> this is an example/nom/fn:path(.) >> >> with the useful result >> >> Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1] >> >> but the following does not (because tokenize() does not return a node) >> >> this is an example/tokenize(nom, " ")/fn:path(.) >> >> what I was looking for is a function returning something like >> >> http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" >> start="0" end="3">this >> http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" >> start="5" end="6">is >> http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" >> start="8" end="9">an >> http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" >> start="11" end="17">example >> >> >>> On Jul 6, 2018, at 1:39 PM, Christian Grün >>> wrote: >>> >>> Hi Giuseppe, >>> >>>> fn:node() returns the path to a node (including the text node): Is there a >>>> similar function to get character offsets within a text node? >>> >>> I am not sure what you need. Do you talk about fn:path? What could the >>> character offset be / do you have an example? >>> >>> Grazie, >>> Christian >>> >>> >>> >>>> On Jul 6, 2018, at 10:24 AM, Christian Grün >>>> wrote: >>>> >>>> Hi Symantis, >>>> >>>> The original line numbers are not stored in XML databases (they may >>>> change after updated, and would consume additional memory), so you >>>> won’t be able to retrieve them with XQuery. >>>> >>>> As far as I know, this does not work in eXist-db either; the eXist >>>> link you referenced gives you the line of the util:line-number >>>> expression in your XQuery module. As Fabrice pointed out (thanks!), >>>> this could also be realized with $err:line-number. >>>> >>>> With Saxon, it works indeed. However, you’ll need you use the -l >>>> command line option (otherwise, due to performance considerations, >>>> line numbers will be discarded as well). >>>> >>>> On query/database level, there are two ways to get a direct reference: >>>> • With fn:path, you get an XPath expression that points to your node. >>>> • With db:node-pre [1], you get a direct reference to the node in a >>>> database. >>>> >>>> Best, >>>> Christian >>>> >>>> [1] http://docs.basex.org/wiki/Database_Module#db:node-id >>>> >>>> >>>> On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD >>>> wrote: >>>> >>>> >>>> As BaseX does not work on the XML textual representation, it might not be >>>> possible. >>>> >>>> >>>> >>>> >>>> >>>> De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la >>>> part de ? ?? >>>> Envoyé : jeudi 5 juillet 2018 17:10 >>>> À : basex-talk@mailman.uni-konstanz.de >>>> Objet : [basex-talk] Add line-number function >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> Hello, could the $err:line-number [1] variable help you ? >>>> >>>> [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch >>>> >>>> Best regards, >>>> >>>> Fabrice ETANCHAUD >>>> cerfrancepch >>>> >>>> No, $err:line-number show line number of xquery file. >>>> I want this: >>>> >>>> Example.xml -> >>>> 1: >>>> 2: >>>> 3: text1 >>>> 4: text2 >>>> 5: text3 >>>> 6: text4 >>>> 7: >>>> 8: >>>> >>>> Xquery -> >>>> let $f := doc("example.xml") >>>> let $e := $f/root/child[1]/grandchild[3] >>>> >>>> let $line := line-number($e) >>>> >>>> And I want get $line = 5 ! >>>> >>>> >>>> >>> >> >
Re: [basex-talk] Add line-number function
This is definitely something you can do in XQuery itself. Just a little example, to get you started (shorter suggestions are welcome): let $text := text { 'this is an example' } let $snippets := analyze-string($text, ' ')/* let $starts := (0, fold-left($snippets, (), function($list, $result) { let $length := string-length($result) return if(empty($list)) then ( $length ) else ( ($list, $list[last()] + $length) ) })) for $snippet at $pos in $snippets where local-name($snippet) = 'non-match' return { $snippet/text() } Cheers, Christian On Fri, Jul 6, 2018 at 1:59 PM Giuseppe Celano wrote: > > Yes, fn:path (not fn:node)! > > the following works > > this is an example/nom/fn:path(.) > > with the useful result > > Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1] > > but the following does not (because tokenize() does not return a node) > > this is an example/tokenize(nom, " ")/fn:path(.) > > what I was looking for is a function returning something like > > http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="0" > end="3">this > http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="5" > end="6">is > http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="8" > end="9">an > http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" > start="11" end="17">example > > > > On Jul 6, 2018, at 1:39 PM, Christian Grün > > wrote: > > > > Hi Giuseppe, > > > >> fn:node() returns the path to a node (including the text node): Is there a > >> similar function to get character offsets within a text node? > > > > I am not sure what you need. Do you talk about fn:path? What could the > > character offset be / do you have an example? > > > > Grazie, > > Christian > > > > > > > >> On Jul 6, 2018, at 10:24 AM, Christian Grün > >> wrote: > >> > >> Hi Symantis, > >> > >> The original line numbers are not stored in XML databases (they may > >> change after updated, and would consume additional memory), so you > >> won’t be able to retrieve them with XQuery. > >> > >> As far as I know, this does not work in eXist-db either; the eXist > >> link you referenced gives you the line of the util:line-number > >> expression in your XQuery module. As Fabrice pointed out (thanks!), > >> this could also be realized with $err:line-number. > >> > >> With Saxon, it works indeed. However, you’ll need you use the -l > >> command line option (otherwise, due to performance considerations, > >> line numbers will be discarded as well). > >> > >> On query/database level, there are two ways to get a direct reference: > >> • With fn:path, you get an XPath expression that points to your node. > >> • With db:node-pre [1], you get a direct reference to the node in a > >> database. > >> > >> Best, > >> Christian > >> > >> [1] http://docs.basex.org/wiki/Database_Module#db:node-id > >> > >> > >> On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD > >> wrote: > >> > >> > >> As BaseX does not work on the XML textual representation, it might not be > >> possible. > >> > >> > >> > >> > >> > >> De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la > >> part de ? ?? > >> Envoyé : jeudi 5 juillet 2018 17:10 > >> À : basex-talk@mailman.uni-konstanz.de > >> Objet : [basex-talk] Add line-number function > >> > >> > >> > >> > >> > >> > >> > >> Hello, could the $err:line-number [1] variable help you ? > >> > >> [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch > >> > >> Best regards, > >> > >> Fabrice ETANCHAUD > >> cerfrancepch > >> > >> No, $err:line-number show line number of xquery file. > >> I want this: > >> > >> Example.xml -> > >> 1: > >> 2: > >> 3: text1 > >> 4: text2 > >> 5: text3 > >> 6: text4 > >> 7: > >> 8: > >> > >> Xquery -> > >> let $f := doc("example.xml") > >> let $e := $f/root/child[1]/grandchild[3] > >> > >> let $line := line-number($e) > >> > >> And I want get $line = 5 ! > >> > >> > >> > > >
Re: [basex-talk] Add line-number function
Yes, fn:path (not fn:node)! the following works this is an example/nom/fn:path(.) with the useful result Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1] but the following does not (because tokenize() does not return a node) this is an example/tokenize(nom, " ")/fn:path(.) what I was looking for is a function returning something like http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="0" end="3">this http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="5" end="6">is http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="8" end="9">an http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="11" end="17">example > On Jul 6, 2018, at 1:39 PM, Christian Grün wrote: > > Hi Giuseppe, > >> fn:node() returns the path to a node (including the text node): Is there a >> similar function to get character offsets within a text node? > > I am not sure what you need. Do you talk about fn:path? What could the > character offset be / do you have an example? > > Grazie, > Christian > > > >> On Jul 6, 2018, at 10:24 AM, Christian Grün >> wrote: >> >> Hi Symantis, >> >> The original line numbers are not stored in XML databases (they may >> change after updated, and would consume additional memory), so you >> won’t be able to retrieve them with XQuery. >> >> As far as I know, this does not work in eXist-db either; the eXist >> link you referenced gives you the line of the util:line-number >> expression in your XQuery module. As Fabrice pointed out (thanks!), >> this could also be realized with $err:line-number. >> >> With Saxon, it works indeed. However, you’ll need you use the -l >> command line option (otherwise, due to performance considerations, >> line numbers will be discarded as well). >> >> On query/database level, there are two ways to get a direct reference: >> • With fn:path, you get an XPath expression that points to your node. >> • With db:node-pre [1], you get a direct reference to the node in a database. >> >> Best, >> Christian >> >> [1] http://docs.basex.org/wiki/Database_Module#db:node-id >> >> >> On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD >> wrote: >> >> >> As BaseX does not work on the XML textual representation, it might not be >> possible. >> >> >> >> >> >> De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la >> part de ? ?? >> Envoyé : jeudi 5 juillet 2018 17:10 >> À : basex-talk@mailman.uni-konstanz.de >> Objet : [basex-talk] Add line-number function >> >> >> >> >> >> >> >> Hello, could the $err:line-number [1] variable help you ? >> >> [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch >> >> Best regards, >> >> Fabrice ETANCHAUD >> cerfrancepch >> >> No, $err:line-number show line number of xquery file. >> I want this: >> >> Example.xml -> >> 1: >> 2: >> 3: text1 >> 4: text2 >> 5: text3 >> 6: text4 >> 7: >> 8: >> >> Xquery -> >> let $f := doc("example.xml") >> let $e := $f/root/child[1]/grandchild[3] >> >> let $line := line-number($e) >> >> And I want get $line = 5 ! >> >> >> >
Re: [basex-talk] Add line-number function
Hi Giuseppe, > fn:node() returns the path to a node (including the text node): Is there a > similar function to get character offsets within a text node? I am not sure what you need. Do you talk about fn:path? What could the character offset be / do you have an example? Grazie, Christian > On Jul 6, 2018, at 10:24 AM, Christian Grün wrote: > > Hi Symantis, > > The original line numbers are not stored in XML databases (they may > change after updated, and would consume additional memory), so you > won’t be able to retrieve them with XQuery. > > As far as I know, this does not work in eXist-db either; the eXist > link you referenced gives you the line of the util:line-number > expression in your XQuery module. As Fabrice pointed out (thanks!), > this could also be realized with $err:line-number. > > With Saxon, it works indeed. However, you’ll need you use the -l > command line option (otherwise, due to performance considerations, > line numbers will be discarded as well). > > On query/database level, there are two ways to get a direct reference: > • With fn:path, you get an XPath expression that points to your node. > • With db:node-pre [1], you get a direct reference to the node in a database. > > Best, > Christian > > [1] http://docs.basex.org/wiki/Database_Module#db:node-id > > > On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD > wrote: > > > As BaseX does not work on the XML textual representation, it might not be > possible. > > > > > > De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la > part de ? ?? > Envoyé : jeudi 5 juillet 2018 17:10 > À : basex-talk@mailman.uni-konstanz.de > Objet : [basex-talk] Add line-number function > > > > > > > > Hello, could the $err:line-number [1] variable help you ? > > [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch > > Best regards, > > Fabrice ETANCHAUD > cerfrancepch > > No, $err:line-number show line number of xquery file. > I want this: > > Example.xml -> > 1: > 2: > 3: text1 > 4: text2 > 5: text3 > 6: text4 > 7: > 8: > > Xquery -> > let $f := doc("example.xml") > let $e := $f/root/child[1]/grandchild[3] > > let $line := line-number($e) > > And I want get $line = 5 ! > > >
Re: [basex-talk] Add line-number function
fn:node() returns the path to a node (including the text node): Is there a similar function to get character offsets within a text node? I am thinking of a case where, for example, one tokenizes a text within an element and would like to get the xpath + offsets for every token. > On Jul 6, 2018, at 10:24 AM, Christian Grün wrote: > > Hi Symantis, > > The original line numbers are not stored in XML databases (they may > change after updated, and would consume additional memory), so you > won’t be able to retrieve them with XQuery. > > As far as I know, this does not work in eXist-db either; the eXist > link you referenced gives you the line of the util:line-number > expression in your XQuery module. As Fabrice pointed out (thanks!), > this could also be realized with $err:line-number. > > With Saxon, it works indeed. However, you’ll need you use the -l > command line option (otherwise, due to performance considerations, > line numbers will be discarded as well). > > On query/database level, there are two ways to get a direct reference: > • With fn:path, you get an XPath expression that points to your node. > • With db:node-pre [1], you get a direct reference to the node in a database. > > Best, > Christian > > [1] http://docs.basex.org/wiki/Database_Module#db:node-id > > > On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD > wrote: >> >> As BaseX does not work on the XML textual representation, it might not be >> possible. >> >> >> >> >> >> De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la >> part de ? ?? >> Envoyé : jeudi 5 juillet 2018 17:10 >> À : basex-talk@mailman.uni-konstanz.de >> Objet : [basex-talk] Add line-number function >> >> >> >> >> >> >> >> Hello, could the $err:line-number [1] variable help you ? >> >> [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch >> >> Best regards, >> >> Fabrice ETANCHAUD >> cerfrancepch >> >> No, $err:line-number show line number of xquery file. >> I want this: >> >> Example.xml -> >> 1: >> 2: >> 3: text1 >> 4: text2 >> 5: text3 >> 6: text4 >> 7: >> 8: >> >> Xquery -> >> let $f := doc("example.xml") >> let $e := $f/root/child[1]/grandchild[3] >> >> let $line := line-number($e) >> >> And I want get $line = 5 ! >
Re: [basex-talk] Add line-number function
Hi Symantis, The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery. As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number. With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well). On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database. Best, Christian [1] http://docs.basex.org/wiki/Database_Module#db:node-id On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD wrote: > > As BaseX does not work on the XML textual representation, it might not be > possible. > > > > > > De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la > part de ? ?? > Envoyé : jeudi 5 juillet 2018 17:10 > À : basex-talk@mailman.uni-konstanz.de > Objet : [basex-talk] Add line-number function > > > > > > > > Hello, could the $err:line-number [1] variable help you ? > > [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch > > Best regards, > > Fabrice ETANCHAUD > cerfrancepch > > No, $err:line-number show line number of xquery file. > I want this: > > Example.xml -> > 1: > 2: > 3: text1 > 4: text2 > 5: text3 > 6: text4 > 7: > 8: > > Xquery -> > let $f := doc("example.xml") > let $e := $f/root/child[1]/grandchild[3] > > let $line := line-number($e) > > And I want get $line = 5 !
Re: [basex-talk] Add line-number function
As BaseX does not work on the XML textual representation, it might not be possible. De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la part de ? ?? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function Hello, could the $err:line-number [1] variable help you ? [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch Best regards, Fabrice ETANCHAUD cerfrancepch No, $err:line-number show line number of xquery file. I want this: Example.xml -> 1: 2: 3: text1 4: text2 5: text3 6: text4 7: 8: Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3] let $line := line-number($e) And I want get $line = 5 !
[basex-talk] Add line-number function
> >Hello, could the $err:line-number [1] variable help you ? > >[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch > >Best regards, > >Fabrice ETANCHAUD >cerfrancepch No, $err:line-number show line number of xquery file. I want this: Example.xml -> 1: 2: 3: text1 4: text2 5: text3 6: text4 7: 8: Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3] let $line := line-number($e) And I want get $line = 5 !
Re: [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ? [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch Best regards, Fabrice ETANCHAUD cerfrancepch De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la part de ? ?? Envoyé : jeudi 5 juillet 2018 06:39 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function Hello! Can you add to BaseX (as module) function "line-number" which retrieves the line number of the expression ? Same as in eXist-db (http://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/util=java:org.exist.xquery.functions.util.UtilModule=true) or saxon (http://www.saxonica.com/html/documentation/functions/saxon/line-number.html). it is very important for us because our users want see error line number in xml docs when our xquery scripts validate them.
[basex-talk] Add line-number function
Hello! Can you add to BaseX (as module) function "line-number" which retrieves the line number of the expression ? Same as in eXist-db ( http://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/util=java:org.exist.xquery.functions.util.UtilModule=true ) or saxon ( http://www.saxonica.com/html/documentation/functions/saxon/line-number.html ). it is very important for us because our users want see error line number in xml docs when our xquery scripts validate them.