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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:40:54+00:00 2026-06-03T08:40:54+00:00

I’m trying to write a program that determines whether two words are cognates. I’ve

  • 0

I’m trying to write a program that determines whether two words are cognates. I’ve written two classes: featTup (basically a wrapper around a tuple containing the values of a letter), and featWord (basically a wrapper around of featTup objects.)

(Sorry this is all so long!)

Here’s some (hopefully relevant) code:

class featTup(object):
    def __init__(self,char):
        self.char = char
        self.phone_vals = None
        self.dia_vals = None
        if self.char in phone_codes:
            self.phone_vals = phone_feats[phone_codes.index(char)]
        elif self.char in dia_codes:
            self.dia_vals = dia_feats[dia_codes.index(char)]   
        ...


class featWord(list):
    def do_dia(self,char_feats,dia_feats):
        #This method handles the changes diacritics make to preceding phones
        for val in dia_feats:
            if dia_val:
                char_feats.change_val(tup,char_feats.index(dia_val),dia_val)

    def get_featWord(self):
        return self.word_as_feats

    def __init__(self,word):
        self.word = word
        self.word_as_feats = [featTup(char) for char in self.word]
        for char in self.word_as_feats:
            if char.is_dia():
                i = self.word_as_feats.char_index(char)
                self.word_as_feats.do_dia(self.word_as_feats[i-1],self.word_as_feats[i])

    def word_len(self):
        return len(self.get_featWord())

    def char_index(self,char):
        return self.word_as_feats.index(char)

The issue is that I want to take a list of words and make featWord objects for all of them. I don’t know how long each list will be, nor do I know how many characters will be in each word.
More code:

def get_words(text1,text2):
    import codecs
    textin1 = codecs.open(text1,encoding='utf8')
    word_list1 = textin1.readlines()
    textin1.close()
    textin2 = codecs.open(text2,encoding='utf8')
    word_list2 = textin2.readlines()
    textin2.close()
    print word_list1,word_list2
    fixed_words1 = []
    fixed_words2 = []
    for word in word_list1:
        fixed_word = word.replace('\n','')
        fixed_words1.append(fixed_word)
    for word in word_list2:
        fixed_word = word.replace('\n','')
        fixed_words2.append(fixed_word)
    print fixed_words1,fixed_words2
    words1 = [(featWord(word)) for word in fixed_words1]
    words2 = [(featWord(word)) for word in fixed_words2]
    # for word1 in fixed_words1:
        # for x in xrange(len(fixed_words1)):
        words1.append(featWord(word))
    for word2 in fixed_words2:
        #for x in xrange(len(fixed_words2)):
        words2.append(featWord(word))
    print words1
    #words1 = [featWord(word) for word in fixed_words1]
    #words2 = [featWord(word) for word in fixed_words2]
    return words1,words2

def get_cog_dict(text1,text2,threshold=10,print_results=True):
    #This is the final method, running are_cog over all words in
    #both lists.
    word_list1,word_list2 = get_words(text1,text2)
    print word_list1, word_list2

As it stands, when I call either of these last two methods, I get lists of empty lists; when I instantiate new featWord objects from strings I just give it (e.g. x = featWord(“ten”), or whatever) it works fine. A relevant thing is that featWord seems to return an empty list instead of (when I instantiate featWord from IDLE, as above, it comes back as a list of featTup instances, which is good). I’m not sure why/if that’s the problem.

It seems to me that (at least part of) my problem stems from improperly initializing the featWord. I’m constructing them, or whatever, but not assigning them names. I’ve tried just about everything I can think of (as the commented-out sections prove), and I’m stumped. There’re answers on here about using dictionaries to name class instances and such, but since I can’t pre-define a dictionary (each word and wordlist is potentially a different length), I’m not sure what to do.

Any help would be GREATLY appreciated. I’m kind of driving myself insane over here. Thanks.

  • 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-03T08:40:55+00:00Added an answer on June 3, 2026 at 8:40 am

    your featWord class derives from list, but you never append anything to self, and you have overridden __init__, so lists __init__ never gets called, too.

    So a featWord instance is just an empty list with some attributes and methods.

    Their __repr__ is list‘s __repr__, that’s why a list of featwords displays as a list of empty lists.

    So: implement a meaningful __repr__, do not subclass from list, append something meaninful to self. Any of that will solve your problem.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.