jweinst1
9/18/2015 - 6:29 AM

functions that retrieve nouns in ruby.

functions that retrieve nouns in ruby.

#functions for noun identifying

def checkcontainer(elem, container)
    for thing in container
        if thing == elem
            return true
        end
    end
    return false
end
#checks if a word succeeds an article
def check_article(i, container)
    articles = ['the', 'an', 'a']
    if checkcontainer(container[i-1], articles)
        return true
    else
        return false
    end
end
#checks if a word preceeds a verb-like word
def check_verb(i, container)
    verbs = ['is', 'was', 'do', 'does', 'dont', 'are', 'were', 'did', 'has', 'had', 'have']
    if checkcontainer(container[i+1], verbs)
        return true
    else
        return false
    end
end

def get_nouns(phrase)
    phrase = phrase.chop
    phrase = phrase.split(" ")
    nouns = []
    n = 0
    until n == phrase.length do
        if check_article(n, phrase)
            nouns << phrase[n]
            n += 1
        elsif check_verb(n, phrase)
            nouns << phrase[n]
            n += 1
        else
            n += 1
        end
    end
    return nouns
end