troubleshooting Question

What's wrong with my app?

Avatar of kimhand
kimhand asked on
Python
3 Comments1 Solution230 ViewsLast Modified:
I am trying to create a  function will change any and all abbreviations so that the will be changed to some thing like    "Mr." will change to  "Mr  <ABBR>"
My program should
1. Read a file of text
2. Split it into sentences
3. Make sure it does not "false" on abbreviations
4. write the edited version to a new file
It reads ok, but that's as far as I get


#!/usr/bin/python
z=open("random.txt").read().split("\n")
for i in range (0,len(z)):
    print i,z[i]
 
def cvAbb(s):
    s = s.replace("Mr.","Mr <ABBR>")
    s = s.replace("Dr.","Dr <ABBR>")
    s = s.replace("Mrs.","Mrs <ABBR>")
    s = s.replace("Phd.","Phd <ABBR>")
    s = s.replace("Prof.","Prof <ABBR>")
    s = s.replace("Revd.","Revd <ABBR>")
    s = s.replace("Rt Hon.","Rt Hon <ABBR>")
    s = s.replace("Lev.","Lev <ABBR>")
    s = s.replace("PP.","PP <ABBR>")
    s = s.replace("FTW.","FTW <ABBR>")
    s = s.replace("IBM.","IBM <ABBR>")
    s = s.replace("PR.","PR <ABBR>")
    s = s.replace("CTO.","CTO <ABBR>")
    s = s.replace("CFO.","CFO <ABBR>")
    s = s.replace("UN.","UN <ABBR>")
    s = s.replace("v.","v <ABBR>")
    s = s.replace("vv.","vv <ABBR>")
    s = s.replace("p.","p <ABBR>")
    s = s.replace("pp.","pp <ABBR>")
    s = s.replace("A.","A <ABBR>")
    s = s.replace("AA.","AA <ABBR>")
    s = s.replace("AAA.","AAA <ABBR>")
    s = s.replace("A.C.","AC <ABBR>")
    s = s.replace("AEO.","AEO <ABBR>")
    s = s.replace("AER.","AER <ABBR>")
    s = s.replace("AG.","AG <ABBR>")
    s = s.replace("AN.","AN <ABBR>")
    s = s.replace("AP.","AP <ABBR>")
    s = s.replace("ARG.","ARG <ABBR>")
    s = s.replace("AV.","AV <ABBR>")
    return s
 
 
def cvBack(s):
    s = s.replace("Mr","Mr.")
    s = s.replace("Dr","Dr.")
    s = s.replace("Mrs","Mrs.")
    s = s.replace("Phd","Phd.")
    s = s.replace("Prof","Prof.")
    s = s.replace("Revd","Revd.")
    s = s.replace("Rt Hon","Rt Hon.")
    s = s.replace("Lev","Lev.")
    s = s.replace("PP","PP.")
    s = s.replace("FTW","FTW.")
    s = s.replace("IBM","IBM.")
    s = s.replace("PR","PR.")
    s = s.replace("CTO","CTO.")
    s = s.replace("CFO","CFO.")
    s = s.replace("UN","UN.")
    s = s.replace("v","v.")
    s = s.replace("vv","vv.")
    s = s.replace("p","p.")
    s = s.replace("pp","pp.")
    s = s.replace("A","A.")
    s = s.replace("AA","AA.")
    s = s.replace("AAA","AAA.")
    s = s.replace("AC","A.C.")
    s = s.replace("AEO","AEO.")
    s = s.replace("AER","AER.")
    s = s.replace("AG","AG.")
    s = s.replace("AN","AN.")
    s = s.replace("AP","AP.")
    s = s.replace("ARG","ARG.")
    s = s.replace("AV","AV.")
    return s
 
u = cvAbb(u)
 
d = u.split("")
for i in range (len(z)):
    print cvBack(d[i])
 
q = []
q.append(z)
 
z = open("randomresults.txt","w)
for i in range (len(q)):
    z.write("%s\n" % q[i])
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros