Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 996237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:50:45+00:00 2026-05-16T06:50:45+00:00

I want to implement the SRX Segmentation Rules using javascript to extract sentences from

  • 0

I want to implement the SRX Segmentation Rules using javascript to extract sentences from text.

In order to do this correctly I will have to follow the SRX rules.

eg. http://www.lisa.org/fileadmin/standards/srx20.html#refTR29

now there are two types of regular expressions

  1. if found sentence should break like “. “
  2. if found sentence should not break like abbreviation U.K or Mr.

For this again there are two parts

  1. before breaking
  2. after breaking

for example if the rule is

<rule break="no">

    <beforebreak>\s*[0-9]+\.</beforebreak>
    <afterbreak>\s</afterbreak>

</rule>

Which says if the pattern “\s*[0-9]+.\s” is found the segment should not break.

how do I implement using javascript, my be split function is not enough ?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:50:45+00:00Added an answer on May 16, 2026 at 6:50 am

    You may want to try something like this:

    function segment(text, rules) {
        if (!text) return text;
        if (!rules) return [text];
    
        var rulePattern = /<rule(?:(\s+break="no")|\s+[^>]+|\s*)>(?:<beforebreak>([^<]+)<\/beforebreak>)?(?:<afterbreak>([^<]+)<\/afterbreak>)?<\/rule>/g;
        cleanXml(rules).replace(rulePattern, 
            function(whole, nobreak, before, after) {
                var r = new RegExp((before||'')+'(?![\uE000\uE001])'+(after?'(?='+after+')':''), 'mg');
                text = text.replace(r, nobreak ? '$&\uE000' : '$&\uE001');
                return '';
            }
        );
    
        var sentences = text.replace(/\uE000/g, '').split(/\uE001/g);
    
        return sentences;
    }
    
    function cleanXml(s) {
        return s && s.replace(/<!--[\s\S]*?-->/g,'').replace(/>\s+</g,'><');
    }
    

    To run this simply call segment() with the text to split, and the rules XML as a string. For example:

    segment('The U.K. Prime Minister, Mr. Blair, was seen out with his family today.',
            '<rule break="no">' +
                '<beforebreak>\sMr\.</beforebreak>' +
                '<afterbreak>\s</afterbreak>' +
            '</rule>' +
            '<rule break="no">' +
                '<beforebreak>\sU\.K\.</beforebreak>' +
                '<afterbreak>\s</afterbreak>' +
            '</rule>' +
            '<rule break="yes">' +
                '<beforebreak>[\.\?!]+</beforebreak>' +
                '<afterbreak>\s</afterbreak>' +
            '</rule>'
    );
    

    The call to segment() will return an array of sentences, so you can simply do something like alert(segment(...).join('\n')) to see the result.

    Known Limitations:

    1. It expects the rules to be after the cascading process that is relevant for the specific language.
    2. It expects the regular expressions used by the rules to conform to the javascript regexp syntax.
    3. It does not handle internal markup.

    All of these limitations seem quite easy to overcome.

    How does this work?

    The segment function uses the rulePattern to extract each rule, identify if it is a breaking or non-breaking rule, and create a regexp based on the beforebreak and afterbreak clauses of the rule. It then scans the text, and marks each matching place by adding a unicode character (taken from a unicode private use area) that marks whether it is a break (\uE001) or a non-break (\uE000). If another marker is already positioned in the same place, the rule is not matched, to preserve rule priorities.

    Then it simply removes the non-break marks, and splits the text according to the break marks.

    @Sourabh: I hope this is still relevant for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a message system using mysql for storage. This is the
I want to implement Campaign Tracking in my application using EasyTracker I have this
i starter in jqgrid, i want implement inline edit in jqgrid i have this
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement an application which will work as a parser. User will
I want to implement login using facebook in my windows phone 7.1 application When
I want to implement the replication and fault tolerance in CORBA using Java. I
I want to implement file upload in RESTful way using openrasta but not able
I want implement a program that can do a a Vision-based Page Segmentation. I
We want to implement Public Transport Guide for Android. Inputs will be beginning and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.