comparing sentences


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comparing sentences
# 1  
Old 10-18-2008
comparing sentences

Hi,

I have a file and that file contains the following sentences.

Code:
Here we show that a virus-encoded transcription factor, viral mRNA, cellular RNA-binding protein heterodimer G3BP/Caprin-1 (p137), translation initiation factors eIF4E and eIF4G, and ribosomal proteins are concentrated in the same subdomains of cytoplasmic DNA factories
The single-stranded DNA- and RNA-binding protein, Puralpha, has been implicated in many biological processes, including control of transcription of multiple genes, initiation of DNA replication, and RNA transport and translation
RNA-binding proteins are involved in processes such as protection of RNAs from RNase degradation, prevention of ribosome binding to mRNA, control of formation of secondary structures of the mRNA that permit or prevent translation initiation, and termination/antitermination of transcription in response to external signals
d)The La autoantigen is an RNA-binding protein that is involved in initiation and termination of RNA polymerase III transcription

Here is the code to match the sentence.

Code:
//Suppose if this is my input string

$str="Here we show that a virus-encoded transcription factor, viral mRNA, cellular RNA-binding protein heterodimer G3BP/Caprin-1 (p137), translation initiation factors eIF4E and eIF4G, and ribosomal proteins are concentrated in the same subdomains of cytoplasmic DNA factories";

open(FH,"sample.txt");
while(<FH>)
{
    if($_=~/$str/)
   {
      print "matched\n";
   }
  else
  {
     print "not match\n";
  }
}
close FH;

If the above string is matching it should print matched but even though that sentences is there still it is not matcing.

How should i match the above sentence?

How can i match sentences like these in perl?

With regards
Vanitha

Last edited by vanitham; 10-20-2008 at 12:47 AM..
# 2  
Old 10-18-2008
Ignore

a)
b)
c)
d)

and try
# 3  
Old 10-18-2008
Hi.

Some special characters need to be escaped in patterns. I did that here with the parens in scalar str:
Code:
#!/usr/bin/perl

# //Suppose if this is my input string

use warnings;

$str='Here we show that a virus-encoded transcription factor, viral mRNA, cellular RNA-binding protein heterodimer G3BP/Caprin-1 \(p137\), translation initiation factors eIF4E and eIF4G, and ribosomal proteins are concentrated in the same subdomains of cytoplasmic DNA factories';

open(FH,"sample.txt");
while(<FH>)
{
    if($_=~/$str/)
    # if($_=~ m|$str|)
   {
      print "matched\n";
   }
  else
  {
     print "not match\n";
  }
}
close FH;

Producing (with your data):
Code:
% ./p1
matched
not match
not match
not match

The commented if is how I often code conditional matching statements ... cheers, drl
# 4  
Old 10-20-2008
Quote:
Originally Posted by swat
Ignore

a)
b)
c)
d)

and try
Hi,

That is just for my refrence sake i have written !!!!

without that also it is not working!!!
# 5  
Old 10-20-2008
Quote:
Originally Posted by drl
Hi.

Some special characters need to be escaped in patterns. I did that here with the parens in scalar str:
Code:
#!/usr/bin/perl

# //Suppose if this is my input string

use warnings;

$str='Here we show that a virus-encoded transcription factor, viral mRNA, cellular RNA-binding protein heterodimer G3BP/Caprin-1 \(p137\), translation initiation factors eIF4E and eIF4G, and ribosomal proteins are concentrated in the same subdomains of cytoplasmic DNA factories';

open(FH,"sample.txt");
while(<FH>)
{
    if($_=~/$str/)
    # if($_=~ m|$str|)
   {
      print "matched\n";
   }
  else
  {
     print "not match\n";
  }
}
close FH;

Producing (with your data):
Code:
% ./p1
matched
not match
not match
not match

The commented if is how I often code conditional matching statements ... cheers, drl
Hi,

I tried but still its not matching!!!

Its giving not match only !!!

what else can be done?

With regards
Vanitha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use $variable in conditional sentences?

Hello all I am doing a Makefile but I can't return the value of $var to use it in conditional sentences: #!/bin/sh GO=$(shell) go GOPATH=$(GO) env GOPATH make: @$(GOPATH) @if ; then mkdir -p "$(GOPATH)/bin" ; fi When I type "make", @$GOPATH returns /home/icvallejo/go... (5 Replies)
Discussion started by: icvallejo
5 Replies

2. Shell Programming and Scripting

Using awk to find sentences.

I am trying to print out sentences that meets a regular expression in awk (I’m open to using other tools, too). I got the regular expression I want to use, "(\+ \{4\})" from user ripat in a grep forum. Unfortunately with grep I couldn't print only the sentence. While searching for awk... (8 Replies)
Discussion started by: danbroz
8 Replies

3. Shell Programming and Scripting

extracting sentences that only contain a word

Hi guys Need your help how do I extract sentences with only a word i.e. today is hot hot very humid humid2 Sample output hot (6 Replies)
Discussion started by: jamestan
6 Replies

4. UNIX for Dummies Questions & Answers

extracting sentences that only contain a word

Hi guys Need your help how do I extract sentences with only a word i.e. today is hot hot very humid humid2 Sample output hot very (0 Replies)
Discussion started by: jamestan
0 Replies

5. Programming

compile a program in C with teradata sentences using cc

hi, I want to compile a program in C. It have a multiple calls to teradata. I have no idea how to compile in Aix. The compiler that I should be use is cc. I tried cc -G -KPIC tdsfbd0358.c this generates a tdsfbd0358.i and after I have no Idea what I have to make, a link? how?... (3 Replies)
Discussion started by: kajum
3 Replies

6. UNIX for Dummies Questions & Answers

How to filter sentences??

Hi, I have few sentences here. $a1="Division of Hematology-Oncology, and Stem cell transplantation, Schneider Childrens Hospital, Albert Einstein College of Medicine, New Hyde Park, New York. "; $a2="Department of Cell Biology and Anatomy, College of Medicine, National Cheng Kung... (3 Replies)
Discussion started by: vanitham
3 Replies

7. Shell Programming and Scripting

Separate sentences from two texts, combine them

I havet two books, one in Swedish, the other in English. Two text files. I want to combine them into one, with each sentence having it's translation next to it. ------------ Text file one. Example sentence in English. Example 2 sentence 2 in English 2. -------------- Text file two. ... (2 Replies)
Discussion started by: LaraMej
2 Replies

8. Shell Programming and Scripting

How to get exact match sentences?

Hi, I have sentences like this: $sent= Protein modeling studies reveal that the RG-rich region is part of a three to four strand antiparallel beta-sheet, which in other RNA binding protein functions as a platform for nucleic acid interactions. Heterogeneous nuclear ribonucleoparticle... (19 Replies)
Discussion started by: vanitham
19 Replies

9. Shell Programming and Scripting

How to identify sentences from a text?

Hi, I have to identify sentences from this text. If i split these statements by this way: @sentence= split(/\.\W*/,$text); I will get these following things also in the output along with proper sentences. Biol Reprod. 2002 Mar;66(3):785-95. Egydio de Carvalho C, Tanaka H,... (2 Replies)
Discussion started by: vanitham
2 Replies

10. UNIX for Dummies Questions & Answers

spliting up sentences

hello, i'm looking to split up text into a list of words but can't figure it out, any help would be great. thanks steven (2 Replies)
Discussion started by: stevox
2 Replies
Login or Register to Ask a Question