コード例 #1
0
ファイル: coordinate.py プロジェクト: pombredanne/cahoots
    def bootstrap(config):
        """
        This method is statically called to bootstrap a parser

        :param config: cahoots config
        :type config: cahoots.config.BaseConfig
        """
        # Will test if something matches regular coordinates
        # 34.56,23.65 or 34.56 23.65 or 34.56 , 23.65
        coord_regex = re.compile(r'^(-?\d{1,3}(?:\.\d+)?)' +
                                 r'(?:(?:(?:\s+)?,(?:\s+)?)|(?:\s+))' +
                                 r'(-?\d{1,3}(?:\.\d+))?$')
        registry.set('CP_coord_regex', coord_regex)

        # Will test if something matches degree coordinates
        # 40.244° N 79.123° W
        deg_regex = re.compile(
            u('^(\d{1,3}\.\d+°?\s+[nNsS])') + u('\s+') +
            u('(\d{1,3}\.\d+°?\s+[wWeE])$'))
        registry.set('CP_deg_regex', deg_regex)

        # Will test if something matches deg/min coordinates
        # 13° 34.425' N 45° 37.983' W
        deg_min_regex = re.compile(
            u('^(\d{1,3}°?\s+\d{1,3}\.\d+\'?\s+[nNsS])') + u('\s+') +
            u('(\d{1,3}°?\s+\d{1,3}\.\d+\'?\s+[wWeE])$'))
        registry.set('CP_deg_min_regex', deg_min_regex)

        # Will test if something matches deg/min/sec coordinates
        # 40° 26' 46.56" N 79° 58' 56.88" W
        deg_min_sec_regex = re.compile(
            u('^(\d{1,3}°?\s+\d{1,3}\'?\s+\d{1,3}(?:\.\d+)?"?\s+[nNsS])') +
            u('\s+') +
            u('(\d{1,3}°?\s+\d{1,3}\'?\s+\d{1,3}(?:\.\d+)?"?\s+[wWeE])$'))
        registry.set('CP_deg_min_sec_regex', deg_min_sec_regex)
コード例 #2
0
 def test_parseWithDegMinSecCoordsYieldsExpectedResult(self):
     results = self.cp.parse(u('40° 26\' 46.56" N 79° 58\' 56.88" W'))
     count = 0
     for result in results:
         count += 1
         self.assertEqual(result.subtype, 'Degree/Minute/Second')
         # Python 2 vs 3 accomidations
         if sys.version_info[0] < 3:
             self.assertEqual(result.result_value, {
                 'latitude': '40.4462666667',
                 'longitude': '-79.9824666667'
             })
             self.assertEqual(
                 result.data, {
                     'map_url':
                     'https://www.google.com/maps?' +
                     'q=40.4462666667,-79.9824666667'
                 })
         else:
             self.assertEqual(
                 result.result_value, {
                     'latitude': '40.446266666666666',
                     'longitude': '-79.98246666666667'
                 })
             self.assertEqual(
                 result.data, {
                     'map_url':
                     'https://www.google.com/maps?' +
                     'q=40.446266666666666,-79.98246666666667'
                 })
         self.assertEqual(result.confidence, 100)
     self.assertEqual(1, count)
コード例 #3
0
ファイル: coordinate.py プロジェクト: pombredanne/cahoots
    def bootstrap(config):
        """
        This method is statically called to bootstrap a parser

        :param config: cahoots config
        :type config: cahoots.config.BaseConfig
        """
        # Will test if something matches regular coordinates
        # 34.56,23.65 or 34.56 23.65 or 34.56 , 23.65
        coord_regex = re.compile(
            r'^(-?\d{1,3}(?:\.\d+)?)' +
            r'(?:(?:(?:\s+)?,(?:\s+)?)|(?:\s+))' +
            r'(-?\d{1,3}(?:\.\d+))?$'
        )
        registry.set('CP_coord_regex', coord_regex)

        # Will test if something matches degree coordinates
        # 40.244° N 79.123° W
        deg_regex = re.compile(
            u('^(\d{1,3}\.\d+°?\s+[nNsS])') +
            u('\s+') +
            u('(\d{1,3}\.\d+°?\s+[wWeE])$')
        )
        registry.set('CP_deg_regex', deg_regex)

        # Will test if something matches deg/min coordinates
        # 13° 34.425' N 45° 37.983' W
        deg_min_regex = re.compile(
            u('^(\d{1,3}°?\s+\d{1,3}\.\d+\'?\s+[nNsS])') +
            u('\s+') +
            u('(\d{1,3}°?\s+\d{1,3}\.\d+\'?\s+[wWeE])$')
        )
        registry.set('CP_deg_min_regex', deg_min_regex)

        # Will test if something matches deg/min/sec coordinates
        # 40° 26' 46.56" N 79° 58' 56.88" W
        deg_min_sec_regex = re.compile(
            u('^(\d{1,3}°?\s+\d{1,3}\'?\s+\d{1,3}(?:\.\d+)?"?\s+[nNsS])') +
            u('\s+') +
            u('(\d{1,3}°?\s+\d{1,3}\'?\s+\d{1,3}(?:\.\d+)?"?\s+[wWeE])$')
        )
        registry.set('CP_deg_min_sec_regex', deg_min_sec_regex)
コード例 #4
0
 def test_parseWithDegCoordsYieldsExpectedResult(self):
     results = self.cp.parse(u('40.244° N 79.123° W'))
     count = 0
     for result in results:
         count += 1
         self.assertEqual(result.subtype, 'Degree')
         self.assertEqual(result.result_value, {
             'latitude': '40.244',
             'longitude': '-79.123'
         })
         self.assertEqual(
             result.data,
             {'map_url': 'https://www.google.com/maps?q=40.244,-79.123'})
         self.assertEqual(result.confidence, 100)
     self.assertEqual(1, count)
コード例 #5
0
ファイル: coordinate.py プロジェクト: msabramo/cahoots
 def test_parseWithDegCoordsYieldsExpectedResult(self):
     results = self.cp.parse(u('40.244° N 79.123° W'))
     count = 0
     for result in results:
         count += 1
         self.assertEqual(result.subtype, 'Degree')
         self.assertEqual(
             result.result_value,
             {'latitude': '40.244', 'longitude': '-79.123'}
         )
         self.assertEqual(
             result.data,
             {'map_url': 'https://www.google.com/maps?q=40.244,-79.123'}
         )
         self.assertEqual(result.confidence, 100)
     self.assertEqual(1, count)
コード例 #6
0
 def test_parseWithDegMinCoordsYieldsExpectedResult(self):
     results = self.cp.parse(u('13° 34.425\' N 45° 37.983\' W'))
     count = 0
     for result in results:
         count += 1
         self.assertEqual(result.subtype, 'Degree/Minute')
         self.assertEqual(result.result_value, {
             'latitude': '13.57375',
             'longitude': '-45.63305'
         })
         self.assertEqual(result.data, {
             'map_url':
             'https://www.google.com/maps?q=13.57375,-45.63305'
         })
         self.assertEqual(result.confidence, 100)
     self.assertEqual(1, count)
コード例 #7
0
ファイル: coordinate.py プロジェクト: msabramo/cahoots
 def test_parseWithDegMinCoordsYieldsExpectedResult(self):
     results = self.cp.parse(u('13° 34.425\' N 45° 37.983\' W'))
     count = 0
     for result in results:
         count += 1
         self.assertEqual(result.subtype, 'Degree/Minute')
         self.assertEqual(
             result.result_value,
             {'latitude': '13.57375', 'longitude': '-45.63305'}
         )
         self.assertEqual(
             result.data,
             {
                 'map_url':
                     'https://www.google.com/maps?q=13.57375,-45.63305'
             }
         )
         self.assertEqual(result.confidence, 100)
     self.assertEqual(1, count)
コード例 #8
0
ファイル: coordinate.py プロジェクト: msabramo/cahoots
 def test_parseWithDegMinSecCoordsYieldsExpectedResult(self):
     results = self.cp.parse(u('40° 26\' 46.56" N 79° 58\' 56.88" W'))
     count = 0
     for result in results:
         count += 1
         self.assertEqual(result.subtype, 'Degree/Minute/Second')
         # Python 2 vs 3 accomidations
         if sys.version_info[0] < 3:
             self.assertEqual(
                 result.result_value,
                 {
                     'latitude': '40.4462666667',
                     'longitude': '-79.9824666667'
                 }
             )
             self.assertEqual(
                 result.data,
                 {
                     'map_url': 'https://www.google.com/maps?' +
                                'q=40.4462666667,-79.9824666667'
                 }
             )
         else:
             self.assertEqual(
                 result.result_value,
                 {
                     'latitude': '40.446266666666666',
                     'longitude': '-79.98246666666667'
                 }
             )
             self.assertEqual(
                 result.data,
                 {
                     'map_url': 'https://www.google.com/maps?' +
                                'q=40.446266666666666,-79.98246666666667'
                 }
             )
         self.assertEqual(result.confidence, 100)
     self.assertEqual(1, count)
コード例 #9
0
ファイル: name.py プロジェクト: msabramo/cahoots
 def test_parseYieldsNothingWithNonPrintableCharacters(self):
     count = 0
     for _ in self.np.parse(u('40.244° N 79.123° W')):
         count += 1
     self.assertEqual(count, 0)
コード例 #10
0
ファイル: character.py プロジェクト: pombredanne/cahoots
 def test_parseNonAsciiCharacterReturnNone(self):
     count = 0
     # pylint: disable=anomalous-unicode-escape-in-string
     for _ in self.cp.parse(u('\u0080')):
         count += 1
     self.assertEqual(count, 0)
コード例 #11
0
ファイル: coordinate.py プロジェクト: pombredanne/cahoots
 def clean_dms_coords(cls, coord_string):
     """Removes items that the LatLon parser doesn't want"""
     coord_string = coord_string.replace(u('°'), '')
     coord_string = coord_string.replace('\'', '')
     coord_string = coord_string.replace('"', '')
     return coord_string
コード例 #12
0
ファイル: coordinate.py プロジェクト: pombredanne/cahoots
 def clean_dms_coords(cls, coord_string):
     """Removes items that the LatLon parser doesn't want"""
     coord_string = coord_string.replace(u('°'), '')
     coord_string = coord_string.replace('\'', '')
     coord_string = coord_string.replace('"', '')
     return coord_string
コード例 #13
0
 def test_parseYieldsNothingWithNonPrintableCharacters(self):
     count = 0
     for _ in self.np.parse(u('40.244° N 79.123° W')):
         count += 1
     self.assertEqual(count, 0)