Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / FileMaker Topics / January 2004

Tip: Looking for answers? Try searching our database.

Extracting the first sentence from a text field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 30 Jan 2004 04:51 GMT
Hi,

I have a field that contains more than one sentence. I would like to extract
the first sentence from that field - anybody know how this can be done using
the text functions?

Many thanks,
Andrew
Maria Tzortzis - 30 Jan 2004 05:16 GMT
Heya,

Left(field1, Position(field1, ".", 0, 1))

Ta,
Maria

> Hi,
>
[quoted text clipped - 4 lines]
> Many thanks,
> Andrew

 Maria Tzortzis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Database Development Officer
  Computer Science & Engineering, UNSW
  ph: 9385 6887 fax: 9385 5995
  www.cse.unsw.edu.au/~mariat/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Helpful Harry - 30 Jan 2004 05:39 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> Many thanks,
> Andrew

Usually a sentence is defined to end in a . ! or ? so you need to know
the position of the first one of these characters.

If your original field is called MyText, then the first sentence can be
obtained by a claculated field with a text result along the lines of:

    FirstSentence = Left(MyText, Min(Position(MyText, ".", 1, 1),
                                     Position(MyText, "!", 1, 1),
                                     Position(MyText, "?", 1, 1)))

This finds the position of the first . ! and ? and works out which one
comes first unsing the Min function, and then simply takes all the
characters starting on the left of MyText up to and including the . !
or ?

BUT, this won't work if your first sentence was something like:

    "Hello, how are you?" asked George as he walked into the room.

The first sentence here ends in 'room.', not 'you?'

You could get around this by ignoring ." !" or ?" but it would get very
messy and may not even be necessary for what you're trying to do.

Helpful Harry                  
"Hopefully helping harassed humans happily handle handiwork hardships"  ;o)
Abbott Schindler - 31 Jan 2004 01:17 GMT
This looks like a good calculation that needs one small change:
Just to make sure that things like decimal numbers in a sentence don't
screw you up, instead of parsing for ".", "?", and "!", I'd suggest
adding a space after each punctuation mark (". ", "? ", and "! ")

> > Hi,
> >
[quoted text clipped - 31 lines]
> Helpful Harry                  
> "Hopefully helping harassed humans happily handle handiwork hardships"  ;o)
Helpful Harry - 31 Jan 2004 05:06 GMT
In article
<abbottnospam-B45B67.18170430012004@news1.west.earthlink.net>, Abbott
Schindler <abbottnospam@nospamkbase.com> wrote:

> This looks like a good calculation that needs one small change:
> Just to make sure that things like decimal numbers in a sentence don't
> screw you up, instead of parsing for ".", "?", and "!", I'd suggest
> adding a space after each punctuation mark (". ", "? ", and "! ")

Good point. You probably should add a space after each character in the
calculation, it would also take care of any sentences with "..." in the
middle of them too.  :o)

    FirstSentence = Left(MyText, Min(Position(MyText, ". ", 1, 1),
                                     Position(MyText, "! ", 1, 1),
                                     Position(MyText, "? ", 1, 1)))

Although that does introduce the problem of speech sentences,
eg.     George said, "Goodbye Jenny." He then left the room.

But this may not be an issue in whatever the original person is trying
to do.

Helpful Harry                  
"Hopefully helping harassed humans happily handle handiwork hardships"  ;o)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.