Re: [basex-talk] Getting element counts in the visualizations?
> Christian Grün: >> And what I'm actually looking for in this case, is a list of the top >> level element names ("A" and "B" in my example) together with a count of >> their children. > Try e.g. one of these two queries: > • count(//A/*), count(//B/*) Those queries give me lines containing 0, one line per count(), unfortunately. > • for $c in /Top/* return count($c/*) Stuff happens in the visualization views when I run this (some things are selected or unselected), but I get no output in the Result window, and the "Query Info" window shows: Result: - Hit(s): 0 Items - Updated: 0 Items - Printed: 0 Bytes Could it be something to do with the namespacing in the document? Ie. that the XPath expressions don't match, even though they would seem to match. I was trying to simplify my example, and that may have been a bad idea...? The actual documents I'm working on, are of the same type as the one in this zip file http://goo.gl/ULH089 The document element is , and the counts I am interested in, are the count of the child elements of the direct children of , with names starting with "Kat". So the actual queries I've tried, have been: - count(//KatLegemiddeldose/*), count(//KatLegemiddelMerkevare/*) - for $c in /FEST/* return count($c/*) >> Hm... I selected a second level element in the Map, filtered it, and >> typed "select *" in the command window, and the upper right corner shows >> "0 Results". > What do you mean with "command window"? "select *" doesn’t sounds > valid to me, but the plain asterisk character (without "select") > should do the job. It’s a valid query – a shortcut for > child::element() –, and it’s gives you all child elements of the nodes > in the current context. Right! With just "*" I got "6728 results"... that was more like it! :-)
Re: [basex-talk] Setting base-dir for xquery:eval
Hi Christian, I have used this technique and it works unless the query string already has a base-uri set. I wonder if there is a case for adding base-uri to the xquery:eval options map to handle this in a cleaner way? /Andy On 19 Feb 2016 07:10, "Marc van Grootel"wrote: > Yes, exactly what I was after. Thanks and good night :) > > --Marc > > > On 18 feb. 2016, at 23:38, Christian Grün > wrote: > > > > Hi Marc, > > > >> when running xquery:eval with a string it will try to resolve paths > >> relative to the code module and not relative to the file the string > >> came from. > > > > You could add a base-uri declaration in your query: > > > > let $uri := 'a/b/c' > > let $query := '1' > > return xquery:eval( > >'declare base-uri "' || $uri || '"; ' || $query > > ) > > > > Does this help? > > Christian > > > > > >> Ideally I would like to be able to set the base-dir for > >> xquery:eval. The asciidoc file isn't always in the correct path > >> relative to the module that I need to import. > >> > >> Other options I'm considering but are less ideal. > >> > >> - Manipulate the module import paths in the query string using regexps > >> - Writing out to a temp file and then use xquery:parse-uri (but this > >> is tricky as I may not want to clutter existing directories with > >> tempfiles only to have the imports work). > >> > >> Unless there are better options I think I'll opt for string massaging > >> using regexps. But maybe someone has a better idea. > >> > >> --Marc >
Re: [basex-talk] Setting base-dir for xquery:eval
Yes, exactly what I was after. Thanks and good night :) --Marc > On 18 feb. 2016, at 23:38, Christian Grünwrote: > > Hi Marc, > >> when running xquery:eval with a string it will try to resolve paths >> relative to the code module and not relative to the file the string >> came from. > > You could add a base-uri declaration in your query: > > let $uri := 'a/b/c' > let $query := '1' > return xquery:eval( >'declare base-uri "' || $uri || '"; ' || $query > ) > > Does this help? > Christian > > >> Ideally I would like to be able to set the base-dir for >> xquery:eval. The asciidoc file isn't always in the correct path >> relative to the module that I need to import. >> >> Other options I'm considering but are less ideal. >> >> - Manipulate the module import paths in the query string using regexps >> - Writing out to a temp file and then use xquery:parse-uri (but this >> is tricky as I may not want to clutter existing directories with >> tempfiles only to have the imports work). >> >> Unless there are better options I think I'll opt for string massaging >> using regexps. But maybe someone has a better idea. >> >> --Marc
Re: [basex-talk] Sending Bytes, Not Strings, To BaseX Using the Ruby Client
Hi Eliot, For most client bindings, files must indeed be sent in UTF-8, so I guess it’s also the case for the Ruby binding. If the sent bytes are correct UTF-8, everything should work be fine. Christian On Thu, Feb 18, 2016 at 6:08 PM, Eliot Kimberwrote: > This test document as a non-ascii character '〺' (\u303A), which I added to > test handling of multi-byte characters. > > Ruby and the BaseX client seem to be handling the UTF-8 correctly but > UTF-16 didn't. I'm guessing it's Ruby's fault because it's treating the > bytes as a string and of course that's not going to work in a naive way. > > Cheers, > > E. > > Eliot Kimber, Owner > Contrext, LLC > http://contrext.com > > > > > On 2/18/16, 11:04 AM, "Eliot Kimber" > ekim...@contrext.com> wrote: > >>I turned my UTF-8 file into a UTF-16 file and trying to commit it to BaseX >>via the Ruby client it did not work: >> >>BaseXClient.rb:50:in `execute': Resource "/opt/basex/?" not found. >>(RuntimeError) >> >>Where "?" is some kind of "unrecognized character" indicator >> >>Cheers, >> >>E. >> >> >> >>Eliot Kimber, Owner >>Contrext, LLC >>http://contrext.com >> >> >> >> >>On 2/18/16, 10:26 AM, "Eliot Kimber" >> >ekim...@contrext.com> wrote: >> >>>I'm implementing server-side git hooks for use in GitLab under Docker >>>where Java is not available (at least that I can see). The hooks load or >>>delete files from databases in BaseX. >>> >>>I'm trying to implement the hooks in Ruby (which is much more pleasant >>>than bash scripting in any case) and I'm using the BaseXClient.rb from >>>https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/ruby >>> >>>I need to create or replace files by sending the bytes--I'd rather not >>>read the input file into a Ruby string and send that since I don't trust >>>Ruby to not hose up the data (even when it's UTF-8 I still don't trust >>>it, >>>but I only started using Ruby yesterday so maybe my mistrust is >>>misplaced?). >>> >>>Using the AddExample.rb as guide, I'm doing this: >>> >>>(Earlier code to open or create database, which works). >>> >>>file = File.new("../../" + path, "rb") >>>bytes = file.read >>>file.close >>>puts "file=/#{bytes}/" >>>@basex.add(path, "#{bytes}") >>> >>>I also tried: >>> >>>@basex.add(path, bytes) >>> >>> >>> >>>And I get this result (I added some debugging messages to sendCmd()): >>> >>>ensureDatabase(): Checking database "_dfst^metadata^temp^master"... >>>BaseXResult: Database '_dfst^metadata^temp^master' was opened in 1.53 ms. >>>Added or modified file: "test-newname.xml" >>>file=/This is a test 20 >>>/ >>> >>>*** sendCmd(): >>>cmd= >>>arg=test-newname.xml >>>input=This is a test 20 >>>BaseXClient.rb:110:in `sendCmd': "test-newname.xml.xml" (Line 1): >>>Premature end of file. (RuntimeError) >>> >>> from commit-hooks/git/server-side/BaseXClient.rb:64:in `add' >>> from commit-hooks/git/server-side/post-receive:80:in `block in update' >>> from commit-hooks/git/server-side/post-receive:74:in `each' >>> from commit-hooks/git/server-side/post-receive:74:in `update' >>> from commit-hooks/git/server-side/post-receive:111:in `block in ' >>> from commit-hooks/git/server-side/post-receive:103:in `each' >>> from commit-hooks/git/server-side/post-receive:103:in `' >>>Eliots-MBP:hooks ekimber$ >>> >>>A couple of things here: >>> >>> >>>Where is the extra ".xml" in the target filename coming from? >>> >>>What is causing the premature end of file? It feels like it's trying >>>interpret the second argument as a filename rather than the data to be >>>loaded. >>> >>>If I use basex.execute("add to #{path} #{bytes}") it works but of course >>>I >>>get duplicate files if I run the command twice. >>> >>>If I try: >>> >>>@basex.execute("replace #{path} #{bytes}") >>> >>>Then I get the same failure. >>> >>> >>>So something is not right. >>> >>>My Docker container is running 8.4.1 beta. >>> >>>What am I missing? >>> >>>Thanks, >>> >>>Eliot >>> >>>Eliot Kimber, Owner >>>Contrext, LLC >>>http://contrext.com >>> >>> >>> >>> >> >> >> > >
Re: [basex-talk] Setting base-dir for xquery:eval
Hi Marc, > when running xquery:eval with a string it will try to resolve paths > relative to the code module and not relative to the file the string > came from. You could add a base-uri declaration in your query: let $uri := 'a/b/c' let $query := '1' return xquery:eval( 'declare base-uri "' || $uri || '"; ' || $query ) Does this help? Christian > Ideally I would like to be able to set the base-dir for > xquery:eval. The asciidoc file isn't always in the correct path > relative to the module that I need to import. > > Other options I'm considering but are less ideal. > > - Manipulate the module import paths in the query string using regexps > - Writing out to a temp file and then use xquery:parse-uri (but this > is tricky as I may not want to clutter existing directories with > tempfiles only to have the imports work). > > Unless there are better options I think I'll opt for string massaging > using regexps. But maybe someone has a better idea. > > --Marc
Re: [basex-talk] Getting element counts in the visualizations?
> And what I'm actually looking for in this case, is a list of the top > level element names ("A" and "B" in my example) together with a count of > their children. Try e.g. one of these two queries: • count(//A/*), count(//B/*) • for $c in /Top/* return count($c/*) > Hm... I selected a second level element in the Map, filtered it, and > typed "select *" in the command window, and the upper right corner shows > "0 Results". What do you mean with "command window"? "select *" doesn’t sounds valid to me, but the plain asterisk character (without "select") should do the job. It’s a valid query – a shortcut for child::element() –, and it’s gives you all child elements of the nodes in the current context.
Re: [basex-talk] Getting element counts in the visualizations?
> Christian Grün: Hi Christian, thanks! > If you want to know the number of child elements from the root > elements, you could run a simple XPath expression via the input bar > [2] or editor panel [3] after opening the database: > count(/*/*) That only gives me the total number of child elements of the document elements, I think...? (The result was 14 in this case). I have a document with a structure like this ... ... And what I'm actually looking for in this case, is a list of the top level element names ("A" and "B" in my example) together with a count of their children. I have tried to google up examples of XQuery expressions to do this today, but I haven't had any success in creating the desired results. > As an alternative, you can first use the visualization to select the > initial nodes, filter it (using the funnel icon in the upper right > corner of the window) and then run the simple query * to see the > number of results in the upper right corner. Hm... I selected a second level element in the Map, filtered it, and typed "select *" in the command window, and the upper right corner shows "0 Results". > Does this help? It's a step on the way. Thanks! :-) > Do you have some basic experience with XPath or XQuery? No experience with XQuery prior to today, but a fair amount of XSLT experience (which implies familiarity with XPath) back in 2000-2005 or thereabouts. But it's been a while.
[basex-talk] Setting base-dir for xquery:eval
Hi, I am having quite some fun with xquery:eval. I am working on a little module for executable documentation (similar to Python doctest). I want to write documentation in asciidoc, parse it and execute source code blocks inside the asciidoc. Parsing works by calling asciidocj and so far I can run simple queries, evaluate them, compare them with an expected outcome and write the result back as evaluated asciidoc. Now I want to tackle more advanced queries that import modules. But when running xquery:eval with a string it will try to resolve paths relative to the code module and not relative to the file the string came from. Ideally I would like to be able to set the base-dir for xquery:eval. The asciidoc file isn't always in the correct path relative to the module that I need to import. Other options I'm considering but are less ideal. - Manipulate the module import paths in the query string using regexps - Writing out to a temp file and then use xquery:parse-uri (but this is tricky as I may not want to clutter existing directories with tempfiles only to have the imports work). Unless there are better options I think I'll opt for string massaging using regexps. But maybe someone has a better idea. --Marc
Re: [basex-talk] Getting element counts in the visualizations?
Hi Steinar, Thanks for your mail. > What I needed from BaseX was finding the size of the contents of the > second level elements (ie. the elements immediately below the root > element). If you want to know the number of child elements from the root elements, you could run a simple XPath expression via the input bar [2] or editor panel [3] after opening the database: count(/*/*) As an alternative, you can first use the visualization to select the initial nodes, filter it (using the funnel icon in the upper right corner of the window) and then run the simple query * to see the number of results in the upper right corner. Does this help? Do you have some basic experience with XPath or XQuery? Christian [1] http://docs.basex.org/wiki/GUI#XQuery [2] http://docs.basex.org/wiki/GUI#Text_Editor
[basex-talk] Getting element counts in the visualizations?
Platform: Intel i7 Windows 7 Enterprise BaseX 8.4 Today I opened an 80MB XML file in the BaseX GUI, and I was amazed at the speed of BaseX, compared to e.g. trying to open, count, and extract stuff from the same file in emacs. What I needed from BaseX was finding the size of the contents of the second level elements (ie. the elements immediately below the root element). The visualizations were great at navigating in the file and the Map visualization showed the sizes I was interested in. I was comparing two files with the same structure, one file with size 60MB, the other with size 80MB, and tried to figure out where the 20MB had gone. On thing I was looking for, but did not find, was the number of child elements of a given element. I was hoping for a tooltip when hovering over an element in the visualizations (map, folder and tree), or a properties dialog when right clicking the elements in the visualization. Is the information present somewhere? (I know the element child count has to be there somewhere, because without it, the map visualization couldn't be rendered...?) How hard is this information to get at? Thanks! - Steinar PS what I ended up doing, was selecting the elements I wanted to find the size of in map and tree, and then saving the contents of the Result view for each element. A bit more clumsy than I would have liked, but much faster than doing it in emacs.
Re: [basex-talk] Sending Bytes, Not Strings, To BaseX Using the Ruby Client
This test document as a non-ascii character '〺' (\u303A), which I added to test handling of multi-byte characters. Ruby and the BaseX client seem to be handling the UTF-8 correctly but UTF-16 didn't. I'm guessing it's Ruby's fault because it's treating the bytes as a string and of course that's not going to work in a naive way. Cheers, E. Eliot Kimber, Owner Contrext, LLC http://contrext.com On 2/18/16, 11:04 AM, "Eliot Kimber"wrote: >I turned my UTF-8 file into a UTF-16 file and trying to commit it to BaseX >via the Ruby client it did not work: > >BaseXClient.rb:50:in `execute': Resource "/opt/basex/?" not found. >(RuntimeError) > >Where "?" is some kind of "unrecognized character" indicator > >Cheers, > >E. > > > >Eliot Kimber, Owner >Contrext, LLC >http://contrext.com > > > > >On 2/18/16, 10:26 AM, "Eliot Kimber" > ekim...@contrext.com> wrote: > >>I'm implementing server-side git hooks for use in GitLab under Docker >>where Java is not available (at least that I can see). The hooks load or >>delete files from databases in BaseX. >> >>I'm trying to implement the hooks in Ruby (which is much more pleasant >>than bash scripting in any case) and I'm using the BaseXClient.rb from >>https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/ruby >> >>I need to create or replace files by sending the bytes--I'd rather not >>read the input file into a Ruby string and send that since I don't trust >>Ruby to not hose up the data (even when it's UTF-8 I still don't trust >>it, >>but I only started using Ruby yesterday so maybe my mistrust is >>misplaced?). >> >>Using the AddExample.rb as guide, I'm doing this: >> >>(Earlier code to open or create database, which works). >> >>file = File.new("../../" + path, "rb") >>bytes = file.read >>file.close >>puts "file=/#{bytes}/" >>@basex.add(path, "#{bytes}") >> >>I also tried: >> >>@basex.add(path, bytes) >> >> >> >>And I get this result (I added some debugging messages to sendCmd()): >> >>ensureDatabase(): Checking database "_dfst^metadata^temp^master"... >>BaseXResult: Database '_dfst^metadata^temp^master' was opened in 1.53 ms. >>Added or modified file: "test-newname.xml" >>file=/This is a test 20 >>/ >> >>*** sendCmd(): >>cmd= >>arg=test-newname.xml >>input=This is a test 20 >>BaseXClient.rb:110:in `sendCmd': "test-newname.xml.xml" (Line 1): >>Premature end of file. (RuntimeError) >> >> from commit-hooks/git/server-side/BaseXClient.rb:64:in `add' >> from commit-hooks/git/server-side/post-receive:80:in `block in update' >> from commit-hooks/git/server-side/post-receive:74:in `each' >> from commit-hooks/git/server-side/post-receive:74:in `update' >> from commit-hooks/git/server-side/post-receive:111:in `block in ' >> from commit-hooks/git/server-side/post-receive:103:in `each' >> from commit-hooks/git/server-side/post-receive:103:in `' >>Eliots-MBP:hooks ekimber$ >> >>A couple of things here: >> >> >>Where is the extra ".xml" in the target filename coming from? >> >>What is causing the premature end of file? It feels like it's trying >>interpret the second argument as a filename rather than the data to be >>loaded. >> >>If I use basex.execute("add to #{path} #{bytes}") it works but of course >>I >>get duplicate files if I run the command twice. >> >>If I try: >> >>@basex.execute("replace #{path} #{bytes}") >> >>Then I get the same failure. >> >> >>So something is not right. >> >>My Docker container is running 8.4.1 beta. >> >>What am I missing? >> >>Thanks, >> >>Eliot >> >>Eliot Kimber, Owner >>Contrext, LLC >>http://contrext.com >> >> >> >> > > >
Re: [basex-talk] Sending Bytes, Not Strings, To BaseX Using the Ruby Client
I turned my UTF-8 file into a UTF-16 file and trying to commit it to BaseX via the Ruby client it did not work: BaseXClient.rb:50:in `execute': Resource "/opt/basex/?" not found. (RuntimeError) Where "?" is some kind of "unrecognized character" indicator Cheers, E. Eliot Kimber, Owner Contrext, LLC http://contrext.com On 2/18/16, 10:26 AM, "Eliot Kimber"wrote: >I'm implementing server-side git hooks for use in GitLab under Docker >where Java is not available (at least that I can see). The hooks load or >delete files from databases in BaseX. > >I'm trying to implement the hooks in Ruby (which is much more pleasant >than bash scripting in any case) and I'm using the BaseXClient.rb from >https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/ruby > >I need to create or replace files by sending the bytes--I'd rather not >read the input file into a Ruby string and send that since I don't trust >Ruby to not hose up the data (even when it's UTF-8 I still don't trust it, >but I only started using Ruby yesterday so maybe my mistrust is >misplaced?). > >Using the AddExample.rb as guide, I'm doing this: > >(Earlier code to open or create database, which works). > >file = File.new("../../" + path, "rb") >bytes = file.read >file.close >puts "file=/#{bytes}/" >@basex.add(path, "#{bytes}") > >I also tried: > >@basex.add(path, bytes) > > > >And I get this result (I added some debugging messages to sendCmd()): > >ensureDatabase(): Checking database "_dfst^metadata^temp^master"... >BaseXResult: Database '_dfst^metadata^temp^master' was opened in 1.53 ms. >Added or modified file: "test-newname.xml" >file=/This is a test 20 >/ > >*** sendCmd(): >cmd= >arg=test-newname.xml >input=This is a test 20 >BaseXClient.rb:110:in `sendCmd': "test-newname.xml.xml" (Line 1): >Premature end of file. (RuntimeError) > > from commit-hooks/git/server-side/BaseXClient.rb:64:in `add' > from commit-hooks/git/server-side/post-receive:80:in `block in update' > from commit-hooks/git/server-side/post-receive:74:in `each' > from commit-hooks/git/server-side/post-receive:74:in `update' > from commit-hooks/git/server-side/post-receive:111:in `block in ' > from commit-hooks/git/server-side/post-receive:103:in `each' > from commit-hooks/git/server-side/post-receive:103:in `' >Eliots-MBP:hooks ekimber$ > >A couple of things here: > > >Where is the extra ".xml" in the target filename coming from? > >What is causing the premature end of file? It feels like it's trying >interpret the second argument as a filename rather than the data to be >loaded. > >If I use basex.execute("add to #{path} #{bytes}") it works but of course I >get duplicate files if I run the command twice. > >If I try: > >@basex.execute("replace #{path} #{bytes}") > >Then I get the same failure. > > >So something is not right. > >My Docker container is running 8.4.1 beta. > >What am I missing? > >Thanks, > >Eliot > >Eliot Kimber, Owner >Contrext, LLC >http://contrext.com > > > >
[basex-talk] Sending Bytes, Not Strings, To BaseX Using the Ruby Client
I'm implementing server-side git hooks for use in GitLab under Docker where Java is not available (at least that I can see). The hooks load or delete files from databases in BaseX. I'm trying to implement the hooks in Ruby (which is much more pleasant than bash scripting in any case) and I'm using the BaseXClient.rb from https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/ruby I need to create or replace files by sending the bytes--I'd rather not read the input file into a Ruby string and send that since I don't trust Ruby to not hose up the data (even when it's UTF-8 I still don't trust it, but I only started using Ruby yesterday so maybe my mistrust is misplaced?). Using the AddExample.rb as guide, I'm doing this: (Earlier code to open or create database, which works). file = File.new("../../" + path, "rb") bytes = file.read file.close puts "file=/#{bytes}/" @basex.add(path, "#{bytes}") I also tried: @basex.add(path, bytes) And I get this result (I added some debugging messages to sendCmd()): ensureDatabase(): Checking database "_dfst^metadata^temp^master"... BaseXResult: Database '_dfst^metadata^temp^master' was opened in 1.53 ms. Added or modified file: "test-newname.xml" file=/This is a test 20 / *** sendCmd(): cmd= arg=test-newname.xml input=This is a test 20 BaseXClient.rb:110:in `sendCmd': "test-newname.xml.xml" (Line 1): Premature end of file. (RuntimeError) from commit-hooks/git/server-side/BaseXClient.rb:64:in `add' from commit-hooks/git/server-side/post-receive:80:in `block in update' from commit-hooks/git/server-side/post-receive:74:in `each' from commit-hooks/git/server-side/post-receive:74:in `update' from commit-hooks/git/server-side/post-receive:111:in `block in ' from commit-hooks/git/server-side/post-receive:103:in `each' from commit-hooks/git/server-side/post-receive:103:in `' Eliots-MBP:hooks ekimber$ A couple of things here: Where is the extra ".xml" in the target filename coming from? What is causing the premature end of file? It feels like it's trying interpret the second argument as a filename rather than the data to be loaded. If I use basex.execute("add to #{path} #{bytes}") it works but of course I get duplicate files if I run the command twice. If I try: @basex.execute("replace #{path} #{bytes}") Then I get the same failure. So something is not right. My Docker container is running 8.4.1 beta. What am I missing? Thanks, Eliot Eliot Kimber, Owner Contrext, LLC http://contrext.com