Example #1
0
def correctDictionary():
    fd = open('wordlist', 'rb')
    obj = pickle.load(fd)
    fd.close()
    newdic = {}
    for i in obj.keys():
        meaning = obj[i]
        newmeaning = []
        #LOL
        newarr = meaning.split(';')
        for k in newarr:
            if (k.find('\n') >= 0):
                arr = k.split('\n')
                temp = ''
                for j in arr:
                    temp += strip(j) + ' '
                if (temp[-1] == ' '):
                    temp = temp[:-1]
                if (temp[0] == ' '):
                    temp = temp[1:]
                newmeaning.append(temp)
            else:
                newmeaning.append(strip(k))
        newdic[strip(i)] = newmeaning
    print newdic
    fd = open('dictionary', 'wb')
    pickle.dump(newdic, fd)
    fd.close()
Example #2
0
def correctDictionary():
	fd=open('wordlist','rb')
	obj=pickle.load(fd)
	fd.close()
	newdic={}
	for i in obj.keys():
		meaning=obj[i]
		newmeaning=[]
		#LOL
		newarr=meaning.split(';')
		for k in newarr:
			if(k.find('\n')>=0):
				arr=k.split('\n')
				temp=''
				for j in arr:
					temp+=strip(j)+' '
				if(temp[-1]==' '):
					temp=temp[:-1]
				if(temp[0]==' '):
					temp=temp[1:]
				newmeaning.append(temp)
			else:
				newmeaning.append(strip(k))
		newdic[strip(i)]=newmeaning
	print newdic	
	fd=open('dictionary','wb')
	pickle.dump(newdic,fd)
	fd.close()
Example #3
0
def selectDirect(sentence):
	if(sentence.find('.')>=0):
		arr=sentence.split('.')
		newstring=' '.join(arr[1:])
		if(newstring.find(':')>=0):
			word=newstring.split(':')[0]
			return strip(word)
	return False
Example #4
0
def main(word,dic):
	print word,dic[word]
	example=[]
	meaning=[]
	opposite=[]
	related={}
	for j in dic[word]:
		init=findSpecial(j)
		if(init=='Ex' or init=='EX'):
			example.append(j)		
			continue
		if(init=='OP' or init=='Op' or init=='op'):
			opposite.append(j)
			continue
		if(init and strip(j)==init+'.'):
			if(not related.has_key(init)):
				related[init]=[]
			if(word not in related[init]):
				related[init].append(word)
			continue
		if(init or findSpecial2(j,' ') or findSpecial2(j,':')):	
			newword=findWord(j,word)
			if(init):
				j=' '.join(j.split('.')[1:])
			else:
				init=findSpecial2(j,' ')
				if(init):
					j=' '.join(j.split(' ')[1:])
				else:
					init=(findSpecial2(j,':'))
					if(init):
						j=' '.join(j.split(':')[1:])
			j=strip(j)
			if(newword):
				exp=	' '.join(j.split(newword))
				exp=strip(exp)
				if(not exp==''):
					meaning.append(strip(exp))
				if(not related.has_key(init)):
					related[init]=[]
				if(newword not in related[init]):
					related[init].append(newword)
				continue
		if(not (init=='CF' or init=='Cf')):
			meaning.append(j)
	return [meaning,example,related,opposite]
Example #5
0
	def getSynonymnFromMeaning(self,dic,word):
		arr=[]
		if(dic[word][1]==None): return arr
		for i in dic[word][1]:
			i=strip(i)
			if(i==None):
				print dic[word][1]," missing"
				continue
			if(i.find(' ')>=0 or i.find(')')>=0 or i=='Ex.' or i=='' or i=='V.' or i=='ADJ.' or i=='N.'):
				continue
			arr.append(i)	
		return arr
Example #6
0
def findWord(sentence,word):
	arr=sentence.split(' ')
	wlen=len(word)
	for i in arr:
		i=strip(i)
		count=0
		ilen=len(i)
		mlen=min(wlen,ilen)
		while count<3 and mlen-count>0 :
			if(word[:mlen-count]==i[:mlen-count]):
				return i
			count+=1
	return False
Example #7
0
 def getSynonymnFromMeaning(self, dic, word):
     arr = []
     if (dic[word][1] == None): return arr
     for i in dic[word][1]:
         i = strip(i)
         if (i == None):
             print dic[word][1], " missing"
             continue
         if (i.find(' ') >= 0 or i.find(')') >= 0 or i == 'Ex.' or i == ''
                 or i == 'V.' or i == 'ADJ.' or i == 'N.'):
             continue
         arr.append(i)
     return arr
Example #8
0
def selectIndirect(word,sentence):
	if(sentence.find('.')>=0):
		arr=sentence.split('.')
		newstring=' '.join(arr[1:])
		if(newstring.find(':')<0 and newstring.find(' ')>=0):
			newarr=newstring.split(' ')
			rest=' '
			newword=strip(newarr[0])
			if(len(newarr)>1):
				rest=' '.join(newarr[1:])
			print word
			ilen=len(word)
			jlen=len(newword)
			mylen=min(ilen,jlen)
			cnt=0
			while(cnt<3 and mylen-cnt>=0):
				if(word[:mylen-cnt]==newword[:mylen-cnt]):
					return newword,rest
				cnt+=1
	return False
Example #9
0
			ilen=len(word)
			jlen=len(newword)
			mylen=min(ilen,jlen)
			cnt=0
			while(cnt<3 and mylen-cnt>=0):
				if(word[:mylen-cnt]==newword[:mylen-cnt]):
					return newword,rest
				cnt+=1
	return False
oppcount=0	
relcount=0
fd=open('dictionary','rb')
dic=pickle.load(fd)
newdic={}
for i in dic.keys():
	i=strip(i)
	newdic[i]={}
	meaning=[]
	example=[]
	related=[]
	otherword={}
	opposite=[]
	part=[]
	for j in dic[i]:
		spl=specialForm(j)
		if(not spl):
			meaning.append(j)
		elif(spl=='Ex'):
			example.append(' '.join(j.split('.')[1:]))
		elif(spl in ['V','N','v','ADJ','ADV']):
			if(spl=='v'): spl='V'
Example #10
0
            mylen = min(ilen, jlen)
            cnt = 0
            while (cnt < 3 and mylen - cnt >= 0):
                if (word[:mylen - cnt] == newword[:mylen - cnt]):
                    return newword, rest
                cnt += 1
    return False


oppcount = 0
relcount = 0
fd = open('dictionary', 'rb')
dic = pickle.load(fd)
newdic = {}
for i in dic.keys():
    i = strip(i)
    newdic[i] = {}
    meaning = []
    example = []
    related = []
    otherword = {}
    opposite = []
    part = []
    for j in dic[i]:
        spl = specialForm(j)
        if (not spl):
            meaning.append(j)
        elif (spl == 'Ex'):
            example.append(' '.join(j.split('.')[1:]))
        elif (spl in ['V', 'N', 'v', 'ADJ', 'ADV']):
            if (spl == 'v'): spl = 'V'
Example #11
0
def processWord(word):
	arr=word.split('\n')
	value=' '.join(arr)
	return strip(value)
Example #12
0
def correction():
	oppcount=0	
	relcount=0
	fd=open('dictionary','rb')
	dic=pickle.load(fd)
	newdic={}
	for i in dic.keys():
		i=strip(i)
		newdic[i]=[[],[],[],[]]
		meaning=[]
		example=[]
		related={}
		opposite=[]
		for j in dic[i]:
			spl=specialForm(j)
			if(not spl):
				meaning.append(j)
				continue
			if(spl=='CF'):
				continue
			if(spl=='v'): spl='V'
			if(spl=='Ex'):
				example.append (' '.join(j.split('.')[1:]))
				continue
			elif(spl=='OP'):
				val=(' '.join(j.split('.')[1:]))
				if(val not in opposite):
					opposite.append(val)
			if(not related.has_key(spl)):
				related[spl]=[]
			elif(spl in ['V','N','v','ADJ','ADV']):
				if(j.find(' ')>=0):
					sparr=j.split(' ')
					if(len(sparr)==2):
						related[spl].append(sparr[1])
						continue
				word=selectDirect(j)
				print word
				if(word):
					exp=j.split(':')[1]
					if(word not in related[spl]):
						related[spl]=[]
					related[spl].append(word)
					meaning.append(exp)
				else:
					word=selectIndirect(i,j)
					print word
					if(word):
						word,exp=word[0],word[1]
						word=strip(word)
						if(word not in related[spl]):
							related[spl].append(word)
						meaning.append(exp)
					else:
						related[spl].append(i)
			else:
				val=(' '.join(j.split('.')[1:]))
				if(val not in related[spl]):
					related[spl].append(val)
		newdic[i][0]=meaning
		newdic[i][1]=example
		newdic[i][2]=related
		newdic[i][3]=opposite
		#print i,newdic[i]
		print oppcount
	print newdic
	for i in newdic.keys():
		for j in  newdic[i][2].keys():
		if(newdic[i][2][j]==[]):
			print i,j
	print newdic['eclectic']
Example #13
0
	newstruct['Ex']=[]
	others={}
	for j in meaning:
		if(j.find('.')>=0):
			pre=j.split('.')[0]
			if(pre.find(' ')<0):
				if(pre=='Ex'):
					newstruct['Ex'].append(j)
				elif(pre in ['N','V','ADJ','ADV','v','n']):,'PL','SG']):
					suf=j.split('.')
					if(len(suf)==1):
						appendent=i
					elif(j.split(' ')==2):
						appendent=j.split(' ')[1]
					else:
						if(suf[1].find(':')>=0):
							appendent=strip(suf[1].split(':')[0])
							j=' '.join(suf[1].split(':')[1:])
					if(others.has_key(pre)):
						if(len(suf)==1):
							others[pre].append(i)
						others[pre].append(j)
					else:
						if(len(suf)==1):
							others[pre].append(i)
						others[pre]=[j]
				else:
					newstruct['meaning'].append(j)