Exemplo n.º 1
0
	def _handle_tag(self, tag, word):
		tag, word, thought = quirk_fix(tag, word)
		if thought is not None:
			self._think(thought)

		if tag in ["NNP", "NN"]: # noun, proper, singular, common
			self._think("I think '{0}' is a context", word)
			if self.last_tag == tag:
				context = "{0} {1}".format(self.last_context, word)
				self._rename_context(self.last_context, context)
				self.last_context = None
				self._set_context(context)
			else:
				self._create_context(word)
				self._set_context(word)

		if tag == "NNS": #noun, common, plural
			if self.last_value and not self.last_unit:
				self._think("I think '{0}' is a unit", word)
				self._create_unit(word)
			if word in self.units:
				self._set_unit(word)

		if tag in ["VBZ", "VBD"]: # verb, present tense, past tense
			if self.last_context:
				if infer.conveys.ownership(word):
					self._think("I think '{0}' conveys ownership", word)
					self.context_ownership = True
				elif infer.is_operation(word):
					self._think("I think '{0}' conveys an operation", word)
					self._set_operation(word)

		if tag in ["PRP", "PRP$"]: # pronoun, personal
			if self.last_context:
				self._think("I think '{0}' refers to '{1}'", word,
					self.last_context)

		if tag == "DT": # determiner
			self._think("I think '{0}' is a determiner.", word)
			if infer.is_operation(word):
				self._think("I think '{0}' is an operation; skipping.", word)
			if infer.conveys.variable(word):
				self._set_variable(word)

		if tag == ".":
			if self.last_context != self.primary_context:
				self._think("Resetting context to '{0}'", self.primary_context)
				self.last_context = self.primary_context

		self.last_tag = tag
Exemplo n.º 2
0
    def _handle_tag(self, tag, word):
        tag, word, thought = quirk_fix(tag, word)
        if thought is not None:
            self._think(thought)

        if tag in ["NNP", "NN"]:  # noun, proper, singular, common
            self._think("I think '{0}' is a context", word)
            if self.last_tag == tag:
                context = "{0} {1}".format(self.last_context, word)
                self._rename_context(self.last_context, context)
                self.last_context = None
                self._set_context(context)
            else:
                self._create_context(word)
                self._set_context(word)

        if tag == "NNS":  #noun, common, plural
            if self.last_value and not self.last_unit:
                self._think("I think '{0}' is a unit", word)
                self._create_unit(word)
            if word in self.units:
                self._set_unit(word)

        if tag in ["VBZ", "VBD"]:  # verb, present tense, past tense
            if self.last_context:
                if infer.conveys.ownership(word):
                    self._think("I think '{0}' conveys ownership", word)
                    self.context_ownership = True
                elif infer.is_operation(word):
                    self._think("I think '{0}' conveys an operation", word)
                    self._set_operation(word)

        if tag in ["PRP", "PRP$"]:  # pronoun, personal
            if self.last_context:
                self._think("I think '{0}' refers to '{1}'", word,
                            self.last_context)

        if tag == "DT":  # determiner
            self._think("I think '{0}' is a determiner.", word)
            if infer.is_operation(word):
                self._think("I think '{0}' is an operation; skipping.", word)
            if infer.conveys.variable(word):
                self._set_variable(word)

        if tag == ".":
            if self.last_context != self.primary_context:
                self._think("Resetting context to '{0}'", self.primary_context)
                self.last_context = self.primary_context

        self.last_tag = tag
Exemplo n.º 3
0
	def _interpret(self, word, tag):
		if ALPHA.match(word) or tag == ".":
			if self.build_expression:
				self._set_variable(word)
			else:
				self._handle_tag(tag, word)
		else:
			if infer.is_number(word):
				self._think("'{0}' is a value (a constant).", word)
				self._set_constant(word)
			if infer.is_relation(word):
				self._think("'{0}' is a relationship.", word)
				self._set_relation(word)
			if infer.is_operation(word):
				self._think("'{0}' is an operation.", word)
				self._set_operation(word)
Exemplo n.º 4
0
 def _interpret(self, word, tag):
     if ALPHA.match(word) or tag == ".":
         if self.build_expression:
             self._set_variable(word)
         else:
             self._handle_tag(tag, word)
     else:
         if infer.is_number(word):
             self._think("'{0}' is a value (a constant).", word)
             self._set_constant(word)
         if infer.is_relation(word):
             self._think("'{0}' is a relationship.", word)
             self._set_relation(word)
         if infer.is_operation(word):
             self._think("'{0}' is an operation.", word)
             self._set_operation(word)