示例#1
0
def get_names(data):
	names=[]
	for sent in nltk.sent_tokenize(doc):
	    for chunk in nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sent))):
	        if hasattr(chunk, 'node'):
	            if chunk.node=='PERSON':
	            	leaf=chunk.leaves()[0]
	            	name = ' '.join(c[0] for c in chunk.leaves())
	            	names.append(name)
	return names
示例#2
0
 def get_names(self, gender):
     if gender == "m":
         path = "male_names.txt"
         alternate_path = "tools/male_names.txt"
     else: 
         path = "female_names.txt"
         alternate_path = "tools/female_names.txt"
     names = []
     try:
         with open(path, "r") as f:
             for name in f:
                 names.append(name.strip().title())
     except FileNotFoundError:
         with open(alternate_path, "r") as f:
             for name in f:
                 names.append(name.strip().title())
     return names
示例#3
0
文件: asn4.py 项目: MeghanaR/Project4
nouns=[] 
for la in tagged: 
    if (la[1].lower() == 'nnp'): 
        nouns.append(la[0].lower()) 
 
name=raw_input("Enter name of freedom fighter") 
if name in mynames: 
    print "Associated:  1.Names 2.Locations" 
    ch=raw_input("Type 1 or 2") 
    ch=int(ch) 
    if ch==1: 
                names=[] 
                for noun in nouns: 
                        for name1 in mynames: 
                            if (noun == name): 
                                    names.append(noun)     
 
                names=list(set(names)) 
                names=names.remove(name) 
                print "The names of freedom fighters associated with "+name+" are:" 
                for i in names: 
                            print i 
    elif ch==2: 
                locations=[] 
                for noun in nouns: 
                        for loc in mylocations: 
                            if (noun == loc): 
                                    locations.append(noun)     
 
                locations=list(set(locations)) 
                print "The location associated with "+name+" are:"