0
I’m having a problem separating lines from several files txt
. These files have a specific pattern but there are files that do not respect it.
These are some of the 5000 files I’m trying to read:
SAMPLE TYPE / MEDICAL SPECIALTY:Dentistry
SAMPLE NAME: Teeth Extraction & I&D - 1
DESCRIPTION:Extraction of teeth #2 and #19 and incision and drainage (I&D) of intraoral and extraoral of left mandibular dental abscess.
(Medical Transcription Sample Report)
* * *
PREOPERATIVE DIAGNOSES:Carious teeth #2 and #19 and left mandibular dental abscess.
POSTOPERATIVE DIAGNOSES: Carious teeth #2 and #19 and left mandibular dental abscess.
PROCEDURES: Extraction of teeth #2 and #19 and incision and drainage of intraoral and extraoral of left mandibular dental abscess.
ANESTHESIA:General, oral endotracheal.
COMPLICATIONS:None.
DRAINS:Penrose 0.25 inch intraoral and vestibule and extraoral.
CONDITION: Stable to PACU.
DESCRIPTION OF PROCEDURE: Patient was brought to the operating room, placed on the table in the supine position and after demonstration of an adequate plane of general anesthesia via the oral endotracheal route, patient was prepped and draped in the usual fashion for an intraoral procedure. In addition, the extraoral area on the left neck was prepped with Betadine and draped accordingly. Gauze throat pack was placed and local anesthetic was administered in the left lower quadrant, total of 3.4 mL of lidocaine 2% with 1:100,000 epinephrine and Marcaine 1.7 mL of 0.5% with 1:200,000 epinephrine. An incision was made with #15 blade in the left submandibular area through the skin and blunt dissection was accomplished with curved mosquito hemostat to the inferior border of the mandible. No purulent drainage was obtained. The 0.25 inch Penrose drain was then placed in the extraoral incision and it was secured with 3-0 silk suture. Moving to the intraoral area, periosteal elevator was used to elevate the periosteum from the buccal aspect of tooth #19. The area did not drain any purulent material. The carious tooth #19 was then extracted by elevator and forceps extraction. After the tooth was removed, the 0.25 inch Penrose drain was placed in a subperiosteal fashion adjacent to the extraction site and secured with 3-0 silk suture. The tube was then repositioned to the left side allowing access to the upper right quadrant where tooth #2 was then extracted by routine elevator and forceps extraction. After the extraction, the throat pack was removed. An orogastric tube was then placed by Dr. X, and stomach contents were suctioned. The pharynx was then suctioned with the Yankauer suction. The patient was awakened, extubated, and taken to the PACU in stable condition.
KEYWORDS:dentistry, yankauer suction, orogastric tube, carious teeth, penrose drain, forceps extraction, dental abscess, incision, elevator, mandibular, dental, abscess, teeth, intraoral, extraction, drainage
Or
SAMPLE TYPE / MEDICAL SPECIALTY:Dermatology
SAMPLE NAME: Epidermal Autograft
DESCRIPTION:A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings. Epidermal autograft on Integra to the back and application of allograft to areas of the lost Integra, not grafted on the back.
(Medical Transcription Sample Report)
* * *
PREOPERATIVE DIAGNOSIS: A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings.
POSTOPERATIVE DIAGNOSIS: A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings.
PROCEDURES PERFORMED:
1\. Epidermal autograft on Integra to the back (3520 cm2).
2\. Application of allograft to areas of the lost Integra, not grafted on the
back (970 cm2).
ANESTHESIA:General endotracheal.
ESTIMATED BLOOD LOSS: Approximately 50 cc.
BLOOD PRODUCTS RECEIVED: One unit of packed red blood cells.
COMPLICATIONS:None.
INDICATIONS:The patient is a 26-year-old male, who sustained a 60% total body surface area flame burn involving the head, face, neck, chest, abdomen, back, bilateral upper extremities, hands, and bilateral lower extremities. He has previously undergone total burn excision with placement of Integra and an initial round of epidermal autografting to the bilateral upper extremities and hands. His donor sites have healed particularly over his buttocks and he returns for a second round of epidermal autografting over the Integra on his back utilizing the buttock donor sites, the extent they will provide coverage.
OPERATIVE FINDINGS:
1\. Variable take of Integra, particularly centrally and inferiorly on the
back. A fair amount of lost Integra over the upper back and shoulders.
2\. No evidence of infection.
3\. Healthy viable wound beds prior to grafting.
PROCEDURE IN DETAIL: The patient was brought to the operating room and positioned supine. General endotracheal anesthesia was uneventfully induced and an appropriate time out was performed. He was then repositioned prone and perioperative IV antibiotics were administered. He was prepped and draped in the usual sterile manner. All staples were removed from the Integra and the adherent areas of Silastic were removed. The entire wound bed was further prepped with scrub brushes and more Betadine followed by a sulfamylon solution. Hemostasis of the wound bed was ensured using epinephrine-soaked Telfa pads. Following dermal tumescence of the buttocks, epidermal autografts were harvested 8 one-thousandths of an inch using the air Zimmer dermatome. These grafts were passed to the back table where they were meshed 3:1. The donor sites were hemostased using epinephrine-soaked Telfa and lap pads. Once all the grafts were meshed, we brought them back up onto the field, positioned them over the wounds beginning inferiorly and moving cephalad where we had best areas of Integra engraftment. We were happy with the lie of the grafts and they were stapled into place. The grafts were then overlaid with Conformant 2, which was also stapled into place. Utilizing all of his buttocks skin, we did not have enough to cover his entire back, so we elected to apply allograft to the cephalad and a few areas on his flanks where we had had poor Integra engraftment. Allograft was thawed and meshed 1:1. It was then brought up onto the field, trimmed to fit and stapled into place over the wound. Once the entirety of the posterior wounds on his back were covered out with epidermal autograft or allograft sulfamylon soaked dressings were applied. Donor sites on his buttocks were dressed in Acticoat and secured with staples. He was then repositioned supine and extubated in the operating room having tolerated the procedure without any apparent complications. He was transported to PACU in stable condition.
KEYWORDS:dermatology, flame burns, body surface area, epidermal autograft, autograft, integra, integra engraftment, wound, grafts, epidermal, allograft
That is, every file of mine will have the structure: Keyword (uppercase or minuscule or with the first uppercase letter) : explanation definition in multiple lines or only in a row or enumerated list.
would like to place each of these blocks on the same line as your keyword. As exemplified in the keyword OPERATIVE FINDINGS:
sometimes can come a block of lines like :
Operative things:1\\. Variable take of Integra, particularly centrally and inferiorly on theback. A fair amount of lost Integra over the upper back and shoulders.2\\. No evidence of infection.3\\. Healthy viable wound beds prior to grafting.\nPROCEDURE IN DETAIL: The patient was brought to the operating room and positioned supine. General endotracheal anesthesia was uneventfully induced and an appropriate time out was performed. He was then repositioned prone and perioperative IV antibiotics were administered. He was prepped and draped in the usual sterile manner. All staples were removed from the Integra and the adherent areas of Silastic were removed. The entire wound bed was further prepped with scrub brushes and more Betadine followed by a sulfamylon solution. Hemostasis of the wound bed was ensured using epinephrine-soaked Telfa pads. Following dermal tumescence of the buttocks, epidermal autografts were harvested 8 one-thousandths of an inch using the air Zimmer dermatome. These grafts were passed to the back table where they were meshed 3:1.
Note that you may have número:número
in these passages therefore sepraration by two points is not enough. My code is like this:
def arrumaDadosPEP(self, inDir, outDir):
with open(inDir, 'r') as f: # abrir e ler o ficheiro
lines = (i.strip() for i in f.readlines()) # retirar todas as quebras de linha
text = ''
for line in lines:
if(':' in line):
expression = line.split(':')[0] # separar e ficar com o que vem antes dos ":", expression
if(expression.isupper()): # ver se e maiuscula
text += '\n{}'.format(line)
continue
text += line
directory, file_name = os.path.split(inDir)
file = open(outDir + file_name, 'w')
file.write(text.replace('* * *','').replace('Keywords:','\nKEYWORDS:'))
file.close()
return(text)
But don’t take the keywords that are lower-case
and sometimes erases space between words and adds space in places it doesn’t have.
That’s a one-class method.
The first match o
SAMPLE NAME:
should be in another line. And these names with : can be minuculas or with the first letter uppercase.– user2535338
It went wrong! Why in this case you have separated the lines as if each is a different string... and it is an entire text or double quotes will only be after the last ' n'
– user2535338
Gave in the same the string with line breaks separated by
"
or all together. When the"
apparently it concatenates everything (I don’t understand python, so it’s just an assumption).SAMPLE NAME:
, that really was something I hadn’t seen at the time I posted.– Caio Oliveira
And for the
SAMPLE NAME
without the:
it will Works?– user2535338