# ****************************************************
# Name des Moduls: mod_wordnet
# Name des Projekts: TaxoSearch
#
# Autor(en):
#        Thorsten Beinhorn, Vesna Cvoro,
#        Khaled Dhaoui und Christian Pretzsch 
#
# Aufgaben des Moduls: siehe Code Dokumentation TaxoSearch
# 
#
# Datum der letzten Aenderung: 26.11.2003
# ****************************************************




from wntools import *


class Word:
	def __init__(self):
		self.form=""
		self.gloss=""
		self.lstSynonyms=[]
		self.lstHypernyms=[]
		self.lstHyponyms=[]

class Wordnet:
	def __init__(self):
		self.lstNouns=[]
		self.lstVerbs=[]
		self.lstAdjectives=[]
		
	def GetCurrentWord(self, intCurPos, strEntryContent):
		strCurWord=''
		intSpaceFoundBegin=strEntryContent.rfind(" ", 0, intCurPos)
		intSpaceFoundEnd=strEntryContent.find(" ", intCurPos, len(strEntryContent))
		if intSpaceFoundBegin>0:
			if intSpaceFoundEnd>0:
				strCurWord=strEntryContent[intSpaceFoundBegin+1:intSpaceFoundEnd]
			else:
				strCurWord=strEntryContent[intSpaceFoundBegin+1:len(strEntryContent)]
		else:
			if intSpaceFoundEnd>0:
				strCurWord=strEntryContent[0:intSpaceFoundEnd]
			else:
				strCurWord=strEntryContent[0:intCurPos]
		return strCurWord
		
	def CreateObjects(self, strWord):
		self.lstNouns=[]
		self.lstVerbs=[]
		self.lstAdjectives=[]
		strMorphy=''
				
		#check if word is a noun
		strMorphy=morphy(strWord,'noun')
		if strMorphy:
			for SenseCounter in range(len(N[strMorphy].senses())):
				tmpNoun=Word()
				tmpNoun.form=strMorphy
				tmpNoun.gloss = N[strMorphy][SenseCounter].synset.gloss
				tmpNoun.inWordnet=0
				
				for Synonym in N[strMorphy][SenseCounter].synset:
					tmpNoun.lstSynonyms.append(Synonym.form)
					
				for HypernymSynset in N[strMorphy][SenseCounter].getPointerTargets(HYPERNYM):
					for Hypernym in HypernymSynset:
						tmpNoun.lstHypernyms.append(Hypernym.form)
					
				for HyponymSynset in N[strMorphy][SenseCounter].getPointerTargets(HYPONYM):
					for Hyponym in HyponymSynset:
						tmpNoun.lstHyponyms.append(Hyponym.form)
					
				self.lstNouns.append(tmpNoun)
			
		#check if word is a verb
		strMorphy=morphy(strWord,'verb')
		if strMorphy:
			for SenseCounter in range(len(V[strMorphy].senses())):
				tmpVerb=Word()
				tmpVerb.form=strMorphy
				tmpVerb.gloss = V[strMorphy][SenseCounter].synset.gloss
				tmpVerb.inWordnet=1
				
				for Synonym in V[strMorphy][SenseCounter].synset:
					tmpVerb.lstSynonyms.append(Synonym.form)
					
				for HypernymSynset in V[strMorphy][SenseCounter].getPointerTargets(HYPERNYM):
					for Hypernym in HypernymSynset:
						tmpVerb.lstHypernyms.append(Hypernym.form)
					
				for HyponymSynset in V[strMorphy][SenseCounter].getPointerTargets(HYPONYM):
					for Hyponym in HyponymSynset:
						tmpVerb.lstHyponyms.append(Hyponym.form)
					
				self.lstVerbs.append(tmpVerb)
				
		#check if word is a adjective
		strMorphy=morphy(strWord,'adj')
		if strMorphy:
			for SenseCounter in range(len(ADJ[strMorphy].senses())):
				tmpAdj=Word()
				tmpAdj.form=strMorphy
				tmpAdj.gloss = ADJ[strMorphy][SenseCounter].synset.gloss
				tmpAdj.inWordnet=1
				
				for Synonym in ADJ[strMorphy][SenseCounter].synset:
					tmpAdj.lstSynonyms.append(Synonym.form)
					
				for HypernymSynset in ADJ[strMorphy][SenseCounter].getPointerTargets(HYPERNYM):
					for Hypernym in HypernymSynset:
						tmpAdj.lstHypernyms.append(Hypernym.form)
					
				for HyponymSynset in ADJ[strMorphy][SenseCounter].getPointerTargets(HYPONYM):
					for Hyponym in HyponymSynset:
						tmpAdj.lstHyponyms.append(Hyponym.form)
					
				self.lstAdjectives.append(tmpAdj)		
