def determine_relation(syn1, syn2):
    
    relation = ''
    
    #both are registered
    if len(syn1) > 0 and len(syn2) > 0:
        #verifiable results 
        
        print 'Common Ancestor: {0}'.format(wordnet.ancestor(syn1[0], syn2[0]))
        print 'Similarity measure between synsets: {0}'.format(wordnet.similarity(syn1[0], syn2[0]))
        
        
        if is_descendant(syn1, syn2):
            relation = "is a verifiable fact"
        elif is_descendant(syn1, syn2, True):
            relation = "is a verifiable true over-generalization"
        elif is_descendant(syn2, syn1):
            relation = "is a verifiable falsehood"
        elif is_descendant(syn2, syn1, True):
            relation = "is a verifiable false over-generalization"
        else:
            relation = "figurative speech (two entries, with no roots)"
        
    else:
        relation = "undetermined, entries not in wordnet" 
    
    return relation
예제 #2
0
파일: word_senses.py 프로젝트: rsteckel/EDA
def wordnet_potential_parent(word1, pos1, word2, pos2, min_sim=0.0):
    syns1 = wn.synsets(word1, pos1)
    syns2 = wn.synsets(word2, pos2)

    parents = []
    for s1 in syns1:
        for s2 in syns2:
            family = wn.ancestor(s1,s2)
            if family:
                sim = wn.similarity(s1,s2)
                if sim > min_sim:
                    parents.append( (family, sim) )
    return parents
예제 #3
0
def all_possible_related(words, pos=None, depth=1):
    all_syns = [y for word in words for y in all_synsets(word, pos=pos)]
    # all_syns = [all_synsets(x, pos=pos) for x in words]
    # all_syns = [x[0] for x in all_syns if x]
    # return all_syns
    # print(all_syns)
    all_ancestors = [wordnet.ancestor(s1, s2) for s1, s2 in itertools.combinations(all_syns, 2)]
    all_ancestors = [x for x in all_ancestors if x]
    # print(all_ancestors)
    mapz = {x.lexname: x for x in all_ancestors}
    all_ancestors = list(mapz.values())
    all_descendents = [y for x in all_ancestors for y in x.hyponyms(recursive=True, depth=depth)]
    ret = [y for x in all_descendents for y in x.senses]
    return clean_senses(ret)
예제 #4
0
# For a given word, WordNet yields a list of synsets that
# represent different "senses" in which the word can be understood.
for synset in wordnet.synsets("train", pos=NOUN):
    print "Description:", synset.gloss      # Definition string.
    print "   Synonyms:", synset.senses     # List of synonyms in this sense.
    print "   Hypernym:", synset.hypernym   # Synset one step higher in the semantic network.
    print "   Hyponyms:", synset.hyponyms() # List of synsets that are more specific.
    print "   Holonyms:", synset.holonyms() # List of synsets of which this synset is part/member.
    print "   Meronyms:", synset.meronyms() # List of synsets that are part/member of this synset.
    print 

# What is the common ancestor (hypernym) of "cat" and "dog"?
a = wordnet.synsets("cat")[0]
b = wordnet.synsets("dog")[0]
print "Common ancestor:", wordnet.ancestor(a, b)
print

# Synset.hypernyms(recursive=True) returns all parents of the synset,
# Synset.hyponyms(recursive=True) returns all children,
# optionally up to a given depth.
# What kind of animal nouns are also verbs?
synset = wordnet.synsets("animal")[0]
for s in synset.hyponyms(recursive=True, depth=2):
    for word in s.senses:
        if word in wordnet.VERBS:
            print word, "=>", wordnet.synsets(word, pos=VERB)

# Synset.similarity() returns an estimate of the semantic similarity to another synset,
# based on Lin's semantic distance measure and Resnik Information Content.
# Lower values indicate higher similarity.
예제 #5
0
for synset in wordnet.synsets("train", pos=NOUN):
    print "Description:", synset.gloss  # Definition string.
    print "   Synonyms:", synset.senses  # List of synonyms in this sense.
    print "   Hypernym:", synset.hypernym  # Synset one step higher in the semantic network.
    print "   Hyponyms:", synset.hyponyms(
    )  # List of synsets that are more specific.
    print "   Holonyms:", synset.holonyms(
    )  # List of synsets of which this synset is part/member.
    print "   Meronyms:", synset.meronyms(
    )  # List of synsets that are part/member of this synset.
    print

# What is the common ancestor (hypernym) of "cat" and "dog"?
a = wordnet.synsets("cat")[0]
b = wordnet.synsets("dog")[0]
print "Common ancestor:", wordnet.ancestor(a, b)
print

# Synset.hypernyms(recursive=True) returns all parents of the synset,
# Synset.hyponyms(recursive=True) returns all children,
# optionally up to a given depth.
# What kind of animal nouns are also verbs?
synset = wordnet.synsets("animal")[0]
for s in synset.hyponyms(recursive=True, depth=2):
    for word in s.senses:
        if word in wordnet.VERBS:
            print word, "=>", wordnet.synsets(word, pos=VERB)

# Synset.similarity() returns an estimate of the semantic similarity to another synset,
# based on Lin's semantic distance measure and Resnik Information Content.
# Lower values indicate higher similarity.
예제 #6
0
    print("Description: %s" % synset.gloss)  # Definition string.
    print("   Synonyms: %s" % synset.senses)  # List of synonyms in this sense.
    print("   Hypernym: %s" %
          synset.hypernym)  # Synset one step higher in the semantic network.
    print("   Hyponyms: %s" %
          synset.hyponyms())  # List of synsets that are more specific.
    print("   Holonyms: %s" % synset.holonyms()
          )  # List of synsets of which this synset is part/member.
    print("   Meronyms: %s" % synset.meronyms()
          )  # List of synsets that are part/member of this synset.
    print("")

# What is the common ancestor (hypernym) of "cat" and "dog"?
a = wordnet.synsets("cat")[0]
b = wordnet.synsets("dog")[0]
print("Common ancestor: %s" % wordnet.ancestor(a, b))
print("")

# Synset.hypernyms(recursive=True) returns all parents of the synset,
# Synset.hyponyms(recursive=True) returns all children,
# optionally up to a given depth.
# What kind of animal nouns are also verbs?
synset = wordnet.synsets("animal")[0]
for s in synset.hyponyms(recursive=True, depth=2):
    for word in s.senses:
        if word in wordnet.VERBS:
            print("%s => %s" % (word, wordnet.synsets(word, pos=VERB)))

# Synset.similarity() returns an estimate of the semantic similarity to another synset,
# based on Lin's semantic distance measure and Resnik Information Content.
# Lower values indicate higher similarity.
예제 #7
0
파일: 06-wordnet.py 프로젝트: clips/pattern
# For a given word, WordNet yields a list of synsets that
# represent different "senses" in which the word can be understood.
for synset in wordnet.synsets("train", pos=NOUN):
    print("Description: %s" % synset.gloss)       # Definition string.
    print("   Synonyms: %s" % synset.senses)      # List of synonyms in this sense.
    print("   Hypernym: %s" % synset.hypernym)    # Synset one step higher in the semantic network.
    print("   Hyponyms: %s" % synset.hyponyms())  # List of synsets that are more specific.
    print("   Holonyms: %s" % synset.holonyms())  # List of synsets of which this synset is part/member.
    print("   Meronyms: %s" % synset.meronyms())  # List of synsets that are part/member of this synset.
    print("")

# What is the common ancestor (hypernym) of "cat" and "dog"?
a = wordnet.synsets("cat")[0]
b = wordnet.synsets("dog")[0]
print("Common ancestor: %s" % wordnet.ancestor(a, b))
print("")

# Synset.hypernyms(recursive=True) returns all parents of the synset,
# Synset.hyponyms(recursive=True) returns all children,
# optionally up to a given depth.
# What kind of animal nouns are also verbs?
synset = wordnet.synsets("animal")[0]
for s in synset.hyponyms(recursive=True, depth=2):
    for word in s.senses:
        if word in wordnet.VERBS():
            print("%s => %s" % (word, wordnet.synsets(word, pos=VERB)))

# Synset.similarity() returns an estimate of the semantic similarity to another synset,
# based on Lin's semantic distance measure and Resnik Information Content.
# Lower values indicate higher similarity.
예제 #8
0
    df['sentence-pos'] = df['sentence'].apply(lambda x: parse(x, chunks=False).replace('/', ''))
    X = vectorizer.fit_transform(df['sentence-pos'])

    selector = SelectKBest(chi2, k=100)

    S = selector.fit_transform(X, df['bps'].tolist())

    fnames = vectorizer.get_feature_names()
    
    indices = selector.get_support(True)                 
    selected_terms = [ fnames[i] for i in indices ]

    return selected_terms





a = wordnet.synsets('tone', pos=wordnet.ADJECTIVE)[0]
b = wordnet.synsets('curly', pos=wordnet.ADJECTIVE)[0]
c = wordnet.synsets('box')[0]
 
print wordnet.ancestor(a, b)
 
print wordnet.similarity(a, a) 
print wordnet.similarity(a, b)
print wordnet.similarity(a, c)  


예제 #9
0
print modality(s)
# wordnet
s = wordnet.synsets('bird')[0]
print 'Definition:', s.gloss  # Definition string.
print '  Synonyms:', s.synonyms  # List of word forms (i.e., synonyms)
print ' Hypernyms:', s.hypernyms(
)  # returns a list of  parent synsets (i.e., more general). Synset (semantic parent).
print ' Hypernyms:', s.hypernyms(recursive=False, depth=None)
print '  Hyponyms:', s.hyponyms(
)  # returns a list child synsets (i.e., more specific).
print '  Hyponyms:', s.hyponyms(recursive=False, depth=None)
print '  Holonyms:', s.holonyms(
)  # List of synsets (of which this is a member).
print '  Meronyms:', s.meronyms()  # List of synsets (members/parts).
print '       POS:', s.pos  # Part-of-speech: NOUN | VERB | ADJECTIVE | ADVERB.
print '  Category:', s.lexname  # Category string, or None.
print 'Info Cont.:', s.ic  # Information Content (float).
print '   Antonym:', s.antonym  # Synset (semantic opposite).
print '   Synsets:', s.similar()  # List of synsets (similar adjectives/verbs).
# sense similarity
a = wordnet.synsets('cat')[0]
b = wordnet.synsets('dog')[0]
c = wordnet.synsets('box')[0]
print wordnet.ancestor(a, b)
print wordnet.similarity(a, a)
print wordnet.similarity(a, b)
print wordnet.similarity(a, c)
# synset sentiment
print wordnet.synsets('happy', ADJECTIVE)[0].weight
print wordnet.synsets('sad', ADJECTIVE)[0].weight