Hire Experts For Answers
Order NowRelated Study Services
- Homework Answers
- Coursework writing help
- Term paper writing help
- Writing Help
- Paper Writing Help
- Research paper help
- Thesis Help
- Dissertation Help
- Case study writing service
- Capstone Project Writing Help
- Lab report Writing
- Take my online class
- Take my online exam
- Do my test for me
- Do my homework
- Do my math homework
- Online Assignment Help
- Do my assignment
- Essay Writing Help
- Write my college essay
- Write my essay for me
DESCRIPTION
Posted
Modified
Viewed
20
Abstract:
You've seen a lot of different things about languages and have used a few. While all languages are good at something, none are good at everything, so selection of a language to use for a problem should closely mirror how you expect to compute the result - most of the time. While there is no and can be no best language to solve all problems, there are fads in coding and development just like anything else, often to the detriment of the popular language. Its capabilities are inflated and it starts to grow 'wide' rather than 'tall. That is, people start figuring out ways to port their favorite language to problems it is not meant to solve and how to expand its range of application, rather than focus on what it does well. Python is unfortunately rather popular.
Introduction:
In the course of preparing assignments, I often need to generate information for you to examine, modify, or fix. One metaphor would be making a puzzle. It is delivered in its end state in pieces and the goal is for you to assemble it. This means I often spend a fair amount of time in text processing, scripting and automatically generating and randomizing various files, information and behaviors. I was using Python to generate some files for a Python assignment and ran in to the issue I spoke of in class - Python does not really push its morphisms. For instance, arrays are common in Java and C, but what if you could only have 1-dimensional arrays? While you don't often use 2, 3, 4 or 5 dimensions, they are there for you. What if you only had pointers to values and pointers could not point to other pointers? It would be very hard to get data in from the commandline in C, since argv requires a pointer to a pointer (i.e. a 2-D array) to work.
While I do certainly like list comprehensions in Python, I wish they built taller and made the list comprehensions go a little farther. If you do simple things with comprehensions, they're fine, but if you complicate things a bit, they get somewhat clunky. Look at 'unfoo.py':
"
import sys
def unfoo(inname, outname):
fin = open(inname, 'r')
fout = open(outname, 'w')
# fin.read() returns the whole file as a string
# fin.readlines( ) returns the whole file as a list of lines
# for line in fin reads a line at a time
for line in fin:
frepl = line.replace('foo','')
fout.write(frepl)
fin.close( )
fout.close( )
def main ( ):
unfoo(sys.argv[1], sys.argv[2])
if __name__ == '__main__':
main()
"
.. that is a nice, clean, simple function. Read in a whole file and replace each occurrence of single word with a different single word and write it out. Easy.
So, the actions above are:
read in file as a list
for each line in that file:
replace all occurrences of 'foo' with a space
write the line out
Take that basic function and add a list of words to swap:
read in list of word replacements as a list of lists (each sublist holds two or three words that will be swapped/replaced for each other)
read in a file as a list
for each line in that file:
if a word in that line appears in a word replacement sublist, replace it with the opposite word (i.e. swap 1st word for 2nd and vice versa)
write the line out
That fairly direct augmentation runs beyond what Python can represent easily. Your assignment is to write it using the skeleton I outline below.
Methodology:
First take the code skeleton below. It is also attached as "confu.py".
"
import sys
def confu(dictname, inname, outname):
confulist = []
linewords = []
#open and read in the dictionary
# the dictionary is a list of lists
# each sublist is a tab-separated list of
# two to three words
file = open(dictname, 'r')
for line in file.readlines():
confulist.append(line.strip().split("\t"))
file.close()
#open up the file of text whose words you
# are going to replace 'inname'
file = open(inname, 'r')
#open up/create the file that will hold the
# modified version of 'infile'
outfile = open(outname, 'w')
#for each line in 'infile' ...
for line in file.readlines():
#get a list of all the words in it ...
linewords = line.strip().split(" ")
# for each word in the file...
#--> fill in line here
#for each sublist in the dictionary...
# ---> fill in line here
# if that word appears in a sublist,
# replace it with one of the other word(s) in
# that sublist
# ---> fill in multiple lines here
# write the modified line out to the 'outfile'
outfile.write(line)
file.close()
outfile.close()
def main ( ):
confu(sys.argv[1], sys.argv[2], sys.argv[3])
if __name__ == '__main__':
main()
"
The first parameter is the 'dictionary' of word replacements. I've attached a handy list of English homophones (words that sound the same, but are spelled differently and have different meanings) as "confusion_source.txt". You can make your own for testing or only use a subset of the one I supplied while you're working in order to shorten the output or make things simpler, but make sure your code works with the file I attached.
The second parameter is the 'input' of words to be replaced. I've attached a basic input with a single line as "basic_infile.txt".
The third parameter is the 'output' where lines with all replaced words are sent to. Be sure to be careful when you give Python that filename. It will overwrite anything you give it without prompting. I recommend you test this in a new directory and back up your code before you test it.
You can run it on iLabs as: "python confu.py confusion_source.txt basic_infile.txt outfilename.txt"
If it is coded correctly, the content of your outfile should be:
"You no it's critical too some up all you're principle sites."
I'd recommend first commenting out the write to the outfile and then replacing lines as you go and printing them to see if you can get the information that is detailed in the comments to print out. As simple as 'unfoo' is, reading in a list of replacement words and replacing them should not be this clunky. The issue is that the words are text and not a simple list. The other issue is matching. Since any word in a sublist can match, there isn't just one way to run through them. There is also a hidden problem! See if you can figure it out!
Remember, it is supposed to simply replace words with other words, so capitalzation and punctuation should be preserved, as well as all spaces and line breaks.
Results:
Submit your modified "confu.py" on or before the due date.
If you can figure it out, submit a description of the 'hidden problem' as a text comment on the Canvas assignment and include a "problem_input.txt" infile with your submission that demonstrates the issue(s). Both the description and the file are required for extra points.
Attachments
No uploads for this question
Explanations and Answers
0
No answers posted
Post your Answer - free or at a fee
NB: Post a homework question for free and get answers - free or paid homework help.
Get answers to: Final Assignment Programming Class or similar questions only at Tutlance.
Related Questions
- Stat200 - Assignment #1: Descriptive Statistics Data Analysis Plan
- Gis Project - Identifying Farmlands In Allegheny County, Pittsburgh
- Can You Solve The Attached Coding Problem In Mpi With Fortran?
- R Code Assignment 4 Questions Please Finish On Time!!!!!!!!!!!
- Practice Inheritance, Virtual Functions And Base Class Pointers.
- Practice Inheritance, Virtual Functions And Base Class Pointers
- Use This File And Download: Company_Attrition.csv Open Up And Clean The File, Create A Jupyter Notebook
- Creating A Regression Model In R That Accurately Predicts Responding Variable 'Score'
- Lab 9&10 Programming Questions
- Creating Gradebook Nasm Virtual Machine
- C++ Assignment Including User-Defined Functions, Vectors/Arrays, And I/O
- Need Help With Three Basic C++ Questions
- Difference In Means Estimator On Average Treatment Effect
- Statistics Assignment: Difference In Means Estimand, Sutva, And Randomization Inference
- Assignment From Statistics Class
- Python 3: Building A Restaurant That Outsources Their Ice Cream Desserts To The Ice Cream Shoppe
- Arcgis Lab Help Please........
- Quiz On Python Object Oriented Programming
- Quiz On Python Object Oriented Programming
- Strategy Memo-Msf Access To Medicines Campaign
- I Need Help Adding A Rest Api Over Http Function To My Programs
- Creating A Deck Of Cards And A Menu For Doing Simple Actions With Those Cards.
- Embedded Systems Assignment Look At Attached File For Instructions.
- Project: Tic Tac Toe 2.0 In Java
- Write Python Code For Analyze People Migration Data Human Migration.
- Coding Assingment. 2 (Python/Sql)
- Performing A Regression Analysis With Time Series Data And Possible Autocorrelation
- Performing A Regression Analysis With Time Series Data And Possible Autocorrelation
- Python Program Homework. Implementation Of The M-Index Calculation
- Python Program Homework. Implementation Of The M-Index Calculation
- Ruby Terminal App - Simple Library App
- C++ Bowling App That Uses Arrays And Prints Scores
- Maths Questions Based Off Calculus And Matlab Coding
- I Need Someone To Convert My Song Lyric Website To A React Application
- I Need Someone To Convert My Song Lyric Website To A React Application
- Programs That Write Html, Write A Program That Writes A Web Page
- Image Processing With Matlab Programming
- C++ Final Project For A College Students
- Convolutions And Digital Holography In Matlab
- Convolutions And Digital Holography In Matlab
- Design Project For Aerospace Engineering...........
- I/O Cycle Coding Project On Website
- Matrix Algebra And Ols, And Simulations Of Key Properties Of The Mean
- C And Python Programming Combined With Math.
- Matlab Program To Calculate Jacobian Matrix And Simulate Resolved-Rate Control For The Planar 3R Robot
- Lab Number 4 Crime In Philadelphia
- Using Tableau, A Story Visualization And 2 Data Architecture Diagrams Need To Be Created For Cms(Healthcare Data)
- Using Tableau, A Story Visualization And 2 Data Architecture Diagrams Need To Be Created For Cms(Healthcare Data)
- A Simple Text-Based Narrative/Adventure Game.
- Project - Stress Concentration