Пример #1
0
def simplify_word(a):

    # print "[{0}],正在分析词汇: {1}".format(time.ctime().split()[3], a),

    try:#测试是否为动词,如果是则返回
        try_present_verb = en.verb.present(a)#try
        if en.is_verb(try_present_verb):
            # if try_present_verb != a:
            #     print " 动词现在时化:{0} -> {1}".format(a,try_present_verb)
            # else:
            #     print ""
            return try_present_verb
    except:#否则继续检查
        pass

    #测试是否是名词
    try_singular_noun = en.noun.singular(a)
    if en.is_noun(try_singular_noun):
        # if try_singular_noun != a:
        #     print " 名词单数化:{0} -> {1}".format(a,try_singular_noun)
        # else:
        #     print ""
        return try_singular_noun

    #如果已经可以判断是名词,动词,形容词,副词,连词
    if en.is_noun(a) or en.is_verb(a) or en.is_adjective(a) or en.is_adverb(a) or en.is_connective(a):
        # print ""
        return a

    return ''
Пример #2
0
def simplify_word(a):

    # print "[{0}],正在分析词汇: {1}".format(time.ctime().split()[3], a),

    try:  #测试是否为动词,如果是则返回
        try_present_verb = en.verb.present(a)  #try
        if en.is_verb(try_present_verb):
            # if try_present_verb != a:
            #     print " 动词现在时化:{0} -> {1}".format(a,try_present_verb)
            # else:
            #     print ""
            return try_present_verb
    except:  #否则继续检查
        pass

    #测试是否是名词
    try_singular_noun = en.noun.singular(a)
    if en.is_noun(try_singular_noun):
        # if try_singular_noun != a:
        #     print " 名词单数化:{0} -> {1}".format(a,try_singular_noun)
        # else:
        #     print ""
        return try_singular_noun

    #如果已经可以判断是名词,动词,形容词,副词,连词
    if en.is_noun(a) or en.is_verb(a) or en.is_adjective(a) or en.is_adverb(
            a) or en.is_connective(a):
        # print ""
        return a

    return ''
Пример #3
0
    def singular_to_plural(self):

        final_list = []
        st = self.get_sentence()

        list_seperate_by_comma = st.split(",")  # divide the sentence to list of strings by all the ','
        for each in list_seperate_by_comma:

            if each[0] == " ":  # prevent bug
                each = each[1:]
            m = each.split(" ")  # split each sentence to list of words

            plural_list = []

            for each in m:
                if en.is_noun(each):
                    each = en.noun.plural(each)
                elif en.is_adjective(each):
                    each = en.adjective.plural(each)
                elif en.is_connective(each):
                    each = self.my_inflect.plural(each)
                elif en.is_persuasive(each):
                    each = en.persuasive.plural(each)
                plural_list.append(each)

            plural_list = " ".join(plural_list)  # convert each list to string
            final_list.append(plural_list)

        final_list = ", ".join(final_list)
        return final_list
Пример #4
0
    def find_grammatical_kind(self):

        st = self.get_sentence()
        st = re.sub(",", "", st)  # delete all commas
        result = []

        m = st.split(" ")

        for each in m:
            flag = False
            if en.noun.is_emotion(each):
                result.append("emotion")
                flag = True
            elif en.is_connective(each):
                result.append("connective")
                flag = True
            elif en.is_verb(each):
                result.append("verb")
                flag = True
            elif en.is_adjective(each):
                result.append("adjective")
                flag = True
            elif en.is_noun(each):
                result.append("noun")
                flag = True
            elif en.is_persuasive(each):
                result.append("persuasive")
                flag = True
            elif en.is_number(each):
                result.append("number")
                flag = True
            if flag == False:
                result.append("unclear")

        return result
Пример #5
0
def simplify_word(a):
    #如果已经可以判断是名词,动词,形容词,副词,连词
    if en.is_noun(a) or en.is_verb(a) or en.is_adjective(a) or en.is_adverb(a) or en.is_connective(a):
        return a
    try:#测试是否为动词,如果是则返回
        en.is_verb(en.verb.present(a))
        return en.verb.present(a)
    except:#否则继续检查
        pass
    
    #测试是否是名词
    if en.is_noun(en.noun.singular(a)):
        return en.noun.singular(a)
    otherwordlist.append(a)
    #print a
    return a
Пример #6
0
def simplify_word(a):
    
    try:#测试是否为动词,如果是则返回
        en.is_verb(en.verb.present(a))
        return en.verb.present(a)
    except:#否则继续检查
        pass
    
    #测试是否是名词
    if en.is_noun(en.noun.singular(a)):
        return en.noun.singular(a)
    
    #如果已经可以判断是名词,动词,形容词,副词,连词
    if en.is_noun(a) or en.is_verb(a) or en.is_adjective(a) or en.is_adverb(a) or en.is_connective(a):
        return a
        
    
    
    
    otherwordlist.append(a)
    return a
Пример #7
0
print(5, en.is_html_tag("</person>"))

# COMMONSENSE #######################################################################

# Returns True if the given word expresses a basic emotion:
# anger, disgust, fear, joy, sadness, surprise.
print(6, en.is_basic_emotion("cheerful"))

# Returns True if the given word is a magic word:
# you, money, save, new, results, health, easy, ...
print(7, en.is_persuasive("money"))

# Returns True if the word is a connective:
# nevertheless, whatever, secondly, ...
# and words like I, the, own, him which have little semantical value.
print(8, en.is_connective("but"))

# NUMBERS ###########################################################################

# Returns the ordinal of the given number,
# 100 -> 100th, 3 -> 3rd
# twenty-one -> twenty-first
print(9, en.number.ordinal(100))
print(10, en.number.ordinal("twenty-one"))

# Writes out the given number:
# 25 -> twenty-five
print(11, en.number.spoken(25))

# QUANTIFICATION ####################################################################
    def __init__(self, w, isTop): #maybe add time of post, what subreddit it came from?
        self.words = w
        self.verbCount = 0;
        self.nounCount = 0;
        self.adjCount = 0;
        self.connectiveCount = 0;
        self.other = 0

        global topVerb
        global topVerb
        global topNoun
        global topAdj
        global topCon
        global topOther
        global topCount

        global botVerb
        global botNoun
        global botAdj
        global botCon
        global botOther
        global botCount

        self.count = 0
        for word in self.words:
            self.count += 1
            fixedWord = unicode(word).lower()
            if en.is_verb(fixedWord):
                if(isTop):
                    topVerb += 1
                else:
                    botVerb += 1

                self.verbCount += 1
            elif en.is_noun(fixedWord):
                if(isTop):
                    topNoun += 1
                else:
                    botNoun += 1

                self.nounCount += 1
            elif en.is_adjective(fixedWord):
                if(isTop):
                    topAdj += 1
                else:
                    botAdj += 1

                self.adjCount += 1
            elif en.is_connective(fixedWord):
                if(isTop):
                    topCon += 1
                else:
                    botCon += 1

                self.connectiveCount += 1
            else:
                if(isTop):
                    topOther += 1
                else:
                    botOther += 1

                self.other += 1
        if isTop:
            topCount += self.count
        else:
            botCount += self.count