Converting xml to MYSQL that reflects the "tag's embedding"?

Dear Ruby guru's,

Can any of you tell me how to convert xml to SQL?

The tags of the text I need to convert are linguistic in nature. E.g.
<sentence><clause><word><morpheme></morpheme></word></clause></

and the like.

What I need, is a database that somehow reflects the embedding. Can
this be done?

Kind regards,
Robert.

Dear Ruby guru's,

Can any of you tell me how to convert xml to SQL?

The tags of the text I need to convert are linguistic in nature. E.g.
<sentence><clause><word><morpheme></morpheme></word></clause></
> and the like.

What I need, is a database that somehow reflects the embedding. Can
this be done?

Kind regards,
Robert.

Dear Robert,

I think what you need is to identify "brackets of text" starting with
something like <sentence> and ending with </sentence> etc., then pass
these brackets to some variable in Mysql.

For Ruby and MySql, see here: http://www.kitebird.com/articles/ruby-mysql.html

The finding of the brackets can be done using regular expressions.
I've written some code below.
You'd still need to choose some convenient variable name for the different
types of brackets (sentence,word etc...)

Best regards,

Axel

···

----------------------------------------------------------------

class String
  def find_positions(opening,closing)
    open_p=
    closing_p=
    temp=self.dup
    while opening.match(temp)
      ref=opening.match(temp)
      open_p<<temp.index(ref[0])
      temp.sub!(ref[0],' '*ref[0].length)
    end
    temp=self.dup
    while closing.match(temp)
      ref=closing.match(temp)
      closing_p<<temp.index(ref[0])
      temp.sub!(ref[0],' '*ref[0].length)
    end
    
    # correctly associate opening and closing "brackets"
    # check again, especially for nested brackets
    
    brackets=
    closing_p.each{|clb|
      temp=open_p.dup
      opb=(temp.delete_if{|y| y>clb}).max
      open_p=open_p-[opb]
      brackets<<[opb,clb]
    }
    return brackets.sort{|x,y| x[0]<=>y[0]}
  end
  def find_brackets_text(opening,closing)
    pos_array=self.find_positions(opening,closing)
    text=
    p 'positions of brackets in the text'
    p pos_array
    pos_array.each{|op,cl|
            p 'opcl'
      p op
      p cl
      text<<self[op...cl]
    }
    return text
  end
end
a="<s><c><w><s><m></m></s></w></c><s></s>blabla</s><s>bla</s>"
c=a.find_brackets_text(/<s>/,/<\/s>/)
p c

--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: GMX E-Mail ✉ sichere & kostenlose E-Mail-Adresse ✉

le colibri wrote:

Dear Ruby guru's,

Can any of you tell me how to convert xml to SQL?

The tags of the text I need to convert are linguistic in nature. E.g.
<sentence><clause><word><morpheme></morpheme></word></clause></
> and the like.

What I need, is a database that somehow reflects the embedding. Can
this be done?

I think what you need is a standard nested set structure, with the various nodes having tags for their type and content. There's a good explanation here: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

···

--
Alex

Axel Etzold wrote:

The finding of the brackets can be done using regular expressions.

Should one use a XML parser for this?

http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html

This doesn't solve the problem of how to map a tree onto relational
database tables, of course.

Lutz

···

--
Posted via http://www.ruby-forum.com/\.

Thanks both Axel and Alex, I try out some of the suggestions.

Regards,
Robert.

···

On Aug 10, 11:51 am, Alex Young <a...@blackkettle.org> wrote:

le colibri wrote:
> Dear Ruby guru's,

> Can any of you tell me how to convert xml to SQL?

> The tags of the text I need to convert are linguistic in nature. E.g.
> <sentence><clause><word><morpheme></morpheme></word></clause></
> > and the like.

> What I need, is a database that somehow reflects the embedding. Can
> this be done?

I think what you need is a standard nested set structure, with the
various nodes having tags for their type and content. There's a good
explanation here:http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

--
Alex