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 8719907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:54:39+00:00 2026-06-13T06:54:39+00:00

I am trying to tag terms using a list of annotations. What I am

  • 0

I am trying to tag terms using a list of annotations. What I am specifically trying to achieve is that if the Perl regex identifies a term from a sentence it should tag the term with tags.

For example:

This drug has adverse effect on Lymphocytes, Lymphnodes, Lymph and pre-lymphocytes. 

My list has the word Lymph, I am trying the following script.

open IN, "clean_cells.txt" or die "import file absent";
@array=<IN>;
foreach $words(@array)  
{
    @cells=split/\t/,$words;
    $value=$cells[0];
    $replace=$cells[1];
    foreach my $fp (glob("$Directory/*.txt")) 
    {
        @id=split('/',$fp);
        $id[1]=~s/.txt//ig; 
        $Pub=$id[1];
        open FILE, "<",$fp or die "Can't open $fp: $!";
        open OUT, ">C:\\Users\\Desktop\\TM\\Files\\$Pub" or die "Check      output status";
        while(<FILE>)
        {
            chomp $_;
            $line=$_;
            s/\b[\w\-]*$value[\w\-]*\b/<$replace>$&<\\$replace>/gi;
            # $string[$i]=$line;
            # while(($string[$i]=~m/\Q$value\E/i)||                                      ($string[$i]=~m/\Q$value(\w+)\E/i)||($string[$i]=~m/\Q(\w+)$value\E/i))
            # # if ($string[$i] =~ m/\b\w*$value\w*\b/i)
            # {
                # $value=~s/$value/<$replace>$value<\$replace>/i;
            # }
            print OUT "$line\n";
        }
        last;

    }   
    last;
}

I am hoping the final sentence should look like this:

This drug has adverse effect on tag Lymphocytes tag, tag Lymphnodes tag, tag Lymph tag and tag pre-lymphocytes tag.

tag: represents $replace in the above script.

The program tags the base word lymoh and not the entire term Lymphocytes, pre-lymphocytes.

  • 1 1 Answer
  • 0 Views
  • 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-06-13T06:54:40+00:00Added an answer on June 13, 2026 at 6:54 am

    You need to keep your words together. The tricky part with that is determining what characters can make up words. A simpler approach (but perhaps not as exact) is to determine what makes up the delimiters. For example, you can use \S+ to match consecutive non-whitespace characters:

    use strict;
    use warnings;
    
    while (<DATA>) {
        for (split /(\S+)/) {    # The parens make the split keep the delimiters
            $_ = "<tag>$_</tag>" if /lymph/i;
            print;
        }
    }
    
    __DATA__
    Lymphocytes, Lymphnodes, Lymph and pre-lymphocytes.
    

    Output:

    <tag>Lymphocytes,</tag> <tag>Lymphnodes,</tag> <tag>Lymph</tag> and <tag>pre-lymphocytes.</tag>
    

    Note that this is a non-destructive method, because the parens in the split regex will capture and return all the parts of the string.

    This simplistic code will preserve your whitespace, though as you can see, it will put commas and other such separator characters inside your tags. This can be fixed by using another character class, such as [^\s,.!?]+ (not whitespace, comma, period, exclamation point or question mark).

    If you replace <DATA> with <>, you can use this script with redirection and skip the code about opening input and output files.

    perl script.pl input > output
    

    I would personally prefer such functionality, rather than hard-coded file paths, and it is often the way *nix programs work.

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

Sidebar

Related Questions

I'm trying to concatenate a class selector using multiple variables that come from user
Trying to create a PhoneGap app using the canvas tag on an iPad. The
I'm trying to insert a new meta tag within the Head, I'm using a
I'm using SimpleXML to parse a data file from an external source. I'm trying
I am creating a module that needs to tag nodes with taxonomy terms when
I am trying to create a select tag that holds values in it and
i m trying to add custom list of tags using excel file and I
I'm trying to add an addition tag to the end of the autocomplete list.
This is a question based on: Trying to get tag-it to work with an
Im trying to add a tag to a group so when I want to

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.