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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:14:36+00:00 2026-06-17T20:14:36+00:00

I’m trying to develop a Python script to examine every sentence in Barack Obama’s

  • 0

I’m trying to develop a Python script to examine every sentence in Barack Obama’s second inaugural address and find similar sentences in past inaugurals. I’ve developed a very crude fuzzy match, and I’m hoping to improve it.

I start by reducing all inaugurals to lists of stopword-free sentences. I then build a frequency index.

Next, I compare each sentence in Obama’s 2013 address to each sentence of every other address, and evaluate the similarity like so:

#compare two lemmatized sentences. Assumes stop words already removed. frequencies is dict of frequencies across all inaugural    
def compare(sentA, sentB, frequencies):
    intersect = [x for x in sentA if x in sentB]
    N = [frequencies[x] for x in intersect]
    #calculate sum that weights uncommon words based on frequency inaugurals
    n = sum([10.0 / (x + 1) for x in N])
    #ratio of matches to total words in both sentences. (John Adams and William Harrison both favored loooooong sentences that tend to produce matches by sheer probability.)
    c = float(len(intersect)) / (len(sentA) + len(sentB))
    return (intersect, N, n, c)

Last, I filter out results based on arbitrary cutoffs for n and c.

It works better than one might think, identifying sentences that share uncommon words in a non-negligible proportion to total words.

For example, it picked up these matches:


Obama, 2013:
For history tells us that while these truths may be self-evident, they have never been self-executing; that while freedom is a gift from God, it must be secured by His people here on Earth.

Kennedy, 1961:
With a good conscience our only sure reward, with history the final judge of our deeds, let us go forth to lead the land we love, asking His blessing and His help, but knowing that here on earth God’s work must truly be our own.


Obama, 2013
Through blood drawn by lash and blood drawn by sword, we learned that no union founded on the principles of liberty and equality could survive half-slave and half-free.

Lincoln, 1861
Yet, if God wills that it continue until all the wealth piled by the bondsman’s two hundred and fifty years of unrequited toil shall be sunk, and until every drop of blood drawn with the lash shall be paid by another drawn with the sword, as was said three thousand years ago, so still it must be said “the judgments of the Lord are true and righteous altogether.


Obama, 2013
This generation of Americans has been tested by crises that steeled our resolve and proved our resilience

Kennedy, 1961
Since this country was founded, each generation of Americans has been summoned to give testimony to its national loyalty.


But it’s very crude.

I don’t have the chops for a major machine-learning project, but I do want to apply more theory if possible. I understand bigram searching, but I’m not sure that will work here — it’s not so much exact bigrams we’re interested in as general proximity of two words that are shared between quotes. Is there a fuzzy sentence comparison that looks at probability and distribution of words without being too rigid? The nature of allusion is that it’s very approximate.

Current effort available on Cloud9IDE

UPDATE, 1/24/13
Per the accepted answer, here’s a simple Python function for bigram windows:

def bigrams(tokens, blur=1):
    grams = []
    for c in range(len(tokens) - 1):
        for i in range(c + 1, min(c + blur + 1, len(tokens))):
            grams.append((tokens[c], tokens[i]))
    return grams
  • 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-06-17T20:14:37+00:00Added an answer on June 17, 2026 at 8:14 pm

    If you are inspired to use bigrams, you could build your bigrams while allowing gaps of one, two, or even three words so as to loosen up the definition of bigram a little bit. This could work since allowing n gaps means not even n times as many “bigrams”, and your corpus is pretty small. With this, for example, a “bigram” from your first paragraph could be (similar, inaugurals).

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

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary

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.