Beispiel #1
0
def setUp1(noun, verb, obj, tense):
	lex = XMLLexicon()  
	#the girl is playing the guitar        
	s1 = Clause()
	try:
		np_sub = s1.add_subject(lex.getWord(noun,"NOUN"))
		np_sub.add_determiner(lex.getWord("the")) 
		vp_play = s1.add_verb(lex.getWordFromVariant(verb, "VERB"))

		#if none
		np_guitar = vp_play.add_object(lex.getWord(obj,"NOUN"))
		np_guitar.add_determiner(lex.getWord("the"))
		s1.set_verb_tense(tense)
		print(s1.realize())

	except :
		try:
			np_sub = s1.add_subject(Noun(noun))
			np_sub.add_determiner(lex.getWord("the"))
			vp_play = s1.add_verb(lex.getWordFromVariant(verb,"VERB"))

			#if none
			np_guitar = vp_play.add_object(Noun(obj))
			np_guitar.add_determiner(lex.getWord("the"))
			s1.set_verb_tense(tense)
			print(s1.realize())
		except Exception as inst:
			print(type(inst))
			print(inst.args)
			pass
Beispiel #2
0
        def setUp2():

                lex = XMLLexicon()

                #my dog's my best friend        
                s1 = Clause()
                a = "my best friend"

                s1 = NounPhrase(a)
                np_own = s1.add_owner(lex.getWord("dog"))
                np_own.add_determiner(lex.getWord("my"))
                
                print(s1.realize())
Beispiel #3
0
        def setUp4():

                lex = XMLLexicon()
        
                #the woman kissed the man behind the curtain
                s1 = Clause()

                np_woman = s1.add_subject(lex.getWord("woman"))
                np_woman.add_determiner(lex.getWord("the"))
                                
                vp_kiss = s1.add_verb(lex.getWord("kiss", "VERB"))
                np_the_curtain = NounPhrase(lex.getWord("curtain", "NOUN"), determiner=lex.getWord("the"))
                pp_the_curtain = PrepositionalPhrase(lex.getWord("behind", "PREPOSITION"), [np_the_curtain])
        
                vp_kiss.add_prepositional_phrase(pp_the_curtain)
        
                np_man = vp_kiss.add_object(lex.getWord("man"))
                np_man.add_determiner(lex.getWord("the"))
                
        
                s1.set_verb_tense("past")

                print(s1.realize())
Beispiel #4
0
        def setUp1():

                lex = XMLLexicon()

                #the girl is playing the guitar        
                s1 = Clause()
                
                np_sub = s1.add_subject(lex.getWord("girl"))
                np_sub.add_determiner(lex.getWord("the"))
                vp_play = s1.add_verb(lex.getWord("play", "VERB"))
        
                np_guitar = vp_play.add_object(lex.getWord("guitar"))
                np_guitar.add_determiner(lex.getWord("the"))
        
                s1.set_verb_tense("present_progressive")

                print(s1.realize())
Beispiel #5
0
        def setUp3():

                lex = XMLLexicon()

                #put the beans in the old machine
                s1 = ImperativeClause()

                vp_put = s1.add_verb(lex.getWord("put", "VERB"))
                np_the_machine = NounPhrase(lex.getWord("machine", "NOUN"), determiner=lex.getWord("the"), adjectives=[lex.getWord("old")])
                pp_in_the_machine = PrepositionalPhrase(lex.getWord("in", "PREPOSITION"), [np_the_machine])
        
                vp_put.add_prepositional_phrase(pp_in_the_machine)
        
        
                np_the_beans = s1.add_subject(lex.getWord("bean"))
                np_the_beans.add_determiner(lex.getWord("the"))
                np_the_beans.set_number("plural")

                print(s1.realize())
Beispiel #6
0
def genSents():

	global CandidSVO
	global sentences
	global dis
	global summary
	global opha
	opha = []
	summary = []
	dis = []
	lex = XMLLexicon()
	flex = Flex()
	lsubj = []
	lobj = []
	lverb = []
	for svo in CandidSVO:
		print(str(svo.sNum),svo.subj[0]+" "+svo.verb[0]+" "+svo.obj[0])
		for trees in sentences[svo.sNum][4]:
			if isinstance(trees,Tree):
				for subs in trees.subtrees():
					if subs.label()=="NP":
						npnoun = []
						for n in subs.leaves():
							npnoun.append(n[0])
						if svo.subj[0] in npnoun:
							lsubj.append(subs)
						elif svo.obj[0] in npnoun:
							lobj.append(subs)
					elif subs.label() =="PP":
						continue
					elif subs.label() =="VP":
						vpverb = []
						for v in subs.leaves():
							vpverb.append(v[0])
						if svo.verb[0] in vpverb:
							lverb.append(subs)
#reminder try getting all them pos tags
#and try getting the object part too
		if sentences[svo.sNum][3] == "en" or  sentences[svo.sNum][3] not in ["tl"]:
			for np in lsubj:
				gen = ""
				nn =""
				redundant = []
				Det = None
				for n in np.leaves():
					adjs = []
					if n[1] in ["NN","NNS","NNP","NNPS"]:
						if n[0] not in redundant:
							nn+=n[0]+" "
							redundant.append(n[0])
					elif n[1] in ["DT"]:
						Det = n[0]
					elif n[1] in ["JJR","JJ","JJS"]:
						adjs.append(n[0])
					else:
						if n[0] not in redundant:
							nn+=n[0]+" "
							redundant.append(n[0])
				Nphrase = NounPhrase(nn,Det,adjs)
				vebs = []
				for vp in lverb:
					vps = []
					redundant = []
					for v in vp.leaves():
						if v[1] in ["VBD","VBZ","VB", "VBN","VBG","VBP","MD"]:
							if v[0] not in redundant:
								if v[1] not in ["MD"]:
									phrase = VerbPhrase(lex.getWordFromVariant(v[0],"VERB"))
								elif v[1] in ["MD"]:
									phrase = VerbPhrase(lex.getWordFromVariant(v[0],"MODAL"))
								if phrase.verb != None:
									if v[1] in ["VB"]:
										phrase.set_tense("present")
									elif v[1] in ["VBZ","VBP"]:
										phrase.set_tense("infinitive")
									elif v[1] in ["VBD"]:
										phrase.set_tense("past")
									elif v[1] in ["VBN"]:
										phrase.set_tense("past_participle")
									elif v[1] in ["VBG"]:
										phrase.set_tense("present_participle")
									elif v[1] in ["MD"]:
										if lex.getWordFromVariant(v[0],"MODAL").base == v[0]:
											phrase.set_tense("present")
										else:
											phrase.set_tense("past")
									vps.append(phrase)
								redundant.append(v[0])
					vebs.append(vps)
				
				for op in lobj:
					ops = []
					nn =""
					redundant = []
					for o in op.leaves():
						adjs = []
						print(o)
						if o[1] in ["NN","NNS","NNP","NNPS"]:
							if o[0] not in redundant:
								nn+=o[0]+" "
								redundant.append(n[0])
						elif o[1] in ["DT"]:
							Det = o[0]
						elif o[1] in ["JJR","JJ","JJS"]:
							adjs.append(o[0])
							nn+=o[0]+" "
						else:
							if o[0] not in redundant:
								nn+=o[0]+" "
								redundant.append(o[0])
						Ophrase = NounPhrase(nn,Det,adjs)
						ops.append(Ophrase)
					opha.append([ops,svo.sNum])
					#printing function
					# not sedis.append((Nphrase,vps)) not used
					gen = ""
					for vps in vebs:
						gen+= Nphrase.realize()+" "
						for vph in vps:
							if vph.verb != None:
								if vps.index(vph) == (len(vps)-1):
									for op in ops:
										print(op.realize())
										vph.add_object(op)
									gen+=vph.realize()+" "
								else:
									gen+=vph.realize()+" "
						summary.append([svo.sNum,gen])
						print(gen)
		else:
			for np in lsubj:
				gen = ""
				nn =""
				redundant = []
				Det = None
				for n in np.leaves():
					adjs = []
					if n[1] in ["NNT","NNST","NNPT","NNPST"]:
						if n[0] not in redundant:
							nn+=n[0]+" "
							redundant.append(n[0])
					elif n[1] in ["DTT"]:
						Det = n[0]
					elif n[1] in ["JJRT","JJT","JJST"]:
						adjs.append(n[0])
					else:
						if n[0] not in redundant:
							nn+=n[0]+" "
							redundant.append(n[0])
				Nphrase = FNP(nn,Det,adjs)
				vebs = []
				for vp in lverb:
					vps = []
					redundant = []
					for v in vp.leaves():
						if v[1] in ["VBDT","VBZT","VBT", "VBNT","VBGT","VBPT"]:
							if v[0] not in redundant:
								phrase = FVP(flex.getWordFromVariant(v[0],"VERB"))
								
								if v[1] in ["VBT"]:
									phrase.set_tense("present")
								elif v[1] in ["VBZT","VBPT"]:
									phrase.set_tense("infinitive")
								elif v[1] in ["VBDT"]:
									phrase.set_tense("past")
								elif v[1] in ["VBNT"]:
									phrase.set_tense("past_participle")
								elif v[1] in ["VBGT"]:
									phrase.set_tense("present_participle")
								vps.append(phrase)
								redundant.append(v[0])
					vebs.append(vps)
				
				for op in lobj:
					ops = []
					nn =""
					redundant = []
					for o in op.leaves():
						adjs = []
						print(o)
						if o[1] in ["NNT","NNST","NNPT","NNPST"]:
							if o[0] not in redundant:
								nn+=o[0]+" "
								redundant.append(n[0])
						elif o[1] in ["DTT"]:
							Det = o[0]
						elif o[1] in ["JJRT","JJT","JJST"]:
							adjs.append(o[0])
							nn+=o[0]+" "
						else:
							if o[0] not in redundant:
								nn+=o[0]+" "
								redundant.append(o[0])
						Ophrase = FNP(nn,Det,adjs)
						ops.append(Ophrase)
					opha.append([ops,svo.sNum])
					#printing function
					# not sedis.append((Nphrase,vps)) not used
					gen = ""
					for vps in vebs:
						gen+= Nphrase.realize()+" "
						for vph in vps:
							if vph.verb != None:
								if vps.index(vph) == (len(vps)-1):
									for op in ops:
										print(op.realize()+ "wat")#di pumapasok dito
										vph.add_object(op)
									gen+=vph.realize()+" "
								else:
									gen+=vph.realize()+" "
						summary.append([svo.sNum,gen])
						print(gen)

				#printing function
		
							#gen+=" "+Ophrase.realize()
						
		lsubj=[]
		lobj=[]
		lverb=[]
Beispiel #7
0
 def setUp(self):
     lex = XMLLexicon()
     
     #the woman kissed the man behind the curtain
     self.s1 = Clause()
     np_woman = self.s1.add_subject(lex.getWord("woman"))
     np_woman.add_determiner(lex.getWord("the"))
     vp_kiss = self.s1.add_verb(lex.getWord("kiss", "VERB"))
     
     np_man = vp_kiss.add_object(lex.getWord("man"))
     np_man.add_determiner(lex.getWord("the"))
     
     self.s1.set_verb_tense("past")
     
     
     #there is the dog on the rock
     
     #the man gives the woman John's flower
     self.s2 = Clause()
     np_man = self.s2.add_subject(lex.getWord("man"))
     np_man.add_determiner(lex.getWord("the"))
     
     vp_give = self.s2.add_verb(lex.getWord("give"))
     vp_give.set_tense("present")
     
     np_flower = vp_give.add_object(lex.getWord("flower"))
     np_flower.add_owner(lex.getWord("john"))
     
     np_woman = vp_give.add_indirect_object(lex.getWord("woman"))
     np_woman.add_determiner(lex.getWord("the"))
     
     #Test imperative
     
     #Make the coffee
     
     self.s3 = ImperativeClause()
     vp_make = self.s3.add_verb(lex.getWord("make", "VERB"))
     np_the_coffee = self.s3.add_subject(lex.getWord("coffee"))
     np_the_coffee.add_determiner(lex.getWord("the"))
     
     #Put the beans in the machine
     self.s4 = ImperativeClause()
     vp_put = self.s4.add_verb(lex.getWord("put", "VERB"))
     np_the_machine = NounPhrase(lex.getWord("machine", "NOUN"), determiner=lex.getWord("the"))
     pp_in_the_machine = PrepositionalPhrase(lex.getWord("in", "PREPOSITION"), [np_the_machine])
     
     vp_put.add_prepositional_phrase(pp_in_the_machine)
     
     
     np_the_beans = self.s4.add_subject(lex.getWord("bean"))
     np_the_beans.add_determiner(lex.getWord("the"))
     np_the_beans.set_number("plural")