Re: [basex-talk] file store question

2016-05-24 Thread Christian Grün
> Does it mean that the caller really need to
> know the type of the resource, in order to determine which db function to
> call ?

Yes – unless you use WebDAV (which will automatically find out if your
input is well-formed XML) or the REST API (which will evaluate the
specified content type) [1]. Please note that BaseX is primarily an
XML database. This is the reason why extra functions for binary
contents have been added.

Christian

[1] http://docs.basex.org/wiki/Web_Application


Re: [basex-talk] A db can only be copied once...

2016-05-24 Thread Christian Grün
Hi France,

> Since a DB cannot be created dynamically from a restxq call

Did you try db:create?

> However, it seems that I am unable to create multiple
> instances from the same DB template.

To answer this question, I need some more information on how you
proceed. Do you use db:copy?

Best,
Christian


[basex-talk] A db can only be copied once...

2016-05-24 Thread France Baril
Hi,

Since a DB cannot be created dynamically from a restxq call, I'm trying to
create some databases by copying an existing one (an empty DB with all the
desired parameters). However, it seems that I am unable to create multiple
instances from the same DB template.

Is there a reason for this limit? I am providing a different target name
for each, so technically there shouldn't be any duplicate writing. Any
workaround to suggest? Beside the creation of multiple template DB source?

Thanks!

-- 
France Baril
Architecte documentaire / Documentation architect
france.ba...@architextus.com


Re: [basex-talk] Open Document spreadsheets and column position

2016-05-24 Thread Graydon Saunders
Hi Christian --

Your version, slightly tweaked:

declare function local:realPos(
$current as element(table:table-cell)
  ) as xs:integer {
let $cells := $current/preceding-sibling::table:table-cell
let $repeated := $cells/@table:number-columns-repeated
let $total := count($cells) + 1 + sum($repeated) - count($repeated)
return xs:integer($total)
  };

because it wanted to return xs:double, rather than xs:integer, ran, on
8.4.4, in 54036.0 ms.  (This is comparable to the previous version where
everything was just [4] and I didn't know about the collapsed cells.)

My previous attempt took 1.011152923E7 ms to complete.

I'm going to remember that hint about "bind expressions to variables"!  Two
whole orders of magnitude improvement.

(And yes, this will always be called on table:table-cell.)

Thank you very much!
Graydon

On Tue, May 24, 2016 at 4:29 PM, Christian Grün 
wrote:

> Hi Graydon,
>
> This might give you faster results (provided that it does the same as
> your function, I’m not 100% sure…):
>
>   declare function local:realPos(
> $current as element(table:table-cell)
>   ) as xs:integer {
> let $cells := $current/preceding-sibling::table:table-cell
> let $repeated := $cells/@table:number-columns-repeated
> return count($cells) + 1 + sum($repeated) - count($repeated)
>   };
>
> Some general hinta: It’s recommendable to bind expressions to
> variables if they will be accessed more than once. Next, fn:path is
> pretty expensive indeed (I guess you’ve already noticed that by
> yourself anyway). Finally, if type definitions in function signatures
> are speficied as strictly as possible, you will get better error
> messages, and it helps others to understand the code (is it correct
> that your function will always be called with elements named
> table:table-cell?).
>
> Hope this helps,
> Christian
>
>
> On Tue, May 24, 2016 at 9:47 PM, Graydon Saunders 
> wrote:
> > Hi all --
> >
> > So in Open Document Spreadsheets, columns with empty cells may be
> collapsed:
> >
> > 
> >   > table:style-name="ce454" />
> >  
> >   office:value-type="string">
> >   label
> >  
> >   office:value-type="string">
> >   description
> >  
> >   > table:style-name="ce455" />
> > 
> >
> > Not all of the rows have have these collapsed empty cells; in some rows,
> all
> > the cells are present because they've got values in them.  And while I
> > wouldn't care in the example row, sometimes more than one
> table:table-cell
> > represents a collapsed column in a position I care about.
> >
> > All the labels are in column D and all the descriptions in column E (in
> > spreadsheet terms), whether all the table:cell elements are present in
> the
> > XML representation of the sheet or not, and I need to reliably find them
> so
> > as to be able to convince myself that the XSLT transform is getting
> correct
> > answers.  (The spreadsheet is about 40 MiB; not so much by recent list
> > standards, but still more than I can hope to read. :)
> >
> > declare function local:realPos($current as node())
> > as xs:integer
> > {
> >  (: the horror, the horror :)
> >  xs:integer(path($current) ! tokenize(.,'/')[last()] !
> > replace(.,'.*\[(\p{Nd}+)\]','$1') ! xs:integer(
> > .)
> >   +
> >
> sum($current/preceding-sibling::table:table-cell/@table:number-columns-repeated)
> >   -
> >
> count($current/preceding-sibling::table:table-cell/@table:number-columns-repeated)
> > )
> > };
> >
> > works, in the sense of "will get the cell corresponding to the intended
> > spreadsheet column even when some of the columns have been collapsed with
> > @table:number-columns-repeated".
> >
> > It's horribly slow and it hurts just to look at, though, so -- is there a
> > better way?
> >
> > (The XSLT transform pre-processes all the collapsed table:table-cell
> > elements back into place, among other tidying.  I'm not at all sure
> that's a
> > better way with XQuery.)
> >
> > Thanks!
> > Graydon
>


Re: [basex-talk] Replacing node sets in a large file

2016-05-24 Thread Michael Sanborn
Seems like this would be perfect. I do need both number and manuf. Using
your combination map, I'm now getting an "Out of Main Memory" error. Tried
on a second computer - same issue. Would it be more likely to work if I
tried it from the command line rather than the GUI? If so, I'll need to
look up how to create a database that way, but I'm sure it's close to hand.
Or is there a better workaround (besides buying a computer with more than
8GB of RAM)?

Thanks again,

Michael

On Tue, May 24, 2016 at 2:10 PM, Christian Grün 
wrote:

> Maybe you need something like this:
>
>   for $partinfo in //unit/partinfo
>   for $part in //part[deep-equal(partinfo, $partinfo)]
>   return replace node $partinfo with $part/node()
>
> The deep-equal will be pretty slow. If the value of the number element
> is unique, you could do something like this:
>
>   for $partinfo in //unit/partinfo
>   let $number := $partinfo/number
>   let $part := //part[partinfo/number, $number]
>   return replace node $partinfo with $part/node()
>
> Using a map will even be faster:
>
>   let $map := map:merge(//part/map:entry(partinfo/number/text(), .))
>   for $partinfo in //unit/partinfo
>   let $part := $map($partinfo/number)
>   return replace node $partinfo with $part/node()
>
> If you need to consider both number and manuf, you could e.g. combine
> these two in the map:
>
>   let $map := map:merge(
> for $part in //part
> return map:entry(string-join($part/partinfo/*, '/'), $part)
>   )
>   for $partinfo in //unit/partinfo
>   let $part := $map(string-join($partinfo/*, '/'))
>   return replace node $partinfo with $part/node()
>
> Does this help?
> Christian
>
>
>
>
> On Tue, May 24, 2016 at 10:54 PM, Michael Sanborn 
> wrote:
> > Thanks for that. The trouble in step 2 is, just wrapping partinfo with
> the
> > part element doesn't get me what I've labelled "misc part content 1" and
> > "misc part content 2". It's not sufficient to have just the tags - I need
> > all the content of the corresponding part elements in the later part of
> the
> > file. Is that something that can be done without too much difficulty?
> >
> > Thanks,
> >
> > Michael
> >
> > On Tue, May 24, 2016 at 12:16 PM, Christian Grün <
> christian.gr...@gmail.com>
> > wrote:
> >>
> >> Hi Michael,
> >>
> >> Yes, this can easily be done with XQuery. There are many ways to do
> >> this; here is just one:
> >>
> >> 1. First, create a database from your input file (e.g. with the BaseX
> GUI)
> >>
> >> 2. Second, run the following query to replace wrap your partinfo
> >> elements with part elements:
> >>
> >>   //unit/partinfo/(replace node . with { . })
> >>
> >> 3. Third, write all page elements to disk:
> >>
> >>   for $page at $c in //page
> >>   return file:write($c || '.xml', $page)
> >>
> >> Hope this helps,
> >> Christian
> >>
> >>
> >>
> >> On Tue, May 24, 2016 at 8:54 PM, Michael Sanborn 
> >> wrote:
> >> > I need to perform a transformation that would be simple in XSLT, but
> the
> >> > input is a file about 250 MBs in size. I'm wondering whether XQuery
> and
> >> > BaseX in particular would be the most efficient way of doing it. I'm
> new
> >> > to
> >> > XQuery, and I've come up with a couple of ways to do this, but they
> turn
> >> > out
> >> > to be very time-consuming, so I'm sure I'm Doing It Wrong. Hoping to
> >> > find
> >> > out the proper way of doing this.
> >> >
> >> > The input consists of 2 sections. There are about 3600 page elements
> >> > with
> >> > this structure:
> >> >
> >> > 
> >> > [misc page content...]
> >> > 
> >> > 
> >> > [misc unit content 1...]
> >> > 
> >> > 54321
> >> > A321
> >> > 
> >> > 
> >> > 12345
> >> > B123
> >> > 
> >> > [misc unit content 2...]
> >> > 
> >> > [multiple units...]
> >> > 
> >> > 
> >> >
> >> > Each unit can have 1 or 2 partinfo elements. The other section has
> about
> >> > 82000 part elements like this:
> >> >
> >> > 
> >> > 
> >> > 54321
> >> > A321
> >> > 
> >> > [misc part content 1]
> >> > 
> >> > [...]
> >> > 
> >> > 
> >> > 12345
> >> > B123
> >> > 
> >> > [misc part content 2]
> >> > 
> >> >
> >> > I want to replace each unit/partinfo with the correpsonding part, like
> >> > this:
> >> >
> >> > 
> >> > [misc page content...]
> >> > 
> >> > 
> >> > [misc unit content 1...]
> >> > 
> >> > 
> >> > 54321
> >> > A321
> >> > 
> >> > [misc part content 1]
> >> > 
> >> > 
> >> > 
> >> > 12345
> >> > B123
> >> > 
> >> > [misc part content 2]
> >> > 
> >> > [misc unit content 2...]
> >> > 
> >> > 

[basex-talk] file store question

2016-05-24 Thread Wang, Genneva
Hi BaseX gurus,

I noticed that if the resource is persisted in basex, there is a way to tell 
what type of the resource it is(db:content-type?). However, I’m wondering for 
new resources to be persisted, is there a way to determine ? Or mostly needs to 
rely on the application to determine which basex call to be make ? I’m seeing 
on the document that db:store is to persist binary database and use db:add for 
other documents. Does it mean that the caller really need to know the type of 
the resource, in order to determine which db function to call ?

Thanks much for your help.

Regards,
-Genneva



Re: [basex-talk] Replacing node sets in a large file

2016-05-24 Thread Michael Sanborn
Thanks for that. The trouble in step 2 is, just wrapping partinfo with the
part element doesn't get me what I've labelled "misc part content 1" and
"misc part content 2". It's not sufficient to have just the tags - I need
all the content of the corresponding part elements in the later part of the
file. Is that something that can be done without too much difficulty?

Thanks,

Michael

On Tue, May 24, 2016 at 12:16 PM, Christian Grün 
wrote:

> Hi Michael,
>
> Yes, this can easily be done with XQuery. There are many ways to do
> this; here is just one:
>
> 1. First, create a database from your input file (e.g. with the BaseX GUI)
>
> 2. Second, run the following query to replace wrap your partinfo
> elements with part elements:
>
>   //unit/partinfo/(replace node . with { . })
>
> 3. Third, write all page elements to disk:
>
>   for $page at $c in //page
>   return file:write($c || '.xml', $page)
>
> Hope this helps,
> Christian
>
>
>
> On Tue, May 24, 2016 at 8:54 PM, Michael Sanborn 
> wrote:
> > I need to perform a transformation that would be simple in XSLT, but the
> > input is a file about 250 MBs in size. I'm wondering whether XQuery and
> > BaseX in particular would be the most efficient way of doing it. I'm new
> to
> > XQuery, and I've come up with a couple of ways to do this, but they turn
> out
> > to be very time-consuming, so I'm sure I'm Doing It Wrong. Hoping to find
> > out the proper way of doing this.
> >
> > The input consists of 2 sections. There are about 3600 page elements with
> > this structure:
> >
> > 
> > [misc page content...]
> > 
> > 
> > [misc unit content 1...]
> > 
> > 54321
> > A321
> > 
> > 
> > 12345
> > B123
> > 
> > [misc unit content 2...]
> > 
> > [multiple units...]
> > 
> > 
> >
> > Each unit can have 1 or 2 partinfo elements. The other section has about
> > 82000 part elements like this:
> >
> > 
> > 
> > 54321
> > A321
> > 
> > [misc part content 1]
> > 
> > [...]
> > 
> > 
> > 12345
> > B123
> > 
> > [misc part content 2]
> > 
> >
> > I want to replace each unit/partinfo with the correpsonding part, like
> this:
> >
> > 
> > [misc page content...]
> > 
> > 
> > [misc unit content 1...]
> > 
> > 
> > 54321
> > A321
> > 
> > [misc part content 1]
> > 
> > 
> > 
> > 12345
> > B123
> > 
> > [misc part content 2]
> > 
> > [misc unit content 2...]
> > 
> > [multiple units...]
> > 
> > 
> >
> > Is BaseX a good tool for this task? If so, how does one go about it?
> >
> > Finally, it would help to be able to output each page element in a
> separate
> > file. Would it be better to have BaseX do this, or to output the whole
> > database and chunk it with another tool?
> >
> > Thanks,
> >
> > Michael
>


Re: [basex-talk] add resource from client

2016-05-24 Thread Gilad Wagner
Hi Christian,
Sorry for lazy explanation.
I will try to rephrase:
Given a server with basex-server and a remote client, I want to take xml
from the client machine and store it on the basex server.
(I know I can copy the file from client to server and then store it, but
it¹s not possible in my case)

Thanks!
Gilad.

On 5/24/16, 1:18 PM, "Christian Grün"  wrote:

>Hi Gilad,
>
>Welcome. Some questions:
>
>> I need to load our db from a client xml
>
>What do you mean with "load our db from a client xml"? Do you want to
>retrieve documents from a BaseX database or store new documents?
>
>> the problem is the server cannot
>> reach the client so remote url is not an option.
>
>So you would like to access a client machine from the server?
>
>Looking forward to more details,
>Christian