Question

#A common problem in academic settings is plagiarism #detection. Fortunately, software can make t...

#A common problem in academic settings is plagiarism
#detection. Fortunately, software can make this pretty easy!
#
#In this problem, you'll be given two files with text in
#them. Write a function called check_plagiarism with two
#parameters, each representing a filename. The function
#should find if there are any instances of 5 or more
#consecutive words appearing in both files. If there are,
#return the longest such string of words (in terms of number
#of words, not length of the string). If there are not,
#return the boolean False.
#
#For simplicity, the files will be lower-case text and spaces
#only: there will be no punctuation, upper-case text, or
#line breaks.
#
#We've given you three files to experiment with. file_1.txt
#and file_2.txt share a series of 5 words: we would expect
#check_plagiarism("file_1.txt", "file_2.txt") to return the
#string "if i go crazy then". file_1.txt and file_3.txt
#share two series of 5 words, and one series of 11 words:
#we would expect check_plagiarism("file_1.txt", "file_3.txt")
#to return the string "i left my body lying somewhere in the
#sands of time". file_2.txt and file_3.txt do not share any
#text, so we would expect check_plagiarism("file_2.txt",
#"file_3.txt") to return the boolean False.
#
#Be careful: there are a lot of ways to do this problem, but
#some would be massively time- or memory-intensive. If you
#get a MemoryError, it means that your solution requires
#storing too much in memory for the code to ever run to
#completion. If you get a message that says "KILLED", it
#means your solution takes too long to run.


#Add your code here!


#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print:
#if i go crazy then
#i left my body lying somewhere in the sands of time
#False
print(check_plagiarism("file_1.txt", "file_2.txt"))
print(check_plagiarism("file_1.txt", "file_3.txt"))
print(check_plagiarism("file_2.txt", "file_3.txt"))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def check_plagiarism(file1, file2):
    d1 = {}
    f1 = open(file1, "r")

    for line in f1:
        words = line.split()
        for i in range(0, len(words) - 5):
            if words[i] not in d1:
                d1[words[i]] = []
            d1[words[i]].append(words[i+1:i+5])
    f1.close()
    myList = []
    f2 = open(file2, "r")
    for line in f2:
        words = line.split()
        for i in range(0, len(words) - 5):
            if words[i] in d1:
                if words[i+1:i+5] in d1[words[i]]:
                    j = i + 5
                    k = i + 1
                    # print(words[k:j+1],d1[words[k]])
                    while(words[k+1:j+1] in d1[words[k]]):
                        k+=1
                        j+=1
                        if (j == len(words)):
                            break
                    if(len(words[i:j]) > len(myList)):
                        myList = words[i:j]
  
    f2.close()
    if len(myList) == 0:
        return False
    else:
        return " ".join(myList)

#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print:
#if i go crazy then
#i left my body lying somewhere in the sands of time
#False
print(check_plagiarism("file_1.txt", "file_2.txt"))
print(check_plagiarism("file_1.txt", "file_3.txt"))
print(check_plagiarism("file_2.txt", "file_3.txt"))

Add a comment
Know the answer?
Add Answer to:
#A common problem in academic settings is plagiarism #detection. Fortunately, software can make t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy!...

    #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy! # #In this problem, you'll be given two files with text in #them. Write a function called check_plagiarism with two #parameters, each representing a filename. The function #should find if there are any instances of 5 or more #consecutive words appearing in both files. If there are, #return the longest such string of words (in terms of number #of words, not length of the...

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • JAVA Primitive Editor (Please help, I am stuck on this assignment which is worth a lot...

    JAVA Primitive Editor (Please help, I am stuck on this assignment which is worth a lot of points. Make sure that the program works because I had someone answer this incorrectly!) The primary goal of the assignment is to develop a Java based primitive editor. We all know what an editor of a text file is. Notepad, Wordpad, TextWrangler, Pages, and Word are all text editors, where you can type text, correct the text in various places by moving the...

  • Hey everyone, I need help making a function with this directions with C++ Language. Can you...

    Hey everyone, I need help making a function with this directions with C++ Language. Can you guys use code like printf and fscanf without iostream or fstream because i havent study that yet. Thanks. Directions: Write a function declaration and definition for the char* function allocCat. This function should take in as a parameter a const Words pointer (Words is a defined struct) The function should allocate exactly enough memory for the concatenation of all of the strings in the...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...

  • C++ programming help. The only change you have to make is in current program, where it...

    C++ programming help. The only change you have to make is in current program, where it says "your code goes here", do not make any changes to any other files, they are just there to show you. This code should be written for arbitrary data, not specifically for this sequence of data. The only place you need to write a code is marked YOUR CODE GOES HERE. You have been supplied a file with data in it (data2.txt). The line...

  • JAVA Primitive Editor The primary goal of the assignment is to develop a Java based primitive...

    JAVA Primitive Editor The primary goal of the assignment is to develop a Java based primitive editor. We all know what an editor of a text file is. Notepad, Wordpad, TextWrangler, Pages, and Word are all text editors, where you can type text, correct the text in various places by moving the cursor to the right place and making changes. The biggest advantage with these editors is that you can see the text and visually see the edits you are...

  • PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test...

    PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test case for the below prompt using the provided java programs Use the setString() function in MyCustomStringInterface to set the value to “Peter Piper picked a peck of pickled peppers.”. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srep.”)....

  • The code: def isPalindrome(text): """ >>> isPalindrome("alula") True...

    The code: def isPalindrome(text): """ >>> isPalindrome("alula") True >>> isPalindrome("love") False >>> isPalindrome("Madam") True >>> isPalindrome(12.5) False >>> isPalindrome(12.21) False >>> isPalindrome("Cigar? Toss it in a can.! It is so tragic.") True >>> isPalindrome("travel.. a town in Alaska") False """ # --- YOU CODE STARTS HERE if type(text) is not str: return False l = len(text) - 1 i = 0 while i < l: if text[i] in string.punctuation or text[i] == ' ': i += 1 elif text[l] in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT