Example #1
0
    def can_response(self, **kwargs):

        tags = kwargs.get('tags')
        plain_text = kwargs.get('plain_text').lower()

        service = ConversionService()
        units = service.extractUnits(plain_text)
        return len(units) > 1
Example #2
0
    def testExponentiation(self):
        service = ConversionService()
        inp = "I want two squared meters"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^2'])

        inp = "I want two square meters"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^2'])

        inp = "I want two sq meters"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^2'])

        inp = "I want two cubic meters"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^3'])

        inp = "I want two meters cubed"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^3'])

        inp = "I want two meters to the fifth power"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^5'])

        inp = "I want two meters to the fifth"
        units = service.extractUnits(inp)
        self.assertEqual(units, ['meters^5'])
Example #3
0
    def testReadability(self):
        inp = "convert 0.000013 inches to centimeters"
        target = pq.Quantity(0.000013, "inches")
        target.units = "cm"

        # Correctness of conversion
        self.compareConversion(inp, target)

        # Correctness of representation
        service = ConversionService()
        self.assertEqual(service.parseUnits(inp),
                         "3.3 times ten to the negative 5 cm")
Example #4
0
    def __init__(self):

        self.tagger = PerceptronTagger()
        self.alarm_ai = AlarmResponse()
        self.converter_ai = ConversionResponse()
        self.summarize_ai = SummarizerResponse()
        self.news_ai = NewsResponse()
        self.maps_ai = MapsResponse()
        self.lemmatizer = WordNetLemmatizer()
        self.parser = spy.English()
        self.conversion = ConversionService()
        self.ai = {
            "alarm_api": self.alarm_ai,
            "unit_conversion": self.converter_ai,
            "summarization": self.summarize_ai,
            "news": self.news_ai,
            "maps_api": self.maps_ai
        }
        self.classifiers = []
        with open('nb_dumped_classifier.pkl', 'rb') as fid:
            self.classifiers.append(cPickle.load(fid))
        with open('sgd_dumped_classifier.pkl', 'rb') as fid:
            self.classifiers.append(cPickle.load(fid))
        with open('pla_dumped_classifier.pkl', 'rb') as fid:
            self.classifiers.append(cPickle.load(fid))
        self.previous_ents = {"PERSON": "", "GPE": ""}
        self.special_tags = {
            'PERSON': ['his', 'her', 'him', 'he', 'she'],
            'GPE': ['it', 'there']
        }
Example #5
0
    def respond(self, **kwargs):

        plain_text = kwargs.get('plain_text').lower()
        service = ConversionService()
        units = service.extractUnits(plain_text)

        inf_eng = inflect.engine()

        try:
            original_num = re.findall(r'\d+', plain_text)

            if len(original_num) == 0:
                try:
                    converted_num = service.convert(plain_text)
                    return "Your ans is " + "%.2f" % (float(
                        str(service.convert(plain_text)).split()[0])
                                                      ) + " " + units[1]
                except TypeError:
                    plain_text = "one " + units[0] + " to " + units[1]
                    original_num = [1]

            converted_num = float(
                "%.2f" % (float(str(service.convert(plain_text)).split()[0])))

            output = str(inf_eng.number_to_words(
                original_num[0])) + " " + units[0] + " equals " + str(
                    inf_eng.number_to_words(converted_num)) + " " + units[1]
            return output

        except TypeError:

            return "Sorry, I cannot convert these units."

        except:

            return "Something Wrong!"
Example #6
0
 def compareConversion(self, inp, target):
     service = ConversionService()
     result = service.convert(inp)
     self.assertEqual(result.magnitude, target.magnitude)
     self.assertEqual(result.units, target.units)
Example #7
0
 def testExtraction(self):
     inp = "I want three pounds of eggs and two inches per squared foot"
     service = ConversionService()
     units = service.extractUnits(inp)
     self.assertEqual(units, ['pounds', 'inches / foot^2'])