hallo,
I need to extract a word and few text that
precedes and follows it (about 30 + 30 chars)
from a long textual document.
Like the description that Google returns when
it has found a given word.
In example from:
"Sylvia Brunner, a marine mammals researcher at the museum in Fairbanks,
identified the decomposing carcass and oversaw its recovery on Wednesday.
The "bloated, black thing on the beach" was about 12 feet from the river's
edge, she said."
I have to find the 'carcass' word
and finally return with:
"identified the decomposing carcass and oversaw its recovery on"
---
Which is the *fast* method in VbNet?
In VB6 I would have used
InStr (with Binary option because faster)
to find the position of the word,
then Mid to extract the preceding text,
then Mid to extract the following text,
then build up my phrase in this way: text1 & word & text2 .
Any suggestion in VBNet ?
New methods, StringBuilder, Regular Expression... or what else?
--------
Thanks
(examples are obviously very appreciated ;-) ) 7 2866
teo,
| Which is the *fast* method in VbNet?
It sounds like you have the methods identified, you simply want someone else
to test them for you. Why not test them yourself, as you probably already
have the situation (program) and data to test them with.
I would probably use a regular expression, as regex feels like the "correct"
solution (not necessarily the fastest method). The trick is going to be
ensuring that it is an efficient expression and not a poorly performing
one... For example using a lazy compare instead of a greedy compare on the
30 before & after...
If I have time later I will see what RegEx I can come up with...
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"teo" <te*@inwind.it> wrote in message
news:ue********************************@4ax.com...
| hallo,
|
| I need to extract a word and few text that
| precedes and follows it (about 30 + 30 chars)
| from a long textual document.
|
| Like the description that Google returns when
| it has found a given word.
|
| In example from:
|
| "Sylvia Brunner, a marine mammals researcher at the museum in Fairbanks,
| identified the decomposing carcass and oversaw its recovery on Wednesday.
| The "bloated, black thing on the beach" was about 12 feet from the river's
| edge, she said."
|
| I have to find the 'carcass' word
| and finally return with:
| "identified the decomposing carcass and oversaw its recovery on"
|
| ---
|
| Which is the *fast* method in VbNet?
|
| In VB6 I would have used
| InStr (with Binary option because faster)
| to find the position of the word,
| then Mid to extract the preceding text,
| then Mid to extract the following text,
| then build up my phrase in this way: text1 & word & text2 .
|
| Any suggestion in VBNet ?
| New methods, StringBuilder, Regular Expression... or what else?
|
| --------
|
|
| Thanks
| (examples are obviously very appreciated ;-) )
|
Use the same method as you would in VB6. Use the IndexOf method to find
the string and the Substring method to extract the part of the text.
However, I don't see the reason for getting the preceding text and
following text, just to put them together, when the string that you want
already exists in the text.
teo wrote: hallo,
I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document.
Like the description that Google returns when it has found a given word.
In example from:
"Sylvia Brunner, a marine mammals researcher at the museum in Fairbanks, identified the decomposing carcass and oversaw its recovery on Wednesday. The "bloated, black thing on the beach" was about 12 feet from the river's edge, she said."
I have to find the 'carcass' word and finally return with: "identified the decomposing carcass and oversaw its recovery on"
---
Which is the *fast* method in VbNet?
In VB6 I would have used InStr (with Binary option because faster) to find the position of the word, then Mid to extract the preceding text, then Mid to extract the following text, then build up my phrase in this way: text1 & word & text2 .
Any suggestion in VBNet ? New methods, StringBuilder, Regular Expression... or what else?
--------
Thanks (examples are obviously very appreciated ;-) )
Teo,
Here is a regex:
Dim input As String = "Sylvia Brunner, a marine mammals researcher
at the museum in Fairbanks, identified the decomposing carcass and oversaw
its recovery on Wednesday. The ""bloated, black thing on the beach"" was
about 12 feet from the river's edge, she said."
Dim pattern As String = ".{1,30}?carcass.{1,30}"
Dim match As Match = Regex.Match(input, pattern,
RegexOptions.Multiline)
If match.Success Then
Debug.WriteLine(match.Value)
End If
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"teo" <te*@inwind.it> wrote in message
news:ue********************************@4ax.com...
| hallo,
|
| I need to extract a word and few text that
| precedes and follows it (about 30 + 30 chars)
| from a long textual document.
|
| Like the description that Google returns when
| it has found a given word.
|
| In example from:
|
| "Sylvia Brunner, a marine mammals researcher at the museum in Fairbanks,
| identified the decomposing carcass and oversaw its recovery on Wednesday.
| The "bloated, black thing on the beach" was about 12 feet from the river's
| edge, she said."
|
| I have to find the 'carcass' word
| and finally return with:
| "identified the decomposing carcass and oversaw its recovery on"
|
| ---
|
| Which is the *fast* method in VbNet?
|
| In VB6 I would have used
| InStr (with Binary option because faster)
| to find the position of the word,
| then Mid to extract the preceding text,
| then Mid to extract the following text,
| then build up my phrase in this way: text1 & word & text2 .
|
| Any suggestion in VBNet ?
| New methods, StringBuilder, Regular Expression... or what else?
|
| --------
|
|
| Thanks
| (examples are obviously very appreciated ;-) )
|
On Sat, 17 Jun 2006 23:12:22 +0200, Göran Andersson <gu***@guffa.com>
wrote: Use the same method as you would in VB6. Use the IndexOf method to find the string and the Substring method to extract the part of the text.
However, I don't see the reason for getting the preceding text and following text, just to put them together, when the string that you want already exists in the text.
The fact is that I'm building a searching engine, and I need to
format the searched word as Bold,
so I'm compelled to have two chunk of text ,
so I can format my final string as this:
plain Text1 + Bold word + plain Text2.
Because I have to extract the integral text from a column of a DB
(then extract only a part of it, as described above),
do you know if SQL syntax is able to perform such extraction?
Or I'm compelled to extract the string using the VB methods
after having stored the integral text in a DataReader?
Thanks;
I didn't want you to do the work for me indeed,
I only liked to know the name of the functions
it is advisable to use for this case... Teo, Here is a regex:
Dim input As String = "Sylvia Brunner, a marine mammals researcher at the museum in Fairbanks, identified the decomposing carcass and oversaw its recovery on Wednesday. The ""bloated, black thing on the beach"" was about 12 feet from the river's edge, she said." Dim pattern As String = ".{1,30}?carcass.{1,30}"
Dim match As Match = Regex.Match(input, pattern, RegexOptions.Multiline)
If match.Success Then Debug.WriteLine(match.Value) End If
| The fact is that I'm building a searching engine, and I need to
| format the searched word as Bold,
Rather then search for the text each time, have you considered, "indexing"
each document.
Then when you need to do a search, you simply check the index, the index
would return where in the text the word was found.
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"teo" <te*@inwind.it> wrote in message
news:su********************************@4ax.com...
| On Sat, 17 Jun 2006 23:12:22 +0200, Göran Andersson <gu***@guffa.com>
| wrote:
|
| >Use the same method as you would in VB6. Use the IndexOf method to find
| >the string and the Substring method to extract the part of the text.
| >
| >However, I don't see the reason for getting the preceding text and
| >following text, just to put them together, when the string that you want
| >already exists in the text.
|
| The fact is that I'm building a searching engine, and I need to
| format the searched word as Bold,
| so I'm compelled to have two chunk of text ,
| so I can format my final string as this:
| plain Text1 + Bold word + plain Text2.
|
| Because I have to extract the integral text from a column of a DB
| (then extract only a part of it, as described above),
| do you know if SQL syntax is able to perform such extraction?
|
| Or I'm compelled to extract the string using the VB methods
| after having stored the integral text in a DataReader?
|
On Sat, 17 Jun 2006 22:42:07 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@tsbradley.net> wrote: | The fact is that I'm building a searching engine, and I need to | format the searched word as Bold, Rather then search for the text each time, have you considered, "indexing" each document.
Then when you need to do a search, you simply check the index, the index would return where in the text the word was found.
I know that there is such an option,
but I didn't think about it about a solution
because it seemed to me that it would have required
a lot of job to do firstly ;
also going to search a given word among the resulting huge list of
indexed words,
I think it would require a lot of time, maybe the same time than
it would require searching for the given every time.
I'm only guessing about, I've no benchmark....
Maybe I'm going to implement such a solution
when I've finished this method I've started to develop now.
----------
Another question:
the RegExp sample we discuss above
returns 30 + 30 , regardless how the 30 on the left start.
I'll try to explain what I mean.
I'd like to have the chunk of text on the left
starting where the sentence containing the given word starts,
(so to have the very first letter capitalized),
like the way Google displays the results,
that is, if you search 'Lewinsky'
Goggle returns with:
To maintain the *Lewinsky* Story's original feel, we will leave much
of this ... These were gifts the president had originally given
to Ms. Lewinsky himself. ...
In this way,
the 'T' letter is at # -16 position,
I renounce to the preceding 14 chars
and decide to start straight at # - 16
and decide to increase the chunk of text on the
right to 44 ( = 30 + 14).
If the "T" isn't within the 30 chars on left,
no problem, I accept the old 30+30 solution.
Is it possible?
-----
Basically,
we need to trace of the . (= dot) char
that signals to us that a sentence (within to 30 left) is going to start.
If a single RegExp doesn't workt,
we could maybe go with doubling the first RegExp (60 +60)
and then
with a second RegExp find the dot char
and then simply extract the following 60 chars chunk of
text on the right.
What about this? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nel |
last post by:
Hi all,
Before I re-invent the wheel here, has anyone willing to share a basic
script to extract META keywords from a string. I have a string, let's say
$pageText that contains the dynamic...
|
by: John van Terheijden |
last post by:
Hi.
I'm trying to make a conversion algorithm that colors even and odd words in
a HTML string with <div> tags.
// input text with all sorts of HTML tags and whitespace
$str = "<h1>Title...
|
by: Sheela |
last post by:
Hi all gurus in tha club,
I scripted a prog that extract a string from an html page excluding
all the tags.
The problem is that it works quite slowly and I wanted to know if
somebody of us as an...
|
by: cassandra.flowers |
last post by:
Hi,
I am using VB6 and want to extract text from a string. But ONLY take out
words that begin with 't' or 'd'. The mainstring is input by the user into
'txtMain' and then by clicking a command...
|
by: Richard L Rosenheim |
last post by:
I have some text where I need to extract some pieces from. The text will be
in a format like this:
a string description color="red" type="unknown"
In the above example, I would be looking to...
| |
by: yerk5 |
last post by:
Does js have some way of doing what I want here:
I want to paste a multiline block of text into a TEXTAREA form field,
and there is data in the block of text that I want to extract into a...
|
by: kellysgirl |
last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written.
The instructions I was given are as follows
In this case, you will create...
|
by: Jacek Dziedzic |
last post by:
Hi!
I need a routine like:
std::string nth_word(const std::string &s, unsigned int n) {
// return n-th word from the string, n is 0-based
// if 's' contains too few words, return ""
//...
|
by: Edwin.Madari |
last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below...
import urllib
line = "GET...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |