Jump to content

extract a sentence containing word in text file


Recommended Posts

But when I asked:

Quote

1) if one sentence has two different matching words in it, should the sentence appear just once?

you replied:

Quote

just once

which means that a sentence with two or more matching words will only appear once, when it matches the first word.  the sentence won’t appear later when showing the other matches. 
therefore, and pretty much randomly, one or more of the three matches will not be grouped with the others when there are sentences with multiple matches.

this doesn’t make sense, why not just show all matches (max 3) together, even if it means having the matching sentence duplicated.

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

you could make it pick sentences randomly, from line 1 to line 22k. sentences have to be unique (result file). the order is the word list order i will count three times (lines) for each word, it's not a problem

 

Edited by vinnyMS
Link to comment
Share on other sites

18 minutes ago, vinnyMS said:

sentences have to be unique (result file).

right, but why?

If I’m looking at words used in their context, why I am bothered that a sentence appears on line 100 when it matches with word “Abacus” and then 1000 lines later because it also contains the word “zoo” ?

whose requirement is this uniqueness? 

Code hard, but don’t hard code...

Link to comment
Share on other sites

39 minutes ago, vinnyMS said:

to have more variety to understand the use of the words as in different context

even if a sentence is duplicated, each word still has three different contexts, so no less variety of word contexts.

Code hard, but don’t hard code...

Link to comment
Share on other sites

Local $sentences=".!? " & StringRegExpReplace(FileRead("2.txt"), "([\!\.\?])", "$1.!?")
FileDelete("results.txt")
For $word In StringSplit(FileRead("1.txt"), @CRLF, 3)
   FileWriteLine("results.txt",@CRLF & "WORD: "& $word)
   $iEPos=1
   For $n = 1 to 3
      $iWPos=StringInStr($sentences, $word, 0, 1, $iEpos)
      If $iWPos=0 Then ExitLoop
      $iSPos=StringInStr($sentences, ".!?", 0, -1, $iwPos)
      $iEPos=StringInStr($sentences, ".!?", 0, 1, $iwPos)
      $sentence=StringStripWS(StringMid($sentences, $iSPos + 3, $iEPos - $iSpos - 3),3)
      FileWriteLine("results.txt", $sentence)
   Next
Next

IMHO, you deserve an A+.

Code hard, but don’t hard code...

Link to comment
Share on other sites

when i try to extract sentences with the word "networks" the program extracts extra text

 

WORD: networks

 Networks and network protocols 

 History of TCP/IP 

 Important features of TCP/IP 

Transmission Control Protocol/Internet Protocol (TCP/IP) is a protocol system—a collection 
of protocols that supports network communications.
This hour describes what a network is and shows why networks need protocols.
Networks and Protocols 

A network is a collection of computers or computer-like devices that can communicate across a 
common transmission medium.

 

Link to comment
Share on other sites

Local $sentences=".!? " & StringRegExpReplace(FileRead("2.txt"), "([\!\.\?][' '])", "$1.!?")
$sentences=StringRegExpReplace($sentences, "([\n][\n])", ".!?")
FileDelete("results.txt")
For $word In StringSplit(FileRead("1.txt"), @CRLF, 3)
   FileWriteLine("results.txt",@CRLF & "WORD: "& $word)
   $iEPos=1
   For $n = 1 to 3
      $iWPos=StringInStr($sentences, $word, 0, 1, $iEpos)
      If $iWPos=0 Then ExitLoop
      $iSPos=StringInStr($sentences, ".!?", 0, -1, $iwPos)
      $iEPos=StringInStr($sentences, ".!?", 0, 1, $iwPos)
      $sentence=StringStripWS(StringMid($sentences, $iSPos + 3, $iEPos - $iSpos - 3),3)
      FileWriteLine("results.txt", $sentence)
   Next
Next

dice.

Code hard, but don’t hard code...

Link to comment
Share on other sites

1 hour ago, vinnyMS said:

doesn't seem to work

sorry about that... 

Im almost done with the fix, just another minute or to...

Why don't you take this time to go back and upvote all the people who tried to help you in this thread, myself excluded?

Code hard, but don’t hard code...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...