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

  • Home
  • SEARCH
  • 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 3624284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:29:19+00:00 2026-05-18T23:29:19+00:00

What are common approaches for translating certain words (or expressions) inside a given text,

  • 0

What are common approaches for translating certain words (or expressions) inside a given text, when the text must be reconstructed (with punctuations and everythin.) ?

The translation comes from a lookup table, and covers words, collocations, and emoticons like L33t, CUL8R, :-), etc.

Simple string search-and-replace is not enough since it can replace part of longer words (cat > dog ≠> caterpillar > dogerpillar).

Assume the following input:

s = "dogbert, started a dilbert dilbertion proces cat-bert :-)"

after translation, i should receive something like:

result = “anna, started a george dilbertion process cat-bert smiley“

I can’t simply tokenize, since i loose punctuations and word positions.

Regular expressions, works for normal words, but don’t catch special expressions like the smiley 🙂 but it does .

re.sub(r'\bword\b','translation',s) ==> translation
re.sub(r'\b:-\)\b','smiley',s) ==> :-)

for now i’m using the above mentioned regex, and simple replace for the non-alphanumeric words, but it’s far from being bulletproof.

(p.s. i’m using python)

  • 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-05-18T23:29:20+00:00Added an answer on May 18, 2026 at 11:29 pm

    I had a similar problem with standard emoticons to be replaced with values. Here is a list of emoticons. I had them in a plain text file (so that I can append/delete to it as and when required) separated by tab like.

    :[        -1
    :/        -1
    :(          -1
    :)         1
    

    Then read it into a dictionary

    emoticons = {}          
    for line in open('data/emoticons.txt').xreadlines():   
            symbol, value = line.split('\t')                                           
            emoticons[str(symbol)] = int(value)
    

    Then a lookup function

    def mark_emoticons(t):
        for w, v in emoticons.items():
            match = re.search(re.escape(w),t)
                if match:
                    print w, "found "
    

    Call the function with

    mark_emoticons('Hello ladies! How are you? Fantastic :) Look at your man ...')
    

    As for L33t-speak I have a separate file slangs.txt, which looks like

    u   you
    ur  you are
    uw  you are welcome 
    wb  welcome back 
    wfm works for me 
    wtf what the fuck
    

    A similar function to read it to dictionary slangs{} and a similar function to replace the slangs.

    def mark_slangs(t):        
        for w, v in slangs.items():
                s = r'\b' + w + r'\b'
                match = re.search(s,t)
                if match:
                        #print w, "found in:",t, "replacing with",readtable.slangs[w]
                        t = re.sub(w,slangs[w].rstrip(),t)
                        ...
    

    From Python library the re.escape()

    re.escape(string)
    Return string with
    all non-alphanumerics backslashed;
    this is useful if you want to match an
    arbitrary literal string that may have
    regular expression metacharacters in
    it.

    Based on your needs you might want to use re.findall()

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

Sidebar

Related Questions

A common way I handle things in Drupal is to create a CCK type,
A lot of websites states that packrat parsers can parse input in linear time.
I have to make an iPhone app for a company which has a web
I am relatively new to .Net and C# development and am having an issue
I'm trying to switch from two-stage rotation to one-stage rotation (to avoid the console
Recently, our development team was approached by a representative from one of the departments
HI @ll! I want to add and remove some items to my datasource for
I'm trying to build a MonoTouch project using xbuild (on a Mac, clearly). Here's
I am using the following technique to load up Javascript dynamically: var script =
I'd like to disable a form after it is submitted in order to prevent

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.