Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] regex, shortest match

From: Dave Pawson <davep@------------->
To:
Date: 8/1/2008 9:22:00 AM
David Carlisle wrote:
I'm looking to parse sentences out of paras.

to be more exact you are trying to parse a sentence with a regular
expression, which would cause you to fail a logic course as natural
language must be the canonical example of a non regular language:-)
Highly likely.





You need to define a sentence.

I tried with the worst examples in the source text.





So perhaps a sentence is terminated by . followed by end of string or
whitespace

 ([^.]|\.[^ \n\r\t])*\.(\s+|$)











but this would of course still fail if the sentence were to contain
". " coming from "D. P. Carlisle" or "dr. " or ...

If you try to parse natural language with a single regular expression,
it will _always_ fail. But you can cover more or less arbitrarily
complicated subsets of the language by making the regexp
correspondingly more complicated (and slow)





<para>Sentance containing Dr. Michael Kay and D.P. Carlisle</para>



<grin/> I'd expect that to break most regexen :-)







  <xsl:template match="para">
    <para>
      <xsl:analyze-string select="." regex="([^.]|\.[^ \n\r\t])*\.(\s+|$)">
        <xsl:matching-substring>
          <s> <xsl:value-of select="normalize-space(.)"/></s>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <error> <xsl:value-of select="normalize-space(.)"/> </error>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </para>
  </xsl:template>

Thanks David. That's better than my improvement.
No 'error' elements in 12000 lines.

Much appreciated.



regards



--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent